MarlinMT  0.1.0
Flags.h
Go to the documentation of this file.
1 #pragma once
2 
3 // -- std header
4 #include <bitset>
5 
6 namespace marlinmt {
7  namespace book {
8 
9  class Flag_t ;
10  namespace Flags {
11  constexpr unsigned long long value( const Flag_t &flag ) ;
12  } // end namespace Flags
13 
15  class Flag_t {
16  static constexpr std::size_t AmtFlags = 8 ;
17 
18  public:
22  explicit constexpr Flag_t( unsigned long long val )
23  : _val{val}, _initValue{val} {}
24 
28  explicit Flag_t( const std::bitset< AmtFlags > &val ) : _val{val} {}
29 
33  Flag_t operator~() const {
34  return Flag_t(~_val);
35  }
36 
40  Flag_t operator&( const Flag_t &f ) const {
41  return Flag_t( _val & f._val ) ;
42  }
43 
47  Flag_t operator|( const Flag_t &f ) const {
48  return Flag_t( _val | f._val ) ;
49  }
50 
55  explicit operator bool() const { return _val.any(); }
56 
60  explicit operator const std::bitset< AmtFlags > &() const { return _val; }
61 
65  bool operator==( const Flag_t &f ) const { return _val == f._val; }
66 
70  bool operator!=( const Flag_t &f ) const { return _val != f._val; }
71 
77  [[nodiscard]] bool contains( const Flag_t &f ) const {
78  return ( _val & f._val ) == f._val ;
79  }
80 
81  explicit operator unsigned long long() const { return _val.to_ullong(); }
82  Flag_t() = default ;
83  Flag_t( const Flag_t & ) = default ;
84  Flag_t &operator=( const Flag_t &flag ) {
85  _val = flag._val ;
86  return *this ;
87  }
88  Flag_t( Flag_t && ) noexcept = default ;
89  Flag_t &operator=( Flag_t &&flag ) noexcept {
90  _val = flag._val ;
91  return *this ;
92  }
93  ~Flag_t() = default ;
94 
95  private:
97  std::bitset< AmtFlags > _val{0} ;
98  const unsigned long long _initValue{0} ;
99  friend constexpr unsigned long long
100  Flags::value( const Flag_t & /*flag*/ ) ;
101  } ;
102 
103 
105  namespace Flags {
106  constexpr unsigned long long value( const Flag_t &flag ) {
107  return flag._initValue ;
108  }
110  namespace Book {
112  constexpr Flag_t Default( 0 ) ;
114  constexpr Flag_t Single( 1U << 0U ) ;
116  constexpr Flag_t MultiShared( 1U << 1U ) ;
119  constexpr Flag_t MultiCopy( 1U << 2U ) ;
121  constexpr Flag_t Store( 1U << 3U ) ;
122  } // end namespace Book
123 
124  } // end namespace Flags
125 
127  namespace Masks {
129  namespace Book {
131  constexpr Flag_t MemoryLayout (
135 
137  constexpr Flag_t StoreOptions(
139  } // end namespace Book
140 
141  } // end namespace Masks
142 
143  } // end namespace book
144 } // end namespace marlinmt
constexpr Flag_t MemoryLayout(Flags::value(Flags::Book::Single)|Flags::value(Flags::Book::MultiShared)|Flags::value(Flags::Book::MultiCopy))
Mask for Flags with memory layout options.
constexpr Flag_t(unsigned long long val)
constructor flag from number.
Definition: Flags.h:22
Flag_t operator|(const Flag_t &f) const
logical OR on tow set of Flags.
Definition: Flags.h:47
constexpr Flag_t StoreOptions(Flags::Book::Store)
Mask for Flags with store option.
bool operator==(const Flag_t &f) const
check for equality.
Definition: Flags.h:65
constexpr unsigned long long value(const Flag_t &flag)
Definition: Flags.h:106
Flag_t & operator=(Flag_t &&flag) noexcept
Definition: Flags.h:89
Flag_t(const std::bitset< AmtFlags > &val)
Construct flag from bitset.
Definition: Flags.h:28
constexpr Flag_t Store(1U<< 3U)
store object in file at end of lifetime
Flag type for flags in marlinmt::book.
Definition: Flags.h:15
const unsigned long long _initValue
Definition: Flags.h:98
constexpr Flag_t MultiShared(1U<< 1U)
create one instance witch concurrent access.
Flag_t operator~() const
bitwise not for Flags
Definition: Flags.h:33
bool operator!=(const Flag_t &f) const
check for inequality.
Definition: Flags.h:70
bool contains(const Flag_t &f) const
check if the flags is a subset of the other.
Definition: Flags.h:77
std::bitset< AmtFlags > _val
flags saved as bits
Definition: Flags.h:97
constexpr Flag_t MultiCopy(1U<< 2U)
create multiple instances of booked object (if possible) to avoid sync points
constexpr Flag_t Default(0)
use default arguments
Flag_t & operator=(const Flag_t &flag)
Definition: Flags.h:84
constexpr Flag_t Single(1U<< 0U)
vanilla object.