AGX Dynamics  2.37.2.0
Container.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 AGX_CONTAINER_H
18 #define AGX_CONTAINER_H
19 
20 #include <agx/macros.h>
21 #include <agx/agxCore_export.h>
22 
23 namespace agxData { class Buffer; }
24 
25 namespace agx
26 {
27  class ThreadScopeAllocator;
28 
29 
35  {
36  public:
37 
43  {
46  MAINTAIN_BUFFER
47  };
48 
49  public:
50 
52  size_t size() const;
53 
63  size_t capacity() const;
64 
66  bool empty() const;
67 
69  void* ptr();
70  const void* ptr() const;
71 
72 
73  public:
74 
76 
77 
80  void _setBuffer(void* buffer) { m_buffer = buffer; }
81  void _setCapacity(size_t capacity) { m_capacity = capacity; }
82  void _setSize(size_t size) { m_size = size; }
84 
85  protected:
86  Container();
87  Container(Container&& other);
88  Container(const Container& other);
89  ~Container();
90 
91  protected:
92  friend class agxData::Buffer;
93  friend class Thread;
94  size_t m_size;
95  size_t m_capacity;
96  void* m_buffer;
97  };
98 
99 
100 
101  /* Implementation */
102  AGX_FORCE_INLINE Container::Container() : m_size(0), m_capacity(0), m_buffer(nullptr) {}
103  AGX_FORCE_INLINE Container::Container(const Container& other)
104  : m_size(0), m_capacity(0), m_buffer(nullptr)
105  {
106  m_size = other.m_size;
107  m_buffer = other.m_buffer;
108  m_capacity = other.m_capacity;
109  }
110 
112  m_size(0),
113  m_capacity(0),
114  m_buffer(nullptr)
115  {
116  // Move values
117  m_buffer = other.m_buffer;
118  m_capacity = other.m_capacity;
119  m_size = other.m_size;
120 
121  // Set default values to the rvalue reference.
122  other.m_buffer = nullptr;
123  other.m_capacity = 0;
124  other.m_size = 0;
125  }
126 
128  {
129  m_buffer = nullptr;
130  m_size = 0;
131  m_capacity = 0;
132  }
133 
134  AGX_FORCE_INLINE size_t Container::size() const { return m_size; }
136  AGX_FORCE_INLINE bool Container::empty() const { return m_size == 0; }
138  AGX_FORCE_INLINE const void *Container::ptr() const { return m_buffer; }
139 }
140 
141 
142 #endif /* _AGX_CONTAINER_H_ */
The Container is the base class for several of the container classes proided by AGX, such as agx::Vector and agx::HashSet.
Definition: Container.h:34
agx::Thread is a representation of an OS specific implementation of a computational thread...
Definition: Thread.h:198
size_t m_size
Definition: Container.h:94
#define m_size
Definition: Vector.h:429
ClearPolicy
agxData::Values from this enumeration is passed to the subclasses&#39; &#39;clear&#39; method in order to control...
Definition: Container.h:42
#define AGX_FORCE_INLINE
Definition: Object.h:59
size_t m_capacity
Definition: Container.h:95
Buffer is deallocated and replaced by an newly allocated empty buffer.
Definition: Container.h:44
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
size_t capacity() const
Returns the size of the memory are used by the container to store its elements.
Definition: Container.h:135
Abstract representation of a data buffer.
Definition: Buffer.h:55
Contains classes for low level data storage for AGX.
Definition: Container.h:23
void * ptr()
Definition: Container.h:137
void * m_buffer
Definition: Container.h:96
size_t size() const
Definition: Container.h:134
Buffer is shrunk if a smoothing average (which is updated each clear call) goes below a threshold...
Definition: Container.h:45
#define m_capacity
Definition: Vector.h:430
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
bool empty() const
Definition: Container.h:136
#define AGXCORE_EXPORT
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97