summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-09-10 16:18:54 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-09-13 13:45:48 +0300
commit796cc3a4d6ce7fd4d857e0985392efccb388dfb1 (patch)
treeb28965df0c17928d146cb383805ca225348f48c6 /include
parentf9c15f708ecf3d87c756a196bdc5de93b78b8cfc (diff)
downloadqtlocation-mapboxgl-796cc3a4d6ce7fd4d857e0985392efccb388dfb1.tar.gz
[core] Bitmask operations for enums
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/storage/resource.hpp18
-rw-r--r--include/mbgl/util/bitmask_operations.hpp33
2 files changed, 35 insertions, 16 deletions
diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp
index 40c4c836b1..d00f336669 100644
--- a/include/mbgl/storage/resource.hpp
+++ b/include/mbgl/storage/resource.hpp
@@ -1,11 +1,10 @@
#pragma once
#include <mbgl/storage/response.hpp>
+#include <mbgl/util/bitmask_operations.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/tileset.hpp>
-#include <mbgl/util/util.hpp>
-#include <mbgl/util/traits.hpp>
#include <string>
@@ -98,21 +97,8 @@ public:
std::shared_ptr<const std::string> priorData;
};
-
-MBGL_CONSTEXPR Resource::LoadingMethod operator|(Resource::LoadingMethod a, Resource::LoadingMethod b) {
- return Resource::LoadingMethod(mbgl::underlying_type(a) | mbgl::underlying_type(b));
-}
-
-MBGL_CONSTEXPR Resource::LoadingMethod& operator|=(Resource::LoadingMethod& a, Resource::LoadingMethod b) {
- return (a = a | b);
-}
-
-MBGL_CONSTEXPR Resource::LoadingMethod operator&(Resource::LoadingMethod a, Resource::LoadingMethod b) {
- return Resource::LoadingMethod(mbgl::underlying_type(a) & mbgl::underlying_type(b));
-}
-
inline bool Resource::hasLoadingMethod(Resource::LoadingMethod method) {
- return (loadingMethod & method) != Resource::LoadingMethod::None;
+ return (loadingMethod & method);
}
} // namespace mbgl
diff --git a/include/mbgl/util/bitmask_operations.hpp b/include/mbgl/util/bitmask_operations.hpp
new file mode 100644
index 0000000000..014fabdea2
--- /dev/null
+++ b/include/mbgl/util/bitmask_operations.hpp
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <mbgl/util/traits.hpp>
+#include <mbgl/util/util.hpp>
+
+namespace mbgl {
+
+template<typename Enum>
+MBGL_CONSTEXPR Enum operator|(Enum a, Enum b) {
+ static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
+ return Enum(mbgl::underlying_type(a) | mbgl::underlying_type(b));
+}
+
+template<typename Enum>
+MBGL_CONSTEXPR Enum& operator|=(Enum& a, Enum b) {
+ static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
+ return (a = a | b);
+}
+
+template<typename Enum>
+MBGL_CONSTEXPR bool operator&(Enum a, Enum b) {
+ static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
+ return bool(mbgl::underlying_type(a) & mbgl::underlying_type(b));
+}
+
+template<typename Enum>
+MBGL_CONSTEXPR Enum operator~(Enum value) {
+ static_assert(std::is_enum<Enum>::value, "Enum must be an enum type");
+ return Enum(~mbgl::underlying_type(value));
+}
+
+
+} // namespace mbgl \ No newline at end of file