File tree Expand file tree Collapse file tree 3 files changed +7
-15
lines changed Expand file tree Collapse file tree 3 files changed +7
-15
lines changed Original file line number Diff line number Diff line change 3
3
#include < chrono>
4
4
#include < functional>
5
5
#include < iostream>
6
- #include < typeinfo >
7
- #include < utility >
6
+ #include < thread >
7
+ #include < unordered_map >
8
8
9
9
using namespace sb ::di;
10
10
using namespace std ::chrono_literals;
Original file line number Diff line number Diff line change 1
1
#include < SevenBit/DI.hpp>
2
2
#include < iostream>
3
- #include < utility>
4
3
5
4
using namespace sb ::di;
6
5
@@ -9,17 +8,9 @@ enum class Permission : int
9
8
NONE = 0 ,
10
9
READ = 1 ,
11
10
UPDATE = 2 ,
11
+ ALL = READ | UPDATE
12
12
};
13
13
14
- Permission operator |(Permission lhs, Permission rhs)
15
- {
16
- return static_cast <Permission>(static_cast <int >(lhs) | static_cast <int >(rhs));
17
- }
18
- Permission operator &(Permission lhs, Permission rhs)
19
- {
20
- return static_cast <Permission>(static_cast <int >(lhs) & static_cast <int >(rhs));
21
- }
22
-
23
14
struct IUserPermission
24
15
{
25
16
virtual Permission getPermissions (int userId) = 0;
@@ -35,7 +26,7 @@ struct UserPermission final : IUserPermission
35
26
36
27
struct AdminPermission final : IUserPermission
37
28
{
38
- Permission getPermissions (int userId) override { return Permission::READ | Permission::UPDATE ; }
29
+ Permission getPermissions (int userId) override { return Permission::ALL ; }
39
30
};
40
31
41
32
struct Data
@@ -77,7 +68,9 @@ class DataService final : public IDataService
77
68
private:
78
69
void assertPermission (const Permission permission)
79
70
{
80
- if ((_userPermission.getPermissions (1 ) & permission) != permission)
71
+ auto userPermission = _userPermission.getPermissions (1 );
72
+ if (int check = static_cast <int >(userPermission) & static_cast <int >(permission);
73
+ static_cast <Permission>(check) != permission)
81
74
{
82
75
throw std::runtime_error (" Insufficient permissions" );
83
76
}
Original file line number Diff line number Diff line change 1
1
#include < SevenBit/DI.hpp>
2
2
#include < iostream>
3
- #include < utility>
4
3
5
4
using namespace sb ::di;
6
5
You can’t perform that action at this time.
0 commit comments