DART 6.12.2
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
58 TemplateNodePtr() : mNode(nullptr) {}
59
62 TemplateNodePtr(NodeT* _ptr)
63 {
64 set(_ptr);
65 }
66
68 template <class OtherNodeT, class OtherBodyNodeT>
73
76 {
77 set(_ptr);
78 return *this;
79 }
80
82 template <class OtherNodeT, class OtherBodyNodeT>
85 {
86 set(_ptr.get());
87 return *this;
88 }
89
91 operator NodeT*() const
92 {
93 return get();
94 }
95
97 NodeT& operator*() const
98 {
99 return *get();
100 }
101
103 NodeT* operator->() const
104 {
105 return get();
106 }
107
109 NodeT* get() const
110 {
111 return mNode;
112 }
113
115 void set(NodeT* _ptr)
116 {
117 if (nullptr == _ptr)
118 {
119 mBodyNodePtr = nullptr;
120 mDestructor = nullptr;
121 mNode = nullptr;
122 return;
123 }
124
125 mBodyNodePtr = _ptr->getBodyNodePtr();
126 mDestructor = _ptr->mDestructor.lock();
127 mNode = _ptr;
128 }
129
130protected:
132 NodeT* mNode;
133
136 std::shared_ptr<NodeDestructor> mDestructor;
137
141};
142
148template <class NodeT, class BodyNodeT>
150{
151public:
152 template <class, class>
154
157
161 {
162 set(_ptr);
163 }
164
166 template <class OtherNodeT, class OtherBodyNodeT>
169 {
170 set(_weakPtr);
171 }
172
174 template <class OtherNodeT, class OtherBodyNodeT>
177 {
178 set(_strongPtr.get());
179 }
180
183 {
184 set(_ptr);
185 return *this;
186 }
187
189 template <class OtherNodeT, class OtherBodyNodeT>
192 {
193 set(_weakPtr);
194 return *this;
195 }
196
198 template <class OtherNodeT, class OtherBodyNodeT>
201 {
202 set(_strongPtr.get());
203 return *this;
204 }
205
210 {
212 if (nullptr == bodyNode)
213 return nullptr;
214
215 std::shared_ptr<NodeDestructor> destructor = mWeakDestructor.lock();
216 if (nullptr == destructor)
217 return nullptr;
218
220 }
221
223 void set(NodeT* _ptr)
224 {
225 if (nullptr == _ptr)
226 {
227 mNode = nullptr;
228 mWeakDestructor.reset();
229 mWeakBodyNodePtr = nullptr;
230 return;
231 }
232
233 mWeakBodyNodePtr = _ptr->getBodyNodePtr();
234 mWeakDestructor = _ptr->getOrCreateDestructor();
235 mNode = _ptr;
236 }
237
239 template <class OtherNodeT, class OtherBodyNodeT>
241 {
242 mNode = _weakPtr.mNode;
245 }
246
247protected:
249 NodeT* mNode;
250
252 std::weak_ptr<NodeDestructor> mWeakDestructor;
253
256};
257
258} // namespace dynamics
259} // namespace dart
260
261#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:109
TemplateNodePtr & operator=(NodeT *_ptr)
Assignment operator.
Definition NodePtr.hpp:75
NodeT & operator*() const
Dereferencing operator.
Definition NodePtr.hpp:97
TemplateBodyNodePtr< BodyNodeT > mBodyNodePtr
Hold onto a BodyNodePtr to the Node's associated BodyNode to make sure that the BodyNode stays alive.
Definition NodePtr.hpp:140
TemplateNodePtr & operator=(const TemplateNodePtr< OtherNodeT, OtherBodyNodeT > &_ptr)
Assignment operator for NodePtrs.
Definition NodePtr.hpp:83
TemplateNodePtr(const TemplateNodePtr< OtherNodeT, OtherBodyNodeT > &_ptr)
Constructor that takes in a strong NodePtr.
Definition NodePtr.hpp:69
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:136
TemplateNodePtr(NodeT *_ptr)
Typical constructor.
Definition NodePtr.hpp:62
NodeT * operator->() const
Dereferencing operation.
Definition NodePtr.hpp:103
NodeT * mNode
Node that this NodePtr refers to.
Definition NodePtr.hpp:132
void set(NodeT *_ptr)
Set the Node for this NodePtr.
Definition NodePtr.hpp:115
TemplateWeakBodyNodePtr is a templated class that enables users to create a non-reference-holding Wea...
Definition BodyNodePtr.hpp:222
TemplateWeakNodePtr is a templated class that enables users to create a weak non-reference-holding We...
Definition NodePtr.hpp:150
NodeT * mNode
Node that this pointer references.
Definition NodePtr.hpp:249
TemplateWeakNodePtr & operator=(NodeT *_ptr)
Assignment operator for raw Node pointers.
Definition NodePtr.hpp:182
std::weak_ptr< NodeDestructor > mWeakDestructor
Destructor for the Node.
Definition NodePtr.hpp:252
TemplateWeakNodePtr & operator=(const TemplateWeakNodePtr< OtherNodeT, OtherBodyNodeT > &_weakPtr)
Assignment operator for WeakNodePtrs.
Definition NodePtr.hpp:190
TemplateNodePtr< NodeT, BodyNodeT > lock() const
Locks the Node reference to ensure that the referenced Node is currently still available.
Definition NodePtr.hpp:209
TemplateWeakNodePtr()
Default constructor.
Definition NodePtr.hpp:156
TemplateWeakNodePtr(NodeT *_ptr)
Typical constructor.
Definition NodePtr.hpp:160
TemplateWeakNodePtr(const TemplateNodePtr< OtherNodeT, OtherBodyNodeT > &_strongPtr)
Constructor that takes in a strong NodePtr.
Definition NodePtr.hpp:175
TemplateWeakNodePtr & operator=(const TemplateNodePtr< OtherNodeT, OtherBodyNodeT > &_strongPtr)
Assignment operator for strong NodePtrs.
Definition NodePtr.hpp:199
void set(const TemplateWeakNodePtr< OtherNodeT, OtherBodyNodeT > &_weakPtr)
Set the Node for this WeakNodePtr based on another WeakNodePtr.
Definition NodePtr.hpp:240
void set(NodeT *_ptr)
Set the Node for this WeakNodePtr.
Definition NodePtr.hpp:223
TemplateWeakBodyNodePtr< BodyNodeT > mWeakBodyNodePtr
Pointer to the BodyNode that the Node is attached to.
Definition NodePtr.hpp:255
TemplateWeakNodePtr(const TemplateWeakNodePtr< OtherNodeT, OtherBodyNodeT > &_weakPtr)
Constructor that takes in a WeakNodePtr.
Definition NodePtr.hpp:167
Definition BulletCollisionDetector.cpp:60