libUTL++
BitArrayElem.h
1 #pragma once
2 
4 
5 #include <libutl/BitArray.h>
6 #include <libutl/String.h>
7 #include <libutl/Uint.h>
8 
10 
11 UTL_NS_BEGIN;
12 
14 
25 
27 class BitArrayElem : public Object
28 {
33 
34 public:
40  BitArrayElem(BitArray* bitArray, uint64_t idx)
41  {
42  ASSERTD(bitArray != nullptr);
43  _bitArray = bitArray;
44  _idx = idx;
45  }
46 
47  virtual void copy(const Object& rhs);
48 
49  virtual String toString() const;
50 
52 
53 
55  {
56  _bitArray->set(_idx, val);
57  return self;
58  }
59 
62  {
63  _bitArray->set(_idx, val);
64  return self;
65  }
66 
69  {
70  _bitArray->set(_idx, val ? 1 : 0);
71  return self;
72  }
73 
76  {
77  _bitArray->set(_idx, ref.get());
78  return self;
79  }
80 
82  uint64_t
83  get() const
84  {
85  return _bitArray->get(_idx);
86  }
87 
89  operator uint_t() const
90  {
91  return (uint_t)_bitArray->get(_idx);
92  }
93 
95  operator uint64_t() const
96  {
97  return _bitArray->get(_idx);
98  }
99 
101  operator bool() const
102  {
103  return (_bitArray->get(_idx) != 0);
104  }
106 
108 
109 
110  bool operator==(bool rhs) const
111  {
112  return (get() == (uint64_t)rhs);
113  }
115  bool operator!=(bool rhs) const
116  {
117  return (get() == (uint64_t)rhs);
118  }
119 
121  bool operator<(uint64_t rhs) const
122  {
123  return (get() < rhs);
124  }
126  bool operator<=(uint64_t rhs) const
127  {
128  return (get() <= rhs);
129  }
131  bool operator>(uint64_t rhs) const
132  {
133  return (get() > rhs);
134  }
136  bool operator>=(uint64_t rhs) const
137  {
138  return (get() >= rhs);
139  }
141  bool operator==(uint64_t rhs) const
142  {
143  return (get() == rhs);
144  }
146  bool operator!=(uint64_t rhs) const
147  {
148  return (get() != rhs);
149  }
150 
152  bool operator<(int64_t rhs) const
153  {
154  return (get() < (uint64_t)rhs);
155  }
157  bool operator<=(int64_t rhs) const
158  {
159  return (get() <= (uint64_t)rhs);
160  }
162  bool operator>(int64_t rhs) const
163  {
164  return (get() > (uint64_t)rhs);
165  }
167  bool operator>=(int64_t rhs) const
168  {
169  return (get() >= (uint64_t)rhs);
170  }
172  bool operator==(int64_t rhs) const
173  {
174  return (get() == (uint64_t)rhs);
175  }
177  bool operator!=(int64_t rhs) const
178  {
179  return (get() != (uint64_t)rhs);
180  }
181 
183  bool operator<(const BitArrayElem& rhs) const
184  {
185  return (get() < rhs.get());
186  }
188  bool operator<=(const BitArrayElem& rhs) const
189  {
190  return (get() <= rhs.get());
191  }
193  bool operator>(const BitArrayElem& rhs) const
194  {
195  return (get() > rhs.get());
196  }
198  bool operator>=(const BitArrayElem& rhs) const
199  {
200  return (get() >= rhs.get());
201  }
203  bool operator==(const BitArrayElem& rhs) const
204  {
205  return (get() == rhs.get());
206  }
208  bool operator!=(const BitArrayElem& rhs) const
209  {
210  return (get() != rhs.get());
211  }
213 private:
214  BitArray* _bitArray;
215  uint64_t _idx;
216 };
217 
219 
220 UTL_NS_END;
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
Reference to a value stored in a BitArray.
Definition: BitArrayElem.h:27
bool operator<(const BitArrayElem &rhs) const
Less-than operator.
Definition: BitArrayElem.h:183
bool operator>=(uint64_t rhs) const
Greater-than-or-equal-to operator.
Definition: BitArrayElem.h:136
uint64_t get() const
Get value.
Definition: BitArrayElem.h:83
bool operator<=(const BitArrayElem &rhs) const
Less-than-or-equal-to operator.
Definition: BitArrayElem.h:188
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
bool operator==(int64_t rhs) const
Equal-to operator.
Definition: BitArrayElem.h:172
Character string.
Definition: String.h:31
bool operator<=(uint64_t rhs) const
Less-than-or-equal-to operator.
Definition: BitArrayElem.h:126
long int64_t
Signed 64-bit integer.
Definition: types.h:164
bool operator!=(uint64_t rhs) const
Unequal-to operator.
Definition: BitArrayElem.h:146
bool operator==(bool rhs) const
Equal-to operator.
Definition: BitArrayElem.h:110
bool operator>=(int64_t rhs) const
Greater-than-or-equal-to operator.
Definition: BitArrayElem.h:167
BitArrayElem & operator=(uint_t val)
Assignment from uint_t.
Definition: BitArrayElem.h:54
bool operator!=(const BitArrayElem &rhs) const
Unequal-to operator.
Definition: BitArrayElem.h:208
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
unsigned long uint64_t
Unsigned 64-bit integer.
Definition: types.h:154
bool operator>(uint64_t rhs) const
Greater-than operator.
Definition: BitArrayElem.h:131
bool operator<(int64_t rhs) const
Less-than operator.
Definition: BitArrayElem.h:152
BitArrayElem & operator=(uint64_t val)
Assignment from uint64_t.
Definition: BitArrayElem.h:61
bool operator!=(bool rhs) const
Unequal-to operator.
Definition: BitArrayElem.h:115
BitArrayElem & operator=(BitArrayElem &ref)
Assignment from non-const BitArrayElem.
Definition: BitArrayElem.h:75
bool operator!=(int64_t rhs) const
Unequal-to operator.
Definition: BitArrayElem.h:177
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
bool operator>(int64_t rhs) const
Greater-than operator.
Definition: BitArrayElem.h:162
#define UTL_CLASS_NO_SERIALIZE
Declare that a class cannot do serialize().
Definition: macros.h:384
#define UTL_CLASS_NO_COMPARE
Declare that a class cannot do compare().
Definition: macros.h:344
BitArrayElem(BitArray *bitArray, uint64_t idx)
Constructor.
Definition: BitArrayElem.h:40
bool operator<(uint64_t rhs) const
Less-than operator.
Definition: BitArrayElem.h:121
bool operator==(const BitArrayElem &rhs) const
Equal-to operator.
Definition: BitArrayElem.h:203
BitArrayElem & operator=(bool val)
Assignment from bool.
Definition: BitArrayElem.h:68
bool operator==(uint64_t rhs) const
Equal-to operator.
Definition: BitArrayElem.h:141
bool operator>(const BitArrayElem &rhs) const
Greater-than operator.
Definition: BitArrayElem.h:193
Root of UTL++ class hierarchy.
Definition: Object.h:52
bool operator>=(const BitArrayElem &rhs) const
Greater-than-or-equal-to operator.
Definition: BitArrayElem.h:198
bool operator<=(int64_t rhs) const
Less-than-or-equal-to operator.
Definition: BitArrayElem.h:157
#define ASSERTD
Do an assertion in DEBUG mode only.
Array of n-bit values.
Definition: BitArray.h:36