Debian Codegraph @

FaCT++.Python/lib/Kernel/flags.h

raw symbols SCIP
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 #include <cstdint>
20
21 #ifndef FLAGS_H
22 #define FLAGS_H
23
24 /// class for carrying different flags; real users shall inherit from it
25 class Flags
26 {
27 public: // types
28 /// type of base integer used for bit-set
29 typedef uint32_t IntType;
30
31 private: // members
32 /// variable to keep all the flags
33 IntType flags = 0;
34
35 protected: // methods for flags maintenance
36 /// get given flag value
37 bool getFlag ( IntType mask ) const { return (flags & mask) != 0; }
38 /// set given flag to 1
39 void setFlag ( IntType mask ) { flags |= mask; }
40 /// set given flag to 0
41 void clearFlag ( IntType mask ) { flags &= ~mask; }
42 /// set given flag to given value
43 void setFlag ( IntType mask, bool Set ) { Set ? setFlag(mask) : clearFlag(mask); }
44
45 /// get all the flags at once
46 IntType getAllFlags ( void ) const { return flags; }
47 /// set all flags to a given value; @return old value of the flags
48 IntType setAllFlags ( IntType value ) { IntType old = flags; flags = value; return old; }
49
50 public: // interface
51 /// empty c'tor
52 Flags() = default;
53 /// init flags with given set of flags
54 explicit Flags ( IntType init ) : flags(init) {}
55 /// copy c'tor
56 Flags ( const Flags& f ) = default;
57 /// assignment
58 Flags& operator = ( const Flags& f ) = default;
59 /// empty d'tor
60 virtual ~Flags() = default;
61 }; // Flags
62
63 // use this macro to create a new flag
64 #define FPP_ADD_FLAG(Name,Mask) \
65 bool is##Name ( void ) const \
66 { return getFlag(Mask); } \
67 void set##Name ( void ) \
68 { setFlag(Mask); } \
69 void clear##Name ( void ) \
70 { clearFlag(Mask); } \
71 void set##Name ( bool action ) \
72 { setFlag(Mask,action); } \
73
74 #endif