dart
Node.hpp
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_NODE_HPP_
34 #define DART_DYNAMICS_NODE_HPP_
35 
36 #include <memory>
37 
38 #include "dart/common/Cloneable.hpp"
39 #include "dart/common/EmbeddedAspect.hpp"
40 #include "dart/common/Subject.hpp"
41 #include "dart/common/VersionCounter.hpp"
42 
43 #include "dart/dynamics/SmartPointer.hpp"
44 
45 namespace dart {
46 namespace dynamics {
47 
48 class BodyNode;
49 class Node;
50 
51 //==============================================================================
52 class NodeDestructor final
53 {
54 public:
56  NodeDestructor(Node* _node);
57 
59  NodeDestructor(const NodeDestructor& _other) = delete;
60 
63 
64  Node* getNode() const;
65 
66 private:
68  Node* mNode;
69 };
70 
71 //==============================================================================
78 DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_BEGIN
79 class Node : public virtual common::Subject,
80  public virtual common::VersionCounter
81 {
82 public:
83  friend class BodyNode;
84  friend class Skeleton;
85  template <class>
86  friend class AccessoryNode;
87  template <class, class>
88  friend class TemplateNodePtr;
89  template <class, class>
90  friend class TemplateWeakNodePtr;
91 
104  class State : public common::Cloneable<State>
105  {
106  };
107 
110  template <class Mixin>
112 
125  class Properties : public common::Cloneable<Properties>
126  {
127  };
128 
131  template <class Mixin>
133 
135  virtual ~Node() = default;
136 
138  virtual const std::string& setName(const std::string& newName) = 0;
139 
141  virtual const std::string& getName() const = 0;
142 
144  virtual void setNodeState(const State& otherState);
145 
148  virtual std::unique_ptr<State> getNodeState() const;
149 
153  virtual void copyNodeStateTo(std::unique_ptr<State>& outputState) const;
154 
156  virtual void setNodeProperties(const Properties& properties);
157 
160  virtual std::unique_ptr<Properties> getNodeProperties() const;
161 
166  virtual void copyNodePropertiesTo(
167  std::unique_ptr<Properties>& outputProperties) const;
168 
170  BodyNodePtr getBodyNodePtr();
171 
173  ConstBodyNodePtr getBodyNodePtr() const;
174 
178  bool isRemoved() const;
179 
181  virtual std::shared_ptr<Skeleton> getSkeleton();
182 
184  virtual std::shared_ptr<const Skeleton> getSkeleton() const;
185 
186 private:
187  std::shared_ptr<NodeDestructor> getOrCreateDestructor();
188 
189 protected:
191  virtual Node* cloneNode(BodyNode* bn) const = 0;
192 
194  Node(BodyNode* _bn);
195 
200  std::string registerNameChange(const std::string& newName);
201 
203  void attach();
204 
206  void stageForRemoval();
207 
213  std::weak_ptr<NodeDestructor> mDestructor;
214 
217 
220 
222  std::size_t mIndexInBodyNode;
223 
225  std::size_t mIndexInSkeleton;
226 
228  std::size_t mIndexInTree;
229 };
230 DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_END
231 
232 //==============================================================================
236 template <class NodeType>
238 {
239 public:
241  virtual ~AccessoryNode() = default;
242 
244  std::size_t getIndexInBodyNode() const;
245 
247  std::size_t getIndexInSkeleton() const;
248 
250  std::size_t getIndexInTree() const;
251 
253  std::size_t getTreeIndex() const;
254 
257  void remove();
258 
261  void reattach();
262 
263 protected:
265  AccessoryNode() = default;
266 };
267 
268 } // namespace dynamics
269 } // namespace dart
270 
271 #include "dart/dynamics/detail/Node.hpp"
272 
273 #endif // DART_DYNAMICS_NODE_HPP_
TemplateWeakNodePtr is a templated class that enables users to create a weak non-reference-holding We...
Definition: NodePtr.hpp:151
The Subject class is a base class for any object that wants to report when it gets destroyed...
Definition: Subject.hpp:57
Cloneable is a CRTP base class that provides an interface for easily creating data structures that ar...
Definition: Cloneable.hpp:53
AccessoryNode provides an interface for Nodes to get their index within the list of Nodes...
Definition: Node.hpp:237
If your Node has a Properties class, then that Properties class should inherit this Node::Properties ...
Definition: Node.hpp:125
Definition: Node.hpp:52
The Node class is a base class for BodyNode and any object that attaches to a BodyNode.
Definition: Node.hpp:79
The MakeCloneable class is used to easily create an Cloneable (such as Node::State) which simply take...
Definition: Cloneable.hpp:83
std::size_t mIndexInBodyNode
The index of this Node within its vector in its BodyNode&#39;s NodeMap.
Definition: Node.hpp:222
VersionCounter is an interface for objects that count their versions.
Definition: VersionCounter.hpp:42
TemplateNodePtr is a templated class that enables users to create a strong reference-counting NodePtr...
Definition: NodePtr.hpp:49
BodyNode * mBodyNode
Pointer to the BodyNode that this Node is attached to.
Definition: Node.hpp:216
Definition: Aspect.cpp:40
If your Node has a State class, then that State class should inherit this Node::State class...
Definition: Node.hpp:104
~NodeDestructor()
Non-virtual destructor (this class cannot be inherited)
Definition: Node.cpp:52
bool mAmAttached
bool that tracks whether this Node is attached to its BodyNode
Definition: Node.hpp:219
BodyNode class represents a single node of the skeleton.
Definition: BodyNode.hpp:74
NodeDestructor(Node *_node)
Constructor.
Definition: Node.cpp:46
std::weak_ptr< NodeDestructor > mDestructor
weak pointer to the destructor for this Node.
Definition: Node.hpp:213
std::size_t mIndexInSkeleton
The index of this Node within its vector in its Skeleton&#39;s NodeMap.
Definition: Node.hpp:225
class Skeleton
Definition: Skeleton.hpp:55
std::size_t mIndexInTree
Index of this Node within its tree.
Definition: Node.hpp:228