12 #ifndef __UN_DataBuffer_h__
13 #define __UN_DataBuffer_h__
36 myBuffer.bumpSize(size);
52 {
return myBuffer[
index ]; }
59 {
return std::move( myBuffer[ index ] ); }
71 {
op( myBuffer[ index ] ); }
82 myBuffer.insert( init_value, index );
88 myBuffer.appendMultiple( value, count );
97 start + size <= src.
size() );
98 myBuffer.append( src.myBuffer.data() +
start,
size );
103 { myBuffer.clear(); }
112 { myBuffer.setCapacityIfNeeded( min_capacity ); }
116 {
return myBuffer.isValidIndex( index ); }
165 exint word_size = wordCapacity( size );
166 myWordBuffer.bumpSize( word_size );
167 myWordBuffer.constant( myZero );
175 BlockType &word = myWordBuffer[ wordIndex(index) ];
177 word = (BlockType(value) << bit) | (word & ~(BlockType(1) << bit));
184 BlockType word = myWordBuffer[ wordIndex(index) ];
186 return (word >> bit) & BlockType(1);
202 if( wordIndex( index ) >= myWordBuffer.size() )
203 myWordBuffer.append();
224 for(
exint i = start,
n = start + size; i <
n; i++ )
232 myWordBuffer.clear();
245 myWordBuffer.setCapacityIfNeeded( wordCapacity( min_capacity ));
251 return index >= 0 && index < mySize;
257 static constexpr
int myBitsPerWord =
sizeof(BlockType)*8;
258 static constexpr
int myWordShift =
SYS_LOG2F(myBitsPerWord);
259 static constexpr
int myWordMask = (1 << myWordShift) - 1;
260 static constexpr BlockType myZero = 0;
263 static inline exint wordIndex(
exint bit_index)
264 {
return (bit_index >> myWordShift); }
269 return (bit_capacity > 0) ?
270 (bit_capacity.
exintValue() - 1) / myBitsPerWord + 1 : 0;
295 : myOptionPtr( std::move(
value) ) {}
331 namespace UN_DataBufferUtils
334 template<
typename V,
typename B>
339 buffer.setData( index, value );
344 template<
typename V,
typename B>
349 buffer.setData( index, std::forward<V>(value) );
353 template<
typename V,
typename B>
354 static inline const V &
355 getDataRef(
const B &buffer,
UN_DataIndex index,
const V &default_value )
358 return buffer.getDataRef( index );
360 return default_value;
369 template<
typename V,
typename B>
374 return V(buffer.getDataVal( index ));
376 return V(default_value);
380 template<
typename V,
typename B>
382 stealData(
B &buffer,
UN_DataIndex index,
const V &default_value )
385 return buffer.stealData( index );
387 return V( default_value );
398 template<
typename OP,
typename B>
403 buffer.updateData( index, op );
constexpr exint exintValue() const
Returns an exint value of this number.
UT_OptionEntryPtr & valuePtr()
void setData(UN_DataIndex index, const T &value)
Sets the data value for the entry at a given index.
V getDataVal(const B &buffer, UN_DataIndex index, const V &default_value)
void setCapacityIfNeeded(UN_DataSize min_capacity)
void appendData(const UN_DataBuffer< bool > &src, UN_DataIndex start, UN_DataSize size)
Appends a span of entries from another buffer.
void setData(UN_DataIndex index, bool value)
Sets the data value for the entry at a given index.
GLsizei const GLfloat * value
bool getDataVal(UN_DataIndex index) const
Returns the data value for the entry at a given index.
void addData(UN_DataIndex index, bool init_value=false)
Adds an entry slot to the data buffer.
void setData(UN_DataIndex index, T &&value)
Sets the data value for the entry at a given index.
const T & operator[](UN_DataIndex index) const
UN_ValueHandle & operator=(UN_ValueHandle const &other)
void clear()
Resets the data to an empty buffer.
UN_DataBuffer(UN_DataSize size)
bool isValidIndex(UN_DataIndex index) const
Return true if given index is valid.
UN_DataBuffer(UN_DataSize size)
void setCapacityIfNeeded(UN_DataSize min_capacity)
void clear()
Resets the data to an empty buffer.
void addData(UN_DataIndex index, const T &init_value=T())
Adds an entry slot to the data buffer.
Data buffer specialization for boolean (bit) values.
T stealData(UN_DataIndex index)
Returns a moved value from an entry in a data buffer.
void appendData(const T &value, exint count)
Appends count copies of the given value.
bool operator[](UN_DataIndex index) const
const UT_OptionEntryPtr & valuePtr() const
UN_ValueHandle(UN_ValueHandle const &other)
bool isValidIndex(UN_DataIndex index) const
Return true if given index is valid.
void updateData(UN_DataIndex index, const OP &op)
void appendData(const UN_DataBuffer< T > &src, UN_DataIndex start, UN_DataSize size)
Appends a span of entries from another buffer.
UN_ValueHandle(UT_OptionEntryPtr &&value)
UN_DataSize size() const
Returns the number of elements held in the data buffer.
~UN_ValueHandle()=default
void appendData(bool value, exint count)
Appends count copies of the given value.
UN_DataSize size() const
Returns the number of bits held in the data buffer.
UT_UniquePtr< UT_OptionEntry > UT_OptionEntryPtr
const T & getDataRef(UN_DataIndex index) const