12 #ifndef __UN_GenericData_h__
13 #define __UN_GenericData_h__
49 bool isValid()
const {
return myValue >= 0; }
67 template<
typename ContainerT,
typename DataIDT>
75 : myContainer(&container), myBufferID(buf_id) {}
90 return myContainer->bufferType(myBufferID);
96 return myContainer->bufferName(myBufferID);
103 myContainer->setGenericData(myBufferID,
id, std::forward<T>(
value));
110 return myContainer->template genericDataRef<T>(myBufferID,
id);
117 return myContainer->template genericDataVal<T>(myBufferID,
id);
124 return myContainer->template stealGenericData<T>(myBufferID,
id);
128 template<
typename T,
typename OP>
131 myContainer->template updateGenericData<T>(myBufferID,
id,
op);
135 ContainerT *myContainer =
nullptr;
233 const D &default_value,
237 auto it = myBufferIndexFromName.find( name );
238 if( it != myBufferIndexFromName.end() )
240 if( myBuffers[it->second].myType == type )
245 auto id = addBuffer( name, type, buffer_size );
249 std::visit( [&default_value](
auto &
buf )
251 using T = std::decay_t<decltype(
buf.myDefault)>;
252 if constexpr( std::is_constructible_v<T, const D &> )
253 buf.myDefault =
T(default_value);
255 UT_ASSERT( !
"Incompatible default value type" );
256 }, myBuffers[
id.value()].myBuffer );
263 {
return myBuffers[
id.value()].myType; }
267 {
return myBuffers.size(); }
275 {
return myBuffers[
id.value()].myName; }
284 auto &
buf = std::get<UN_GenericBuffer<T>>(
285 myBuffers[buf_id.
value()].myBuffer );
286 UN_DataBufferUtils::setData( buf.myBuffer, index, value );
296 auto &
buf = std::get<UN_GenericBuffer<std::decay_t<T>>>(
297 myBuffers[buf_id.
value()].myBuffer );
298 UN_DataBufferUtils::setData( buf.myBuffer, index,
299 std::forward<T>(
value) );
310 auto &
buf = std::get<UN_GenericBuffer<T>>(
311 myBuffers[buf_id.
value()].myBuffer );
312 return UN_DataBufferUtils::getDataRef( buf.myBuffer, index,
325 auto &
buf = std::get<UN_GenericBuffer<T>>(
326 myBuffers[buf_id.
value()].myBuffer );
338 auto &
buf = std::get<UN_GenericBuffer<T>>(
339 myBuffers[buf_id.
value()].myBuffer );
340 return UN_DataBufferUtils::stealData(
341 buf.myBuffer, index, buf.myDefault );
346 template<
typename T,
typename OP>
352 auto &
buf = std::get<UN_GenericBuffer<T>>(
353 myBuffers[buf_id.
value()].myBuffer );
354 UN_DataBufferUtils::updateData( buf.myBuffer, index, op );
366 void removeAllData();
369 void setCapacityIfNeeded(
UN_DataSize min_capacity );
376 bool isDataSizeConsistent(
378 bool isDataSizeConsistent()
const;
UN_GenericBufferType
Supported types for generic data buffers.
GLenum GLuint GLenum GLsizei const GLchar * buf
V getDataVal(const B &buffer, UN_DataIndex index, const V &default_value)
UN_GenericDataBufferRef(ContainerT &container, UN_GenericBufferID buf_id)
T getDataVal(UN_GenericBufferID buf_id, UN_DataIndex index) const
UN_DataBuffer< T > myBuffer
UN_GenericBufferType bufferType(UN_GenericBufferID id) const
Returns the type of the buffer identified by the given ID.
UN_GenericDataBufferRef()=default
void updateData(DataIDT id, const OP &op)
Updates the data value in-place via a callable.
GLsizei const GLfloat * value
T dataVal(DataIDT id) const
Returns a copy of the data value for a given data ID.
std::variant< UN_GenericBuffer< UT_StringHolder >, UN_GenericBuffer< UT_StringArray >, UN_GenericBuffer< bool >, UN_GenericBuffer< exint >, UN_GenericBuffer< float >, UN_GenericBuffer< UT_Vector2D >, UN_GenericBuffer< UT_Color > > UN_GenericBufferVariant
void setData(DataIDT id, T &&value)
Sets the data value for a given data ID.
ContainerT & container() const
UN_GenericBufferType bufferType(UN_GenericBufferID id) const
Returns the data buffer type.
T stealData(DataIDT id)
Moves the data value out of the buffer for a given data ID.
void setData(UN_GenericBufferID buf_id, UN_DataIndex index, T &&value)
Sets the data value via move for a given buffer and index.
const UT_StringHolder & bufferName(UN_GenericBufferID id) const
Returns the name of the buffer identified by the given ID.
GLint GLint GLsizei GLint GLenum GLenum type
UN_GenericBufferID bufferID() const
const T & getDataRef(UN_GenericBufferID buf_id, UN_DataIndex index) const
UN_GenericBuffer(UN_DataSize size, D &&default_value)
GLuint const GLchar * name
exint numBuffers() const
Returns the number of generic buffers.
const T & dataRef(DataIDT id) const
Returns a const ref to the data value for a given data ID.
IMATH_NAMESPACE::V2f IMATH_NAMESPACE::Box2i std::string this attribute is obsolete as of OpenEXR v3 float
void setData(UN_GenericBufferID buf_id, UN_DataIndex index, const T &value)
Sets the data value for a given buffer and index.
UN_GenericBufferID(exint v)
UN_GenericBuffer(UN_DataSize size=UN_DataSize(0))
UN_GenericBufferID()=default
UN_GenericBufferID addBuffer(const UT_StringRef &name, UN_GenericBufferType type, const D &default_value, UN_DataSize buffer_size)
void updateData(UN_GenericBufferID buf_id, UN_DataIndex index, const OP &op)
const UT_StringHolder & bufferName(UN_GenericBufferID id) const
Returns the name of the data buffer.
T stealData(UN_GenericBufferID buf_id, UN_DataIndex index)