DART 6.10.1
Loading...
Searching...
No Matches
NodePtr.hpp
Go to the documentation of this file.
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_DETAIL_NODEPTR_HPP_
34#define DART_DYNAMICS_DETAIL_NODEPTR_HPP_
35
37
38namespace dart {
39namespace dynamics {
40
41class NodeDestructor;
42
48template <class NodeT, class BodyNodeT>
50{
51public:
52 template <class, class>
53 friend class TemplateNodePtr;
54
55 using element_type = NodeT;
56
59 {
60 }
61
64 TemplateNodePtr(NodeT* _ptr)
65 {
66 set(_ptr);
67 }
68
70 template <class OtherNodeT, class OtherBodyNodeT>
75
78 {
79 set(_ptr);
80 return *this;
81 }
82
84 template <class OtherNodeT, class OtherBodyNodeT>
87 {
88 set(_ptr.get());
89 return *this;
90 }
91
93 operator NodeT*() const
94 {
95 return get();
96 }
97
99 NodeT& operator*() const
100 {
101 return *get();
102 }
103
105 NodeT* operator->() const
106 {
107 return get();
108 }
109
111 NodeT* get() const
112 {
113 return mNode;
114 }
115
117 void set(NodeT* _ptr)
118 {
119 if (nullptr == _ptr)
120 {
121 mBodyNodePtr = nullptr;
122 mDestructor = nullptr;
123 mNode = nullptr;
124 return;
125 }
126
127 mBodyNodePtr = _ptr->getBodyNodePtr();
128 mDestructor = _ptr->mDestructor.lock();
129 mNode = _ptr;
130 }
131
132protected:
134 NodeT* mNode;
135
138 std::shared_ptr<NodeDestructor> mDestructor;
139
143};
144
150template <class NodeT, class BodyNodeT>
152{
153public:
154 template <class, class>
156
159 {
160 }
161
165 {
166 set(_ptr);
167 }
168
170 template <class OtherNodeT, class OtherBodyNodeT>
173 {
174 set(_weakPtr);
175 }
176
178 template <class OtherNodeT, class OtherBodyNodeT>
181 {
182 set(_strongPtr.get());
183 }
184
187 {
188 set(_ptr);
189 return *this;
190 }
191
193 template <class OtherNodeT, class OtherBodyNodeT>
196 {
197 set(_weakPtr);
198 return *this;
199 }
200
202 template <class OtherNodeT, class OtherBodyNodeT>
205 {
206 set(_strongPtr.get());
207 return *this;
208 }
209
214 {
216 if (nullptr == bodyNode)
217 return nullptr;
218
219 std::shared_ptr<NodeDestructor> destructor = mWeakDestructor.lock();
220 if (nullptr == destructor)
221 return nullptr;
222
224 }
225
227 void set(NodeT* _ptr)
228 {
229 if (nullptr == _ptr)
230 {
231 mNode = nullptr;
232 mWeakDestructor.reset();
233 mWeakBodyNodePtr = nullptr;
234 return;
235 }
236
237 mWeakBodyNodePtr = _ptr->getBodyNodePtr();
238 mWeakDestructor = _ptr->getOrCreateDestructor();
239 mNode = _ptr;
240 }
241
243 template <class OtherNodeT, class OtherBodyNodeT>
245 {
246 mNode = _weakPtr.mNode;
249 }
250
251protected:
253 NodeT* mNode;
254
256 std::weak_ptr<NodeDestructor> mWeakDestructor;
257
260};
261
262} // namespace dynamics
263} // namespace dart
264
265#endif // DART_DYNAMICS_DETAIL_NODEPTR_HPP_
TemplateBodyNodePtr is a templated class that enables users to create a reference-counting BodyNodePt...
Definition BodyNodePtr.hpp:110
TemplateNodePtr is a templated class that enables users to create a strong reference-counting NodePtr...
Definition NodePtr.hpp:50
NodeT * get() const
Get the raw Node pointer.
Definition NodePtr.hpp:111
TemplateNodePtr & operator=(NodeT *_ptr)
Assignment operator.
Definition NodePtr.hpp:77
NodeT & operator*() const
Dereferencing operator.
Definition NodePtr.hpp:99
TemplateBodyNodePtr< BodyNodeT > mBodyNodePtr
Hold onto a BodyNodePtr to the Node's associated BodyNode to make sure that the BodyNode stays alive.
Definition NodePtr.hpp:142
TemplateNodePtr & operator=(const TemplateNodePtr< OtherNodeT, OtherBodyNodeT > &_ptr)
Assignment operator for NodePtrs.
Definition NodePtr.hpp:85
TemplateNodePtr(const TemplateNodePtr< OtherNodeT, OtherBodyNodeT > &_ptr)
Constructor that takes in a strong NodePtr.
Definition NodePtr.hpp:71
TemplateNodePtr()
Default constructor.
Definition NodePtr.hpp:58
NodeT element_type
Definition NodePtr.hpp:55
std::shared_ptr< NodeDestructor > mDestructor
Hold onto a shared_ptr to the Node's Destructor to make sure the Node stays alive.
Definition NodePtr.hpp:138
TemplateNodePtr(NodeT *_ptr)
Typical constructor.
Definition NodePtr.hpp:64
NodeT * operator->() const
Dereferencing operation.
Definition NodePtr.hpp:105
NodeT * mNode
Node that this NodePtr refers to.
Definition NodePtr.hpp:134
void set(NodeT *_ptr)
Set the Node for this NodePtr.
Definition NodePtr.hpp:117
TemplateWeakBodyNodePtr is a templated class that enables users to create a non-reference-holding Wea...
Definition BodyNodePtr.hpp:224
TemplateWeakNodePtr is a templated class that enables users to create a weak non-reference-holding We...
Definition NodePtr.hpp:152
NodeT * mNode
Node that this pointer references.
Definition NodePtr.hpp:253
TemplateWeakNodePtr & operator=(NodeT *_ptr)
Assignment operator for raw Node pointers.
Definition NodePtr.hpp:186
std::weak_ptr< NodeDestructor > mWeakDestructor
Destructor for the Node.
Definition NodePtr.hpp:256
TemplateWeakNodePtr & operator=(const TemplateWeakNodePtr< OtherNodeT, OtherBodyNodeT > &_weakPtr)
Assignment operator for WeakNodePtrs.
Definition NodePtr.hpp:194
TemplateNodePtr< NodeT, BodyNodeT > lock() const
Locks the Node reference to ensure that the referenced Node is currently still available.
Definition NodePtr.hpp:213
TemplateWeakNodePtr()
Default constructor.
Definition NodePtr.hpp:158
TemplateWeakNodePtr(NodeT *_ptr)
Typical constructor.
Definition NodePtr.hpp:164
TemplateWeakNodePtr(const TemplateNodePtr< OtherNodeT, OtherBodyNodeT > &_strongPtr)
Constructor that takes in a strong NodePtr.
Definition NodePtr.hpp:179
TemplateWeakNodePtr & operator=(const TemplateNodePtr< OtherNodeT, OtherBodyNodeT > &_strongPtr)
Assignment operator for strong NodePtrs.
Definition NodePtr.hpp:203
void set(const TemplateWeakNodePtr< OtherNodeT, OtherBodyNodeT > &_weakPtr)
Set the Node for this WeakNodePtr based on another WeakNodePtr.
Definition NodePtr.hpp:244
void set(NodeT *_ptr)
Set the Node for this WeakNodePtr.
Definition NodePtr.hpp:227
TemplateWeakBodyNodePtr< BodyNodeT > mWeakBodyNodePtr
Pointer to the BodyNode that the Node is attached to.
Definition NodePtr.hpp:259
TemplateWeakNodePtr(const TemplateWeakNodePtr< OtherNodeT, OtherBodyNodeT > &_weakPtr)
Constructor that takes in a WeakNodePtr.
Definition NodePtr.hpp:171
Definition BulletCollisionDetector.cpp:65