DART 6.10.1
Loading...
Searching...
No Matches
SpecializedNodeManager.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2021, 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_DYNAMICS_DETAIL_SPECIALIZEDNODEMANAGER_HPP_
34#define DART_DYNAMICS_DETAIL_SPECIALIZEDNODEMANAGER_HPP_
35
37
38namespace dart {
39namespace dynamics {
40
41// This preprocessor token should only be used by the unittest that is
42// responsible for checking that the specialized routines are being used to
43// access specialized Aspects
44#ifdef DART_UNITTEST_SPECIALIZED_NODE_ACCESS
45bool usedSpecializedNodeAccess;
46#endif // DART_UNITTEST_SPECIALIZED_NODE_ACCESS
47
48//==============================================================================
49template <class SpecNode>
51{
52 mNodeMap[typeid(SpecNode)] = std::vector<Node*>();
53 mSpecNodeIterator = mNodeMap.find(typeid(SpecNode));
54}
55
56//==============================================================================
57template <class SpecNode>
58template <class NodeType>
60{
61 return _getNumNodes(type<NodeType>());
62}
63
64//==============================================================================
65template <class SpecNode>
66template <class NodeType>
68{
69 return _getNode(type<NodeType>(), index);
70}
71
72//==============================================================================
73template <class SpecNode>
74template <class NodeType>
76 std::size_t index) const
77{
78 return const_cast<BodyNodeSpecializedFor<SpecNode>*>(this)->_getNode(
80}
81
82//==============================================================================
83template <class SpecNode>
84template <class NodeType>
86{
87 return _isSpecializedForNode(type<NodeType>());
88}
89
90//==============================================================================
91template <class SpecNode>
92template <class NodeType>
94{
95 return detail::BasicNodeManagerForBodyNode::getNumNodes<NodeType>();
96}
97
98//==============================================================================
99template <class SpecNode>
101{
102#ifdef DART_UNITTEST_SPECIALIZED_NODE_ACCESS
103 usedSpecializedNodeAccess = true;
104#endif // DART_UNITTEST_SPECIALIZED_NODE_ACCESS
105
106 return mSpecNodeIterator->second.size();
107}
108
109//==============================================================================
110template <class SpecNode>
111template <class NodeType>
113 type<NodeType>, std::size_t index)
114{
115 return detail::BasicNodeManagerForBodyNode::getNode<NodeType>(index);
116}
117
118//==============================================================================
119template <class SpecNode>
121 type<SpecNode>, std::size_t index)
122{
123#ifdef DART_UNITTEST_SPECIALIZED_NODE_ACCESS
124 usedSpecializedNodeAccess = true;
125#endif // DART_UNITTEST_SPECIALIZED_NODE_ACCESS
126
127 return static_cast<SpecNode*>(
128 getVectorObjectIfAvailable(index, mSpecNodeIterator->second));
129}
130
131//==============================================================================
132template <class SpecNode>
133template <class NodeType>
136{
137 return false;
138}
139
140//==============================================================================
141template <class SpecNode>
144{
145 return true;
146}
147
148//==============================================================================
149template <class SpecNode>
151{
152 mSpecializedTreeNodes[typeid(SpecNode)] = &mTreeSpecNodeIterators;
153
154 mNodeNameMgrMap[typeid(SpecNode)] = common::NameManager<Node*>();
155 mSpecNodeNameMgrIterator = mNodeNameMgrMap.find(typeid(SpecNode));
156}
157
158//==============================================================================
159template <class SpecNode>
160template <class NodeType>
162 std::size_t treeIndex) const
163{
164 return _getNumNodes(type<NodeType>(), treeIndex);
165}
166
167//==============================================================================
168template <class SpecNode>
169template <class NodeType>
171 std::size_t treeIndex, std::size_t nodeIndex)
172{
173 return _getNode(type<NodeType>(), treeIndex, nodeIndex);
174}
175
176//==============================================================================
177template <class SpecNode>
178template <class NodeType>
180 std::size_t treeIndex, std::size_t nodeIndex) const
181{
182 return const_cast<SkeletonSpecializedFor<SpecNode>*>(this)->_getNode(
183 type<NodeType>(), treeIndex, nodeIndex);
184}
185
186//==============================================================================
187template <class SpecNode>
188template <class NodeType>
190{
191 return _getNode(type<NodeType>(), name);
192}
193
194//==============================================================================
195template <class SpecNode>
196template <class NodeType>
198 const std::string& name) const
199{
200 return const_cast<SkeletonSpecializedFor<SpecNode>*>(this)->_getNode(
202}
203
204//==============================================================================
205template <class SpecNode>
206template <class NodeType>
208{
209 return _isSpecializedForNode(type<NodeType>());
210}
211
212//==============================================================================
213template <class SpecNode>
214template <class NodeType>
216 type<NodeType>, std::size_t treeIndex) const
217{
218 return detail::BasicNodeManagerForSkeleton::getNumNodes<NodeType>(treeIndex);
219}
220
221//==============================================================================
222template <class SpecNode>
224 type<SpecNode>, std::size_t treeIndex) const
225{
226#ifdef DART_UNITTEST_SPECIALIZED_NODE_ACCESS
227 usedSpecializedNodeAccess = true;
228#endif // DART_UNITTEST_SPECIALIZED_NODE_ACCESS
229
230 if (treeIndex >= mTreeNodeMaps.size())
231 {
232 dterr << "[Skeleton::getNumNodes<" << typeid(SpecNode).name() << ">] "
233 << "Requested tree index (" << treeIndex << "), but there are only ("
234 << mTreeNodeMaps.size() << ") trees available\n";
235 assert(false);
236 return 0;
237 }
238
239 return mTreeSpecNodeIterators[treeIndex]->second.size();
240}
241
242//==============================================================================
243template <class SpecNode>
244template <class NodeType>
246 type<NodeType>, std::size_t treeIndex, std::size_t nodeIndex)
247{
248 return detail::BasicNodeManagerForSkeleton::getNode<NodeType>(
249 treeIndex, nodeIndex);
250}
251
252//==============================================================================
253template <class SpecNode>
255 type<SpecNode>, std::size_t treeIndex, std::size_t nodeIndex)
256{
257#ifdef DART_UNITTEST_SPECIALIZED_NODE_ACCESS
258 usedSpecializedNodeAccess = true;
259#endif // DART_UNITTEST_SPECIALIZED_NODE_ACCESS
260
261 if (treeIndex >= mTreeNodeMaps.size())
262 {
263 dterr << "[Skeleton::getNode<" << typeid(SpecNode).name() << ">] "
264 << "Requested tree index (" << treeIndex << "), but there are only ("
265 << mTreeNodeMaps.size() << ") trees available\n";
266 assert(false);
267 return nullptr;
268 }
269
270 NodeMap::iterator& it = mTreeSpecNodeIterators[treeIndex];
271
272 if (nodeIndex >= it->second.size())
273 {
274 dterr << "[Skeleton::getNode<" << typeid(SpecNode).name() << ">] "
275 << "Requested index (" << nodeIndex << ") within tree (" << treeIndex
276 << "), but there are only (" << it->second.size() << ") Nodes of the "
277 << "requested type within that tree\n";
278 assert(false);
279 return nullptr;
280 }
281
282 return static_cast<SpecNode*>(it->second[nodeIndex]);
283}
284
285//==============================================================================
286template <class SpecNode>
287template <class NodeType>
289 type<NodeType>, const std::string& name)
290{
291 return detail::BasicNodeManagerForSkeleton::getNode<NodeType>(name);
292}
293
294//==============================================================================
295template <class SpecNode>
297 type<SpecNode>, const std::string& name)
298{
299#ifdef DART_UNITTEST_SPECIALIZED_NODE_ACCESS
300 usedSpecializedNodeAccess = true;
301#endif // DART_UNITTEST_SPECIALIZED_NODE_ACCESS
302
303 return static_cast<SpecNode*>(
304 mSpecNodeNameMgrIterator->second.getObject(name));
305}
306
307//==============================================================================
308template <class SpecNode>
309template <class NodeType>
312{
313 return false;
314}
315
316//==============================================================================
317template <class SpecNode>
320{
321 return true;
322}
323
324} // namespace dynamics
325} // namespace dart
326
327#endif // DART_DYNAMICS_DETAIL_SPECIALIZEDNODEMANAGER_HPP_
#define dterr
Output an error message.
Definition Console.hpp:49
std::string * name
Definition SkelParser.cpp:1697
std::size_t index
Definition SkelParser.cpp:1672
class NameManager
Definition NameManager.hpp:62
Declaration of the variadic template.
Definition SpecializedNodeManager.hpp:50
Declaration of the variadic template.
Definition SpecializedNodeManager.hpp:124
Definition BulletCollisionDetector.cpp:65