AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
StackAllocator.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17
18#ifndef AGX_STACK_ALLOCATOR_H
19#define AGX_STACK_ALLOCATOR_H
20
21#ifndef SWIG_CPPWRAPPER_BUILD
22
24
25#include <agx/agx.h>
26
27namespace 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
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.
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
std::ptrdiff_t difference_type
The agx namespace contains the dynamics/math part of the AGX Dynamics API.