33 #ifndef DART_DYNAMICS_DETAIL_BASICNODEMANAGER_HPP_ 34 #define DART_DYNAMICS_DETAIL_BASICNODEMANAGER_HPP_ 38 #include <unordered_set> 40 #include "dart/common/ClassWithVirtualBase.hpp" 41 #include "dart/common/Empty.hpp" 42 #include "dart/common/NameManager.hpp" 43 #include "dart/dynamics/Node.hpp" 52 using NodeMap = std::map<std::type_index, std::vector<Node*> >;
53 using NodeDestructorSet = std::unordered_set<NodeDestructorPtr>;
54 using NodeNameMgrMap = std::map<std::type_index, common::NameManager<Node*> >;
55 using SpecializedTreeNodes
56 = std::map<std::type_index, std::vector<NodeMap::iterator>*>;
67 template <
class NodeType>
71 template <
class NodeType>
72 NodeType*
getNode(std::size_t index);
75 template <
class NodeType>
76 const NodeType*
getNode(std::size_t index)
const;
79 template <
class NodeType>
95 DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_BEGIN
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>
119 NodeType*
getNode(
const std::string& name);
122 template <
class NodeType>
123 const NodeType*
getNode(
const std::string& name)
const;
140 DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_END
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));
161 return static_cast<NodeType*
>(getVectorObjectIfAvailable(index, it->second));
165 template <
class NodeType>
173 template <
class NodeType>
181 template <
class NodeType>
183 std::size_t treeIndex)
const 185 if (treeIndex >= mTreeNodeMaps.size())
187 dterr <<
"[Skeleton::getNumNodes<" <<
typeid(NodeType).name() <<
">] " 188 <<
"Requested tree index (" << treeIndex <<
"), but there are only (" 189 << mTreeNodeMaps.size() <<
") trees available\n";
194 const NodeMap& nodeMap = mTreeNodeMaps[treeIndex];
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)
207 if (treeIndex >= mTreeNodeMaps.size())
209 dterr <<
"[Skeleton::getNode<" <<
typeid(NodeType).name() <<
">] " 210 <<
"Requested tree index (" << treeIndex <<
"), but there are only (" 211 << mTreeNodeMaps.size() <<
") trees available\n";
216 const NodeMap& nodeMap = mTreeNodeMaps[treeIndex];
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));
255 if (mNodeNameMgrMap.end() == it)
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) 413 #endif // DART_DYNAMICS_DETAIL_BASICNODEMANAGER_HPP_ std::vector< NodeMap > mTreeNodeMaps
A NodeMap for each tree to allow tree Nodes to be accessed independently.
Definition: BasicNodeManager.hpp:130
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
Definition: BasicNodeManager.hpp:96
NodeNameMgrMap mNodeNameMgrMap
NameManager for tracking Nodes.
Definition: BasicNodeManager.hpp:127
static constexpr bool isSpecializedForNode()
Check if this Manager is specialized for a specific type of Node.
Definition: BasicNodeManager.hpp:174
SpecializedTreeNodes mSpecializedTreeNodes
A map that allows SpecializedNodeManagers to have a direct iterator to the tree-wise storage of its s...
Definition: BasicNodeManager.hpp:138
Definition: BasicNodeManager.hpp:49
Definition: Aspect.cpp:40
NodeMap mNodeMap
Map that retrieves the Nodes of a specified type.
Definition: BasicNodeManager.hpp:89
NodeDestructorSet mNodeDestructors
A set for storing the Node destructors.
Definition: BasicNodeManager.hpp:92
Definition: BasicNodeManager.hpp:84
BasicNodeManagerForBodyNode()=default
Default constructor.
NodeType * getNode(std::size_t index)
Get the Node of the specified type and the specified index.
Definition: BasicNodeManager.hpp:155
std::size_t getNumNodes() const
Get the number of Nodes corresponding to the specified type.