11 #ifndef __APEX_BUFFER_H__
12 #define __APEX_BUFFER_H__
59 myTypeDefinition = typedfn;
83 void *myData =
nullptr;
87 #define APEX_INVALID_DATAID -1
108 myTypedBuffers.clear();
115 for (
auto &
buf : myTypedBuffers)
117 if (
buf.typeDefinition() == type_defn)
127 return &myTypedBuffers[index];
134 for (
auto &
buf : myTypedBuffers)
136 if (
buf.typeDefinition() == type_defn)
142 if (result >= myTypedBuffers.size())
151 exint type_index = typeIndex(type_defn);
154 UTdebugPrint(
"Attempt to allocate multiple buffers of the same type!");
157 exint t_buf_idx = myTypedBuffers.emplace_back(type_defn);
158 myTypedBuffers[t_buf_idx].allocate(size);
168 void lock() { myIsLocked =
true; }
173 bool myIsLocked =
false;
194 if (!typed_buffer ||
offset < 0)
204 if (!typed_buffer ||
offset < 0)
223 template <
typename T>
225 isType(
const APEX_Argument &
arg)
227 const APEX_TypeDefinitionBase *test_type = findTypeDef<T>();
228 return arg.type_defn == test_type;
233 template <
typename T>
235 castArg(APEX_Argument *
arg)
237 if (!isType<T>(*arg))
239 void *arg_ptr = arg->getVoidPtr();
240 return reinterpret_cast<T *
>(arg_ptr);
245 template <
typename T>
247 castArg(
const APEX_Argument *arg)
249 if (!isType<T>(*arg))
251 const void *arg_ptr = arg->getVoidPtr();
252 return reinterpret_cast<const T *
>(arg_ptr);
256 template <
typename T>
258 castArgValue(APEX_Argument &arg)
276 if (
Bool *value = castArg<Bool>(&arg))
278 else if (
Int *value = castArg<Int>(&arg))
279 result = (*value != 0);
291 if (
Int *value = castArg<Int>(&arg))
293 else if (
Bool *value = castArg<Bool>(&arg))
294 result = (*value? 1 : 0);
301 copyArgData(APEX_Argument *
dst,
const APEX_Argument *
src,
bool allow_implicit_conversion=
false)
306 void *dst_ptr = dst->getVoidPtr();
307 const void *src_ptr = src->getVoidPtr();
308 if (dst->type_defn != src->type_defn)
310 if (!allow_implicit_conversion)
313 if (isType<Bool>(*dst) && isType<Int>(*src))
316 Int val_int = *castArg<Int>(
src);
317 Bool val_bool = val_int != 0;
318 Bool &dst_val = *castArg<Bool>(
dst);
322 else if (isType<Int>(*dst) && isType<Bool>(*src))
325 Bool val_bool = *castArg<Bool>(
src);
326 Int val_int = val_bool? 1 : 0;
327 Int &dst_val = *castArg<Int>(
dst);
334 if (!dst->type_defn->isCopyable())
336 if (dst_ptr == src_ptr)
338 dst->type_defn->setData(dst_ptr, src_ptr);
356 #endif // __APEX_BUFFER_H__
#define UTdebugPrint(...)
GLenum GLuint GLenum GLsizei const GLchar * buf
APEX_DataID dataId() const
static APEX_DataID nextDataId()
Get a new unique data ID.
const APEX_TypeDefinitionBase * typeDefinition()
GLsizei const GLfloat * value
Expandable storage of arbitrary runtime types for APEX program state. Indexed by APEX_Buffer.
**But if you need a result
void * data(exint index=0)
APEX_API void APEXformatString(String &result, const String &format_str, const UT_Array< const APEX_Argument * > &args)
auto arg(const Char *name, const T &arg) -> detail::named_arg< Char, T >
Holds all of the memory for execution state of a compiled APEX graph.
std::optional< T > UT_Optional
constexpr auto set(type rhs) -> int
APEX_TypedBuffer(const APEX_TypeDefinitionBase *typedfn)
void copyDataId(const APEX_TrackedArgument &other)
APEX_TypedBuffer * findTypedBuffer(const APEX_TypeDefinitionBase *type_defn)
Get the type-specific storage for a given type, or nullptr if not found.
const void * getVoidPtr() const
void lock()
Prevent further modifications to the layout of this buffer.
exint typeIndex(const APEX_TypeDefinitionBase *type_defn)
Get the index at which a given type is stored in this buffer, or -1 if not present.
**If you just want to fire and args
exint allocate(const APEX_TypeDefinitionBase *type_defn, exint size)
APEX_API UT_StringHolder APEXformatArg(const APEX_Argument *arg)
Returns the value of the argument as a string.
Represents a location for a single object inside of an APEX_Buffer.
APEX_TypedBuffer * getTypedBuffer(exint index)