libcommonc++  0.7
Flags.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_Flags_hxx
24 #define __ccxx_Flags_hxx
25 
26 #include <commonc++/Common.h++>
28 
29 namespace ccxx {
30 
37 template<typename T> class Flags
38 {
39  public:
40 
42  Flags(const T& flags = 0);
43 
45  ~Flags();
46 
53  bool isSet(int index) const;
54 
61  void set(int index, bool on = true);
62 
71  bool anySet(const T& mask) const;
72 
81  bool allSet(const T& mask) const;
82 
84  bool operator[](int index) const;
85 
86  class BitRef;
87 
93  BitRef operator[](int index);
94 
100  void clear(int flag);
101 
104  void clear();
105 
107  operator T() const
108  { return(_flags); }
109 
111  Flags& operator=(const T& flags);
112 
114  class BitRef
115  {
116  public:
117 
118  BitRef(Flags& flags, int index);
119  BitRef& operator=(bool value);
120 
121  private:
122 
123  Flags& _flags;
124  int _index;
125  };
128  private:
129 
130  T _flags;
131 };
132 
133 #include <commonc++/FlagsImpl.h++>
134 
135 } // namespace ccxx
136 
137 #endif // __ccxx_Flags_hxx
138 
A wrapper template for primitive integer types that represent flag bitmasks.
Definition: Flags.h++:37
bool operator[](int index) const
Index operator.
bool anySet(const T &mask) const
Compare the flags to a mask, returning true if any of the bits in the mask are set in the flags...
Flags(const T &flags=0)
Construct a new Flags object with an initial value of 0.
bool isSet(int index) const
Test if the bit at the given index is set.
void clear()
Clear all of the bits.
Flags & operator=(const T &flags)
Assignment operator.
bool allSet(const T &mask) const
Compare the flags to a mask, returning true if all of the bits in the mask are set in the flags...
Definition: AllocationMap.c++:25
~Flags()
Destructor.