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;
143 template <
class NodeType>
146 NodeMap::const_iterator it =
mNodeMap.find(
typeid(NodeType));
150 return it->second.size();
154 template <
class NodeType>
157 NodeMap::const_iterator it =
mNodeMap.find(
typeid(NodeType));
165 template <
class NodeType>
173 template <
class NodeType>
181 template <
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();
203 template <
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]);
241 template <
class NodeType>
243 std::size_t treeIndex, std::size_t nodeIndex)
const
246 treeIndex, nodeIndex);
250 template <
class NodeType>
253 NodeNameMgrMap::const_iterator it =
mNodeNameMgrMap.find(
typeid(NodeType));
258 return static_cast<NodeType*
>(it->second.getObject(
name));
262 template <
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); \
287 #define DART_BAKE_SPECIALIZED_NODE(AspectName) \
288 DART_BAKE_SPECIALIZED_NODE_IRREGULAR(AspectName, AspectName, AspectName##s)
291 #define DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR( \
292 TypeName, AspectName, PluralAspectName) \
293 DART_BAKE_SPECIALIZED_NODE_IRREGULAR(TypeName, AspectName, PluralAspectName) \
294 inline std::size_t getNum##PluralAspectName(std::size_t treeIndex) const \
296 return getNumNodes<TypeName>(treeIndex); \
298 inline TypeName* get##AspectName( \
299 std::size_t treeIndex, std::size_t nodeIndex) \
301 return getNode<TypeName>(treeIndex, nodeIndex); \
303 inline const TypeName* get##AspectName( \
304 std::size_t treeIndex, std::size_t nodeIndex) const \
306 return getNode<TypeName>(treeIndex, nodeIndex); \
309 inline TypeName* get##AspectName(const std::string& name) \
311 return getNode<TypeName>(name); \
313 inline const TypeName* get##AspectName(const std::string& name) const \
315 return getNode<TypeName>(name); \
319 #define DART_BAKE_SPECIALIZED_NODE_SKEL(AspectName) \
320 DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR( \
321 AspectName, AspectName, AspectName##s)
324 #define DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DECLARATIONS( \
325 TypeName, AspectName, PluralAspectName) \
326 std::size_t getNum##PluralAspectName() const; \
327 TypeName* get##AspectName(std::size_t index); \
328 const TypeName* get##AspectName(std::size_t index) const;
331 #define DART_BAKE_SPECIALIZED_NODE_DECLARATIONS(AspectName) \
332 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DECLARATIONS( \
333 AspectName, AspectName, AspectName##s)
336 #define DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DECLARATIONS( \
337 TypeName, AspectName, PluralAspectName) \
338 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DECLARATIONS( \
339 TypeName, AspectName, PluralAspectName) \
340 std::size_t getNum##PluralAspectName(std::size_t treeIndex) const; \
341 TypeName* get##AspectName(std::size_t treeIndex, std::size_t nodeIndex); \
342 const TypeName* get##AspectName( \
343 std::size_t treeIndex, std::size_t nodeIndex) const; \
345 TypeName* get##AspectName(const std::string& name); \
346 const TypeName* get##AspectName(const std::string& name) const;
349 #define DART_BAKE_SPECIALIZED_NODE_SKEL_DECLARATIONS(AspectName) \
350 DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DECLARATIONS( \
351 AspectName, AspectName, AspectName##s)
354 #define DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DEFINITIONS( \
355 ClassName, TypeName, AspectName, PluralAspectName) \
356 std::size_t ClassName ::getNum##PluralAspectName() const \
358 return getNumNodes<TypeName>(); \
360 TypeName* ClassName ::get##AspectName(std::size_t index) \
362 return getNode<TypeName>(index); \
364 const TypeName* ClassName ::get##AspectName(std::size_t index) const \
366 return getNode<TypeName>(index); \
370 #define DART_BAKE_SPECIALIZED_NODE_DEFINITIONS(ClassName, AspectName) \
371 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DEFINITIONS( \
372 ClassName, AspectName, AspectName, AspectName##s)
375 #define DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DEFINITIONS( \
376 ClassName, TypeName, AspectName, PluralAspectName) \
377 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DEFINITIONS( \
378 ClassName, TypeName, AspectName, PluralAspectName) \
379 std::size_t ClassName ::getNum##PluralAspectName(std::size_t treeIndex) \
382 return getNumNodes<TypeName>(treeIndex); \
384 TypeName* ClassName ::get##AspectName( \
385 std::size_t treeIndex, std::size_t nodeIndex) \
387 return getNode<TypeName>(treeIndex, nodeIndex); \
389 const TypeName* ClassName ::get##AspectName( \
390 std::size_t treeIndex, std::size_t nodeIndex) const \
392 return getNode<TypeName>(treeIndex, nodeIndex); \
395 TypeName* ClassName ::get##AspectName(const std::string& name) \
397 return getNode<TypeName>(name); \
399 const TypeName* ClassName ::get##AspectName(const std::string& name) const \
401 return getNode<TypeName>(name); \
405 #define DART_BAKE_SPECIALIZED_NODE_SKEL_DEFINITIONS(ClassName, AspectName) \
406 DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DEFINITIONS( \
407 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:1697
std::size_t index
Definition: SkelParser.cpp:1672
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
NodeNameMgrMap mNodeNameMgrMap
NameManager for tracking Nodes.
Definition: BasicNodeManager.hpp:127
static T getVectorObjectIfAvailable(std::size_t index, const std::vector< T > &vec)
Definition: StlHelpers.hpp:55
Definition: BulletCollisionDetector.cpp:65
Definition: BasicNodeManager.hpp:85