DART  6.7.3
DegreeOfFreedomPtr.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_DEGREEOFFREEDOMPTR_HPP_
34 #define DART_DYNAMICS_DETAIL_DEGREEOFFREEDOMPTR_HPP_
35 
38 
39 namespace dart {
40 namespace dynamics {
41 
51 template <class DegreeOfFreedomT, class BodyNodeT>
53 {
54 public:
55 
56  template<class, class> friend class TemplateDegreeOfFreedomPtr;
57 
60 
63  TemplateDegreeOfFreedomPtr(DegreeOfFreedomT* _ptr) { set(_ptr); }
64 
66  template <class OtherDegreeOfFreedomT, class OtherBodyNodeT>
68  const TemplateDegreeOfFreedomPtr<OtherDegreeOfFreedomT,
69  OtherBodyNodeT>& _dofp)
70  {
71  set(_dofp.get());
72  }
73 
75  TemplateDegreeOfFreedomPtr& operator = (DegreeOfFreedomT* _ptr)
76  {
77  set(_ptr);
78  return *this;
79  }
80 
82  template <class OtherDegreeOfFreedomT, class OtherBodyNodeT>
84  const TemplateDegreeOfFreedomPtr<OtherDegreeOfFreedomT,
85  OtherBodyNodeT>& _dofp)
86  {
87  set(_dofp.get());
88  return *this;
89  }
90 
92  operator DegreeOfFreedomT*() const { return get(); }
93 
95  DegreeOfFreedomT& operator*() const { return *get(); }
96 
98  DegreeOfFreedomT* operator->() const { return get(); }
99 
101  DegreeOfFreedomT* get() const
102  {
103  if(nullptr == mBodyNodePtr)
104  return nullptr;
105 
106  return mBodyNodePtr->getParentJoint()->getDof(mIndex);
107  }
108 
111  {
112  return mBodyNodePtr;
113  }
114 
117  std::size_t getLocalIndex() const
118  {
119  if(nullptr == mBodyNodePtr)
120  return INVALID_INDEX;
121 
122  return mIndex;
123  }
124 
126  void set(DegreeOfFreedomT* _ptr)
127  {
128  if(nullptr == _ptr)
129  {
130  mBodyNodePtr = nullptr;
131  return;
132  }
133 
134  mBodyNodePtr = _ptr->getChildBodyNode();
135  mIndex = _ptr->getIndexInJoint();
136  }
137 
138  //----------------------------------------------------------------------------
140  //----------------------------------------------------------------------------
141 
143  template <class OtherDofT, class OtherBodyNodeT>
145  OtherBodyNodeT>& _rhs) const
146  {
147  if(nullptr == mBodyNodePtr && nullptr == _rhs.mBodyNodePtr)
148  return true;
149 
150  if( (mBodyNodePtr == _rhs.mBodyNodePtr) && (mIndex == _rhs.mIndex) )
151  return true;
152 
153  return false;
154  }
155 
157  template <class OtherDofT, class OtherBodyNodeT>
159  OtherBodyNodeT>& _rhs) const
160  {
161  return !( *this == _rhs );
162  }
163 
165  template <class OtherDofT, class OtherBodyNodeT>
167  OtherBodyNodeT>& _rhs) const
168  {
169  if( mBodyNodePtr == _rhs.mBodyNodePtr )
170  return (mIndex < _rhs.mIndex);
171 
172  return (mBodyNodePtr < _rhs.mBodyNodePtr);
173  }
174 
176  template <class OtherDofT, class OtherBodyNodeT>
178  OtherBodyNodeT>& _rhs) const
179  {
180  if( mBodyNodePtr == _rhs.mBodyNodePtr )
181  return (mIndex > _rhs.mIndex);
182 
183  return (mBodyNodePtr > _rhs.mBodyNodePtr);
184  }
185 
187  template <class OtherDofT, class OtherBodyNodeT>
189  OtherBodyNodeT>& _rhs) const
190  {
191  return (*this < _rhs) || (*this == _rhs);
192  }
193 
195  template <class OtherDofT, class OtherBodyNodeT>
197  OtherBodyNodeT>& _rhs) const
198  {
199  return (*this > _rhs) || (*this == _rhs);
200  }
201 
203 
204 private:
207 
209  std::size_t mIndex;
210 };
211 
218 template <class DegreeOfFreedomT, class BodyNodeT>
220 {
221 public:
222 
223  template<class, class> friend class TemplateWeakDegreeOfFreedomPtr;
224 
227 
230  TemplateWeakDegreeOfFreedomPtr(DegreeOfFreedomT* _ptr) { set(_ptr); }
231 
233  template <class OtherDofT, class OtherBodyNodeT>
235  const TemplateWeakDegreeOfFreedomPtr<OtherDofT,
236  OtherBodyNodeT>& _weakPtr)
237  {
238  set(_weakPtr);
239  }
240 
242  template <class OtherDofT, class OtherBodyNodeT>
244  const TemplateDegreeOfFreedomPtr<OtherDofT,
245  OtherBodyNodeT>& _strongPtr)
246  {
247  set(_strongPtr.get());
248  }
249 
252  {
253  set(_ptr);
254  return *this;
255  }
256 
258  template <class OtherDofT, class OtherBodyNodeT>
260  const TemplateWeakDegreeOfFreedomPtr<OtherDofT,
261  OtherBodyNodeT>& _weakPtr)
262  {
263  set(_weakPtr);
264  return *this;
265  }
266 
268  template <class OtherDofT, class OtherBodyNodeT>
270  const TemplateDegreeOfFreedomPtr<OtherDofT,
271  OtherBodyNodeT>& _strongPtr)
272  {
273  set(_strongPtr.get());
274  return *this;
275  }
276 
282  {
284  if(nullptr == bodyNode)
285  return nullptr;
286 
288  bodyNode->getParentJoint()->getDof(mIndex));
289  }
290 
292  void set(DegreeOfFreedomT* _ptr)
293  {
294  if(nullptr == _ptr)
295  {
296  mWeakBodyNode = nullptr;
297  mIndex = 0;
298  return;
299  }
300 
301  mWeakBodyNode = _ptr->getChildBodyNode();
302  mIndex = _ptr->getIndexInJoint();
303  }
304 
307  template <class OtherDofT, class OtherBodyNodeT>
308  void set(const TemplateWeakDegreeOfFreedomPtr<OtherDofT,
309  OtherBodyNodeT>& _weakPtr)
310  {
311  mWeakBodyNode = _weakPtr.mWeakBodyNode;
312  mIndex = _weakPtr.mIndex;
313  }
314 
315 private:
318 
320  std::size_t mIndex;
321 };
322 
323 } // namespace dynamics
324 } // namespace dart
325 
326 #endif // DART_DYNAMICS_DETAIL_DEGREEOFFREEDOMPTR_HPP_
TemplateBodyNodePtr is a templated class that enables users to create a reference-counting BodyNodePt...
Definition: BodyNodePtr.hpp:111
TemplateDegreeOfFreedomPtr is a templated class that enables users to create a reference-counting Deg...
Definition: DegreeOfFreedomPtr.hpp:53
DegreeOfFreedomT & operator*() const
Dereferencing operator.
Definition: DegreeOfFreedomPtr.hpp:95
TemplateBodyNodePtr< BodyNodeT > mBodyNodePtr
Reference-holding pointer to the child BodyNode of this DegreeOfFreedom.
Definition: DegreeOfFreedomPtr.hpp:206
bool operator>=(const TemplateDegreeOfFreedomPtr< OtherDofT, OtherBodyNodeT > &_rhs) const
Greater than or equal to.
Definition: DegreeOfFreedomPtr.hpp:196
bool operator<=(const TemplateDegreeOfFreedomPtr< OtherDofT, OtherBodyNodeT > &_rhs) const
Less than or equal to.
Definition: DegreeOfFreedomPtr.hpp:188
bool operator==(const TemplateDegreeOfFreedomPtr< OtherDofT, OtherBodyNodeT > &_rhs) const
Equality.
Definition: DegreeOfFreedomPtr.hpp:144
bool operator>(const TemplateDegreeOfFreedomPtr< OtherDofT, OtherBodyNodeT > &_rhs) const
Greater than.
Definition: DegreeOfFreedomPtr.hpp:177
TemplateDegreeOfFreedomPtr()=default
Default constructor.
TemplateDegreeOfFreedomPtr(DegreeOfFreedomT *_ptr)
Typical constructor.
Definition: DegreeOfFreedomPtr.hpp:63
TemplateDegreeOfFreedomPtr(const TemplateDegreeOfFreedomPtr< OtherDegreeOfFreedomT, OtherBodyNodeT > &_dofp)
Constructor that takes in a strong DegreeOfFreedomPtrs.
Definition: DegreeOfFreedomPtr.hpp:67
DegreeOfFreedomT * operator->() const
Dereferencing operation.
Definition: DegreeOfFreedomPtr.hpp:98
TemplateDegreeOfFreedomPtr & operator=(DegreeOfFreedomT *_ptr)
Assignment operator.
Definition: DegreeOfFreedomPtr.hpp:75
TemplateBodyNodePtr< BodyNodeT > getBodyNodePtr() const
Get the BodyNode that this DegreeOfFreedomPtr is tied to.
Definition: DegreeOfFreedomPtr.hpp:110
void set(DegreeOfFreedomT *_ptr)
Set the DegreeOfFreedom for this DegreeOfFreedomPtr.
Definition: DegreeOfFreedomPtr.hpp:126
bool operator!=(const TemplateDegreeOfFreedomPtr< OtherDofT, OtherBodyNodeT > &_rhs) const
Inequality.
Definition: DegreeOfFreedomPtr.hpp:158
bool operator<(const TemplateDegreeOfFreedomPtr< OtherDofT, OtherBodyNodeT > &_rhs) const
Less than.
Definition: DegreeOfFreedomPtr.hpp:166
std::size_t getLocalIndex() const
Get the local generalized coordinate index that this DegreeOfFreedomPtr is tied to.
Definition: DegreeOfFreedomPtr.hpp:117
DegreeOfFreedomT * get() const
Get the raw DegreeOfFreedom pointer.
Definition: DegreeOfFreedomPtr.hpp:101
std::size_t mIndex
Local index of this DegreeOfFreedom within its Joint.
Definition: DegreeOfFreedomPtr.hpp:209
TemplateWeakBodyNodePtr is a templated class that enables users to create a non-reference-holding Wea...
Definition: BodyNodePtr.hpp:199
TemplateWeakDegreeOfFreedomPtr is a templated class that enables users to create a non-reference-hold...
Definition: DegreeOfFreedomPtr.hpp:220
void set(DegreeOfFreedomT *_ptr)
Set the DegreeOfFreedom for this WeakDegreeOfFreedomPtr.
Definition: DegreeOfFreedomPtr.hpp:292
TemplateWeakDegreeOfFreedomPtr(const TemplateWeakDegreeOfFreedomPtr< OtherDofT, OtherBodyNodeT > &_weakPtr)
Constructor that takes in a WeakDegreeOfFreedomPtr.
Definition: DegreeOfFreedomPtr.hpp:234
TemplateWeakDegreeOfFreedomPtr(const TemplateDegreeOfFreedomPtr< OtherDofT, OtherBodyNodeT > &_strongPtr)
Constructor that takes in a strong DegreeOfFreedomPtr.
Definition: DegreeOfFreedomPtr.hpp:243
TemplateWeakDegreeOfFreedomPtr()
Default constructor.
Definition: DegreeOfFreedomPtr.hpp:226
TemplateWeakBodyNodePtr< BodyNodeT > mWeakBodyNode
Weak pointer to the child BodyNode of this DegreeOfFreedom.
Definition: DegreeOfFreedomPtr.hpp:317
TemplateWeakDegreeOfFreedomPtr(DegreeOfFreedomT *_ptr)
Typical constructor.
Definition: DegreeOfFreedomPtr.hpp:230
void set(const TemplateWeakDegreeOfFreedomPtr< OtherDofT, OtherBodyNodeT > &_weakPtr)
Attempt to set the DegreeOfFreedom for this WeakDegreeOfFreedomPtr based on another WeakDegreeOfFreed...
Definition: DegreeOfFreedomPtr.hpp:308
TemplateWeakDegreeOfFreedomPtr & operator=(DegreeOfFreedomT *_ptr)
Assignment operator for raw DegreeOfFreedom pointers.
Definition: DegreeOfFreedomPtr.hpp:251
std::size_t mIndex
Local index of this DegreeOfFreedom within its Joint.
Definition: DegreeOfFreedomPtr.hpp:320
TemplateDegreeOfFreedomPtr< DegreeOfFreedomT, BodyNodeT > lock() const
Locks the DegreeOfFreedom reference to ensure that the referenced DegreeOfFreedom is currently still ...
Definition: DegreeOfFreedomPtr.hpp:281
constexpr std::size_t INVALID_INDEX
Definition: InvalidIndex.hpp:41
Definition: BulletCollisionDetector.cpp:63