AGXDynamics  2.35.0.3
Buffer.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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_BUFFER_H
18 #define AGXDATA_BUFFER_H
19 
20 #include <agx/agx.h>
21 #include <agx/Component.h>
22 #include <agx/Event.h>
23 
24 #include <agxData/Array.h>
25 #include <agxData/Value.h>
26 #include <agxData/ShareHandle.h>
27 
28 #include <agx/Vector.h>
29 
30 #ifdef _MSC_VER
31 # pragma warning(push)
32 # pragma warning(disable: 6011) // Disable warningC6011: dereferencing nullptr pointer
33 #endif
34 
35 
36 namespace agx
37 {
38  typedef VectorPOD<Index> IndexVector;
39  class GlobalResultBuffer;
40 }
41 
42 namespace agxData
43 {
44  class Attribute;
45  class EntityStorage;
46 
49 
56  {
57  public:
58  static agx::Model *ClassModel();
59 
60  static Buffer *load(agx::TiXmlElement *eBuffer, agx::Device *device);
61  virtual void configure(agx::TiXmlElement *eBuffer) override;
62  virtual void snapshot(agx::TiXmlNode *eParent, const agx::String& directory) const override;
63 
64  public:
68 
69  // Generated event interface, defined in Buffer.agxEvent
71 
72 #ifndef SWIG
73  void addListener(EventListener *listener);
74  void removeListener(EventListener *listener);
75  bool hasListener(EventListener *listener);
76 #endif
77 
80 
81 
83 
86 
87  public:
88  Buffer(const agx::Name& name, const agxData::Format *format);
89  Buffer(const agxData::Format *format);
90 
95  const agxData::Type *getType() const;
96 
101  const agxData::Format *getFormat() const;
102 
103 
105  template <typename T>
106  agxData::Array<T>& getArray();
107 
108  template <typename T>
109  const agxData::Array<T>& getArray() const;
110 
111 
112  agxData::AbstractArray& getArray();
113  const agxData::AbstractArray& getArray() const;
114 
118  size_t size() const;
119 
123  size_t capacity() const;
124 
128  bool empty() const;
129 
133  void resize(size_t size, bool initializeElements = true);
134  void presize(size_t size, size_t initialSize); // Resize without generating events, use with caution
135 
139  void clear();
140 
144  void reserve(size_t size);
145 
149  agx::UInt64 getRevision() const;
150 
154  void* ptr();
155  const void* ptr() const;
156 
157  template <typename T>
158  T *ptr();
159 
160  template <typename T>
161  const T *ptr() const;
162 
166  void initialize(const agx::IndexRange& range);
167 
171  template <typename T>
172  T& getElement(size_t index);
173 
174  template <typename T>
175  const T& getElement(size_t index) const;
176 
177 
178  void commit();
179  void commit(agx::IndexRange32 range);
180  void commit(agx::Index index);
181  void commit(const agxData::IndexArray& indexList);
182 
183 
187  void *getElement(size_t index);
188  const void *getElement(size_t index) const;
189 
190  void *kernelOverflowReallocation(size_t size);
191  void deleteOverflowBuffer(void *buffer, size_t numElements);
192 
193  void *allocateBackBuffer();
194  void swapBackBuffer(void *backBuffer);
195 
199  size_t getElementArraySize() const;
200 
201 
205  Buffer *clone() const;
206 
210  Buffer *clone(const agx::IndexRange& range) const;
211  Buffer *clone(const agxData::IndexArray& indices) const;
212  Buffer *clone(const agx::IndexVector& indices) const;
213 
217  static void copy(Buffer *target, const Buffer *source);
218  static void copy(Buffer *target, size_t targetOffset, const Buffer *source, size_t sourceOffset, size_t numElements);
219  static void copyGather(Buffer *target, const Buffer *source, const agxData::IndexArray& indices);
220  static void copyScatter(Buffer *target, const Buffer *source, const agxData::IndexArray& indices);
221 
222 
226  void print() const;
227  void print(agx::IndexRange range) const;
228 
229  void print(std::ostream& stream) const;
230  void print(std::ostream& stream, agx::IndexRange range) const;
231 
236  const agxData::EntityStorage *getStorage() const;
237 
241  agxData::Attribute *getAttribute();
242  const agxData::Attribute *getAttribute() const;
243 
247  agx::GlobalResultBuffer *getGlobalResult();
248  const agx::GlobalResultBuffer *getGlobalResult() const;
249 
250 
254  Buffer *getGlobalOrderBuffer();
255  const Buffer *getGlobalOrderBuffer() const;
256 
257  Buffer *getOrCreateGlobalOrderBuffer();
258 
259 
263  Buffer *getElementBuffer();
264  const Buffer *getElementBuffer() const;
265 
269  void setElementBuffer(Buffer *buffer);
270 
274  void setDefaultValue(agxData::Value *value);
275 
279  agxData::Value *getDefaultValue();
280  const agxData::Value *getDefaultValue() const;
281 
286  void setElementInitializer(const RangeCallback& callback);
287  void setElementDestructor(const RangeCallback& callback);
288 
289  Buffer *getOriginalBuffer();
290  const Buffer *getOriginalBuffer() const;
291 
292  const agxData::Value::Event::CallbackType& getResizeCallback() const;
293  const agxData::Value::Event::CallbackType& getReserveCallback() const;
294 
295  virtual void buildNavigationTree(agxJson::Value& eNode) const override;
296 
297  public:
298  void registerSharedContainer(agx::Container *container);
299  void unregisterSharedContainer(agx::Container *container);
300 
301  void setRevision(agx::UInt64 revision);
302 
303  protected:
304  virtual ~Buffer();
305 
306  virtual void reallocate(size_t size);
307  static void initializeElements(Buffer *buffer, const agx::IndexRange& range);
308  static void destroyElements(Buffer *buffer, const agx::IndexRange& range);
309 
310  private:
312  void setGlobalResult(agx::GlobalResultBuffer *globalResult);
313  void signalReallocation();
314 
315  private:
316  friend class EntityStorage;
317  friend class BufferProxyAllocator;
318  void keyFrameReserve(size_t capacity);
319 
320  void init();
321  void resizeCallback(agxData::Value *value);
322  void reserveCallback(agxData::Value *value);
323  void readBinaryDump(const agx::String& path);
324  void writeBinaryDump(const agx::String& path);
325  void connect(EntityStorage *storage, Attribute *attribute);
326  void setElementArraySize(const agxData::Value *value);
327 
328 
329  agxData::ValueRefT<agx::UInt> m_elementArraySize;
330 
331  private:
332  friend class agx::Device;
333  void setOriginalBuffer(Buffer *buffer);
334 
335  protected:
336  size_t m_size;
337  size_t m_capacity;
339 
340  void *m_ptr;
355  EventDispatch m_eventDispatch;
356 
359 
360  friend class ShareHandle;
363 
364  template <typename T>
365  friend class Vector;
366  };
367 
368  // Container allocator for Vector, HashTable, etc.
370  {
371  public:
372  BufferProxyAllocator(Buffer *buffer = nullptr);
374 
375  void setBuffer(Buffer *buffer);
376 
377  void update() const;
378  void commit();
379 
380  // Automatically called by container
381  void setContainer(agx::Container *container);
382 
383  void *allocateBytes(size_t numBytes);
384  void deallocateBytes(void *buffer, size_t numBytes);
385 
386  BufferProxyAllocator& operator=(const BufferProxyAllocator& other);
387  private:
388  BufferRef m_buffer;
389  agx::Container *m_container;
390  int m_reallocations;
391  };
392 
393 
394  // Templated buffer
395  template <typename T>
396  class BufferT : public Buffer
397  {
398  public:
399  template <typename T2>
400  static bool ValidateCast(const agx::Referenced *object);
401 
402  public:
403  typedef T Type;
404  typedef T value_type;
405  typedef T* iterator;
406  typedef const T* const_iterator;
407 
408  public:
409  BufferT();
410  BufferT(const agx::Name& name);
411 
412 
413  void push_back(const T& value);
414  void pop_back();
415 
416  void clear();
417 
418  template <typename T2>
419  bool contains(const T2& value) const;
420 
421  template <typename T2>
422  size_t find(const T2& value) const;
423 
424  T& operator[] (size_t index);
425  const T& operator[] (size_t index) const;
426 
427  T& at(size_t index);
428  const T& at(size_t index) const;
429 
430  T& front();
431  const T& front() const;
432 
433  T& back();
434  const T& back() const;
435 
436 
437  iterator begin();
438  const_iterator begin() const;
439 
440  iterator end();
441  const_iterator end() const;
442 
443  void commit();
444  void commit(agx::IndexRange32 range);
445  void commit(agx::Index index);
446  void commit(const agxData::IndexArray& indexList);
447  void commit(const agx::IndexVector& indexList);
448 
449  protected:
450  virtual ~BufferT();
451 
452  private:
453  Array<T>& array();
454  const Array<T>& array() const;
455  };
456 
457 
458  /* Implementation */
459  AGX_FORCE_INLINE size_t Buffer::size() const { return m_size; }
460  AGX_FORCE_INLINE size_t Buffer::capacity() const { return m_capacity; }
461  AGX_FORCE_INLINE bool Buffer::empty() const { return m_size == 0; }
462 
463 
465 
466  AGX_FORCE_INLINE size_t Buffer::getElementArraySize() const { return m_elementArraySize.get() ? m_elementArraySize->get() : 1; }
467 
470 
473 
474  AGX_FORCE_INLINE Type *Buffer::getType() { return m_format->getType(); }
475  AGX_FORCE_INLINE const Type *Buffer::getType() const { return m_format->getType(); }
477  AGX_FORCE_INLINE const Format *Buffer::getFormat() const { return m_format; }
478 
481 
482  template <typename T>
484  {
485  agxAssertN(m_format->is(agxData::getFormat<T>()) && m_format->getSize() == agxData::getFormat<T>()->getSize(), "Type mismatch! Buffer has type %s, requested array of type %s", m_format->fullName().c_str(), agxData::getFormat<T>()->fullName().c_str());
486  return reinterpret_cast<agxData::Array<T>&>(m_array);
487  }
488 
489  template <typename T>
491  {
492  return const_cast<Buffer *>(this)->getArray<T>();
493  }
494 
496  AGX_FORCE_INLINE const AbstractArray& Buffer::getArray() const { return m_array; }
497 
498 
499  AGX_FORCE_INLINE void *Buffer::ptr() { return m_ptr; }
500  AGX_FORCE_INLINE const void *Buffer::ptr() const { return m_ptr; }
501 
502  template <typename T>
504  {
505  agxAssertN(agxCore::isShutdown() || this->getFormat()->is(agxData::getFormat<T>()), "%s not the same as %s", agxData::getFormat<T>()->fullName().c_str(), this->getFormat()->fullName().c_str());
506  return static_cast<T *>(m_ptr);
507  }
508 
509  template <typename T>
510  AGX_FORCE_INLINE const T *Buffer::ptr() const
511  {
512  return const_cast<Buffer *>(this)->ptr<T>();
513  }
514 
515 
516  template <typename T>
518  {
519  agxAssert(m_ptr);
520  agxAssert(index < this->capacity());
521  agxAssertN(agxCore::isShutdown() || this->getFormat()->is(agxData::getFormat<T>()), "%s not the same as %s", agxData::getFormat<T>()->fullName().c_str(), this->getFormat()->fullName().c_str());
522  agxAssert(this->getFormat()->getSize() == sizeof(T));
523 
524  T *tmp = (T *)m_ptr;
525  return tmp[index];
526  }
527 
528  template <typename T>
529  AGX_FORCE_INLINE const T& Buffer::getElement(size_t index) const
530  {
531  return const_cast<Buffer *>(this)->getElement<T>(index);
532  }
533 
534 
536  {
537  agxAssert(m_ptr);
538  agxAssert(index < this->capacity());
539  return (void *)((char *)m_ptr + index * this->getFormat()->getSize());
540  }
541 
542  AGX_FORCE_INLINE const void *Buffer::getElement(size_t index) const
543  {
544  return const_cast<Buffer *>(this)->getElement(index);
545  }
546 
547 
550 
551  AGX_FORCE_INLINE void Buffer::setGlobalResult(agx::GlobalResultBuffer *globalResult) { m_globalResult = globalResult; }
552 
553 
556 
559 
560  //--------------------------------------------
561 
562 
563  template <typename T>
565  {
566  agxAssert(m_buffer);
567  agxAssert(m_buffer->getGlobalResult());
568  return m_buffer->getGlobalResult();
569  }
570 
571  template <typename T>
573  {
574  return this->getGlobalResult()->allocateResult(numElements);
575  }
576 
577  template <typename T>
578  AGX_FORCE_INLINE size_t Array<T>::commitResult(size_t numElements, const void *localResult, agx::Index sortIndex)
579  {
580  if (numElements == 0)
581  return agx::InvalidIndex;
582 
583  return this->getGlobalResult()->commit(*this, numElements, localResult, sortIndex);
584  }
585 
586  template <typename T>
587  AGX_FORCE_INLINE size_t Array<T>::commitResult(size_t numElements, const void *localResult)
588  {
589  if (numElements == 0)
590  return agx::InvalidIndex;
591 
592  return this->getGlobalResult()->commit(*this, numElements, localResult);
593  }
594 
595  template <typename T> template <typename T2>
596  AGX_FORCE_INLINE size_t Array<T>::commitResult(const T2& vector, agx::Index sortIndex)
597  {
598  if (vector.empty())
599  return agx::InvalidIndex;
600 
601  return this->getGlobalResult()->commit(*this, vector, sortIndex);
602  }
603 
604 
605  template <typename T> template <typename T2>
606  AGX_FORCE_INLINE size_t Array<T>::commitResult(const T2& vector)
607  {
608  if (vector.empty())
609  return agx::InvalidIndex;
610 
611  return this->getGlobalResult()->commit(*this, vector);
612  }
613 
614  //---------------------------------------------------------------
615 
616  AGX_FORCE_INLINE AbstractArray& Data::asArray() { return *static_cast<AbstractArray *>(this); }
617  AGX_FORCE_INLINE const AbstractArray& Data::asArray() const { return *static_cast<const AbstractArray *>(this); }
618 
619  template <typename T>
620  AGX_FORCE_INLINE Array<T>& Data::asArray() { return *static_cast<Array<T> *>(this); }
621 
622  template <typename T>
623  AGX_FORCE_INLINE const Array<T>& Data::asArray() const { return *static_cast<const Array<T> *>(this); }
624 
625  //---------------------------------------------------------------
626 
628  {}
629 
631  {
632  if (buffer != nullptr)
633  {
634  this->init(buffer);
635  }
636  else
637  {
638  this->init();
639  }
640  }
641 
643  {
644  this->init(buffer, range);
645  }
646 
648  {
649  agxAssert(localRange.end() <= other.m_range.size());
650  agx::IndexRange32 range(other.m_range.begin() + localRange.begin(), other.m_range.begin() + localRange.end());
651  this->init(other.m_buffer, range);
652  }
653 
655  {
656  m_ptr = nullptr;
657  m_buffer = nullptr;
659  }
660 
662  {
663  agxAssert(buffer);
664  // agxAssert(buffer->getType() == this->getType());
665  agxAssert(range.end() <= std::max(buffer->size(), (size_t)buffer->getArray().range().end()));
666 
667  m_buffer = buffer;
668  m_range = range;
669  this->sync();
670  }
671 
672 
674  {
675  agxAssert(buffer);
676  this->init(buffer, agx::IndexRange32(0, agx::UInt32(buffer->size())));
677  }
678 
680  {
681  agxAssert(buffer);
682  m_buffer = buffer;
683  this->sync();
684  }
685 
686 
688  {
690  agxAssert(range.end() <= std::max(m_buffer->size(), (size_t)m_buffer->getArray().range().end()));
691  m_range = range;
692  this->sync();
693  }
694 
695 
696  AGX_FORCE_INLINE void AbstractArray::setRange(size_t startIndex, size_t endIndex)
697  {
698  this->setRange(agx::IndexRange32(agx::UInt32(startIndex), agx::UInt32(endIndex)));
699  }
700 
701 
703  {
705  m_ptr = ((char*)m_buffer->ptr()) + m_range.begin() * m_buffer->getFormat()->getSize();
706  }
707 
709  {
710  return m_range.size();
711  }
712 
714  {
715  return m_range.size() == 0;
716  }
717 
718 
720  AGX_FORCE_INLINE const Buffer* AbstractArray::buffer() const { return m_buffer; }
723 
724  AGX_FORCE_INLINE bool AbstractArray::isValid() const { return m_buffer != nullptr; }
725 
727  AGX_FORCE_INLINE const Format* AbstractArray::getFormat() const { return m_buffer != nullptr ? m_buffer->getFormat() : nullptr; }
728 
729 
730  //---------------------------------------------------------------
731 
732  template <typename T>
734  {
735  Array<T> result;
736  #include <agx/PushDisableWarnings.h>
737  result.m_ptr = buffer;
738  result.m_range = agx::IndexRange32(0, size);
739  #include <agx/PopDisableWarnings.h>
740  return result;
741  }
742 
743  template <typename T>
744  AGX_FORCE_INLINE const Array<T> Array<T>::raw(const T* buffer, agx::Index size)
745  {
746  Array<T> result;
747  #include <agx/PushDisableWarnings.h>
748  result.m_ptr = (T *)buffer;
749  result.m_range = agx::IndexRange32(0, size);
750  #include <agx/PopDisableWarnings.h>
751  return result;
752  }
753 
754  template <typename T>
756  {
757  }
758 
759  template <typename T>
761  {
762  #ifndef AGX_ENTITY_WRAPPER
763  agxAssert( agxCore::isShutdown() || (buffer->getFormat()->is(agxData::getFormat<T>()) && buffer->getFormat()->getSize() == agxData::getFormat<T>()->getSize()));
764  #endif
765  }
766 
767 
768  template <typename T>
770  {
771  #ifndef AGX_ENTITY_WRAPPER
772  agxAssert( agxCore::isShutdown() || (buffer->getFormat()->is(agxData::getFormat<T>()) && buffer->getFormat()->getSize() == agxData::getFormat<T>()->getSize()));
773  #endif
774  }
775 
776  template <typename T>
777  AGX_FORCE_INLINE Array<T>::Array(const Array<T>& other, agx::IndexRange32 localRange) : AbstractArray(other, localRange)
778  {
779  }
780 
781  template <typename T>
783  {
784  this->m_ptr = vec.ptr();
785  this->m_range = agx::IndexRange32(0, (agx::Index)vec.size());
786  }
787 
788  template <typename T>
790  {
791  agxAssert(range.begin() < range.end() && range.end() <= vec.size());
792  this->m_ptr = vec.ptr();
793  this->m_range = range;
794  }
795 
796  template <typename T>
798  {
799  this->m_ptr = vec.ptr();
800  this->m_range = agx::IndexRange32(0, (agx::Index)vec.size());
801  }
802 
803  template <typename T>
805  {
806  agxAssert(range.begin() < range.end() && range.end() <= vec.size());
807  this->m_ptr = vec.ptr();
808  this->m_range = range;
809  }
810 
811  template <typename T>
813  {
814  agxAssert(m_ptr);
815  agxAssert1(!m_range.empty(), "Can not take back element of an empty array!");
816  return ((T*)m_ptr)[m_range.size()-1];
817  }
818 
819  template <typename T>
821  {
822  agxAssert(m_ptr);
823  agxAssert1(!m_range.empty(), "Can not take back element of an empty array!");
824  return ((T*)m_ptr)[m_range.size()-1];
825  }
826 
827  template <typename T>
829  {
830  agxAssert(m_ptr);
831  agxAssert1(!m_range.empty(), "Can not take front element of an empty array!");
832  return ((T*)m_ptr)[0];
833  }
834 
835  template <typename T>
837  {
838  agxAssert(m_ptr);
839  agxAssert1(!m_range.empty(), "Can not take front element of an empty array!");
840  return ((T*)m_ptr)[0];
841  }
842 
843 
844  template <typename T>
846  {
847  agxAssert1(m_ptr, "Array does not have an active buffer!");
848  agxAssertN(index < m_range.size(), "Array index %llu is out of bounds, size is %llu", (long long unsigned)index, (long long unsigned)m_range.size());
849  return ((T*)m_ptr)[index];
850  }
851 
852 
853  template <typename T>
854  AGX_FORCE_INLINE const T& Array<T>::operator[] (size_t index) const
855  {
856  return const_cast<Array<T>*>(this)->operator[](index);
857  }
858 
859  template <typename T>
861  {
862  agxAssert(m_ptr);
863  agxVerifyN(index < m_range.size(), "Array index %llu is out of bounds, size is %llu", (long long unsigned)index, (long long unsigned)m_range.size());
864  return ((T*)m_ptr)[index];
865  }
866 
867  template <typename T>
868  AGX_FORCE_INLINE const T& Array<T>::at(size_t index) const
869  {
870  return const_cast<Array<T>*>(this)->at(index);
871  }
872 
873 
874  template <typename T>
876  {
877  return Array<T>(m_buffer, agx::IndexRange32(m_range.begin() + subRange.begin(), m_range.begin() + subRange.end()));
878  }
879 
880 
881  template <typename T>
883  {
884  return this->slice(subRange);
885  }
886 
887  template <typename T>
889 
890  template <typename T>
891  AGX_FORCE_INLINE typename Array<T>::const_iterator Array<T>::begin() const { return ptr(); }
892 
893  template <typename T>
894  AGX_FORCE_INLINE typename Array<T>::iterator Array<T>::end() { return ptr() + size(); }
895 
896  template <typename T>
897  AGX_FORCE_INLINE typename Array<T>::const_iterator Array<T>::end() const { return ptr() + size(); }
898 
899  template <typename T>
900  AGX_FORCE_INLINE T* Array<T>::ptr() { return (T*)m_ptr; }
901 
902 
903  template <typename T>
904  AGX_FORCE_INLINE const T* Array<T>::ptr() const { return (const T*)m_ptr; }
905 
906 
907  template <typename T> template <typename T2>
908  AGX_FORCE_INLINE size_t Array<T>::find(const T2& element) const
909  {
910  for (size_t i = 0, numElements = size(); i < numElements; ++i)
911  {
912  if ((*this)[i] == element)
913  return i;
914  }
915 
916  return agx::InvalidIndex;
917  }
918 
919  template <typename T> template <typename T2>
920  AGX_FORCE_INLINE bool Array<T>::contains(const T2& element) const
921  {
922  return this->find(element) != agx::InvalidIndex;
923  }
924 
925 
926  template <typename T>
927  std::ostream& operator << ( std::ostream& output, const Array<T>& array)
928  {
929  for (size_t i = 0; i < array.size(); i++)
930  {
931  output << array[i];
932 
933  if (i < array.size()-1)
934  output << ", ";
935  }
936 
937  return output;
938  }
939 
940 
941  //--------------------------------------------
942 
943 
944  template <typename T> template <typename T2>
946  {
947  const Buffer *buffer = dynamic_cast<const Buffer *>(object);
948  return buffer ? buffer->getFormat() == agxData::getFormat<T>() : false;
949  }
950 
951  template <typename T>
953  {
954  }
955 
956  template <typename T>
958  {
959  }
960 
961  template <typename T>
963  {
964  }
965 
966 
967  template <typename T>
969  {
970  agxAssert(agxData::getFormat<T>() == this->getFormat());
971  return reinterpret_cast<Array<T>&>(m_array);
972  }
973 
974  template <typename T>
975  AGX_FORCE_INLINE const Array<T>& BufferT<T>::array() const
976  {
977  return const_cast<BufferT<T> *>(this)->array();
978  }
979 
980 
981 
982  template <typename T>
984  {
985  if (m_size == m_capacity)
986  this->reserve(std::max((size_t)4, (size_t)((agx::Real)m_size * Buffer::CAPACITY_MULTIPLIER)));
987 
988  m_size++;
989  array().range().end()++;
990  ::new((void *)&array().back()) T(value);
991  }
992 
993  template <typename T>
995  {
996  agxAssert(!array().empty());
997 
998  array().back().~T();
999  array().range().end()--;
1000  m_size--;
1001  }
1002 
1003  template <typename T>
1005  {
1006  for (size_t i = 0; i < m_size; ++i)
1007  array()[i].~T();
1008 
1009  m_size = 0;
1010  array().range().end() = 0;
1011  }
1012 
1013  template <typename T> template <typename T2>
1014  AGX_FORCE_INLINE bool BufferT<T>::contains(const T2& value) const
1015  {
1016  return array().contains(value);
1017  }
1018 
1019  template <typename T> template <typename T2>
1020  AGX_FORCE_INLINE size_t BufferT<T>::find(const T2& value) const
1021  {
1022  return array().find(value);
1023  }
1024 
1025  template <typename T>
1027  {
1028  return array()[index];
1029  }
1030 
1031  template <typename T>
1032  AGX_FORCE_INLINE const T& BufferT<T>::operator[] (size_t index) const
1033  {
1034  return const_cast<BufferT<T> *>(this)->operator[](index);
1035  }
1036 
1037  template <typename T>
1039  {
1040  return array().at(index);
1041  }
1042 
1043  template <typename T>
1044  AGX_FORCE_INLINE const T& BufferT<T>::at(size_t index) const
1045  {
1046  return const_cast<BufferT<T> *>(this)->at(index);
1047  }
1048 
1049  template <typename T>
1051  {
1052  return array().front();
1053  }
1054 
1055  template <typename T>
1056  AGX_FORCE_INLINE const T& BufferT<T>::front() const
1057  {
1058  return const_cast<BufferT<T> *>(this)->front();
1059  }
1060 
1061  template <typename T>
1063  {
1064  return array().back();
1065  }
1066 
1067  template <typename T>
1068  AGX_FORCE_INLINE const T& BufferT<T>::back() const
1069  {
1070  return const_cast<BufferT<T> *>(this)->back();
1071  }
1072 
1073 
1074 
1075  template <typename T>
1077  {
1078  return array().begin();
1079  }
1080 
1081  template <typename T>
1083  {
1084  return array().begin();
1085  }
1086 
1087  template <typename T>
1089  {
1090  return array().end();
1091  }
1092 
1093  template <typename T>
1095  {
1096  return array().end();
1097  }
1098 
1099  template <typename T>
1101  {
1102  Buffer::commit();
1103  }
1104 
1105  template <typename T>
1107  {
1108  Buffer::commit(range);
1109  }
1110 
1111  template <typename T>
1113  {
1114  Buffer::commit(index);
1115  }
1116 
1117  template <typename T>
1119  {
1120  Buffer::commit(indexList);
1121  }
1122 
1123  template <typename T>
1125  {
1126  Buffer::commit(agxData::IndexArray::raw(indexList.ptr(), indexList.size()));
1127  }
1128 
1129 
1130 }
1131 
1133 
1134 #ifdef _MSC_VER
1135 # pragma warning(pop)
1136 #endif
1137 
1138 
1139 #endif /* AGXDATA_BUFFER_H */
agx::UInt64
uint64_t UInt64
Definition: Integer.h:41
agxData::AbstractArray::m_range
agx::IndexRange32 m_range
Definition: Array.h:97
agx::Vector::ptr
T * ptr()
Get access to the internal data buffer.
Definition: Vector.h:677
agxData::BufferT::contains
bool contains(const T2 &value) const
Definition: Buffer.h:1014
agxData::Buffer::m_array
AbstractArray m_array
Definition: Buffer.h:342
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agxData::Buffer::MIN_BUFFER_CAPACITY
static agx::UInt MIN_BUFFER_CAPACITY
Definition: Buffer.h:66
agxData::Buffer::m_revision
agx::UInt64 m_revision
Definition: Buffer.h:338
agxData::BufferT::front
T & front()
Definition: Buffer.h:1050
agx::end
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
Definition: LinearProbingHashSet.h:612
agxData::Value
Abstract representation of a value.
Definition: Value.h:42
agxData::Buffer::getAttribute
agxData::Attribute * getAttribute()
Definition: Buffer.h:471
agx::Real
double Real
Definition: Real.h:42
agxData::AbstractArray
Arrays are fast accessors into the data, or a portion of it, held by a Buffer.
Definition: Array.h:36
agxData::Data::asArray
const AbstractArray & asArray() const
Definition: Buffer.h:616
agx::IndexRangeT::size
T size() const
Definition: IndexRange.h:168
agxData::AbstractArray::AbstractArray
AbstractArray()
Create a new invalid array.
Definition: Buffer.h:627
Vector.h
agxData::Buffer::m_defaultElementValue
agxData::ValueRef m_defaultElementValue
Definition: Buffer.h:348
agxAssert1
#define agxAssert1(expr, msg)
Definition: debug.h:144
agxData::getFormat
AGXCORE_EXPORT Format * getFormat(const agx::String &typeFormatName)
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxData::BufferT
Definition: Buffer.h:396
agx::ByteAllocator
Byte allocator.
Definition: Allocator.h:56
agx::Container::size
size_t size() const
Definition: Container.h:134
agxData::AbstractArray::empty
bool empty() const
Definition: Buffer.h:713
agxData::BufferT::~BufferT
virtual ~BufferT()
Definition: Buffer.h:962
agxData::Buffer::m_elementBuffer
agxData::BufferRef m_elementBuffer
Definition: Buffer.h:349
agxData::BufferT::find
size_t find(const T2 &value) const
Definition: Buffer.h:1020
agxData::Buffer::capacityParameter
agxData::ValueRefT< agx::UInt > capacityParameter
Definition: Buffer.h:79
agx::Model::is
bool is(const agx::Model *other) const
agxData::Buffer::m_initializer
RangeCallback m_initializer
Definition: Buffer.h:357
agx::VectorPOD::ptr
T * ptr()
Get access to the internal data buffer.
Definition: Vector.h:1324
agxData::getType
AGXCORE_EXPORT Type * getType(const agx::String &name)
agxData::AbstractArray::sync
void sync()
Updates the internal data access pointer. Called when the back end buffer is reallocated.
Definition: Buffer.h:702
agxData::Buffer::m_eventDispatch
EventDispatch m_eventDispatch
Definition: Buffer.h:355
agxAssert
#define agxAssert(expr)
Definition: debug.h:143
agxData::Buffer::ALIGNMENT
static agx::UInt ALIGNMENT
Definition: Buffer.h:67
agxData::Array::Array
Array()
Create a new invalid array.
Definition: Buffer.h:755
m_capacity
#define m_capacity
Definition: Vector.h:430
agxData::Format
A format is an implementation of a agxData::Type.
Definition: Format.h:63
agxData::EntityStorage
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
agx::IndexVector
VectorPOD< Index > IndexVector
Definition: agx_vector_types.h:109
agxData::AbstractArray::m_buffer
agxData::Buffer * m_buffer
Definition: Array.h:96
agxData::BufferT::operator[]
T & operator[](size_t index)
Definition: Buffer.h:1026
agxData::Array::raw
static agxData::Array< T > raw(T *buffer, agx::Index size)
Array creation helper method that creates an array covering the given memory area.
Definition: Buffer.h:733
agxData::BufferT::ValidateCast
static bool ValidateCast(const agx::Referenced *object)
Definition: Buffer.h:945
BufferEvent.Implementation.h
agx::EventT< Callback1< Value * > >::CallbackType
Callback1< Value * > CallbackType
Definition: Event.h:37
Array.h
agxData::Buffer::m_size
size_t m_size
Definition: Buffer.h:336
agx::VectorPOD< Index >
agx::GlobalResultBuffer
Definition: GlobalResult.h:299
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agxData
Contains classes for low level data storage for AGX.
Definition: Container.h:23
agx::Model
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:40
agx::begin
LinearProbingHashSetImplementation< KeyT, HashT >::iterator begin(LinearProbingHashSetImplementation< KeyT, HashT > &set)
Definition: LinearProbingHashSet.h:606
agxData::Array
Type-specific Array used for fast access into the data held by a Buffer.
Definition: agxData.h:30
agxData::Buffer::m_format
FormatRef m_format
Definition: Buffer.h:347
agx::IndexRangeT< agx::UInt >
agxData::Array::commitResult
size_t commitResult(size_t numElements, const void *localResult, agx::Index sortIndex)
Definition: Buffer.h:578
agxData::AbstractArray::init
void init()
Set to empty array.
Definition: Buffer.h:654
agxData::ValueT::get
const T & get() const
Definition: Value.h:448
AGX_DECLARE_VECTOR_TYPES
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
agxData::Buffer::empty
bool empty() const
Definition: Buffer.h:461
agxData::Vector
Definition: ata/Vector.h:27
agxData::Buffer::size
size_t size() const
Definition: Buffer.h:459
agxData::Buffer::m_initElements
bool m_initElements
Definition: Buffer.h:343
agx::ref_ptr< Format >
agxData::Buffer::m_usedResizeMethod
bool m_usedResizeMethod
Definition: Buffer.h:344
agxData::ShareHandle
Definition: ShareHandle.h:32
agxData::BufferT::back
T & back()
Definition: Buffer.h:1062
agxData::Buffer::getElementArraySize
size_t getElementArraySize() const
Definition: Buffer.h:466
agxData::Buffer::m_attribute
Attribute * m_attribute
Definition: Buffer.h:346
agxData::BufferT::value_type
T value_type
Definition: Buffer.h:404
agxVerifyN
#define agxVerifyN(expr, format,...)
Definition: debug.h:133
PushDisableWarnings.h
agxData::Buffer::getElementBuffer
Buffer * getElementBuffer()
If the buffer contains arrays/vectors, the actual elements are stored in another buffer.
Definition: Buffer.h:554
agxTerrain::Profiler::getStorage
AGXTERRAIN_EXPORT TimingStorage & getStorage()
agxData::Buffer::m_ptr
void * m_ptr
Definition: Buffer.h:340
agxData::AbstractArray::buffer
const agxData::Buffer * buffer() const
Definition: Buffer.h:719
ShareHandle.h
agx::Index
UInt32 Index
Definition: Integer.h:52
agxData::AbstractArray::getFormat
agxData::Format * getFormat()
Definition: Buffer.h:726
agxData::Type
Abstracted type.
Definition: Type.h:97
agxData::AbstractArray::setRange
void setRange(size_t startIndex, size_t endIndex)
Set the range of the buffer that the array will cover.
Definition: Buffer.h:696
agxData::Buffer::m_allocator
agx::ByteAllocator m_allocator
Definition: Buffer.h:341
agxData::Buffer
Abstract representation of a data buffer.
Definition: Buffer.h:55
agxData::Array::allocateResult
agx::GlobalResult::Transaction allocateResult(size_t numElements)
Definition: Buffer.h:572
m_size
#define m_size
Definition: Vector.h:429
Component.h
agxData::Buffer::m_resizeCallback
agxData::Value::Event::CallbackType m_resizeCallback
Definition: Buffer.h:352
Event.h
agx::Object::fullName
agx::String fullName() const
agxData::Buffer::reallocationEvent
Event reallocationEvent
Triggered when buffer is reallocated.
Definition: Buffer.h:85
agxData::Buffer::capacity
size_t capacity() const
Definition: Buffer.h:460
agx::Name
Representation of a name string.
Definition: Name.h:32
agxData::Buffer::sizeParameter
agxData::ValueRefT< agx::UInt > sizeParameter
Definition: Buffer.h:78
agxData::BufferT::BufferT
BufferT()
Definition: Buffer.h:952
agxData::BufferT::commit
void commit()
Definition: Buffer.h:1100
agxData::BufferT::end
iterator end()
Definition: Buffer.h:1088
agxData::AbstractArray::range
agx::IndexRange32 & range()
Definition: Buffer.h:721
agx::Component
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
agxData::Buffer::getElement
T & getElement(size_t index)
Definition: Buffer.h:517
agxData::Buffer::getArray
agxData::Array< T > & getArray()
Convenience method to get an direct data array.
agxData::AbstractArray::isValid
bool isValid() const
Definition: Buffer.h:724
agx.h
agxData::Buffer::CAPACITY_MULTIPLIER
static agx::Real CAPACITY_MULTIPLIER
Definition: Buffer.h:65
agxData::Buffer::m_globalOrderBuffer
agxData::BufferRef m_globalOrderBuffer
Definition: Buffer.h:350
agxData::Buffer::getGlobalResult
agx::GlobalResultBuffer * getGlobalResult()
Definition: Buffer.h:548
agx::IndexRangeT::begin
T & begin()
Definition: IndexRange.h:214
agxData::Buffer::m_shareHandle
agxData::ShareHandleRef m_shareHandle
Definition: Buffer.h:361
agxData::Buffer::m_globalResult
agx::GlobalResultBuffer * m_globalResult
Definition: Buffer.h:354
agx::Event1< Buffer * >
agx::Referenced::is
bool is() const
Subclass test.
agxCore::isShutdown
bool AGXCORE_EXPORT isShutdown()
agx::GlobalResult::Transaction
Transactions are used to reserve exclusive memory areas in which the threads can write their data.
Definition: GlobalResult.h:72
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
agxData::Array::iterator
T * iterator
Definition: Array.h:116
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agxData::Buffer::m_originalBuffer
agxData::Buffer * m_originalBuffer
Definition: Buffer.h:362
agx::UInt
uint32_t UInt
Definition: Integer.h:34
agxData::Buffer::getRevision
agx::UInt64 getRevision() const
Definition: Buffer.h:464
agxData::Buffer::getFormat
agxData::Format * getFormat()
Definition: Buffer.h:476
agxData::BufferProxyAllocator
Definition: Buffer.h:369
agxData::Buffer::Event
agx::Event1< Buffer * > Event
Definition: Buffer.h:82
agxData::BufferT::clear
void clear()
Definition: Buffer.h:1004
agxData::ValueRefT< agx::UInt >
agxData::Buffer::m_reserveCallback
agxData::Value::Event::CallbackType m_reserveCallback
Definition: Buffer.h:353
agx::Container
The Container is the base class for several of the container classes proided by AGX,...
Definition: Container.h:34
agxData::Buffer::commit
void commit()
agxData::BufferT::begin
iterator begin()
Definition: Buffer.h:1076
agxData::BufferT::Type
T Type
Definition: Buffer.h:403
agxData::BufferT::at
T & at(size_t index)
Definition: Buffer.h:1038
agx::Device
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:57
agxData::Array::getGlobalResult
agx::GlobalResult * getGlobalResult()
Definition: Buffer.h:564
agxData::BufferT::push_back
void push_back(const T &value)
Definition: Buffer.h:983
agx::AgXString< std::string >
agxAssertN
#define agxAssertN(expr, format,...)
Definition: debug.h:145
agx::init
void AGXPHYSICS_EXPORT init()
Initialize agx.
agx::IndexRangeT::end
T & end()
Definition: IndexRange.h:217
agxData::BufferT::const_iterator
const typedef T * const_iterator
Definition: Buffer.h:406
agxData::Buffer::getDefaultValue
agxData::Value * getDefaultValue()
Definition: Buffer.h:479
agxData::Buffer::m_storage
EntityStorage * m_storage
Definition: Buffer.h:345
agx::InvalidIndex
const AGXCORE_EXPORT InvalidIndexStruct InvalidIndex
operator<<
std::ostream & operator<<(std::ostream &o, const agx::Vec6 &v)
Definition: Vec6.h:230
agxTerrain::Profiler::clear
AGXTERRAIN_EXPORT void clear()
agx::Callback2< Buffer *, const agx::IndexRange & >
agxData::Data::m_ptr
void * m_ptr
Definition: Data.h:72
agxData::Buffer::getStorage
agxData::EntityStorage * getStorage()
Definition: Buffer.h:468
agxData::Attribute
An abstract attribute description, part of an Entity.
Definition: Attribute.h:57
agxData::Buffer::m_capacity
size_t m_capacity
Definition: Buffer.h:337
agx::max
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:874
agxData::Buffer::getGlobalOrderBuffer
Buffer * getGlobalOrderBuffer()
If the buffer is used as a global result, we provide a permutation buffer for parallel determinism.
Definition: Buffer.h:557
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agx::IndexRange32
IndexRangeT< agx::UInt32 > IndexRange32
Definition: IndexRange.h:141
agxData::BufferT::iterator
T * iterator
Definition: Buffer.h:405
agxData::BufferT::pop_back
void pop_back()
Definition: Buffer.h:994
agxData::Buffer::m_sharedContainer
agx::Container * m_sharedContainer
Definition: Buffer.h:351
agxData::Format::getSize
size_t getSize() const
Definition: Format.h:593
Value.h
agxData::Buffer::getType
agxData::Type * getType()
Definition: Buffer.h:474
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agxData::Buffer::m_destructor
RangeCallback m_destructor
Definition: Buffer.h:358
agxData::AbstractArray::_setBuffer
void _setBuffer(agxData::Buffer *buffer)
Set the buffer while maintaining the current range, should normally not be used.
Definition: Buffer.h:679
agxData::AbstractArray::size
size_t size() const
Definition: Buffer.h:708
agxData::Buffer::RangeCallback
agx::Callback2< Buffer *, const agx::IndexRange & > RangeCallback
Specify a custom element initializer callback.
Definition: Buffer.h:285
agx::ref_ptr::get
T * get() const
Definition: ref_ptr.h:256
agxData::Buffer::ptr
void * ptr()
Get access to the raw data buffer.
Definition: Buffer.h:499
agx::GlobalResult
GlobalResult is used by kernels to generate result data from different threads.
Definition: GlobalResult.h:51
PopDisableWarnings.h
BufferEvent.Declaration.h