ae2f_docs
BitVec.hpp
Go to the documentation of this file.
1/**
2 * @file BitVec.hpp
3 * @author ae2f
4 * @brief
5 * @date 2025-02-01
6 *
7 * @copyright Copyright (c) 2025
8 *
9 */
10
11
12#if !defined(ae2f_BitVector_hpp)
13#define ae2f_BitVector_hpp
14
15#include "./LangVer.h"
16
17#if __ae2f_stdcheck_CC(201103L)
18#include <type_traits>
19
20#include "./BitVec.h"
21#include "Pack/Beg.h"
22
23namespace ae2f {
24
25 /** @brief
26 * @tparam t
27 * Is the class binding for BitVec.h
28 **/
29 template<typename t>
30 class rBitVec {
31 static ae2f_BitVecSizeDef(t);
32 static ae2f_BitVecFndOneDef(t);
33
34 public:
36
37 /// @brief
38 /// The actual integer.
39 t obj;
40
41 constexprmethod rBitVec(const t& obj) noexcept : obj(obj) {
42
43 static_assert(std::is_integral<t>::value, "t is not integer");
44 }
45 constexprmethod rBitVec(const t&& obj) noexcept : obj(obj) {
46 static_assert(std::is_integral<t>::value, "t is not integer");
47 }
48
49 template<typename T = t>
50 constexprmethod rBitVec(const rBitVec<T>& vec) noexcept : obj(vec.obj) {
51 static_assert(std::is_integral<t>::value, "t is not integer");
52 static_assert(std::is_integral<T>::value, "T is not integer");
53 }
54
55 template<typename T = t>
56 constexprmethod rBitVec(const rBitVec<T>&& vec) noexcept : obj(vec.obj) {
57 static_assert(std::is_integral<t>::value, "t is not integer");
58 static_assert(std::is_integral<T>::value, "T is not integer");
59 }
60
61 constexprmethod static rBitVec<t> Filled(idx_t length) noexcept {
62 return rBitVec(_ae2f_BitVecFilled(length, t));
63 }
64
65 constexprmethod bool Get(idx_t i) const noexcept {
66 return ae2f_BitVecGet(obj, i);
67 }
68
69 constexprmethod rBitVec<t> GetRangedConst(idx_t start, idx_t end) const noexcept {
70 return ae2f_BitVecGetRanged(this->obj, start, end);
71 }
72 constexprmethod rBitVec<t>& Set(idx_t i, bool val) noexcept {
73 obj = ae2f_BitVecSet(this->obj, i, val);
74 return *this;
75 }
76
77 constexprmethod rBitVec<t> SetConst(idx_t i, bool val) const noexcept {
78 return ae2f_BitVecSet(this->obj, i, val);
79 }
80 constexprmethod rBitVec<t> SetRangedConst(idx_t start, idx_t end, rBitVec<t> val) const noexcept {
81 return ae2f_BitVecSetRanged(this->obj, start, end, val.obj);
82 }
83 constexprmethod rBitVec<t>& SetRanged(idx_t start, idx_t end, rBitVec<t> val) noexcept {
84 this->obj = const_cast<const rBitVec<t>*>(this)->SetRangedConst(start, end, val).obj;
85 return *this;
86 }
87
88 constexprmethod const idx_t Size() const noexcept {
89 return ae2f_BitVecSizeDefName(t)(this->obj);
90 }
91
92 constextendedmethod const rBitVec<t> FndOne() const noexcept {
93 return ae2f_BitVecFndOneDefName(t)(this->obj);
94 }
95 };
96 }
97
98#include "Pack/End.h"
99#else
100#include "./BitVec.h"
101#endif
102
103#endif // !defined(ae2f_Macro_BitVector_hpp) && defined(__cplusplus)
#define ae2f_BitVecGet(vector, idx)
Gets a bit of [vector] from index of [idx].
Definition BitVec.h:69
#define ae2f_BitVecSizeDef(t)
Gets the vec's last index where the flag set to 1.
Definition BitVec.h:114
#define ae2f_BitVecFndOneDefName(t)
Gets the vector that vec's first flag set to 1.
Definition BitVec.h:127
#define ae2f_BitVecSet(vector, idx, val)
Sets a bit of [vector] from index of [idx] by [val].
Definition BitVec.h:101
#define ae2f_BitVecGetRanged(vector, start, end)
Gets the bits of [vector] between index of [start] and [end]. It will normalise the values of [start...
Definition BitVec.h:60
#define _ae2f_BitVecFilled(len, vec_t)
Generates the vector filled in 1.
Definition BitVec.h:30
#define ae2f_BitVecFndOneDef(t)
Gets the vector that vec's first flag set to 1.
Definition BitVec.h:133
#define ae2f_BitVecSizeDefName(t)
Gets the vec's last index where the flag set to 1.
Definition BitVec.h:108
#define ae2f_BitVecSetRanged(vector, start, end, val)
Sets the bits of [vector] from index of [start] and [end] by [val]. It will normalise the values of ...
Definition BitVec.h:91
uint8_t ae2f_BitVecI_t
The pre-defined index type for Bit vector.
Definition BitVec.h:25
#define constexprmethod
Definition Constexpr.hpp:50
#define constextendedmethod
Definition Constexpr.hpp:43
#define __ae2f_stdcheck_CC(v)
Definition LangVer.h:72
int main()
constexprmethod rBitVec< t > SetRangedConst(idx_t start, idx_t end, rBitVec< t > val) const noexcept
Definition BitVec.hpp:80
constexprmethod rBitVec(const t &&obj) noexcept
Definition BitVec.hpp:45
t obj
The actual integer.
Definition BitVec.hpp:39
constextendedmethod const rBitVec< t > FndOne() const noexcept
Definition BitVec.hpp:92
constexprmethod rBitVec< t > GetRangedConst(idx_t start, idx_t end) const noexcept
Definition BitVec.hpp:69
constexprmethod rBitVec< t > SetConst(idx_t i, bool val) const noexcept
Definition BitVec.hpp:77
constexprmethod rBitVec(const rBitVec< T > &&vec) noexcept
Definition BitVec.hpp:56
constexprmethod bool Get(idx_t i) const noexcept
Definition BitVec.hpp:65
constexprmethod rBitVec(const rBitVec< T > &vec) noexcept
Definition BitVec.hpp:50
constexprmethod rBitVec(const t &obj) noexcept
Definition BitVec.hpp:41
constexprmethod rBitVec< t > & Set(idx_t i, bool val) noexcept
Definition BitVec.hpp:72
constexprmethod rBitVec< t > & SetRanged(idx_t start, idx_t end, rBitVec< t > val) noexcept
Definition BitVec.hpp:83
static constexprmethod rBitVec< t > Filled(idx_t length) noexcept
Definition BitVec.hpp:61
constexprmethod const idx_t Size() const noexcept
Definition BitVec.hpp:88
ae2f_BitVecI_t idx_t
Definition BitVec.hpp:35
This namespace contains the class from this library.
Definition BitVec.hpp:23