1212
1313namespace Rfx
1414{
15+
16+ #ifdef _DEBUG
17+ constexpr bool debug_mode = true ;
18+ #else
19+ constexpr bool debug_mode = false ;
20+ #endif
21+
1522template <typename T>
1623concept BitStreamable = (std::is_arithmetic_v<T> || std::is_enum_v<T>);
1724
@@ -37,6 +44,9 @@ TIter copyBits(TRange first, TRange last, TIter pos)
3744 requires(BitStreamable<std::iter_value_t <TRange>> && std::same_as<std::iter_value_t <TIter>, std::byte>)
3845{
3946 size_t size = last - first;
47+ if (debug_mode && size == 0 )
48+ return pos;
49+
4050 const std::byte* ptr = reinterpret_cast <const std::byte*>(&(*first));
4151 return std::copy (ptr, ptr + (sizeof (std::iter_value_t <TRange>) * size), pos);
4252}
@@ -67,6 +77,9 @@ TIter copyBits(TIter pos, TRange first, TRange last)
6777 requires(BitStreamable<std::iter_value_t <TRange>> && std::same_as<std::iter_value_t <TIter>, std::byte>)
6878{
6979 size_t size = last - first;
80+ if (debug_mode && size == 0 )
81+ return pos;
82+
7083 std::byte* ptr = reinterpret_cast <std::byte*>(&(*first));
7184 auto endPos = pos + (sizeof (std::iter_value_t <TRange>) * size);
7285 std::copy (pos, endPos, ptr);
@@ -91,16 +104,6 @@ void pushBits(const TRange& range, Blob& blob)
91104 copyBits (range.begin (), range.end (), it);
92105}
93106
94- template <std::ranges::range TRange>
95- void pushBits (const TRange& range, Blob& blob)
96- requires(BitStreamable<std::ranges::range_value_t <TRange>> && !std::ranges::sized_range<TRange>)
97- {
98- for (auto it = range.begin (); it != range.end (); ++it)
99- {
100- auto pos = blob.grow (sizeof (std::ranges::range_value_t <TRange>));
101- copyBits (*it, pos);
102- }
103- }
104107
105108// /////////////////////////////////////////////////////////////////////////////
106109
@@ -124,8 +127,6 @@ T popBits(BlobRange& blobRange)
124127 return value;
125128}
126129
127-
128-
129130// / for containers of BitStreamable (like std::list<double>)
130131template <std::ranges::sized_range TRange>
131132auto popBits (TRange& valueRange, BlobRange blobRange)
@@ -136,16 +137,6 @@ auto popBits(TRange& valueRange, BlobRange blobRange)
136137 return copyBits (blobRange.begin (), valueRange.begin (), valueRange.end ());
137138}
138139
139- // / for ranges of BitStreamables of unkown size (like std::ranges::subrange<std::list<double>::iterator>)
140- template <std::ranges::range TRange>
141- auto popBits (TRange& valueRange, BlobRange blobRange)
142- requires(BitStreamable<std::ranges::range_value_t <TRange>> && !std::ranges::sized_range<TRange>)
143- {
144- Blob::const_iterator it = blobRange.begin ();
145- for (auto & value: valueRange)
146- it = popBits (value, BlobRange (it, blobRange.end ()));
147- return it;
148- }
149140
150141
151142
0 commit comments