17#ifndef AGXDATA_FORMAT_H
18#define AGXDATA_FORMAT_H
31# pragma warning(disable:4100)
57 void* target,
const Format* targetFormat,
const void* source,
const Format* sourceFormat,
size_t numElements);
81 Format(
const agx::Name& formatName,
const agx::Name& implementationName,
size_t size, TransformFunction byteSwapFunction, TransformFunction copyFunction);
102 const agx::Name& getImplementationName()
const;
107 size_t getSize()
const;
118 void swapByteOrder(
void *target,
const void *source,
size_t numElements)
const;
142 virtual void copyElements(
void *buffer,
const void *source,
size_t numElements)
const;
148 virtual void moveElements(
void *target,
void *source,
size_t numElements)
const;
184 friend class TypeManager;
194 TransformFunction transformer,
const Format* targetFormat,
const Format* sourceFormat);
207 Format *getElementFormat();
208 const Format *getElementFormat()
const;
213 using Format::copyElement;
214 using Format::moveElement;
216 template <
typename T>
219 template <
typename T>
240 virtual void copyElement(
void *target,
const void *source)
const override;
241 virtual void copyElements(
void *target,
const void *source,
size_t numElements)
const override;
242 virtual void moveElement(
void *target,
void *source)
const override;
243 virtual void moveElements(
void *target,
void *source,
size_t numElements)
const override;
245 virtual void swapElements(
void *element1,
void *element2)
const override;
258 VectorFormat(
Format *elementFormat);
260 virtual void initializeElement(
void *element,
const void *value)
const override;
261 virtual void initializeElements(
void *buffer,
const void *value,
size_t numElements)
const override;
262 virtual void constructElement(
void *element)
const override;
263 virtual void constructElements(
void *buffer,
size_t numElements)
const override;
264 virtual void destroyElement(
void *element)
const override;
265 virtual void destroyElements(
void *buffer,
size_t numElements)
const override;
266 virtual void copyElement(
void *target,
const void *source)
const override;
267 virtual void copyElements(
void *target,
const void *source,
size_t numElements)
const override;
268 virtual void moveElement(
void *target,
void *source)
const override;
269 virtual void moveElements(
void *target,
void *source,
size_t numElements)
const override;
270 virtual void swapElements(
void *element1,
void *element2)
const override;
273 virtual ~VectorFormat();
281 HashSetFormat(Format *elementFormat);
283 virtual void initializeElement(
void *element,
const void *value)
const override;
284 virtual void initializeElements(
void *buffer,
const void *value,
size_t numElements)
const override;
285 virtual void constructElement(
void *element)
const override;
286 virtual void constructElements(
void *buffer,
size_t numElements)
const override;
287 virtual void destroyElement(
void *element)
const override;
288 virtual void destroyElements(
void *buffer,
size_t numElements)
const override;
289 virtual void copyElement(
void *target,
const void *source)
const override;
290 virtual void copyElements(
void *target,
const void *source,
size_t numElements)
const override;
291 virtual void moveElement(
void *target,
void *source)
const override;
292 virtual void moveElements(
void *target,
void *source,
size_t numElements)
const override;
293 virtual void swapElements(
void *element1,
void *element2)
const override;
296 virtual ~HashSetFormat();
315 virtual void copyElement(
void *target,
const void *source)
const override;
316 virtual void copyElements(
void *target,
const void *source,
size_t numElements)
const override;
317 virtual void moveElement(
void *target,
void *source)
const override;
318 virtual void moveElements(
void *target,
void *source,
size_t numElements)
const override;
319 virtual void swapElements(
void *element1,
void *element2)
const override;
329 template <
typename T>
338 virtual void initializeElements(
void *buffer,
const void *value,
size_t numElements)
const override;
342 virtual void destroyElements(
void *buffer,
size_t numElements)
const override;
343 virtual void copyElement(
void *target,
const void *source)
const override;
344 virtual void copyElements(
void *target,
const void *source,
size_t numElements)
const override;
345 virtual void moveElement(
void *target,
void *source)
const override;
346 virtual void moveElements(
void *target,
void *source,
size_t numElements)
const override;
347 virtual void permuteElements(
void *target,
void *source,
const agx::Index *permutation,
size_t numElements)
const override;
350 virtual void swapElements(
void *element1,
void *element2)
const override;
364 typedef void (*FormatConstructorFn)();
377 FormatConstructorFn m_constructor;
378 bool m_isInitialized;
382 template <
size_t NUM_BYTES>
422 bool hasReal32()
const {
return m_callbackReal32.isValid(); }
423 bool hasReal64()
const {
return m_callbackReal64.isValid(); }
424 bool hasInt8()
const {
return m_callbackInt8.isValid(); }
425 bool hasUInt8()
const {
return m_callbackUInt8.isValid(); }
426 bool hasInt16()
const {
return m_callbackInt16.isValid(); }
427 bool hasUInt16()
const {
return m_callbackUInt16.isValid(); }
428 bool hasInt32()
const {
return m_callbackInt32.isValid(); }
429 bool hasUInt32()
const {
return m_callbackUInt32.isValid(); }
430 bool hasInt64()
const {
return m_callbackInt64.isValid(); }
431 bool hasUInt64()
const {
return m_callbackUInt64.isValid(); }
432 bool hasBool()
const {
return m_callbackBool.isValid(); }
435 CallbackType m_callbackReal32;
436 CallbackType m_callbackReal64;
437 CallbackType m_callbackInt8;
438 CallbackType m_callbackUInt8;
439 CallbackType m_callbackInt16;
440 CallbackType m_callbackUInt16;
441 CallbackType m_callbackInt32;
442 CallbackType m_callbackUInt32;
443 CallbackType m_callbackInt64;
444 CallbackType m_callbackUInt64;
445 CallbackType m_callbackBool;
455 template<
typename T>
459 std::cout <<
"Format: Hit typeless callDispatch() for C++ type " <<
typeid(T).name() << std::endl;
499 return callDispatch<T>( callbackList, m_stride, m_padding );
531 void Format::registerFormatPrimitives(const
Format* format,
agx::UInt32 stride,
agx::UInt32 padding )
533 size_t elementSize =
sizeof(T) * stride;
534 agxVerifyN(elementSize == format->getSize(),
"Size mismatch, format %s is %u bytes, packed element is %u bytes", format->fullName().c_str(), (
unsigned)format->getSize(), (
unsigned)elementSize);
535 agxVerifyN( padding < stride,
"Format: A format cannot be all padding, or contain more padding than total memory usage. "
536 "stride: %d, padding: %d.", stride, padding );
538 "Format: The format \'%s\' have already been registered.", format->fullName().c_str() );
546 #define AGX_FORMAT_INITIALIZER(_Name) \
547 static void AGX_CONCAT(__agx_createFormat, __LINE__)(); \
548 static agxData::FormatInitializer AGX_CONCAT(__agx_formatInitializer, __LINE__)(_Name, &AGX_CONCAT(__agx_createFormat, __LINE__)); \
549 static void AGX_CONCAT(__agx_createFormat, __LINE__)()
571# pragma warning(disable: 4800)
574 template <
typename TargetT,
typename SourceT>
577 for (
size_t i = 0; i < numElements; ++i)
578 ((TargetT *)targetBuffer)[i] = (TargetT)((SourceT *)sourceBuffer)[i];
581 template <
typename T>
584 ::memcpy(target, source, numElements *
sizeof(T));
604 template <class T, typename std::enable_if<std::is_copy_constructible<T>::value>::type* =
nullptr >
607 ::new((T *)element) T(*(
const T *)value);
610 template <class T, typename std::enable_if<!std::is_copy_constructible<T>::value>::type* =
nullptr >
614 ::new((T *)element) T();
618 template <
typename T>
622 template <
typename T>
630 template <
typename T>
639 *(SizeStruct *)element = *(
const SizeStruct *)value;
643 template <
typename T>
646 for (
size_t i = 0; i < numElements; ++i) {
656 for (
size_t i = 0; i < numElements; ++i)
657 ((SizeStruct *)buffer)[i] = *(
const SizeStruct *)value;
662 template <
typename T>
665 ::new((T *)element) T();
669 template <
typename T>
672 for (
size_t i = 0; i < numElements; ++i)
673 ::new(&((T *)buffer)[i]) T();
676 template <
typename T>
679 ((T *)element)->~T();
682 ::memset(element, 0xFF,
sizeof(T));
686 template <
typename T>
689 for (
size_t i = 0; i < numElements; ++i)
690 ((T *)buffer)[i].~T();
693 if (buffer !=
nullptr) {
694 ::memset(buffer, 0xFF, numElements *
sizeof(T));
700 template <
typename T>
703 *(T *)target = *(
const T *)source;
706 template <
typename T>
709 for (
size_t i = 0; i < numElements; ++i)
710 ((T *)target)[i] = ((
const T *)source)[i];
715 template <
typename T>
730 template <
typename T>
743 source._setBuffer(
nullptr);
744 source._setCapacity(0);
755 template <
typename T>
764 template <
typename T>
774 template <
typename KeyT,
typename DataT>
784 template <
typename T>
790 template <
typename T>
793 for (
size_t i = 0; i < numElements; ++i)
797 template <
typename T>
800 for (
size_t i = 0; i < numElements; ++i)
805 template <
typename T>
814 #pragma warning( pop )
#define AGX_DECLARE_POINTER_TYPES(type)
List of callbacks used by the primitive type handling by user code.
void callBool(agx::UInt32 stride, agx::UInt32 padding)
agx::Callback2< agx::UInt32, agx::UInt32 > CallbackType
void callInt16(agx::UInt32 stride, agx::UInt32 padding)
void callInt32(agx::UInt32 stride, agx::UInt32 padding)
void callUInt32(agx::UInt32 stride, agx::UInt32 padding)
void callUInt8(agx::UInt32 stride, agx::UInt32 padding)
CallbackList(CallbackType callbackReal32, CallbackType callbackReal64, CallbackType callbackInt8, CallbackType callbackUInt8, CallbackType callbackInt16, CallbackType callbackUInt16, CallbackType callbackInt32, CallbackType callbackUInt32, CallbackType callbackInt64, CallbackType callbackUInt64, CallbackType callbackBool)
void callUInt16(agx::UInt32 stride, agx::UInt32 padding)
void callReal32(agx::UInt32 stride, agx::UInt32 padding)
void callReal64(agx::UInt32 stride, agx::UInt32 padding)
void callUInt64(agx::UInt32 stride, agx::UInt32 padding)
void callInt8(agx::UInt32 stride, agx::UInt32 padding)
void callInt64(agx::UInt32 stride, agx::UInt32 padding)
Abstract representation of a value.
Templated callback with two arguments.
Inheritance with partial specialization due to bug with ref_ptr containers.
iterator insert(const KeyT &key, const ValueT value)
Insert a key/value pair into the hash table.
iterator end()
Iterator marking end of hash table.
iterator find(const KeyT &key)
Find a key/value pair in the hash table given a key.
Inheritance with partial specialization due to bug with ref_ptr containers.
A model is an abstract representation of the class of an agx::Object.
Representation of a name string.
#define agxVerifyN(expr, format,...)
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
Contains classes for low level data storage for AGX.
void GenericCopyFunction(void *target, const void *source, size_t numElements)
void GenericTransformFunction(void *targetBuffer, const void *sourceBuffer, size_t numElements)
void AGXCORE_EXPORT Swap3x32Function(void *target, const void *source, size_t numElements)
void AGXCORE_EXPORT registerTransformer(TransformFunction transformer, const Format *targetFormat, const Format *sourceFormat)
Register a format-format transformer.
void AGXCORE_EXPORT Swap32Function(void *target, const void *source, size_t numElements)
void AGXCORE_EXPORT Swap3x64Function(void *target, const void *source, size_t numElements)
bool callDispatch< agx::UInt8 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
AGXCORE_EXPORT TypeCallerTable __agx_typeCallerTable
void AGXCORE_EXPORT Swap16Function(void *target, const void *source, size_t numElements)
bool callDispatch< agx::Int64 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
void FormatTdoInitializeElement(T *element, const T *value)
bool callDispatch< agx::Int16 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
bool callDispatch< agx::Bool >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
bool callDispatch< agx::Int32 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
bool callDispatch< agx::Int8 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
AGXCORE_EXPORT Type * getType(const agx::String &name)
void AGXCORE_EXPORT Swap2x64Function(void *target, const void *source, size_t numElements)
bool callDispatch(CallbackList *, agx::UInt32, agx::UInt32)
TransformFunction AGXCORE_EXPORT getTransformer(const Format *targetFormat, const Format *sourceFormat)
Get a specific transformer.
void AGXCORE_EXPORT Swap8Function(void *target, const void *source, size_t numElements)
Standard swap functions.
bool callDispatch< agx::UInt32 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
bool callDispatch< agx::UInt64 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
bool callDispatch< agx::Real64 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
void AGXCORE_EXPORT Swap8x64Function(void *target, const void *source, size_t numElements)
bool callDispatch< agx::UInt16 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
void AGXCORE_EXPORT Swap6x64Function(void *target, const void *source, size_t numElements)
void AGXCORE_EXPORT Swap6x32Function(void *target, const void *source, size_t numElements)
bool callDispatch< agx::Real32 >(CallbackList *callbackList, agx::UInt32 stride, agx::UInt32 padding)
void AGXCORE_EXPORT Swap2x32Function(void *target, const void *source, size_t numElements)
void AGXCORE_EXPORT Swap4x64Function(void *target, const void *source, size_t numElements)
void(* TransformFunction)(void *target, const void *source, size_t numElements)
void AGXCORE_EXPORT Swap64Function(void *target, const void *source, size_t numElements)
void AGXCORE_EXPORT Swap4x32Function(void *target, const void *source, size_t numElements)
void AGXCORE_EXPORT Swap8x32Function(void *target, const void *source, size_t numElements)
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
void swap(agx::Name &lhs, agx::Name &rhs)