DART 6.7.3
Loading...
Searching...
No Matches
Memory.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2019, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_COMMON_MEMORY_HPP_
34#define DART_COMMON_MEMORY_HPP_
35
36#include <map>
37#include <memory>
38#include <vector>
39
40#include "dart/config.hpp"
43
44namespace dart {
45namespace common {
46
47template <typename _Tp, typename... _Args>
48std::shared_ptr<_Tp> make_aligned_shared(_Args&&... __args);
49
50template<typename T, typename... Args>
51std::unique_ptr<T> make_unique(Args&&... args);
52
53#if EIGEN_VERSION_AT_LEAST(3,2,1) && EIGEN_VERSION_AT_MOST(3,2,8)
54
55template <typename _Tp>
56using aligned_vector = std::vector<_Tp,
57 dart::common::detail::aligned_allocator_cpp11<_Tp>>;
58
59template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>>
60using aligned_map = std::map<_Key, _Tp, _Compare,
61 dart::common::detail::aligned_allocator_cpp11<std::pair<const _Key, _Tp>>>;
62
63#else
64
65template <typename _Tp>
66using aligned_vector = std::vector<_Tp, Eigen::aligned_allocator<_Tp>>;
67
68template <typename _Key, typename _Tp, typename _Compare = std::less<_Key>>
69using aligned_map = std::map<_Key, _Tp, _Compare,
70 Eigen::aligned_allocator<std::pair<const _Key, _Tp>>>;
71
72#endif
73
74} // namespace common
75} // namespace dart
76
77#define DART_RAW_PTR_CREATOR_NAME create
78#define DART_SHARED_PTR_CREATOR_NAME createShared
79#define DART_UNIQUE_PTR_CREATOR_NAME createUnique
80
81// Define static creator function that returns a smart pointer to an object
82#define _DART_DEFINE_OBJECT_CREATOR( \
83 class_name, func_name, ptr_type, creator) \
84 template <typename... Args> \
85 static ptr_type<class_name> func_name(Args&&... args) \
86 { \
87 return creator<class_name>(std::forward<Args>(args)...); \
88 }
89
90// Define static creator function that returns a smart pointer to an object with
91// protected constructor
92#define _DART_DEFINE_OBJECT_CREATOR_FOR_PROTECTED_CTOR( \
93 class_name, func_name, ptr_type, creator) \
94private: \
95 struct private_structure \
96 { \
97 explicit private_structure() \
98 { \
99 } \
100 }; \
101 \
102public: \
103 template <typename... Args> \
104 class_name(const private_structure&, Args&&... args) \
105 : class_name(std::forward<Args>(args)...) \
106 { \
107 } \
108 template <typename... Args> \
109 static ptr_type<class_name> func_name(Args&&... args) \
110 { \
111 return creator<class_name>( \
112 private_structure{}, std::forward<Args>(args)...); \
113 }
114
115// Define static creator function that returns a raw pointer to the object.
116// This static functions will be defined: create()
117#define DART_DEFINE_RAW_OBJECT_CREATOR(class_name) \
118 template <typename... Args> \
119 static class_name* DART_RAW_PTR_CREATOR_NAME(Args&&... args) \
120 { \
121 return new class_name(std::forward<Args>(args)...); \
122 }
123
124// Define static creator function that returns std::shared_ptr to the object.
125// This static functions will be defined: createShared()
126#define DART_DEFINE_SHARED_OBJECT_CREATOR(class_name) \
127 \
128 _DART_DEFINE_OBJECT_CREATOR( \
129 class_name, \
130 DART_SHARED_PTR_CREATOR_NAME, \
131 std::shared_ptr, \
132 std::make_shared)
133
134// Define static creator function that returns std::shared_ptr to the object
135// where the constructor is protected.
136// This static functions will be defined: createShared()
137#define DART_DEFINE_SHARED_OBJECT_CREATOR_FOR_PROTECTED_CTOR(class_name) \
138 \
139 _DART_DEFINE_OBJECT_CREATOR_FOR_PROTECTED_CTOR( \
140 class_name, \
141 DART_SHARED_PTR_CREATOR_NAME, \
142 std::shared_ptr, \
143 std::make_shared)
144
145// Define static creator function that returns std::shared_ptr to the object
146// requires aligned memory allocation.
147// This static functions will be defined: createShared()
148#define DART_DEFINE_ALIGNED_SHARED_OBJECT_CREATOR(class_name) \
149 \
150 _DART_DEFINE_OBJECT_CREATOR( \
151 class_name, \
152 DART_SHARED_PTR_CREATOR_NAME, \
153 std::shared_ptr, \
154 ::dart::common::make_aligned_shared)
155
156// Define static creator function that returns std::shared_ptr to the object
157// requires aligned memory allocation where the constructor is protected.
158// This static functions will be defined: createShared()
159#define DART_DEFINE_ALIGNED_SHARED_OBJECT_CREATOR_FOR_PROTECTED_CTOR( \
160 class_name) \
161 \
162 _DART_DEFINE_OBJECT_CREATOR_FOR_PROTECTED_CTOR( \
163 class_name, \
164 DART_SHARED_PTR_CREATOR_NAME, \
165 std::shared_ptr, \
166 ::dart::common::make_aligned_shared)
167
168// Define static creator function that returns std::unique_ptr to the object
169#define DART_DEFINE_UNIQUE_OBJECT_CREATOR(class_name) duke \
170 \
171 _DART_DEFINE_OBJECT_CREATOR( \
172 class_name, \
173 DART_UNIQUE_PTR_CREATOR_NAME, \
174 std::unique_ptr, \
175 ::dart::common::make_unique)
176
177// Define static creator function that returns std::unique_ptr to the object
178// where the constructor is protected
179#define DART_DEFINE_UNIQUE_OBJECT_CREATOR_FOR_PROTECTED_CTOR(class_name) \
180 \
181 _DART_DEFINE_OBJECT_CREATOR_FOR_PROTECTED_CTOR( \
182 class_name, \
183 DART_UNIQUE_PTR_CREATOR_NAME, \
184 std::unique_ptr, \
185 ::dart::common::make_unique)
186
187// Define two static creator functions that returns std::unique_ptr and
188// std::unique_ptr, respectively, to the object
189#define DART_DEFINE_OBJECT_CREATORS(class_name) \
190 DART_DEFINE_SHARED_OBJECT_CREATOR(class_name) \
191 DART_DEFINE_UNIQUE_OBJECT_CREATOR(class_name)
192
193// Define two static creator functions that returns std::unique_ptr and
194// std::unique_ptr, respectively, to the object where the constructor is
195// protected
196#define DART_DEFINE_OBJECT_CREATORS_FOR_PROTECTED_CTOR(X) \
197 DART_DEFINE_SHARED_OBJECT_CREATOR_FOR_PROTECTED_CTOR(X) \
198 DART_DEFINE_UNIQUE_OBJECT_CREATOR_FOR_PROTECTED_CTOR(X)
199
200// Define two static creator functions that returns std::unique_ptr and
201// std::unique_ptr, respectively, to the object
202#if DART_ENABLE_SIMD
203 #define DART_DEFINE_ALIGNED_OBJECT_CREATORS(class_name) \
204 DART_DEFINE_ALIGNED_SHARED_OBJECT_CREATOR(class_name) \
205 DART_DEFINE_UNIQUE_OBJECT_CREATOR(class_name)
206#else
207 #define DART_DEFINE_ALIGNED_OBJECT_CREATORS(class_name) \
208 DART_DEFINE_OBJECT_CREATORS(class_name)
209#endif
210
211// Define two static creator functions that returns std::unique_ptr and
212// std::unique_ptr, respectively, to the object where the constructor is
213// protected
214#if DART_ENABLE_SIMD
215 #define DART_DEFINE_ALIGNED_OBJECT_CREATORS_FOR_PROTECTED_CTOR(class_name) \
216 DART_DEFINE_CREATE_ALIGNED_PTR_SHARED_FOR_PROTECTED_CTOR(class_name) \
217 DART_DEFINE_UNIQUE_OBJECT_CREATOR_FOR_PROTECTED_CTOR(class_name)
218#else
219 #define DART_DEFINE_ALIGNED_OBJECT_CREATORS_FOR_PROTECTED_CTOR(class_name) \
220 DART_DEFINE_OBJECT_CREATORS_FOR_PROTECTED_CTOR(class_name)
221#endif
222
224
225#endif // DART_COMMON_MEMORY_HPP_
std::shared_ptr< _Tp > make_aligned_shared(_Args &&... __args)
Definition Memory-impl.hpp:51
std::unique_ptr< T > make_unique(Args &&... args)
Definition Memory-impl.hpp:66
std::map< _Key, _Tp, _Compare, Eigen::aligned_allocator< std::pair< const _Key, _Tp > > > aligned_map
Definition Memory.hpp:70
std::vector< _Tp, Eigen::aligned_allocator< _Tp > > aligned_vector
Definition Memory.hpp:66
Definition BulletCollisionDetector.cpp:63