nx_cloud_storage_sdk  1.0
Cloud Storage SDK
flags.h
Go to the documentation of this file.
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2 
3 #pragma once
4 
55 #include <type_traits>
56 
57 #if !defined(NX_KIT_API)
58  #define NX_KIT_API
59 #endif
60 
61 namespace nx {
62 namespace kit {
63 
64 namespace flags_detail {
65 
66 template <typename Enum>
67 constexpr typename std::underlying_type<Enum>::type toUnderlyingType(Enum value)
68 {
69  return static_cast<typename std::underlying_type<Enum>::type>(value);
70 }
71 
72 } // namespace flags_detail
73 
78 #define NX_KIT_ENABLE_FLAGS(ENUM) \
79  static_assert(std::is_enum<ENUM>::value, "Flag type must be an enum"); \
80  \
81  \
82  constexpr bool operator!(ENUM x) \
83  { \
84  return ::nx::kit::flags_detail::toUnderlyingType(x) == 0; \
85  } \
86  \
87  \
88  \
89  constexpr ENUM operator~(ENUM x) \
90  { \
91  return static_cast<ENUM>(~::nx::kit::flags_detail::toUnderlyingType(x)); \
92  } \
93  \
94  \
95  constexpr ENUM operator&(ENUM x, ENUM y) \
96  { \
97  return static_cast<ENUM>( \
98  ::nx::kit::flags_detail::toUnderlyingType(x) \
99  & ::nx::kit::flags_detail::toUnderlyingType(y)); \
100  } \
101  \
102  \
103  inline ENUM& operator&=(ENUM& x, ENUM y) \
104  { \
105  return x = x & y; \
106  } \
107  \
108  \
109  constexpr ENUM operator|(ENUM x, ENUM y) \
110  { \
111  return static_cast<ENUM>( \
112  ::nx::kit::flags_detail::toUnderlyingType(x) \
113  | ::nx::kit::flags_detail::toUnderlyingType(y)); \
114  } \
115  \
116  \
117  inline ENUM& operator|=(ENUM& x, ENUM y) \
118  { \
119  return x = x | y; \
120  } \
121  \
122  \
123  constexpr ENUM operator^(ENUM x, ENUM y) \
124  { \
125  return static_cast<ENUM>( \
126  ::nx::kit::flags_detail::toUnderlyingType(x) \
127  ^ ::nx::kit::flags_detail::toUnderlyingType(y)); \
128  } \
129  \
130  \
131  inline ENUM& operator^=(ENUM& x, ENUM y) \
132  { \
133  return x = x ^ y; \
134  }
135 
136 } // namespace kit
137 } // namespace nx
Definition: apple_utils.h:6