DART 6.7.3
Loading...
Searching...
No Matches
JointPtr.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_DETAIL_JOINTPTR_HPP_
34#define DART_DYNAMICS_DETAIL_JOINTPTR_HPP_
35
37
38namespace dart {
39namespace dynamics {
40
47template <class JointT, class BodyNodeT>
49{
50public:
51
52 template<class, class> friend class TemplateJointPtr;
53
54 typedef JointT element_type;
55
57 TemplateJointPtr() = default;
58
61 TemplateJointPtr(JointT* _ptr) { set(_ptr); }
62
64 template <class OtherJointT, class OtherBodyNodeT>
70
73 {
74 set(_ptr);
75 return *this;
76 }
77
79 template <class OtherJointT, class OtherBodyNodeT>
82 {
83 set(_jptr.get());
84 return *this;
85 }
86
88 operator JointT*() const { return get(); }
89
91 JointT& operator*() const { return *get(); }
92
94 JointT* operator->() const { return get(); }
95
97 JointT* get() const
98 {
99 if(nullptr == mBodyNodePtr)
100 return nullptr;
101
102 return mBodyNodePtr->getParentJoint();
103 }
104
110
112 void set(JointT* _ptr)
113 {
114 if(nullptr == _ptr)
115 {
116 mBodyNodePtr = nullptr;
117 return;
118 }
119
120 mBodyNodePtr = _ptr->getChildBodyNode();
121 }
122
123 //----------------------------------------------------------------------------
125 //----------------------------------------------------------------------------
126
128 template <class OtherJointT, class OtherBodyNodeT>
129 bool operator == (const TemplateJointPtr<OtherJointT,
130 OtherBodyNodeT>& _rhs) const
131 {
132 return mBodyNodePtr == _rhs.mBodyNodePtr;
133 }
134
136 template <class OtherJointT, class OtherBodyNodeT>
137 bool operator != (const TemplateJointPtr<OtherJointT,
138 OtherBodyNodeT>& _rhs) const
139 {
140 return !( *this == _rhs );
141 }
142
144 template <class OtherJointT, class OtherBodyNodeT>
145 bool operator < (const TemplateJointPtr<OtherJointT,
146 OtherBodyNodeT>& _rhs) const
147 {
148 return (mBodyNodePtr < _rhs.mBodyNodePtr);
149 }
150
152 template <class OtherJointT, class OtherBodyNodeT>
153 bool operator > (const TemplateJointPtr<OtherJointT,
154 OtherBodyNodeT>& _rhs) const
155 {
156 return (mBodyNodePtr > _rhs.mBodyNodePtr);
157 }
158
160 template <class OtherJointT, class OtherBodyNodeT>
161 bool operator <= (const TemplateJointPtr<OtherJointT,
162 OtherBodyNodeT>& _rhs) const
163 {
164 return (*this < _rhs) || (*this == _rhs);
165 }
166
168 template <class OtherJointT, class OtherBodyNodeT>
169 bool operator >= (const TemplateJointPtr<OtherJointT,
170 OtherBodyNodeT>& _rhs) const
171 {
172 return (*this > _rhs) || (*this == _rhs);
173 }
174
176
177private:
180};
181
187template <class JointT, class BodyNodeT>
189{
190public:
191
192 template<class, class> friend class TemplateWeakJointPtr;
193
196
199 TemplateWeakJointPtr(JointT* _ptr) { set(_ptr); }
200
202 template <class OtherJointT, class OtherBodyNodeT>
205 {
206 set(_weakPtr);
207 }
208
210 template <class OtherJointT, class OtherBodyNodeT>
213 {
214 set(_strongPtr.get());
215 }
216
219 {
220 set(_ptr);
221 return *this;
222 }
223
225 template <class OtherJointT, class OtherBodyNodeT>
228 {
229 set(_weakPtr);
230 return *this;
231 }
232
234 template <class OtherJointT, class OtherBodyNodeT>
237 {
238 set(_strongPtr.get());
239 return *this;
240 }
241
246 {
248 if(nullptr == bodyNode)
249 return nullptr;
250
251 return TemplateJointPtr<JointT, BodyNodeT>(bodyNode->getParentJoint());
252 }
253
255 void set(JointT* _ptr)
256 {
257 if(nullptr == _ptr)
258 {
259 mWeakBodyNode = nullptr;
260 return;
261 }
262
263 mWeakBodyNode = _ptr->getChildBodyNode();
264 }
265
267 template <class OtherJointT, class OtherBodyNodeT>
269 {
270 mWeakBodyNode = _weakPtr.mWeakBodyNode;
271 }
272
273private:
276};
277
278} // namespace dart
279} // namespace dynamics
280
281#endif // DART_DYNAMICS_DETAIL_JOINTPTR_HPP_
TemplateBodyNodePtr is a templated class that enables users to create a reference-counting BodyNodePt...
Definition BodyNodePtr.hpp:111
TemplateJointPtr is a templated class that enables users to create a strong reference-counting JointP...
Definition JointPtr.hpp:49
bool operator>=(const TemplateJointPtr< OtherJointT, OtherBodyNodeT > &_rhs) const
Greater than or equal to.
Definition JointPtr.hpp:169
TemplateJointPtr(JointT *_ptr)
Typical constructor.
Definition JointPtr.hpp:61
bool operator==(const TemplateJointPtr< OtherJointT, OtherBodyNodeT > &_rhs) const
Equality.
Definition JointPtr.hpp:129
TemplateJointPtr()=default
Default constructor.
bool operator<(const TemplateJointPtr< OtherJointT, OtherBodyNodeT > &_rhs) const
Less than.
Definition JointPtr.hpp:145
TemplateJointPtr & operator=(JointT *_ptr)
Assignment operator.
Definition JointPtr.hpp:72
void set(JointT *_ptr)
Set the Joint for this JointPtr.
Definition JointPtr.hpp:112
bool operator<=(const TemplateJointPtr< OtherJointT, OtherBodyNodeT > &_rhs) const
Less than or equal to.
Definition JointPtr.hpp:161
TemplateBodyNodePtr< BodyNodeT > getBodyNodePtr() const
Get the BodyNode that this JointPtr is tied to.
Definition JointPtr.hpp:106
TemplateJointPtr(const TemplateJointPtr< OtherJointT, OtherBodyNodeT > &_jptr)
Constructor that takes in a strong JointPtr.
Definition JointPtr.hpp:65
JointT * operator->() const
Dereferencing operation.
Definition JointPtr.hpp:94
JointT & operator*() const
Dereferencing operator.
Definition JointPtr.hpp:91
bool operator>(const TemplateJointPtr< OtherJointT, OtherBodyNodeT > &_rhs) const
Greater than.
Definition JointPtr.hpp:153
JointT element_type
Definition JointPtr.hpp:54
JointT * get() const
Get the raw Joint pointer.
Definition JointPtr.hpp:97
TemplateBodyNodePtr< BodyNodeT > mBodyNodePtr
Reference-holding pointer to the child BodyNode of this Joint.
Definition JointPtr.hpp:179
bool operator!=(const TemplateJointPtr< OtherJointT, OtherBodyNodeT > &_rhs) const
Inequality.
Definition JointPtr.hpp:137
TemplateWeakBodyNodePtr is a templated class that enables users to create a non-reference-holding Wea...
Definition BodyNodePtr.hpp:199
TemplateWeakJointPtr is a templated class that enables users to create a non-reference-holding WeakJo...
Definition JointPtr.hpp:189
TemplateWeakJointPtr(const TemplateWeakJointPtr< OtherJointT, OtherBodyNodeT > &_weakPtr)
Constructor that takes in a WeakJointPtr.
Definition JointPtr.hpp:203
TemplateWeakJointPtr(JointT *_ptr)
Typical constructor.
Definition JointPtr.hpp:199
void set(JointT *_ptr)
Set the Joint for this WeakJointPtr.
Definition JointPtr.hpp:255
TemplateWeakJointPtr & operator=(JointT *_ptr)
Assignment operator for raw Joint pointers.
Definition JointPtr.hpp:218
TemplateWeakJointPtr()=default
Default constructor.
void set(const TemplateWeakJointPtr< OtherJointT, OtherBodyNodeT > &_weakPtr)
Set the Joint for this WeakJointPtr based on another WeakJointPtr.
Definition JointPtr.hpp:268
TemplateWeakJointPtr(const TemplateJointPtr< OtherJointT, OtherBodyNodeT > &_strongPtr)
Constructor that takes in a strong JointPtr.
Definition JointPtr.hpp:211
TemplateWeakBodyNodePtr< BodyNodeT > mWeakBodyNode
Weak poiner to the child BodyNode of this Joint.
Definition JointPtr.hpp:275
TemplateJointPtr< JointT, BodyNodeT > lock() const
Locks the Joint reference to ensure that the referenced Joint is currently still available.
Definition JointPtr.hpp:245
Definition BulletCollisionDetector.cpp:63