Kiwano Engine v1.3.x
Flag.h
1// Copyright (c) 2019-2020 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/BitOperator.h>
23#include <cstdint> // uint8_t
24
25namespace kiwano
26{
27
28template <typename _Ty>
29class Flag
30{
31public:
32 static_assert(std::is_arithmetic<_Ty>::value, "_Ty must be an arithmetic type");
33
34 typedef _Ty value_type;
35
36 _Ty value;
37
38 inline Flag()
39 : value()
40 {
41 }
42
43 inline Flag(_Ty value)
44 : value(value)
45 {
46 }
47
48 inline void Set(_Ty value)
49 {
50 bits::Set(this->value, value);
51 }
52
53 inline void Unset(_Ty value)
54 {
55 bits::Unset(this->value, value);
56 }
57
58 inline bool Has(_Ty value) const
59 {
60 return bits::Has(this->value, value);
61 }
62};
63
64template <typename _Ty>
65struct IsFlag : public std::false_type
66{
67};
68
69template <typename _Ty>
70struct IsFlag<Flag<_Ty>> : public std::true_type
71{
72};
73
82
83} // namespace kiwano
Definition: Flag.h:30
Definition: Flag.h:66