AGX Dynamics  2.37.3.2
Format.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXDATA_FORMAT_H
18 #define AGXDATA_FORMAT_H
19 
20 #include <typeinfo>
21 
22 #include <agx/agx.h>
23 #include <agx/agxCore_export.h>
24 #include <agx/String.h>
25 #include <agx/Model.h>
26 #include <agx/Name.h>
27 #include <iostream>
28 
29 #ifdef _MSC_VER
30 # pragma warning(push)
31 # pragma warning(disable:4100) // : warning C4100: 'buffer' : unreferenced formal parameter
32 #endif
33 
34 
35 namespace agxData
36 {
37  class Value;
38 
40 
41  class Type;
42  typedef void (*TransformFunction)(void *target, const void *source, size_t numElements);
43 
44  // Used by the format-to-primitive type conversion system to let the user
45  // call overloaded methods based on an abstract Format instance.
46  class CallbackList;
47 
50  TransformFunction transformer, const Format* targetFormat, const Format* sourceFormat);
51 
53  TransformFunction AGXCORE_EXPORT getTransformer(const Format* targetFormat, const Format* sourceFormat);
54 
57  void* target, const Format* targetFormat, const void* source, const Format* sourceFormat, size_t numElements);
58 
59 
64  {
65  public:
66  static agx::Model *ClassModel();
67 
68  public:
72  static Format *Auto();
73 
77  static Format *Void();
78 
79  public:
80 
81  Format(const agx::Name& formatName, const agx::Name& implementationName, size_t size, TransformFunction byteSwapFunction, TransformFunction copyFunction);
82 
86  Type *getType();
87  const Type *getType() const;
88 
92  // const agx::Name& getName() const;
93 
97  agx::String fullName() const;
98 
102  const agx::Name& getImplementationName() const;
103 
107  size_t getSize() const;
108 
112  agxData::Value *getDefaultValue();
113  const agxData::Value *getDefaultValue() const;
114 
118  void swapByteOrder(void *target, const void *source, size_t numElements) const;
119 
123  virtual void initializeElement(void *element, const void *value) const;
124  virtual void initializeElements(void *buffer, const void *value, size_t numElements) const;
125 
129  virtual void constructElement(void *element) const;
130  virtual void constructElements(void *buffer, size_t numElements) const;
131 
135  virtual void destroyElement(void *element) const;
136  virtual void destroyElements(void *buffer, size_t numElements) const;
137 
141  virtual void copyElement(void *target, const void *source) const;
142  virtual void copyElements(void *buffer, const void *source, size_t numElements) const;
143 
147  virtual void moveElement(void *target, void *source) const;
148  virtual void moveElements(void *target, void *source, size_t numElements) const;
149 
153  virtual void permuteElements(void *target, void *source, const agx::Index *permutation, size_t numElements) const;
154 
158  virtual void swapElements(void *element1, void *element2) const;
159 
160  public:
162  const TransformerTable& getTransformers() const;
163 
164 
165 
170  template<typename T>
171  static void registerFormatPrimitives( const agxData::Format* format, agx::UInt32 stride, agx::UInt32 padding );
172 
174  static bool callFormatPrimitive( const Format* format, CallbackList* callbackList );
175 
176  protected:
177  virtual ~Format();
178 
179  void cleanup();
180 
181  friend class Type;
182  void setType(Type *type);
183 
184  friend class TypeManager;
185  private:
186  Type *m_type;
187  size_t m_size;
188  // agx::Name m_name;
189  agx::Name m_implementationName;
190  TransformFunction m_swapFunction;
191  agxData::Value *m_defaultValue;
192 
194  TransformFunction transformer, const Format* targetFormat, const Format* sourceFormat);
195  friend TransformFunction AGXCORE_EXPORT getTransformer(const Format* targetFormat, const Format* sourceFormat);
196  TransformerTable m_transformerTable;
197  };
198 
203  {
204  public:
205  ContainerFormat(const agx::Name& containerName, Format *elementFormat, size_t size);
206 
207  Format *getElementFormat();
208  const Format *getElementFormat() const;
209 
210  protected:
211  virtual ~ContainerFormat();
212 
213  using Format::copyElement;
214  using Format::moveElement;
215 
216  template <typename T>
217  void copyElement(T& target, const T& source) const;
218 
219  template <typename T>
220  void moveElement(T& target, T& source) const;
221 
222 
223  private:
224  FormatRef m_elementFormat;
225  };
226 
227 
228 
230  {
231  public:
232  ArrayFormat(Format *elementFormat);
233 
234  virtual void initializeElement(void *element, const void *value) const override;
235  virtual void initializeElements(void *buffer, const void *value, size_t numElements) const override;
236  virtual void constructElement(void *element) const override;
237  virtual void constructElements(void *buffer, size_t numElements) const override;
238  virtual void destroyElement(void *element) const override;
239  virtual void destroyElements(void *buffer, size_t numElements) const override;
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;
244  virtual void permuteElements(void *target, void *source, const agx::Index *permutation, size_t numElements) const override;
245  virtual void swapElements(void *element1, void *element2) const override;
246 
247  protected:
248  virtual ~ArrayFormat();
249 
250  private:
251  };
252 
253 
254 #if 0
255  class AGXCORE_EXPORT VectorFormat : public ContainerFormat
256  {
257  public:
258  VectorFormat(Format *elementFormat);
259 
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;
271 
272  protected:
273  virtual ~VectorFormat();
274 
275  private:
276  };
277 
278  class AGXCORE_EXPORT HashSetFormat : public ContainerFormat
279  {
280  public:
281  HashSetFormat(Format *elementFormat);
282 
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;
294 
295  protected:
296  virtual ~HashSetFormat();
297 
298  private:
299  };
300 
301 #endif
302 
303 
305  {
306  public:
307  GenericFormat(size_t size);
308 
309  virtual void initializeElement(void *element, const void *value) const override;
310  virtual void initializeElements(void *buffer, const void *value, size_t numElements) const override;
311  virtual void constructElement(void *element) const override;
312  virtual void constructElements(void *buffer, size_t numElements) const override;
313  virtual void destroyElement(void *element) const override;
314  virtual void destroyElements(void *buffer, size_t numElements) const override;
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;
320 
321  protected:
322  virtual ~GenericFormat();
323 
324  };
325 
329  template <typename T>
330  class FormatT : public Format
331  {
332  public:
333  typedef T Type;
334 
335  FormatT(const agx::Name& formatName, TransformFunction byteSwapFunction = nullptr);
336 
337  virtual void initializeElement(void *element, const void *value) const override;
338  virtual void initializeElements(void *buffer, const void *value, size_t numElements) const override;
339  virtual void constructElement(void *element) const override;
340  virtual void constructElements(void *buffer, size_t numElements) const override;
341  virtual void destroyElement(void *element) 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;
348 
349 
350  virtual void swapElements(void *element1, void *element2) const override;
351 
352  protected:
353  virtual ~FormatT();
354 
355  private:
356  // T m_defaultValue;
357  };
358 
359 
360  // Used to register formats
362  {
363  public:
364  typedef void (*FormatConstructorFn)();
365 
366  FormatInitializer(const char *name, FormatConstructorFn constructor);
367 
368  static void createFormats();
369  static void removeFormats();
370 
371  void init();
372 
373  const char *getName() const;
374 
375  private:
376  const char *m_name;
377  FormatConstructorFn m_constructor;
378  bool m_isInitialized;
379  };
380 
381 
382  template <size_t NUM_BYTES>
384  {
385  char elements[NUM_BYTES];
386  };
387 
388 
389 
390 
391 
392 
400  {
401  public:
403  CallbackList( CallbackType callbackReal32, CallbackType callbackReal64,
404  CallbackType callbackInt8, CallbackType callbackUInt8,
405  CallbackType callbackInt16, CallbackType callbackUInt16,
406  CallbackType callbackInt32, CallbackType callbackUInt32,
407  CallbackType callbackInt64, CallbackType callbackUInt64,
408  CallbackType callbackBool);
409 
410  void callReal32( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackReal32( stride, padding ); }
411  void callReal64( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackReal64( stride, padding ); }
412  void callInt8( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackInt8( stride, padding ); }
413  void callUInt8( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackUInt8( stride, padding ); }
414  void callInt16( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackInt16( stride, padding ); }
415  void callUInt16( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackUInt16( stride, padding ); }
416  void callInt32( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackInt32( stride, padding ); }
417  void callUInt32( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackUInt32( stride, padding ); }
418  void callInt64( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackInt64( stride, padding ); }
419  void callUInt64( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackUInt64( stride, padding ); }
420  void callBool( agx::UInt32 stride, agx::UInt32 padding ) { m_callbackBool( stride, padding ); }
421 
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(); }
433 
434  private:
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;
446  };
447 
448 
449  /*
450  The primitive type callback system uses a template based dispatch mechanism
451  that calls the correct callback in a Callback list, passing on the proper
452  'primitivesPerElement' argument. Template specializations handles the
453  calling of the correct callback function.
454  */
455  template< typename T>
456  bool callDispatch( CallbackList* /*callbackList*/, agx::UInt32 /*stride*/, agx::UInt32 /*padding*/ )
457  {
458  // Should anything be done here? We have neither LOGGER nor agxData::getFormat<T>() due to include loops.
459  std::cout << "Format: Hit typeless callDispatch() for C++ type " << typeid(T).name() << std::endl;
460  return false;
461  }
462 
463  // Template specializations for the primitive types we currently support.
464 
465  template<> bool callDispatch<agx::Real32>( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
466  template<> bool callDispatch<agx::Real64>( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
467  template<> bool callDispatch<agx::Int8> ( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
468  template<> bool callDispatch<agx::UInt8> ( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
469  template<> bool callDispatch<agx::Int16> ( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
470  template<> bool callDispatch<agx::UInt16>( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
471  template<> bool callDispatch<agx::Int32> ( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
472  template<> bool callDispatch<agx::UInt32>( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
473  template<> bool callDispatch<agx::Int64> ( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
474  template<> bool callDispatch<agx::UInt64>( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
475  template<> bool callDispatch<agx::Bool> ( CallbackList* callbackList, agx::UInt32 stride, agx::UInt32 padding );
476 
477 
478  /*
479  Class hierarchy that handles the calling of the correct dispatch function.
480  There is a table that maps from a format name to an instance of one of these
481  FormatCallers.
482  */
484  {
485  public:
486  virtual bool call( CallbackList* callbackList ) = 0;
487  virtual ~FormatCaller() {}
488  };
489 
490  template<typename T>
492  {
493  public:
494  typedef T Type;
495 
496  FormatCallerT( agx::UInt32 stride, agx::UInt32 padding ) : m_stride(stride), m_padding(padding) {}
497  virtual bool call( CallbackList* callbackList )
498  {
499  return callDispatch<T>( callbackList, m_stride, m_padding );
500  }
501 
502  virtual ~FormatCallerT() {}
503  private:
504  agx::UInt32 m_stride;
505  agx::UInt32 m_padding;
506  };
507 
508 
509 
516  void AGXCORE_EXPORT forceClearTypeCallerTable();
518 
519  // Table holding mappings from a full format name to a FormatCaller with the correct template type.
521  AGXCORE_EXPORT extern TypeCallerTable __agx_typeCallerTable;
522 
523 
524  /*
525  Bind a FormatCaller to a format. Each format can only be registered once.
526  \param format The high level format that we want a primitive type mapping for.
527  \param stride The number of primitives per object of the format.
528  \param padding The number of primitives at the end of each object that are padding.
529  */
530  template<typename T>
531  void Format::registerFormatPrimitives(const Format* format, agx::UInt32 stride, agx::UInt32 padding )
532  {
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 );
537  agxVerifyN( __agx_typeCallerTable.find( format ) == __agx_typeCallerTable.end(),
538  "Format: The format \'%s\' have already been registered.", format->fullName().c_str() );
539  __agx_typeCallerTable.insert( format, new FormatCallerT<T>(stride, padding) );
540  }
541 
542 
543 
544 
545 
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__)()
550 
551 
553  void AGXCORE_EXPORT Swap8Function(void *target, const void *source, size_t numElements);
554  void AGXCORE_EXPORT Swap16Function(void *target, const void *source, size_t numElements);
555 
556  void AGXCORE_EXPORT Swap32Function(void *target, const void *source, size_t numElements);
557  void AGXCORE_EXPORT Swap2x32Function(void *target, const void *source, size_t numElements);
558  void AGXCORE_EXPORT Swap3x32Function(void *target, const void *source, size_t numElements);
559  void AGXCORE_EXPORT Swap4x32Function(void *target, const void *source, size_t numElements);
560  void AGXCORE_EXPORT Swap6x32Function(void *target, const void *source, size_t numElements);
561  void AGXCORE_EXPORT Swap8x32Function(void *target, const void *source, size_t numElements);
562 
563  void AGXCORE_EXPORT Swap64Function(void *target, const void *source, size_t numElements);
564  void AGXCORE_EXPORT Swap2x64Function(void *target, const void *source, size_t numElements);
565  void AGXCORE_EXPORT Swap3x64Function(void *target, const void *source, size_t numElements);
566  void AGXCORE_EXPORT Swap4x64Function(void *target, const void *source, size_t numElements);
567  void AGXCORE_EXPORT Swap6x64Function(void *target, const void *source, size_t numElements);
568  void AGXCORE_EXPORT Swap8x64Function(void *target, const void *source, size_t numElements);
569 
570 #ifdef _MSC_VER
571 # pragma warning(disable: 4800) // Disable warnings about performance (bool true or false)
572 #endif
573 
574  template <typename TargetT, typename SourceT>
575  void GenericTransformFunction(void *targetBuffer, const void *sourceBuffer, size_t numElements)
576  {
577  for (size_t i = 0; i < numElements; ++i)
578  ((TargetT *)targetBuffer)[i] = (TargetT)((SourceT *)sourceBuffer)[i];
579  }
580 
581  template <typename T>
582  void GenericCopyFunction(void *target, const void *source, size_t numElements)
583  {
584  ::memcpy(target, source, numElements * sizeof(T));
585  }
586 
587 
588  /* Implementation */
589  AGX_FORCE_INLINE Type *Format::getType() { return m_type; }
590  AGX_FORCE_INLINE const Type *Format::getType() const { return m_type; }
591  // AGX_FORCE_INLINE const agx::Name& Format::getName() const { return m_name; }
592  AGX_FORCE_INLINE const agx::Name& Format::getImplementationName() const { return m_implementationName; }
593  AGX_FORCE_INLINE size_t Format::getSize() const { return m_size; }
594  AGX_FORCE_INLINE const Format::TransformerTable& Format::getTransformers() const { return m_transformerTable; }
595 
596 
597  //-----------------------------------------------------------------------------------------------------
598 
600  AGX_FORCE_INLINE const Format *ContainerFormat::getElementFormat() const { return m_elementFormat; }
601 
602  //-----------------------------------------------------------------------------------------------------
603 
604  template <class T, typename std::enable_if<std::is_copy_constructible<T>::value>::type* = nullptr >
605  inline void FormatTdoInitializeElement( T* element, const T* value )
606  {
607  ::new((T *)element) T(*(const T *)value);
608  }
609 
610  template <class T, typename std::enable_if<!std::is_copy_constructible<T>::value>::type* = nullptr >
611  inline void FormatTdoInitializeElement( T* element, const T* )
612  {
613  // No copy-constructor, default constructor instead.
614  ::new((T *)element) T();
615  }
616 
617  //-----------------------------------------------------------------------------------------------------
618  template <typename T>
619  FormatT<T>::FormatT(const agx::Name& formatName, TransformFunction byteSwapFunction) : Format(formatName, typeid(T).name(), sizeof(T), byteSwapFunction, GenericCopyFunction<T>)
620  {}
621 
622  template <typename T>
624  {
625  this->cleanup();
626  }
627 
628 
629 
630  template <typename T>
631  void FormatT<T>::initializeElement(void *element, const void *value) const
632  {
633  // ::new((T *)element) T(*(const T *)value);
634  FormatTdoInitializeElement( (T*) element, (const T*) value );
635 
636  #if 0
637  // Use GenericStruct to copy raw data, discarding custom assignment operator semantics
638  typedef GenericStruct<sizeof(T)> SizeStruct;
639  *(SizeStruct *)element = *(const SizeStruct *)value;
640  #endif
641  }
642 
643  template <typename T>
644  void FormatT<T>::initializeElements(void *buffer, const void *value, size_t numElements) const
645  {
646  for (size_t i = 0; i < numElements; ++i) {
647 
648  // ::new(&((T *)buffer)[i]) T(*(const T *)value);
649  FormatTdoInitializeElement( &((T *)buffer)[i], (const T*) value );
650  }
651 
652  #if 0
653  // Use GenericStruct to copy raw data, discarding custom assignment operator semantics
654  typedef GenericStruct<sizeof(T)> SizeStruct;
655 
656  for (size_t i = 0; i < numElements; ++i)
657  ((SizeStruct *)buffer)[i] = *(const SizeStruct *)value;
658  #endif
659  }
660 
661 
662  template <typename T>
663  void FormatT<T>::constructElement(void *element) const
664  {
665  ::new((T *)element) T();
666  }
667 
668 
669  template <typename T>
670  void FormatT<T>::constructElements(void *buffer, size_t numElements) const
671  {
672  for (size_t i = 0; i < numElements; ++i)
673  ::new(&((T *)buffer)[i]) T();
674  }
675 
676  template <typename T>
677  void FormatT<T>::destroyElement(void *element) const
678  {
679  ((T *)element)->~T();
680 
681  #ifdef AGX_DEBUG
682  ::memset(element, 0xFF, sizeof(T));
683  #endif
684  }
685 
686  template <typename T>
687  void FormatT<T>::destroyElements(void *buffer, size_t numElements) const
688  {
689  for (size_t i = 0; i < numElements; ++i)
690  ((T *)buffer)[i].~T();
691 
692  #ifdef AGX_DEBUG
693  if (buffer != nullptr) {
694  ::memset(buffer, 0xFF, numElements * sizeof(T));
695  }
696  #endif
697  }
698 
699 
700  template <typename T>
701  void FormatT<T>::copyElement(void *target, const void *source) const
702  {
703  *(T *)target = *(const T *)source;
704  }
705 
706  template <typename T>
707  void FormatT<T>::copyElements(void *target, const void *source, size_t numElements) const
708  {
709  for (size_t i = 0; i < numElements; ++i)
710  ((T *)target)[i] = ((const T *)source)[i];
711  }
712 
713 
714 
715  template <typename T>
717  {
718  AGX_FORCE_INLINE static void move(T& target, T& source)
719  {
720  target = source;
721  }
722 
723  AGX_FORCE_INLINE static void swap(T& a, T& b)
724  {
725  std::swap(a, b);
726  }
727  };
728 
729 
730  template <typename T>
732  {
734 
735  AGX_FORCE_INLINE static void move(T& target, T& source)
736  {
737  target.~T();
738 
739  // Redirect target vector to existing element buffer (avoids copying the whole element buffer)
740  (CopyElement&)target = (CopyElement&)source;
741 
742  // Clear old vector header
743  source._setBuffer(nullptr);
744  source._setCapacity(0);
745  source._setSize(0);
746  }
747 
748  AGX_FORCE_INLINE static void swap(T& a, T& b)
749  {
750  std::swap(*(CopyElement *)&a, *(CopyElement *)&b);
751  }
752 
753  };
754 
755  template <typename T>
756  struct FormatMoveSwap< agx::Vector<T> >
757  {
759 
760  AGX_FORCE_INLINE static void move(VectorT& target, VectorT& source) { FormatMoveSwapContainer<VectorT>::move(target, source); }
761  AGX_FORCE_INLINE static void swap(VectorT& a, VectorT& b) { FormatMoveSwapContainer<VectorT>::swap(a, b); }
762  };
763 
764  template <typename T>
765  struct FormatMoveSwap< agx::HashSet<T> >
766  {
768 
769  AGX_FORCE_INLINE static void move(HashT& target, HashT& source) { FormatMoveSwapContainer<HashT>::move(target, source); }
770  AGX_FORCE_INLINE static void swap(HashT& a, HashT& b) { FormatMoveSwapContainer<HashT>::swap(a, b); }
771  };
772 
773 
774  template <typename KeyT, typename DataT>
775  struct FormatMoveSwap< agx::HashTable<KeyT, DataT> >
776  {
778 
779  AGX_FORCE_INLINE static void move(HashT& target, HashT& source) { FormatMoveSwapContainer<HashT>::move(target, source); }
780  AGX_FORCE_INLINE static void swap(HashT& a, HashT& b) { FormatMoveSwapContainer<HashT>::swap(a, b); }
781  };
782 
783 
784  template <typename T>
785  void FormatT<T>::moveElement(void *target, void *source) const
786  {
787  FormatMoveSwap<T>::move(*(T *)target, *(T *)source);
788  }
789 
790  template <typename T>
791  void FormatT<T>::moveElements(void *target, void *source, size_t numElements) const
792  {
793  for (size_t i = 0; i < numElements; ++i)
794  FormatMoveSwap<T>::move(((T *)target)[i], ((T *)source)[i]);
795  }
796 
797  template <typename T>
798  void FormatT<T>::permuteElements(void *target, void *source, const agx::Index *permutation, size_t numElements) const
799  {
800  for (size_t i = 0; i < numElements; ++i)
801  FormatMoveSwap<T>::move(((T *)target)[i], ((T *)source)[permutation[i]]);
802  }
803 
804 
805  template <typename T>
806  void FormatT<T>::swapElements(void *element1, void *element2) const
807  {
808  FormatMoveSwap<T>::swap(*(T *)element1, *(T *)element2);
809  }
810 
811 }
812 
813 #if defined(_MSC_VER)
814  #pragma warning( pop ) // restoring: warning( disable : 4100 )
815 #endif
816 
817 #endif /* _AGXDATA_FORMAT_H_ */
agx::HashTable< Format *, TransformFunction > TransformerTable
Definition: Format.h:161
size_t getSize() const
Definition: Format.h:593
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
AGXCORE_EXPORT Type * getType(const agx::String &name)
virtual void moveElement(void *target, void *source) const override
Move elements.
Definition: Format.h:785
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:669
void callUInt16(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:415
virtual void moveElement(void *target, void *source) const
Move elements.
void AGXCORE_EXPORT Swap4x64Function(void *target, const void *source, size_t numElements)
virtual void destroyElement(void *element) const override
Destroy elements.
Definition: Format.h:677
bool hasInt64() const
Definition: Format.h:430
#define agxVerifyN(expr, format,...)
Definition: debug.h:133
static void move(HashT &target, HashT &source)
Definition: Format.h:769
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
void AGXCORE_EXPORT Swap8x64Function(void *target, const void *source, size_t numElements)
Abstract representation of a value.
Definition: Value.h:48
virtual void destroyElements(void *buffer, size_t numElements) const override
Definition: Format.h:687
virtual void moveElements(void *target, void *source, size_t numElements) const override
Definition: Format.h:791
void AGXCORE_EXPORT Swap8x32Function(void *target, const void *source, size_t numElements)
bool hasBool() const
Definition: Format.h:432
void(* TransformFunction)(void *target, const void *source, size_t numElements)
Definition: Format.h:42
#define m_size
Definition: Vector.h:429
void GenericCopyFunction(void *target, const void *source, size_t numElements)
Definition: Format.h:582
void AGXCORE_EXPORT Swap2x32Function(void *target, const void *source, size_t numElements)
bool hasUInt8() const
Definition: Format.h:425
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
bool callDispatch(CallbackList *, agx::UInt32, agx::UInt32)
Definition: Format.h:456
virtual void copyElement(void *target, const void *source) const
Copy elements.
static void swap(T &a, T &b)
Definition: Format.h:723
A format is an implementation of a agxData::Type.
Definition: Format.h:63
bool hasInt8() const
Definition: Format.h:424
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
void callInt8(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:412
void AGXCORE_EXPORT Swap16Function(void *target, const void *source, size_t numElements)
void callUInt64(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:419
FormatT(const agx::Name &formatName, TransformFunction byteSwapFunction=nullptr)
Definition: Format.h:619
void AGXCORE_EXPORT Swap4x32Function(void *target, const void *source, size_t numElements)
void callBool(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:420
bool hasReal32() const
Definition: Format.h:422
Representation of a name string.
Definition: Name.h:32
#define AGX_FORCE_INLINE
Definition: Object.h:59
void GenericTransformFunction(void *targetBuffer, const void *sourceBuffer, size_t numElements)
Definition: Format.h:575
virtual ~FormatCallerT()
Definition: Format.h:502
void FormatTdoInitializeElement(T *element, const T *value)
Definition: Format.h:605
virtual ~FormatCaller()
Definition: Format.h:487
virtual void constructElements(void *buffer, size_t numElements) const override
Definition: Format.h:670
void AGXCORE_EXPORT Swap8Function(void *target, const void *source, size_t numElements)
Standard swap functions.
void AGXCORE_EXPORT Swap32Function(void *target, const void *source, size_t numElements)
bool hasInt16() const
Definition: Format.h:426
Templated vector class.
Definition: Vector.h:52
List of callbacks used by the primitive type handling by user code.
Definition: Format.h:399
Templated format, connects the type abstractions to the programming language.
Definition: Format.h:330
bool hasUInt16() const
Definition: Format.h:427
virtual ~FormatT()
Definition: Format.h:623
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Abstracted type.
Definition: Type.h:97
bool hasReal64() const
Definition: Format.h:423
FormatCallerT(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:496
AGXCORE_EXPORT TypeCallerTable __agx_typeCallerTable
void AGXCORE_EXPORT Swap3x32Function(void *target, const void *source, size_t numElements)
virtual void initializeElement(void *element, const void *value) const override
Initialize elements.
Definition: Format.h:631
Contains classes for low level data storage for AGX.
Definition: Container.h:23
UInt32 Index
Definition: Integer.h:52
void AGXCORE_EXPORT Swap3x64Function(void *target, const void *source, size_t numElements)
virtual void initializeElements(void *buffer, const void *value, size_t numElements) const override
Definition: Format.h:644
virtual bool call(CallbackList *callbackList)
Definition: Format.h:497
static void move(HashT &target, HashT &source)
Definition: Format.h:779
void AGXCORE_EXPORT Swap6x32Function(void *target, const void *source, size_t numElements)
bool hasInt32() const
Definition: Format.h:428
agx::Callback2< agx::UInt32, agx::UInt32 > CallbackType
Definition: Format.h:402
static void swap(VectorT &a, VectorT &b)
Definition: Format.h:761
void callReal32(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:410
virtual void swapElements(void *element1, void *element2) const override
Swap elements.
Definition: Format.h:806
static void move(T &target, T &source)
Definition: Format.h:718
GenericStruct< sizeof(T)> CopyElement
Definition: Format.h:733
virtual void copyElement(void *target, const void *source) const override
Copy elements.
Definition: Format.h:701
void AGXCORE_EXPORT registerTransformer(TransformFunction transformer, const Format *targetFormat, const Format *sourceFormat)
Register a format-format transformer.
Container format, eg.
Definition: Format.h:202
virtual void constructElement(void *element) const override
Construct elements.
Definition: Format.h:663
void callInt32(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:416
TransformFunction AGXCORE_EXPORT getTransformer(const Format *targetFormat, const Format *sourceFormat)
Get a specific transformer.
const agx::Name & getImplementationName() const
Definition: Format.h:592
void callUInt32(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:417
static void swap(HashT &a, HashT &b)
Definition: Format.h:770
static void swap(T &a, T &b)
Definition: Format.h:748
Type * getType()
Definition: Format.h:589
void callReal64(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:411
bool hasUInt32() const
Definition: Format.h:429
void callInt64(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:418
Format * getElementFormat()
Definition: Format.h:599
Inheritance with partial specialization due to bug with ref_ptr containers.
bool hasUInt64() const
Definition: Format.h:431
virtual void copyElements(void *target, const void *source, size_t numElements) const override
Definition: Format.h:707
LinearProbingHashTable< KeyT, DataT, HashT, AllocatorT > HashTable
Definition: HashTable.h:24
static void move(VectorT &target, VectorT &source)
Definition: Format.h:760
static void move(T &target, T &source)
Definition: Format.h:735
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
void AGXCORE_EXPORT Swap6x64Function(void *target, const void *source, size_t numElements)
void AGXCORE_EXPORT Swap2x64Function(void *target, const void *source, size_t numElements)
#define AGXCORE_EXPORT
void callInt16(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:414
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
virtual void permuteElements(void *target, void *source, const agx::Index *permutation, size_t numElements) const override
Permute elements.
Definition: Format.h:798
void callUInt8(agx::UInt32 stride, agx::UInt32 padding)
Definition: Format.h:413
const TransformerTable & getTransformers() const
Definition: Format.h:594
void AGXCORE_EXPORT Swap64Function(void *target, const void *source, size_t numElements)