OSVR-Core
Flag.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_Flag_h_GUID_9D7B0F8D_1156_4B8A_21D0_64729F213C14
26 #define INCLUDED_Flag_h_GUID_9D7B0F8D_1156_4B8A_21D0_64729F213C14
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 // - none
33 
34 // Standard includes
35 // - none
36 
37 namespace osvr {
38 namespace util {
39 
43  class Flag {
44  public:
46  Flag() : m_val(false) {}
47 
49  explicit operator bool() const { return get(); }
50 
52  bool get() const { return m_val; }
53 
55  void set() { m_val = true; }
56 
59  Flag &operator+=(bool newVal) {
60  m_val |= newVal;
61  return *this;
62  }
64  Flag &operator+=(Flag const &rhs) {
65  m_val |= rhs.m_val;
66  return *this;
67  }
68 
70  void reset() { m_val = false; }
71 
72  private:
73  bool m_val;
74  };
75 
76 } // namespace util
77 } // namespace osvr
78 #endif // INCLUDED_Flag_h_GUID_9D7B0F8D_1156_4B8A_21D0_64729F213C14
Definition: RunLoopManager.h:42
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Flag()
Initialize the flag as false.
Definition: Flag.h:46
Flag & operator+=(Flag const &rhs)
Update the flag with another flag.
Definition: Flag.h:64
void reset()
Reset the flag back to false.
Definition: Flag.h:70
Flag & operator+=(bool newVal)
Update the flag with (typically) a function call result: state is true if state was true or newVal is...
Definition: Flag.h:59
A class that lightly wraps a bool, in order to provide easier maintenance of a "dirty" flag...
Definition: Flag.h:43