AGX Dynamics  2.35.0.1
StackAllocator.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 
18 #ifndef AGX_STACK_ALLOCATOR_H
19 #define AGX_STACK_ALLOCATOR_H
20 
21 #ifndef SWIG_CPPWRAPPER_BUILD
22 
23 #include <agx/agxPhysics_export.h>
24 
25 #include <agx/agx.h>
26 
27 namespace agx {
28 
29 
53  template <class T, int N >
55  private:
56  T m_data[N];
57  public:
58  // type definitions
59  typedef T value_type;
60  typedef T* pointer;
61  typedef const T* const_pointer;
62  typedef T& reference;
63  typedef const T& const_reference;
64  typedef std::size_t size_type;
65  typedef std::ptrdiff_t difference_type;
66 
67  // return address of values
68  pointer address (reference value) const {
69  return &value;
70  }
72  return &value;
73  }
74 
75  /* constructors and destructor
76  * - nothing to do because the allocator has no state
77  */
78  StackAllocator() throw() {
79  }
80 
81  ~StackAllocator() throw() {
82  }
83 
84  // return maximum number of elements that can be allocated
85  size_type max_size () const throw() {
86  return N;
87  }
88 
89  // allocate but don't initialize num elements of type T
90  pointer allocate (size_type num, const void* = 0) {
91  return m_data;
92  }
93 
94  // initialize elements of allocated storage p with value value
95  void construct (pointer p, const T& value) {
96  // initialize memory with placement new
97  new((void*)p)T(value);
98  }
99 
100  // destroy elements of initialized storage p
101  void destroy (pointer p) {
102  // destroy objects by calling their destructor
103  p->~T();
104  }
105 
106  // deallocate storage p of deleted elements
107  void deallocate (pointer p, size_type num) {
108  }
109  };
110 } // namespace agx
111 
112 #endif // SWIG_CPPWRAPPER_BUILD
113 #endif
The StackAllocator class is designed to be used with the STL vector class.
std::size_t size_type
pointer allocate(size_type num, const void *=0)
pointer address(reference value) const
size_type max_size() const
void construct(pointer p, const T &value)
void destroy(pointer p)
void deallocate(pointer p, size_type num)
const_pointer address(const_reference value) const
const T & const_reference
std::ptrdiff_t difference_type
The agx namespace contains the dynamics/math part of the AGX Dynamics API.