Debian Codegraph @

Kernel/flags.h

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2005-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef FLAGS_H
21 #define FLAGS_H
22
23 /// class for carrying different flags; real users shall inherit from it
24 class Flags
25 {
26 public: // types
27 /// type of base integer used for bit-set
28 typedef uint32_t IntType;
29
30 private: // members
31 /// variable to keep all the flags
32 IntType flags = 0;
33
34 protected: // methods for flags maintenance
35 /// get given flag value
36 bool getFlag ( IntType mask ) const { return (flags & mask) != 0; }
37 /// set given flag to 1
38 void setFlag ( IntType mask ) { flags |= mask; }
39 /// set given flag to 0
40 void clearFlag ( IntType mask ) { flags &= ~mask; }
41 /// set given flag to given value
42 void setFlag ( IntType mask, bool Set ) { Set ? setFlag(mask) : clearFlag(mask); }
43
44 /// get all the flags at once
45 IntType getAllFlags ( void ) const { return flags; }
46 /// set all flags to a given value; @return old value of the flags
47 IntType setAllFlags ( IntType value ) { IntType old = flags; flags = value; return old; }
48
49 public: // interface
50 /// empty c'tor
51 Flags() = default;
52 /// init flags with given set of flags
53 explicit Flags ( IntType init ) : flags(init) {}
54 /// copy c'tor
55 Flags ( const Flags& f ) = default;
56 /// assignment
57 Flags& operator = ( const Flags& f ) = default;
58 /// empty d'tor
59 virtual ~Flags() = default;
60 }; // Flags
61
62 // use this macro to create a new flag
63 #define FPP_ADD_FLAG(Name,Mask) \
64 bool is##Name ( void ) const \
65 { return getFlag(Mask); } \
66 void set##Name ( void ) \
67 { setFlag(Mask); } \
68 void clear##Name ( void ) \
69 { clearFlag(Mask); } \
70 void set##Name ( bool action ) \
71 { setFlag(Mask,action); } \
72
73 #endif