[core] Bitmask operations for enums
This commit is contained in:
@@ -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
|
||||
|
||||
33
include/mbgl/util/bitmask_operations.hpp
Normal file
33
include/mbgl/util/bitmask_operations.hpp
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user