AGX Dynamics  2.38.0.2
StackAllocator.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 
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
agxPhysics_export.h
agx::StackAllocator::~StackAllocator
~StackAllocator()
Definition: StackAllocator.h:81
agx::StackAllocator::const_pointer
const typedef T * const_pointer
Definition: StackAllocator.h:61
agx::StackAllocator::StackAllocator
StackAllocator()
Definition: StackAllocator.h:78
agx::StackAllocator::deallocate
void deallocate(pointer p, size_type num)
Definition: StackAllocator.h:107
agx::StackAllocator
The StackAllocator class is designed to be used with the STL vector class.
Definition: StackAllocator.h:54
agx::StackAllocator::difference_type
std::ptrdiff_t difference_type
Definition: StackAllocator.h:65
agx::StackAllocator::value_type
T value_type
Definition: StackAllocator.h:59
agx::StackAllocator::max_size
size_type max_size() const
Definition: StackAllocator.h:85
agx::StackAllocator::construct
void construct(pointer p, const T &value)
Definition: StackAllocator.h:95
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agx::StackAllocator::size_type
std::size_t size_type
Definition: StackAllocator.h:64
agx::StackAllocator::reference
T & reference
Definition: StackAllocator.h:62
agx.h
agx::StackAllocator::address
pointer address(reference value) const
Definition: StackAllocator.h:68
agx::StackAllocator::const_reference
const typedef T & const_reference
Definition: StackAllocator.h:63
agx::StackAllocator::destroy
void destroy(pointer p)
Definition: StackAllocator.h:101
agx::StackAllocator::pointer
T * pointer
Definition: StackAllocator.h:60
agx::StackAllocator::allocate
pointer allocate(size_type num, const void *=0)
Definition: StackAllocator.h:90
agx::StackAllocator::address
const_pointer address(const_reference value) const
Definition: StackAllocator.h:71