33#ifndef DART_DYNAMICS_DETAIL_BASICNODEMANAGER_HPP_
34#define DART_DYNAMICS_DETAIL_BASICNODEMANAGER_HPP_
38#include <unordered_set>
52 using NodeMap = std::map<std::type_index, std::vector<Node*> >;
54 using NodeNameMgrMap = std::map<std::type_index, common::NameManager<Node*> >;
56 = std::map<std::type_index, std::vector<NodeMap::iterator>*>;
67 template <
class NodeType>
71 template <
class NodeType>
75 template <
class NodeType>
79 template <
class NodeType>
104 template <
class NodeType>
105 std::size_t
getNumNodes(std::size_t treeIndex)
const;
109 template <
class NodeType>
110 NodeType*
getNode(std::size_t treeIndex, std::size_t nodeIndex);
114 template <
class NodeType>
115 const NodeType*
getNode(std::size_t treeIndex, std::size_t nodeIndex)
const;
118 template <
class NodeType>
122 template <
class NodeType>
123 const NodeType*
getNode(
const std::string&
name)
const;
143template <
class NodeType>
146 NodeMap::const_iterator it =
mNodeMap.find(
typeid(NodeType));
150 return it->second.size();
154template <
class NodeType>
157 NodeMap::const_iterator it =
mNodeMap.find(
typeid(NodeType));
161 return static_cast<NodeType*
>(getVectorObjectIfAvailable(
index, it->second));
165template <
class NodeType>
173template <
class NodeType>
181template <
class NodeType>
183 std::size_t treeIndex)
const
187 dterr <<
"[Skeleton::getNumNodes<" <<
typeid(NodeType).
name() <<
">] "
188 <<
"Requested tree index (" << treeIndex <<
"), but there are only ("
195 NodeMap::const_iterator it = nodeMap.find(
typeid(NodeType));
196 if (nodeMap.end() == it)
199 return it->second.size();
203template <
class NodeType>
205 std::size_t treeIndex, std::size_t nodeIndex)
209 dterr <<
"[Skeleton::getNode<" <<
typeid(NodeType).
name() <<
">] "
210 <<
"Requested tree index (" << treeIndex <<
"), but there are only ("
217 NodeMap::const_iterator it = nodeMap.find(
typeid(NodeType));
218 if (nodeMap.end() == it)
220 dterr <<
"[Skeleton::getNode<" <<
typeid(NodeType).
name() <<
">] "
221 <<
"Requested index (" << nodeIndex <<
") within tree (" << treeIndex
222 <<
"), but there are no Nodes of the requested type in this tree\n";
227 if (nodeIndex >= it->second.size())
229 dterr <<
"[Skeleton::getNode<" <<
typeid(NodeType).
name() <<
">] "
230 <<
"Requested index (" << nodeIndex <<
") within tree (" << treeIndex
231 <<
"), but there are only (" << it->second.size() <<
") Nodes of the "
232 <<
"requested type within that tree\n";
237 return static_cast<NodeType*
>(it->second[nodeIndex]);
241template <
class NodeType>
243 std::size_t treeIndex, std::size_t nodeIndex)
const
246 treeIndex, nodeIndex);
250template <
class NodeType>
253 NodeNameMgrMap::const_iterator it =
mNodeNameMgrMap.find(
typeid(NodeType));
258 return static_cast<NodeType*
>(it->second.getObject(
name));
262template <
class NodeType>
264 const std::string&
name)
const
271#define DART_BAKE_SPECIALIZED_NODE_IRREGULAR( \
272 TypeName, AspectName, PluralAspectName) \
273 inline std::size_t getNum##PluralAspectName() const \
275 return getNumNodes<TypeName>(); \
277 inline TypeName* get##AspectName(std::size_t index) \
279 return getNode<TypeName>(index); \
281 inline const TypeName* get##AspectName(std::size_t index) const \
283 return getNode<TypeName>(index); \
285 template <typename Func> \
286 void each##AspectName(Func func) const \
288 if constexpr (std::is_same_v< \
289 std::invoke_result_t<Func, const AspectName*>, \
292 for (auto i = 0u; i < getNum##PluralAspectName(); ++i) \
294 if (!func(get##AspectName(i))) \
300 for (auto i = 0u; i < getNum##PluralAspectName(); ++i) \
302 func(get##AspectName(i)); \
306 template <typename Func> \
307 void each##AspectName(Func func) \
309 if constexpr (std::is_same_v< \
310 std::invoke_result_t<Func, AspectName*>, \
313 for (auto i = 0u; i < getNum##PluralAspectName(); ++i) \
315 if (!func(get##AspectName(i))) \
321 for (auto i = 0u; i < getNum##PluralAspectName(); ++i) \
323 func(get##AspectName(i)); \
329#define DART_BAKE_SPECIALIZED_NODE(AspectName) \
330 DART_BAKE_SPECIALIZED_NODE_IRREGULAR(AspectName, AspectName, AspectName##s)
333#define DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR( \
334 TypeName, AspectName, PluralAspectName) \
335 DART_BAKE_SPECIALIZED_NODE_IRREGULAR(TypeName, AspectName, PluralAspectName) \
336 inline std::size_t getNum##PluralAspectName(std::size_t treeIndex) const \
338 return getNumNodes<TypeName>(treeIndex); \
340 inline TypeName* get##AspectName( \
341 std::size_t treeIndex, std::size_t nodeIndex) \
343 return getNode<TypeName>(treeIndex, nodeIndex); \
345 inline const TypeName* get##AspectName( \
346 std::size_t treeIndex, std::size_t nodeIndex) const \
348 return getNode<TypeName>(treeIndex, nodeIndex); \
351 inline TypeName* get##AspectName(const std::string& name) \
353 return getNode<TypeName>(name); \
355 inline const TypeName* get##AspectName(const std::string& name) const \
357 return getNode<TypeName>(name); \
359 template <typename Func> \
360 void each##AspectName(std::size_t treeIndex, Func func) const \
362 if constexpr (std::is_same_v< \
363 std::invoke_result_t<Func, const AspectName*>, \
366 for (auto i = 0u; i < getNum##PluralAspectName(treeIndex); ++i) \
368 if (!func(get##AspectName(treeIndex, i))) \
374 for (auto i = 0u; i < getNum##PluralAspectName(treeIndex); ++i) \
376 func(get##AspectName(treeIndex, i)); \
380 template <typename Func> \
381 void each##AspectName(std::size_t treeIndex, Func func) \
383 if constexpr (std::is_same_v< \
384 std::invoke_result_t<Func, AspectName*>, \
387 for (auto i = 0u; i < getNum##PluralAspectName(treeIndex); ++i) \
389 if (!func(get##AspectName(treeIndex, i))) \
395 for (auto i = 0u; i < getNum##PluralAspectName(treeIndex); ++i) \
397 func(get##AspectName(treeIndex, i)); \
403#define DART_BAKE_SPECIALIZED_NODE_SKEL(AspectName) \
404 DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR( \
405 AspectName, AspectName, AspectName##s)
408#define DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DECLARATIONS( \
409 TypeName, AspectName, PluralAspectName) \
410 std::size_t getNum##PluralAspectName() const; \
411 TypeName* get##AspectName(std::size_t index); \
412 const TypeName* get##AspectName(std::size_t index) const; \
413 template <typename Func> \
414 void each##AspectName(Func func) const \
416 if constexpr (std::is_same_v< \
417 std::invoke_result_t<Func, const AspectName*>, \
420 for (auto i = 0u; i < getNum##PluralAspectName(); ++i) \
422 if (!func(get##AspectName(i))) \
428 for (auto i = 0u; i < getNum##PluralAspectName(); ++i) \
430 func(get##AspectName(i)); \
434 template <typename Func> \
435 void each##AspectName(Func func) \
437 if constexpr (std::is_same_v< \
438 std::invoke_result_t<Func, AspectName*>, \
441 for (auto i = 0u; i < getNum##PluralAspectName(); ++i) \
443 if (!func(get##AspectName(i))) \
449 for (auto i = 0u; i < getNum##PluralAspectName(); ++i) \
451 func(get##AspectName(i)); \
457#define DART_BAKE_SPECIALIZED_NODE_DECLARATIONS(AspectName) \
458 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DECLARATIONS( \
459 AspectName, AspectName, AspectName##s)
462#define DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DECLARATIONS( \
463 TypeName, AspectName, PluralAspectName) \
464 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DECLARATIONS( \
465 TypeName, AspectName, PluralAspectName) \
466 std::size_t getNum##PluralAspectName(std::size_t treeIndex) const; \
467 TypeName* get##AspectName(std::size_t treeIndex, std::size_t nodeIndex); \
468 const TypeName* get##AspectName( \
469 std::size_t treeIndex, std::size_t nodeIndex) const; \
471 TypeName* get##AspectName(const std::string& name); \
472 const TypeName* get##AspectName(const std::string& name) const; \
474 template <typename Func> \
475 void each##AspectName(std::size_t treeIndex, Func func) const \
477 if constexpr (std::is_same_v< \
478 std::invoke_result_t<Func, const AspectName*>, \
481 for (auto i = 0u; i < getNum##PluralAspectName(treeIndex); ++i) \
483 if (!func(get##AspectName(treeIndex, i))) \
489 for (auto i = 0u; i < getNum##PluralAspectName(treeIndex); ++i) \
491 func(get##AspectName(treeIndex, i)); \
495 template <typename Func> \
496 void each##AspectName(std::size_t treeIndex, Func func) \
498 if constexpr (std::is_same_v< \
499 std::invoke_result_t<Func, AspectName*>, \
502 for (auto i = 0u; i < getNum##PluralAspectName(treeIndex); ++i) \
504 if (!func(get##AspectName(treeIndex, i))) \
510 for (auto i = 0u; i < getNum##PluralAspectName(treeIndex); ++i) \
512 func(get##AspectName(treeIndex, i)); \
518#define DART_BAKE_SPECIALIZED_NODE_SKEL_DECLARATIONS(AspectName) \
519 DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DECLARATIONS( \
520 AspectName, AspectName, AspectName##s)
523#define DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DEFINITIONS( \
524 ClassName, TypeName, AspectName, PluralAspectName) \
525 std::size_t ClassName ::getNum##PluralAspectName() const \
527 return getNumNodes<TypeName>(); \
529 TypeName* ClassName ::get##AspectName(std::size_t index) \
531 return getNode<TypeName>(index); \
533 const TypeName* ClassName ::get##AspectName(std::size_t index) const \
535 return getNode<TypeName>(index); \
539#define DART_BAKE_SPECIALIZED_NODE_DEFINITIONS(ClassName, AspectName) \
540 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DEFINITIONS( \
541 ClassName, AspectName, AspectName, AspectName##s)
544#define DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DEFINITIONS( \
545 ClassName, TypeName, AspectName, PluralAspectName) \
546 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DEFINITIONS( \
547 ClassName, TypeName, AspectName, PluralAspectName) \
548 std::size_t ClassName ::getNum##PluralAspectName(std::size_t treeIndex) \
551 return getNumNodes<TypeName>(treeIndex); \
553 TypeName* ClassName ::get##AspectName( \
554 std::size_t treeIndex, std::size_t nodeIndex) \
556 return getNode<TypeName>(treeIndex, nodeIndex); \
558 const TypeName* ClassName ::get##AspectName( \
559 std::size_t treeIndex, std::size_t nodeIndex) const \
561 return getNode<TypeName>(treeIndex, nodeIndex); \
564 TypeName* ClassName ::get##AspectName(const std::string& name) \
566 return getNode<TypeName>(name); \
568 const TypeName* ClassName ::get##AspectName(const std::string& name) const \
570 return getNode<TypeName>(name); \
574#define DART_BAKE_SPECIALIZED_NODE_SKEL_DEFINITIONS(ClassName, AspectName) \
575 DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DEFINITIONS( \
576 ClassName, AspectName, AspectName, AspectName##s)
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_END
Definition ClassWithVirtualBase.hpp:44
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_BEGIN
Definition ClassWithVirtualBase.hpp:43
#define dterr
Output an error message.
Definition Console.hpp:49
std::string * name
Definition SkelParser.cpp:1698
std::size_t index
Definition SkelParser.cpp:1673
Definition BasicNodeManager.hpp:50
std::map< std::type_index, common::NameManager< Node * > > NodeNameMgrMap
Definition BasicNodeManager.hpp:54
BasicNodeManagerForBodyNode()=default
Default constructor.
std::unordered_set< NodeDestructorPtr > NodeDestructorSet
Definition BasicNodeManager.hpp:53
NodeDestructorSet mNodeDestructors
A set for storing the Node destructors.
Definition BasicNodeManager.hpp:92
NodeType * getNode(std::size_t index)
Get the Node of the specified type and the specified index.
Definition BasicNodeManager.hpp:155
std::map< std::type_index, std::vector< NodeMap::iterator > * > SpecializedTreeNodes
Definition BasicNodeManager.hpp:56
static constexpr bool isSpecializedForNode()
Check if this Manager is specialized for a specific type of Node.
Definition BasicNodeManager.hpp:174
NodeMap mNodeMap
Map that retrieves the Nodes of a specified type.
Definition BasicNodeManager.hpp:89
std::map< std::type_index, std::vector< Node * > > NodeMap
Definition BasicNodeManager.hpp:52
std::size_t getNumNodes() const
Get the number of Nodes corresponding to the specified type.
Definition BasicNodeManager.hpp:144
BasicNodeManagerForBodyNode(const BasicNodeManagerForBodyNode &)=delete
Delete copy constructors and assignment operators.
BasicNodeManagerForBodyNode & operator=(const BasicNodeManagerForBodyNode &)=delete
Definition BasicNodeManager.hpp:97
NodeType * getNode(std::size_t treeIndex, std::size_t nodeIndex)
Get the nodeIndexth Node of the specified type within the tree of treeIndex.
Definition BasicNodeManager.hpp:204
std::vector< NodeMap > mTreeNodeMaps
A NodeMap for each tree to allow tree Nodes to be accessed independently.
Definition BasicNodeManager.hpp:130
SpecializedTreeNodes mSpecializedTreeNodes
A map that allows SpecializedNodeManagers to have a direct iterator to the tree-wise storage of its s...
Definition BasicNodeManager.hpp:138
std::size_t getNumNodes() const
Get the number of Nodes corresponding to the specified type.
Definition BasicNodeManager.hpp:144
NodeNameMgrMap mNodeNameMgrMap
NameManager for tracking Nodes.
Definition BasicNodeManager.hpp:127
Definition BulletCollisionDetector.cpp:60
Definition BasicNodeManager.hpp:85