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*> >;
65 template <
class NodeType>
69 template <
class NodeType>
73 template <
class NodeType>
77 template <
class NodeType>
82 template <
class T>
struct type { };
101 template <
class NodeType>
102 std::size_t
getNumNodes(std::size_t treeIndex)
const;
106 template <
class NodeType>
107 NodeType*
getNode(std::size_t treeIndex, std::size_t nodeIndex);
111 template <
class NodeType>
112 const NodeType*
getNode(std::size_t treeIndex, std::size_t nodeIndex)
const;
115 template <
class NodeType>
119 template <
class NodeType>
120 const NodeType*
getNode(
const std::string&
name)
const;
141 template <
class NodeType>
144 NodeMap::const_iterator it =
mNodeMap.find(
typeid(NodeType));
148 return it->second.size();
152 template <
class NodeType>
155 NodeMap::const_iterator it =
mNodeMap.find(
typeid(NodeType));
159 return static_cast<NodeType*
>(
164 template <
class NodeType>
171 template <
class NodeType>
179 template <
class NodeType>
184 dterr <<
"[Skeleton::getNumNodes<" <<
typeid(NodeType).
name() <<
">] "
185 <<
"Requested tree index (" << treeIndex <<
"), but there are only ("
192 NodeMap::const_iterator it = nodeMap.find(
typeid(NodeType));
193 if(nodeMap.end() == it)
196 return it->second.size();
200 template <
class NodeType>
202 std::size_t treeIndex, std::size_t nodeIndex)
206 dterr <<
"[Skeleton::getNode<" <<
typeid(NodeType).
name() <<
">] "
207 <<
"Requested tree index (" << treeIndex <<
"), but there are only ("
214 NodeMap::const_iterator it = nodeMap.find(
typeid(NodeType));
215 if(nodeMap.end() == it)
217 dterr <<
"[Skeleton::getNode<" <<
typeid(NodeType).
name() <<
">] "
218 <<
"Requested index (" << nodeIndex <<
") within tree (" << treeIndex
219 <<
"), but there are no Nodes of the requested type in this tree\n";
224 if(nodeIndex >= it->second.size())
226 dterr <<
"[Skeleton::getNode<" <<
typeid(NodeType).
name() <<
">] "
227 <<
"Requested index (" << nodeIndex <<
") within tree (" << treeIndex
228 <<
"), but there are only (" << it->second.size() <<
") Nodes of the "
229 <<
"requested type within that tree\n";
234 return static_cast<NodeType*
>(it->second[nodeIndex]);
238 template <
class NodeType>
240 std::size_t treeIndex, std::size_t nodeIndex)
const
243 treeIndex, nodeIndex);
247 template <
class NodeType>
250 NodeNameMgrMap::const_iterator it =
mNodeNameMgrMap.find(
typeid(NodeType));
255 return static_cast<NodeType*
>(it->second.getObject(
name));
259 template <
class NodeType>
261 const std::string&
name)
const
264 this)->getNode<NodeType>(
name);
268 #define DART_BAKE_SPECIALIZED_NODE_IRREGULAR( TypeName, AspectName, PluralAspectName )\
269 inline std::size_t getNum ## PluralAspectName () const\
270 { return getNumNodes< TypeName >(); }\
271 inline TypeName * get ## AspectName (std::size_t index)\
272 { return getNode< TypeName >(index); }\
273 inline const TypeName * get ## AspectName (std::size_t index) const\
274 { return getNode< TypeName >(index); }
277 #define DART_BAKE_SPECIALIZED_NODE( AspectName )\
278 DART_BAKE_SPECIALIZED_NODE_IRREGULAR( AspectName, AspectName, AspectName ## s )
281 #define DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR( TypeName, AspectName, PluralAspectName )\
282 DART_BAKE_SPECIALIZED_NODE_IRREGULAR( TypeName, AspectName, PluralAspectName )\
283 inline std::size_t getNum ## PluralAspectName (std::size_t treeIndex) const\
284 { return getNumNodes< TypeName >(treeIndex); }\
285 inline TypeName * get ## AspectName (std::size_t treeIndex, std::size_t nodeIndex)\
286 { return getNode< TypeName >(treeIndex, nodeIndex); }\
287 inline const TypeName * get ## AspectName (std::size_t treeIndex, std::size_t nodeIndex) const\
288 { return getNode< TypeName >(treeIndex, nodeIndex); }\
290 inline TypeName * get ## AspectName (const std::string& name)\
291 { return getNode< TypeName >(name); }\
292 inline const TypeName * get ## AspectName (const std::string& name) const\
293 { return getNode< TypeName >(name); }
296 #define DART_BAKE_SPECIALIZED_NODE_SKEL( AspectName )\
297 DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR( AspectName, AspectName, AspectName ## s)
300 #define DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DECLARATIONS( TypeName, AspectName, PluralAspectName )\
301 std::size_t getNum ## PluralAspectName () const;\
302 TypeName * get ## AspectName (std::size_t index);\
303 const TypeName * get ## AspectName (std::size_t index) const;
306 #define DART_BAKE_SPECIALIZED_NODE_DECLARATIONS( AspectName )\
307 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DECLARATIONS( AspectName, AspectName, AspectName ## s )
310 #define DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DECLARATIONS( TypeName, AspectName, PluralAspectName )\
311 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DECLARATIONS( TypeName, AspectName, PluralAspectName )\
312 std::size_t getNum ## PluralAspectName (std::size_t treeIndex) const;\
313 TypeName * get ## AspectName (std::size_t treeIndex, std::size_t nodeIndex);\
314 const TypeName * get ## AspectName (std::size_t treeIndex, std::size_t nodeIndex) const;\
316 TypeName * get ## AspectName (const std::string& name);\
317 const TypeName * get ## AspectName (const std::string& name) const;
320 #define DART_BAKE_SPECIALIZED_NODE_SKEL_DECLARATIONS( AspectName )\
321 DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DECLARATIONS( AspectName, AspectName, AspectName ## s )
324 #define DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DEFINITIONS( ClassName, TypeName, AspectName, PluralAspectName )\
325 std::size_t ClassName :: getNum ## PluralAspectName () const\
326 { return getNumNodes< TypeName >(); }\
327 TypeName * ClassName :: get ## AspectName (std::size_t index)\
328 { return getNode< TypeName >(index); }\
329 const TypeName * ClassName :: get ## AspectName (std::size_t index) const\
330 { return getNode< TypeName >(index); }
333 #define DART_BAKE_SPECIALIZED_NODE_DEFINITIONS( ClassName, AspectName )\
334 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DEFINITIONS( ClassName, AspectName, AspectName, AspectName ## s )
337 #define DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DEFINITIONS( ClassName, TypeName, AspectName, PluralAspectName )\
338 DART_BAKE_SPECIALIZED_NODE_IRREGULAR_DEFINITIONS( ClassName, TypeName, AspectName, PluralAspectName )\
339 std::size_t ClassName :: getNum ## PluralAspectName (std::size_t treeIndex) const\
340 { return getNumNodes< TypeName >(treeIndex); }\
341 TypeName * ClassName :: get ## AspectName (std::size_t treeIndex, std::size_t nodeIndex)\
342 { return getNode< TypeName >(treeIndex, nodeIndex); }\
343 const TypeName * ClassName :: get ## AspectName (std::size_t treeIndex, std::size_t nodeIndex) const\
344 { return getNode< TypeName >(treeIndex, nodeIndex); }\
346 TypeName * ClassName :: get ## AspectName (const std::string& name)\
347 { return getNode< TypeName >(name); }\
348 const TypeName * ClassName :: get ## AspectName (const std::string& name) const\
349 { return getNode< TypeName >(name); }
352 #define DART_BAKE_SPECIALIZED_NODE_SKEL_DEFINITIONS( ClassName, AspectName )\
353 DART_BAKE_SPECIALIZED_NODE_SKEL_IRREGULAR_DEFINITIONS( ClassName, AspectName, AspectName, AspectName ## s )
#define dterr
Output an error message.
Definition: Console.hpp:49
std::string * name
Definition: SkelParser.cpp:1642
std::size_t index
Definition: SkelParser.cpp:1617
Definition: BasicNodeManager.hpp:49
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:88
NodeType * getNode(std::size_t index)
Get the Node of the specified type and the specified index.
Definition: BasicNodeManager.hpp:153
std::map< std::type_index, std::vector< NodeMap::iterator > * > SpecializedTreeNodes
Definition: BasicNodeManager.hpp:55
static constexpr bool isSpecializedForNode()
Check if this Manager is specialized for a specific type of Node.
Definition: BasicNodeManager.hpp:172
NodeMap mNodeMap
Map that retrieves the Nodes of a specified type.
Definition: BasicNodeManager.hpp:85
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:142
BasicNodeManagerForBodyNode(const BasicNodeManagerForBodyNode &)=delete
Delete copy constructors and assignment operators.
BasicNodeManagerForBodyNode & operator=(const BasicNodeManagerForBodyNode &)=delete
std::map< std::type_index, common::NameManager< Node * > > NodeNameMgrMap
Definition: BasicNodeManager.hpp:54
Definition: BasicNodeManager.hpp:93
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:201
std::vector< NodeMap > mTreeNodeMaps
A NodeMap for each tree to allow tree Nodes to be accessed independently.
Definition: BasicNodeManager.hpp:128
SpecializedTreeNodes mSpecializedTreeNodes
A map that allows SpecializedNodeManagers to have a direct iterator to the tree-wise storage of its s...
Definition: BasicNodeManager.hpp:136
NodeNameMgrMap mNodeNameMgrMap
NameManager for tracking Nodes.
Definition: BasicNodeManager.hpp:125
static T getVectorObjectIfAvailable(std::size_t index, const std::vector< T > &vec)
Definition: StlHelpers.hpp:51
Definition: BulletCollisionDetector.cpp:63
Definition: BasicNodeManager.hpp:82