Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TBitFlags.ipp
Go to the documentation of this file.
1#pragma once
2
3#include "Utility/TBitFlags.h"
4
5namespace ph
6{
7
8template<typename Value, typename Input>
10 m_bits(0)
11{}
12
13template<typename Value, typename Input>
14inline constexpr TBitFlags<Value, Input>::TBitFlags(const FlagsSet& flagsSet) :
15 TBitFlags(static_cast<Input>(collectFlags(flagsSet)))
16{}
17
18template<typename Value, typename Input>
19inline constexpr TBitFlags<Value, Input>::TBitFlags(const Input flagsSet) :
20 m_bits(static_cast<Value>(flagsSet))
21{}
22
23template<typename Value, typename Input>
24template<typename OtherInput>
26 m_bits(otherFlags.get())
27{}
28
29template<typename Value, typename Input>
30inline constexpr TBitFlags<Value, Input>& TBitFlags<Value, Input>::unionWith(const FlagsSet& flagsSet)
31{
32 TBitFlags flags;
33 flags.m_bits = collectFlags(flagsSet);
34 return unionWith(flags);
35}
36
37template<typename Value, typename Input>
39{
40 m_bits |= flags.m_bits;
41
42 return *this;
44
45template<typename Value, typename Input>
46inline constexpr TBitFlags<Value, Input>& TBitFlags<Value, Input>::intersectWith(const FlagsSet& flagsSet)
47{
48 m_bits &= collectFlags(flagsSet);
50 return *this;
51}
52
53template<typename Value, typename Input>
54inline constexpr TBitFlags<Value, Input>& TBitFlags<Value, Input>::set(const FlagsSet& flagsSet)
55{
56 return set(static_cast<Input>(collectFlags(flagsSet)));
57}
58
59template<typename Value, typename Input>
60inline constexpr TBitFlags<Value, Input>& TBitFlags<Value, Input>::set(const Input flagsSet)
61{
62 m_bits = static_cast<Value>(flagsSet);
63 return *this;
64}
66template<typename Value, typename Input>
67inline constexpr TBitFlags<Value, Input>& TBitFlags<Value, Input>::turnOn(const FlagsSet& flagsSet)
68{
69 return unionWith(flagsSet);
70}
71
72template<typename Value, typename Input>
73inline constexpr TBitFlags<Value, Input>& TBitFlags<Value, Input>::turnOff(const FlagsSet& flagsSet)
74{
75 m_bits &= ~(collectFlags(flagsSet));
76
77 return *this;
78}
79
80template<typename Value, typename Input>
81inline constexpr bool TBitFlags<Value, Input>::hasNone(const FlagsSet& flagsSet) const
82{
83 return hasNone(static_cast<Input>(collectFlags(flagsSet)));
84}
86template<typename Value, typename Input>
87inline constexpr bool TBitFlags<Value, Input>::hasAny(const FlagsSet& flagsSet) const
88{
89 return hasAny(static_cast<Input>(collectFlags(flagsSet)));
90}
91
92template<typename Value, typename Input>
93inline constexpr bool TBitFlags<Value, Input>::hasAll(const FlagsSet& flagsSet) const
94{
95 return hasAll(static_cast<Input>(collectFlags(flagsSet)));
96}
97
98template<typename Value, typename Input>
99inline constexpr bool TBitFlags<Value, Input>::hasExactly(const FlagsSet& flagsSet) const
100{
101 return hasExactly(static_cast<Input>(collectFlags(flagsSet)));
102}
103
104template<typename Value, typename Input>
105inline constexpr bool TBitFlags<Value, Input>::hasNone(const Input flagsSet) const
106{
107 const auto flagsValue = static_cast<Value>(flagsSet);
108 return (m_bits & flagsValue) == 0;
110
111template<typename Value, typename Input>
112inline constexpr bool TBitFlags<Value, Input>::hasAny(const Input flagsSet) const
113{
114 const auto flagsValue = static_cast<Value>(flagsSet);
115 return (m_bits & flagsValue) != 0;
116}
117
118template<typename Value, typename Input>
119inline constexpr bool TBitFlags<Value, Input>::hasAll(const Input flagsSet) const
121 const auto flagsValue = static_cast<Value>(flagsSet);
122 return (m_bits & flagsValue) == flagsValue;
123}
124
125template<typename Value, typename Input>
126inline constexpr bool TBitFlags<Value, Input>::hasExactly(const Input flagsSet) const
127{
128 const auto flagsValue = static_cast<Value>(flagsSet);
129 return m_bits == flagsValue;
130}
131
132template<typename Value, typename Input>
133inline constexpr bool TBitFlags<Value, Input>::has(const Input singleFlag) const
134{
135 return hasAll(singleFlag);
136}
137
138template<typename Value, typename Input>
139inline constexpr bool TBitFlags<Value, Input>::hasNo(const Input singleFlag) const
140{
141 return hasNone(singleFlag);
142}
143
144template<typename Value, typename Input>
145inline constexpr bool TBitFlags<Value, Input>::isEmpty() const
146{
147 return m_bits == 0;
148}
149
150template<typename Value, typename Input>
151inline constexpr bool TBitFlags<Value, Input>::isEqual(const TBitFlags& other) const
152{
153 return m_bits == other.m_bits;
154}
155
156template<typename Value, typename Input>
157inline constexpr Value TBitFlags<Value, Input>::get() const
158{
159 return m_bits;
160}
161
162template<typename Value, typename Input>
163inline constexpr Value TBitFlags<Value, Input>::collectFlags(const FlagsSet& flagsSet)
164{
165 Value inputFlags = 0;
166 for(const Input& flag : flagsSet)
167 {
168 inputFlags |= static_cast<Value>(flag);
169 }
170
171 return inputFlags;
172}
173
174}// end namespace ph
Manipulate a value type where each bit is a binary flag.
Definition TBitFlags.h:17
constexpr bool hasExactly(const FlagsSet &flagsSet) const
Checks whether this instance contains exactly the specified flags. No more, no less.
Definition TBitFlags.ipp:99
constexpr bool has(Input singleFlag) const
Checks whether this single flag is fully contained.
Definition TBitFlags.ipp:133
constexpr bool isEmpty() const
Checks whether this instance contains no flags.
Definition TBitFlags.ipp:145
constexpr TBitFlags & set(const FlagsSet &flagsSet)
Definition TBitFlags.ipp:54
constexpr TBitFlags & intersectWith(const FlagsSet &flagsSet)
Intersects this instance with the specified flags.
Definition TBitFlags.ipp:46
constexpr TBitFlags & turnOff(const FlagsSet &flagsSet)
Definition TBitFlags.ipp:73
constexpr bool hasAny(const FlagsSet &flagsSet) const
Checks whether this instance contains at least one of the specified flags.
Definition TBitFlags.ipp:87
constexpr bool hasNo(Input singleFlag) const
Checks whether this single flag is fully absent.
Definition TBitFlags.ipp:139
constexpr bool hasNone(const FlagsSet &flagsSet) const
Checks whether this instance contains no specified flags.
Definition TBitFlags.ipp:81
constexpr TBitFlags()
Creates an instance with no flags.
Definition TBitFlags.ipp:9
constexpr Value get() const
Get the value representing current flags.
Definition TBitFlags.ipp:157
constexpr bool hasAll(const FlagsSet &flagsSet) const
Checks whether this instance contains all of the specified flags.
Definition TBitFlags.ipp:93
constexpr TBitFlags & turnOn(const FlagsSet &flagsSet)
Enable/disable specified flags.
Definition TBitFlags.ipp:67
constexpr TBitFlags & unionWith(const FlagsSet &flagsSet)
Unions specified flags into this instance.
Definition TBitFlags.ipp:30
constexpr bool isEqual(const TBitFlags &other) const
Definition TBitFlags.ipp:151
The root for all renderer implementations.
Definition EEngineProject.h:6