11 #ifndef __APEX_BUFFER_H__
12 #define __APEX_BUFFER_H__
58 myTypeDefinition = typedfn;
82 void *myData =
nullptr;
86 #define APEX_INVALID_DATAID -1
107 myTypedBuffers.clear();
114 for (
auto &
buf : myTypedBuffers)
116 if (
buf.typeDefinition() == type_defn)
126 return &myTypedBuffers[index];
133 for (
auto &
buf : myTypedBuffers)
135 if (
buf.typeDefinition() == type_defn)
141 if (result >= myTypedBuffers.size())
150 exint type_index = typeIndex(type_defn);
153 UTdebugPrint(
"Attempt to allocate multiple buffers of the same type!");
156 exint t_buf_idx = myTypedBuffers.emplace_back(type_defn);
157 myTypedBuffers[t_buf_idx].allocate(size);
167 void lock() { myIsLocked =
true; }
172 bool myIsLocked =
false;
193 if (!typed_buffer ||
offset < 0)
203 if (!typed_buffer ||
offset < 0)
222 template <
typename T>
224 isType(
const APEX_Argument &
arg)
226 const APEX_TypeDefinitionBase *test_type = findTypeDef<T>();
227 return arg.type_defn == test_type;
232 template <
typename T>
234 castArg(APEX_Argument *
arg)
236 if (!isType<T>(*arg))
238 void *arg_ptr = arg->getVoidPtr();
239 return reinterpret_cast<T *
>(arg_ptr);
244 template <
typename T>
246 castArg(
const APEX_Argument *arg)
248 if (!isType<T>(*arg))
250 const void *arg_ptr = arg->getVoidPtr();
251 return reinterpret_cast<const T *
>(arg_ptr);
256 copyArgData(APEX_Argument *
dst,
const APEX_Argument *
src,
bool allow_implicit_conversion=
false)
261 void *dst_ptr = dst->getVoidPtr();
262 const void *src_ptr = src->getVoidPtr();
263 if (dst->type_defn != src->type_defn)
265 if (!allow_implicit_conversion)
268 if (isType<Bool>(*dst) && isType<Int>(*src))
271 Int val_int = *castArg<Int>(
src);
272 Bool val_bool = val_int != 0;
273 Bool &dst_val = *castArg<Bool>(
dst);
277 else if (isType<Int>(*dst) && isType<Bool>(*src))
280 Bool val_bool = *castArg<Bool>(
src);
281 Int val_int = val_bool? 1 : 0;
282 Int &dst_val = *castArg<Int>(
dst);
289 if (!dst->type_defn->isCopyable())
291 if (dst_ptr == src_ptr)
293 dst->type_defn->setData(dst_ptr, src_ptr);
297 template <
typename T>
301 const APEX_Argument *arg)
304 const T *
val = castArg<T>(
arg);
313 using ArrayT = ApexArray<T>;
314 const ArrayT *val = castArg<ArrayT>(
arg);
328 const APEX_Argument *arg)
333 if (APEXformatArgT<String>(fmt_arg, arg))
335 if (APEXformatArgT<Bool>(fmt_arg, arg))
337 if (APEXformatArgT<Int>(fmt_arg, arg))
339 if (APEXformatArgT<Float>(fmt_arg, arg))
341 if (APEXformatArgT<Vector2>(fmt_arg, arg))
343 if (APEXformatArgT<Vector3>(fmt_arg, arg))
345 if (APEXformatArgT<Vector4>(fmt_arg, arg))
347 if (APEXformatArgT<Matrix3>(fmt_arg, arg))
349 if (APEXformatArgT<Matrix4>(fmt_arg, arg))
351 if (APEXformatArgT<Geometry>(fmt_arg, arg))
358 APEXformatArg(
const APEX_Argument *arg)
361 if (!APEXformatArg(fmt_arg, arg))
379 for (
const APEX_Argument *arg : args)
387 if (APEXformatArg(fmt_arg, arg))
395 tmp += arg->type_defn->repr();
403 result = std::move(output);
408 #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.
SYS_FORCE_INLINE const char * buffer() const
**But if you need a result
void * data(exint index=0)
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.
exint emplace_back(S &&...s)
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)
Represents a location for a single object inside of an APEX_Buffer.
size_t appendFormatByArray(const char *fmt, const UT_Array< UT::Format::ArgValue > &args, bool report_errors=true)
Like appendFormat() except it that uses an array of arguments.
APEX_TypedBuffer * getTypedBuffer(exint index)