DART 6.7.3
Loading...
Searching...
No Matches
Node.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2019, 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
42
44
45namespace dart {
46namespace dynamics {
47
48class BodyNode;
49class Node;
50
51//==============================================================================
52class NodeDestructor final
53{
54public:
55
57 NodeDestructor(Node* _node);
58
60 NodeDestructor(const NodeDestructor& _other) = delete;
61
64
65 Node* getNode() const;
66
67private:
68
71
72};
73
74//==============================================================================
81class Node :
82 public virtual common::Subject,
83 public virtual common::VersionCounter
84{
85public:
86
87 friend class BodyNode;
88 friend class Skeleton;
89 template<class> friend class AccessoryNode;
90 template<class, class> friend class TemplateNodePtr;
91 template<class, class> friend class TemplateWeakNodePtr;
92
105 class State : public common::Cloneable<State> { };
106
109 template <class Mixin>
111
124 class Properties : public common::Cloneable<Properties> { };
125
128 template <class Mixin>
130
132 virtual ~Node() = default;
133
135 virtual const std::string& setName(const std::string& newName) = 0;
136
138 virtual const std::string& getName() const = 0;
139
141 virtual void setNodeState(const State& otherState);
142
145 virtual std::unique_ptr<State> getNodeState() const;
146
150 virtual void copyNodeStateTo(std::unique_ptr<State>& outputState) const;
151
153 virtual void setNodeProperties(const Properties& properties);
154
157 virtual std::unique_ptr<Properties> getNodeProperties() const;
158
163 virtual void copyNodePropertiesTo(
164 std::unique_ptr<Properties>& outputProperties) const;
165
168
171
175 bool isRemoved() const;
176
178 virtual std::shared_ptr<Skeleton> getSkeleton();
179
181 virtual std::shared_ptr<const Skeleton> getSkeleton() const;
182
183private:
184
185 std::shared_ptr<NodeDestructor> getOrCreateDestructor();
186
187protected:
188
190 virtual Node* cloneNode(BodyNode* bn) const = 0;
191
193 Node(BodyNode* _bn);
194
199 std::string registerNameChange(const std::string& newName);
200
202 void attach();
203
205 void stageForRemoval();
206
212 std::weak_ptr<NodeDestructor> mDestructor;
213
216
219
221 std::size_t mIndexInBodyNode;
222
224 std::size_t mIndexInSkeleton;
225
227 std::size_t mIndexInTree;
228};
229
230//==============================================================================
234template <class NodeType>
236{
237public:
238
240 virtual ~AccessoryNode() = default;
241
243 std::size_t getIndexInBodyNode() const;
244
246 std::size_t getIndexInSkeleton() const;
247
249 std::size_t getIndexInTree() const;
250
252 std::size_t getTreeIndex() const;
253
256 void remove();
257
260 void reattach();
261
262protected:
263
265 AccessoryNode() = default;
266
267};
268
269} // namespace dynamics
270} // namespace dart
271
273
274#endif // DART_DYNAMICS_NODE_HPP_
BodyPropPtr properties
Definition SdfParser.cpp:80
Cloneable is a CRTP base class that provides an interface for easily creating data structures that ar...
Definition Cloneable.hpp:54
The MakeCloneable class is used to easily create an Cloneable (such as Node::State) which simply take...
Definition Cloneable.hpp:85
The Subject class is a base class for any object that wants to report when it gets destroyed.
Definition Subject.hpp:58
VersionCounter is an interface for objects that count their versions.
Definition VersionCounter.hpp:43
AccessoryNode provides an interface for Nodes to get their index within the list of Nodes,...
Definition Node.hpp:236
std::size_t getTreeIndex() const
Get the index of this Node's tree within its Skeleton.
Definition Node.hpp:68
AccessoryNode()=default
Prevent a non-inheriting class from constructing one.
virtual ~AccessoryNode()=default
Virtual destructor.
std::size_t getIndexInBodyNode() const
Get the index of this Node within its BodyNode.
Definition Node.hpp:47
std::size_t getIndexInSkeleton() const
Get the index of this Node within its Skeleton.
Definition Node.hpp:54
void remove()
Stage the Node for removal.
Definition Node.hpp:75
void reattach()
Undo the effectos of calling remove().
Definition Node.hpp:82
std::size_t getIndexInTree() const
Get the index of this Node within its tree.
Definition Node.hpp:61
BodyNode class represents a single node of the skeleton.
Definition BodyNode.hpp:78
Definition Node.hpp:53
~NodeDestructor()
Non-virtual destructor (this class cannot be inherited)
Definition Node.cpp:53
Node * getNode() const
Definition Node.cpp:59
NodeDestructor(const NodeDestructor &_other)=delete
Do not copy.
Node * mNode
Node that this Destructor is responsible for.
Definition Node.hpp:70
If your Node has a Properties class, then that Properties class should inherit this Node::Properties ...
Definition Node.hpp:124
If your Node has a State class, then that State class should inherit this Node::State class.
Definition Node.hpp:105
The Node class is a base class for BodyNode and any object that attaches to a BodyNode.
Definition Node.hpp:84
BodyNodePtr getBodyNodePtr()
Get a pointer to the BodyNode that this Node is associated with.
Definition Node.cpp:102
void attach()
Attach the Node to its BodyNode.
Definition Node.cpp:186
virtual std::unique_ptr< Properties > getNodeProperties() const
Get the Properties of this Node.
Definition Node.cpp:89
std::string registerNameChange(const std::string &newName)
Inform the Skeleton that the name of this Node has changed.
Definition Node.cpp:169
std::size_t mIndexInTree
Index of this Node within its tree.
Definition Node.hpp:227
bool mAmAttached
bool that tracks whether this Node is attached to its BodyNode
Definition Node.hpp:218
std::size_t mIndexInSkeleton
The index of this Node within its vector in its Skeleton's NodeMap.
Definition Node.hpp:224
virtual void setNodeProperties(const Properties &properties)
Set the Properties of this Node. By default, this does nothing.
Definition Node.cpp:83
std::weak_ptr< NodeDestructor > mDestructor
weak pointer to the destructor for this Node.
Definition Node.hpp:212
bool isRemoved() const
Returns true if this Node has been staged for removal from its BodyNode.
Definition Node.cpp:114
virtual void copyNodeStateTo(std::unique_ptr< State > &outputState) const
Copy the State of this Node into a unique_ptr.
Definition Node.cpp:77
virtual void setNodeState(const State &otherState)
Set the State of this Node. By default, this does nothing.
Definition Node.cpp:65
std::size_t mIndexInBodyNode
The index of this Node within its vector in its BodyNode's NodeMap.
Definition Node.hpp:221
virtual void copyNodePropertiesTo(std::unique_ptr< Properties > &outputProperties) const
Copy the Properties of this Node into a unique_ptr.
Definition Node.cpp:95
virtual std::shared_ptr< Skeleton > getSkeleton()
Return the Skeleton that this Node is attached to.
Definition Node.cpp:126
BodyNode * mBodyNode
Pointer to the BodyNode that this Node is attached to.
Definition Node.hpp:215
virtual Node * cloneNode(BodyNode *bn) const =0
Allow your Node implementation to be cloned into a new BodyNode.
virtual ~Node()=default
Virtual destructor.
virtual const std::string & getName() const =0
Get the name of this Node.
std::shared_ptr< NodeDestructor > getOrCreateDestructor()
Definition Node.cpp:138
virtual std::unique_ptr< State > getNodeState() const
Get the State of this Node.
Definition Node.cpp:71
virtual const std::string & setName(const std::string &newName)=0
Set the name of this Node.
void stageForRemoval()
When all external references to the Node disappear, it will be deleted.
Definition Node.cpp:237
class Skeleton
Definition Skeleton.hpp:59
TemplateBodyNodePtr is a templated class that enables users to create a reference-counting BodyNodePt...
Definition BodyNodePtr.hpp:111
TemplateNodePtr is a templated class that enables users to create a strong reference-counting NodePtr...
Definition NodePtr.hpp:50
TemplateWeakNodePtr is a templated class that enables users to create a weak non-reference-holding We...
Definition NodePtr.hpp:140
Definition BulletCollisionDetector.cpp:63