blob: 2cfc7e36dc862590a466065208010aa4286f1d70 [file] [log] [blame]
Zane Shelley871adec2019-07-30 11:01:39 -05001#pragma once
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05002
Ben Tynera8126fd2019-08-01 19:40:07 -05003#include <stdint.h>
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05004
Zane Shelley871adec2019-07-30 11:01:39 -05005namespace libhei
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05006{
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -05007
8class BitStringBuffer;
9
Zane Shelley72fd2e42022-11-12 12:14:53 -060010// ##############################################################################
11// BitString class
12// ##############################################################################
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050013
14/**
15 * A BitString is general purpose class providing the ability to manipulate
16 * individual bits within an allocated section of contiguous memory.
17 *
18 * A BitString does not "own" the memory, it only accesses and manipulates the
19 * bits in the range specified. Users will need to ensure memory is allocated
20 * and deallocated appropriately. As an alternative, a BitStringBuffer is a
21 * BitString that will allocate and maintain its own memory.
22 *
23 * The length of a BitString is only limited by the amount of memory that
24 * contains the data buffer.
25 *
Ben Tynera8126fd2019-08-01 19:40:07 -050026 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050027 *
Ben Tynera8126fd2019-08-01 19:40:07 -050028 * - The bit positions are ordered 0 to n (left to right), where n is the bit
29 * length minus one.
30 * - The data stored in memory is assumed to be in big-endian byte format.
31 *
32 * So, for example:
33 *
34 * uint8_t a[2]; // 16 bits of memory
35 * BitString bs { 16, a }; // init BitString for a
Zane Shelley83da2452019-10-25 15:45:34 -050036 * bs.setFieldRight(0, 16, 0x1122); // set all 16 bits to 0x1122
Ben Tynera8126fd2019-08-01 19:40:07 -050037 *
38 * Results in:
39 *
40 * a[0] == bs.getFieldRight(0, 8) (i.e. 0x11)
41 * a[1] == bs.getFieldRight(8, 8) (i.e. 0x22)
42 *
43 * It is very important you do NOT do this:
44 *
45 * uint16_t x = 0x1122; // 16 bits of memory
46 * BitString bs { 16, &x }; // init BitString for x
47 *
48 * The results are undefined, or at least not portable. For example:
49 *
50 * Big-endian:
51 * x is stored in memory as |0x11|0x22|.
52 * Therefore, bs.getFieldRight(0, 8) returns 0x11.
53 *
54 * Little-endian:
55 * x is stored in memory as |0x22|0x11|.
56 * Therefore, bs.getFieldRight(0, 8) returns 0x22.
57 *
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050058 */
59class BitString
60{
Ben Tynera8126fd2019-08-01 19:40:07 -050061 private: // constants
Zane Shelleyd0af3582019-09-19 10:48:59 -050062 static const uint64_t UINT64_BIT_LEN;
63 static const uint64_t UINT8_BIT_LEN;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050064
65 public: // functions
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050066 /**
67 * @brief Constructor
68 * @param i_bitLen The number of bits in the bit string.
69 * @param i_bufAddr The starting address of the memory buffer.
Ben Tynera8126fd2019-08-01 19:40:07 -050070 * @param i_offset By default, position 0 will be the first bit of the
71 * buffer's start address. However, this parameter can be
72 * used to indicate that position 0 actually starts
73 * somewhere in the middle of the buffer.
74 * @pre Use getMinBytes() to calulate the minimum number of bytes needed
75 * to allocate sufficient memory space for this bit string.
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050076 */
Zane Shelleyfe27b652019-10-28 11:33:07 -050077 BitString(uint64_t i_bitLen, void* i_bufAddr, uint64_t i_offset = 0) :
Zane Shelley5a78fa82022-09-16 16:49:58 -050078 iv_bitLen(i_bitLen), iv_bufAddr(static_cast<uint8_t*>(i_bufAddr)),
79 iv_offset(i_offset)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050080 {}
81
82 /** @brief Destructor */
83 virtual ~BitString() {}
84
85 /** @return The number of bits in the bit string buffer. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -050086 uint64_t getBitLen() const
87 {
88 return iv_bitLen;
89 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050090
91 /** @return The address of the bit string buffer. Note that this may
92 * return nullptr. */
Zane Shelley5a78fa82022-09-16 16:49:58 -050093 uint8_t* getBufAddr() const
Zane Shelley7f7a42d2019-10-28 13:28:31 -050094 {
95 return iv_bufAddr;
96 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -050097
98 /**
99 * @param i_bitLen The number of bits for a bit string.
100 * @param i_offset Optional starting position of the bit string within the
101 * memory buffer.
Ben Tynera8126fd2019-08-01 19:40:07 -0500102 * @return The minimum number of bytes required to allocate sufficient
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500103 * memory space for a bit string.
104 */
Zane Shelley83da2452019-10-25 15:45:34 -0500105 static uint64_t getMinBytes(uint64_t i_bitLen, uint64_t i_offset = 0)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500106 {
Zane Shelley83da2452019-10-25 15:45:34 -0500107 return (i_bitLen + i_offset + UINT8_BIT_LEN - 1) / UINT8_BIT_LEN;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500108 }
109
110 /**
111 * @brief Returns a left-justified value of the given length from the bit
112 * string starting at the given position.
113 * @param i_pos The starting position of the target range.
114 * @param i_len The number of bits of the target range.
115 * @return The value of the field range specified (left-justified).
116 * @pre nullptr != getBufAddr()
117 * @pre 0 < i_len
Ben Tynera8126fd2019-08-01 19:40:07 -0500118 * @pre i_len <= UINT64_BIT_LEN
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500119 * @pre i_pos + i_len <= getBitLen()
120 */
Zane Shelley83da2452019-10-25 15:45:34 -0500121 uint64_t getFieldLeft(uint64_t i_pos, uint64_t i_len) const
Ben Tynera8126fd2019-08-01 19:40:07 -0500122 {
123 return getFieldRight(i_pos, i_len) << (UINT64_BIT_LEN - i_len);
124 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500125
126 /**
127 * @brief Returns a right-justified value of the given length from the bit
128 * string starting at the given position.
129 * @param i_pos The starting position of the target range.
130 * @param i_len The number of bits of the target range.
131 * @return The value of the field range specified (right-justified).
132 * @pre nullptr != getBufAddr()
133 * @pre 0 < i_len
Ben Tynera8126fd2019-08-01 19:40:07 -0500134 * @pre i_len <= UINT64_BIT_LEN
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500135 * @pre i_pos + i_len <= getBitLen()
136 */
Zane Shelley83da2452019-10-25 15:45:34 -0500137 uint64_t getFieldRight(uint64_t i_pos, uint64_t i_len) const;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500138
139 /**
140 * @brief Sets a left-justified value of the given length into the bit
141 * string starting at the given position.
142 * @param i_pos The starting position of the target range.
143 * @param i_len The number of bits of the target range.
144 * @param i_val The left-justified value to set.
145 * @pre nullptr != getBufAddr()
146 * @pre 0 < i_len
Ben Tynera8126fd2019-08-01 19:40:07 -0500147 * @pre i_len <= UINT64_BIT_LEN
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500148 * @pre i_pos + i_len <= getBitLen()
149 */
Zane Shelley83da2452019-10-25 15:45:34 -0500150 void setFieldLeft(uint64_t i_pos, uint64_t i_len, uint64_t i_val);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500151
152 /**
153 * @brief Sets a right-justified value of the given length into the bit
154 * string starting at the given position.
155 * @param i_pos The starting position of the target range.
156 * @param i_len The number of bits of the target range.
157 * @param i_val The right-justified value to set.
158 * @pre nullptr != getBufAddr()
159 * @pre 0 < i_len
Ben Tynera8126fd2019-08-01 19:40:07 -0500160 * @pre i_len <= UINT64_BIT_LEN
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500161 * @pre i_pos + i_len <= getBitLen()
162 */
Zane Shelley83da2452019-10-25 15:45:34 -0500163 void setFieldRight(uint64_t i_pos, uint64_t i_len, uint64_t i_val)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500164 {
Zane Shelley83da2452019-10-25 15:45:34 -0500165 setFieldLeft(i_pos, i_len, i_val << (UINT64_BIT_LEN - i_len));
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500166 }
167
168 /**
169 * @param i_pos The target position.
170 * @return True if the bit at the given position is set(1), false otherwise.
171 * @pre i_pos < getBitLen().
172 */
Zane Shelley83da2452019-10-25 15:45:34 -0500173 bool isBitSet(uint64_t i_pos) const
Ben Tynera8126fd2019-08-01 19:40:07 -0500174 {
175 return 0 != getFieldRight(i_pos, 1);
176 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500177
178 /**
179 * @brief Sets the target position to 1.
180 * @param i_pos The target position.
181 * @pre i_pos < getBitLen().
182 */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500183 void setBit(uint64_t i_pos)
184 {
185 setFieldRight(i_pos, 1, 1);
186 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500187
188 /** @brief Sets the entire bit string to 1's. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500189 void setAll()
190 {
191 setPattern(UINT64_MAX);
192 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500193
194 /**
195 * @brief Sets the target position to 0.
196 * @param i_pos The target position.
197 * @pre i_pos < getBitLen().
198 */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500199 void clearBit(uint64_t i_pos)
200 {
201 setFieldRight(i_pos, 1, 0);
202 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500203
204 /** @brief Sets the entire bit string to 0's. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500205 void clearAll()
206 {
207 setPattern(0);
208 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500209
210 /**
211 * @brief Sets a range within the string based on the pattern and length
212 * provided.
213 * @param i_sPos Starting position of this string.
214 * @param i_sLen The length of the target range.
215 * @param i_pattern The pattern to set (right justified).
216 * @param i_pLen The length of the pattern.
217 * @pre nullptr != getBufAddr()
218 * @pre 0 < i_sLen
219 * @pre i_sPos + i_sLen <= getBitLen()
Ben Tynera8126fd2019-08-01 19:40:07 -0500220 * @pre 0 < i_pLen <= UINT64_BIT_LEN
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500221 * @post The pattern is repeated/truncated as needed.
222 *
223 * Examples: i_sPos(0), i_sLen(10), i_pattern(0xA), i_pLen(4)
224 * Old String: 0000000000
225 * New String: 1010101010
226 *
227 * i_sPos(3), i_sLen(4), i_pattern(0x3), i_pLen(3)
228 * Old String: 0001001000
229 * New String: 0000110000
230 */
Zane Shelley83da2452019-10-25 15:45:34 -0500231 void setPattern(uint64_t i_sPos, uint64_t i_sLen, uint64_t i_pattern,
232 uint64_t i_pLen);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500233
234 /**
235 * @brief Sets entire string based on the pattern and length provided.
236 * @param i_pattern The pattern to set (right justified).
237 * @param i_pLen The length of the pattern.
238 * @note See definition above for prerequisites.
239 * @post The entire string is filled with the pattern.
240 * @post The pattern is repeated/truncated as needed.
241 */
Zane Shelley83da2452019-10-25 15:45:34 -0500242 void setPattern(uint64_t i_pattern, uint64_t i_pLen)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500243 {
Zane Shelley83da2452019-10-25 15:45:34 -0500244 setPattern(0, getBitLen(), i_pattern, i_pLen);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500245 }
246
247 /**
Ben Tynera8126fd2019-08-01 19:40:07 -0500248 * @brief Sets entire string based on the pattern provided.
249 * @param i_pattern The pattern to set (right justified).
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500250 * @note See definition above for prerequisites.
251 * @post The entire string is filled with the pattern.
252 * @post The pattern is repeated/truncated as needed.
253 */
Zane Shelley83da2452019-10-25 15:45:34 -0500254 void setPattern(uint64_t i_pattern)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500255 {
Zane Shelley83da2452019-10-25 15:45:34 -0500256 setPattern(i_pattern, sizeof(i_pattern) * 8);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500257 }
258
259 /**
260 * @brief Set bits in this string based on the given string.
261 * @param i_sStr The source string.
262 * @param i_sPos The starting position of the source string.
263 * @param i_sLen The number of bits to copy from the source string.
264 * @param i_dPos The starting position of the this string.
265 * @pre nullptr != getBufAddr()
266 * @pre nullptr != i_sStr.getBufAddr()
267 * @pre 0 < i_sLen
268 * @pre i_sPos + i_sLen <= i_sStr.getBitLen()
269 * @pre i_dPos < getBitLen()
270 * @post Source bits in given range are copied to this starting at i_dPos.
271 * @note If the length of the given string is greater than the length of
272 * this string, then the extra bits are ignored.
273 * @note If the length of the given string is less than the length of this
274 * string, then the extra bits in this string are not modified.
275 * @note This string and the source string may specify overlapping memory.
276 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500277 void setString(const BitString& i_sStr, uint64_t i_sPos, uint64_t i_sLen,
Zane Shelley83da2452019-10-25 15:45:34 -0500278 uint64_t i_dPos = 0);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500279
280 /**
281 * @brief Set bits in this string based on the provided string.
282 * @param i_sStr The source string.
283 * @note This will try to copy as much of the source as possible to this
284 * string, starting with the first bit in each string.
285 * @note See the other definition of this function for details and
286 * restrictions.
287 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500288 void setString(const BitString& i_sStr)
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500289 {
Zane Shelley83da2452019-10-25 15:45:34 -0500290 setString(i_sStr, 0, i_sStr.getBitLen());
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500291 }
292
293 /**
294 * @brief Masks (clears) any bits set in this string that correspond to bits
295 * set in the given string (this & ~mask).
Ben Tynera8126fd2019-08-01 19:40:07 -0500296 * @param i_mask The mask string (right justified).
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500297 * @note If the length of the given string is greater than the length of
298 * this string, then the extra bits are ignored.
299 * @note If the length of the given string is less than the length of this
300 * string, then the extra bits in this string are not modified.
301 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500302 void maskString(const BitString& i_mask);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500303
304 /**
305 * @param i_str The string to compare.
306 * @return True if the strings are equivalent, false otherwise.
307 * @pre Both strings must be of equal length and have same values to be
308 * equal.
309 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500310 bool isEqual(const BitString& i_str) const;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500311
312 /** @return True if there are no bit set(1) in this bit string, false
313 * otherwise. */
314 bool isZero() const;
315
316 /**
317 * @param i_pos The starting position of the target range.
318 * @param i_len The length of the target range.
319 * @return The number of bits that are set(1) in given range of this string.
320 * @pre nullptr != getBufAddr()
321 * @pre i_pos + i_len <= getBitLen()
322 */
Zane Shelley83da2452019-10-25 15:45:34 -0500323 uint64_t getSetCount(uint64_t i_pos, uint64_t i_len) const;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500324
325 /** @return The number of bits that are set(1) in this string. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500326 uint64_t getSetCount() const
327 {
328 return getSetCount(0, getBitLen());
329 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500330
331 /** @brief Comparison operator. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500332 bool operator==(const BitString& i_str) const
333 {
334 return isEqual(i_str);
335 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500336
Zane Shelley6eb61902020-05-15 22:25:58 -0500337 /**
338 * @brief Less-than operator.
339 *
340 * IMPORTANT:
341 * The purpose of this function is primarily for sorting these objects in
342 * data structures like map and vector. It does not guarantee a less than
343 * comparison of the bit strings because bit strings can vary in length and
344 * it is difficult to define that kind of comparison.
345 */
Zane Shelleyec06f822019-12-05 22:23:19 -0600346 bool operator<(const BitString& i_str) const;
347
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500348 /** @brief Bitwise NOT operator. */
349 BitStringBuffer operator~() const;
350
351 /** @brief Bitwise AND operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500352 BitStringBuffer operator&(const BitString& i_bs) const;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500353
354 /** @brief Bitwise OR operator. */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500355 BitStringBuffer operator|(const BitString& i_bs) const;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500356
357 /** @brief Right shift operator. */
Zane Shelley83da2452019-10-25 15:45:34 -0500358 BitStringBuffer operator>>(uint64_t i_shift) const;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500359
360 /** @brief Left shift operator. */
Zane Shelley83da2452019-10-25 15:45:34 -0500361 BitStringBuffer operator<<(uint64_t i_shift) const;
Zane Shelleyd0af3582019-09-19 10:48:59 -0500362
363 /**
364 * @brief Explicitly disables copy from BitString.
365 *
Zane Shelleyfe27b652019-10-28 11:33:07 -0500366 * Prevents assigning a BitString& to a BitString, which would strip
Zane Shelleyd0af3582019-09-19 10:48:59 -0500367 * polymorphism.
368 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500369 BitString(const BitString& i_bs) = delete;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500370
Ben Tynera8126fd2019-08-01 19:40:07 -0500371 /**
372 * @brief Explicitly disables assignment from BitStringBuffer.
373 *
374 * Allowing this would be dangerous if the BitStringBuffer goes out of scope
375 * because the BitString would point to memory that is no longer in context.
376 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500377 BitString& operator=(const BitStringBuffer& i_bsb) = delete;
Ben Tynera8126fd2019-08-01 19:40:07 -0500378
379 /**
380 * @brief Explicitly disables copy from BitStringBuffer.
381 *
382 * Allowing this would be dangerous if the BitStringBuffer goes out of scope
383 * because the BitString would point to memory that is no longer in context.
384 */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500385 BitString(const BitStringBuffer& i_bsb) = delete;
Ben Tynera8126fd2019-08-01 19:40:07 -0500386
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500387 protected: // functions
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500388 /**
389 * @param i_newBufAddr The starting address of the new bit string buffer.
390 * @pre Before calling this function, make sure you deallocate the old
391 * buffer to avoid memory leaks.
392 */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500393 void setBufAddr(void* i_newBufAddr)
394 {
Zane Shelley5a78fa82022-09-16 16:49:58 -0500395 iv_bufAddr = static_cast<uint8_t*>(i_newBufAddr);
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500396 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500397
398 /** @param i_newBitLen The new bit length of this bit string buffer. */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500399 void setBitLen(uint64_t i_newBitLen)
400 {
401 iv_bitLen = i_newBitLen;
402 }
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500403
404 private: // functions
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500405 /**
406 * @brief Given a bit position within the bit string, this function returns
407 * the address that contains the bit position and the bit position
408 * relative to that address.
409 * @param o_relPos The returned relative position.
410 * @param i_absPos The inputted absolute position.
411 * @return The relative address.
412 * @pre nullptr != getBufAddr()
413 * @pre i_absPos < getBitLen()
414 */
Zane Shelley7f7a42d2019-10-28 13:28:31 -0500415 uint8_t* getRelativePosition(uint64_t& o_relPos, uint64_t i_absPos) const;
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500416
Zane Shelley7c8faa12019-10-28 22:26:28 -0500417 private:
Zane Shelley5a78fa82022-09-16 16:49:58 -0500418 uint64_t iv_bitLen; ///< The bit length of this buffer.
419 uint8_t* iv_bufAddr; ///< The beginning address of this buffer.
420 uint64_t iv_offset; ///< Start position offset
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500421};
422
Zane Shelley72fd2e42022-11-12 12:14:53 -0600423// ##############################################################################
424// BitStringBuffer class
425// ##############################################################################
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500426
427/** A BitStringBuffer is a BitString that maintains its own buffer in memory. It
428 * guarantees that sufficient memory is allocated and deallocated in the
429 * constructor and destructor, respectively. In addition, the assignment
430 * operator will adjust the amount of memory needed, as necessary, for the
431 * assignment. */
432class BitStringBuffer : public BitString
433{
434 public: // functions
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500435 /**
436 * @brief Constructor
437 * @param i_bitLen Number of bits in the string.
438 */
Zane Shelley83da2452019-10-25 15:45:34 -0500439 explicit BitStringBuffer(uint64_t i_bitLen);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500440
441 /** @brief Destructor */
442 ~BitStringBuffer();
443
444 /** @brief Copy constructor from BitString */
Zane Shelleyd0659242020-05-15 23:02:29 -0500445 explicit BitStringBuffer(const BitString& i_bs);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500446
447 /** @brief Copy constructor from BitStringBuffer */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500448 BitStringBuffer(const BitStringBuffer& i_bsb);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500449
450 /** @brief Assignment from BitString */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500451 BitStringBuffer& operator=(const BitString& i_bs);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500452
453 /** @brief Assignment from BitStringBuffer */
Zane Shelleyfe27b652019-10-28 11:33:07 -0500454 BitStringBuffer& operator=(const BitStringBuffer& i_bsb);
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500455
456 private: // functions
Zane Shelleyfd3f9cc2019-07-29 15:02:24 -0500457 /** @brief Deallocates the old buffer, if needed, and initializes the new
458 * buffer. */
459 void initBuffer();
460};
461
Zane Shelley871adec2019-07-30 11:01:39 -0500462} // end namespace libhei