DART  6.10.1
SpecializedForAspect.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_COMMON_SPECIALIZEDFORASPECT_HPP_
34 #define DART_COMMON_SPECIALIZEDFORASPECT_HPP_
35 
38 #include "dart/common/Virtual.hpp"
39 
40 namespace dart {
41 namespace common {
42 
44 template <class... OtherSpecAspects>
46 {
47 public:
48  virtual ~SpecializedForAspect() = default;
49 };
50 
51 //==============================================================================
55 
56 template <class SpecAspect>
57 class SpecializedForAspect<SpecAspect> : public virtual Composite
58 {
59 public:
62 
63  virtual ~SpecializedForAspect() = default;
64 
66  template <class T>
67  bool has() const;
68 
70  template <class T>
71  T* get();
72 
74  template <class T>
75  const T* get() const;
76 
80  template <class T>
81  void set(const T* aspect);
82 
86  template <class T>
87  void set(std::unique_ptr<T>&& aspect);
88 
90  template <class T, typename... Args>
91  T* createAspect(Args&&... args);
92 
94  template <class T>
95  void removeAspect();
96 
100  template <class T>
101  std::unique_ptr<T> releaseAspect();
102 
104  template <class T>
105  static constexpr bool isSpecializedFor();
106 
107 protected:
108  template <class T>
109  struct type
110  {
111  };
112 
114  template <class T>
115  bool _has(type<T>) const;
116 
118  bool _has(type<SpecAspect>) const;
119 
121  template <class T>
122  T* _get(type<T>);
123 
125  SpecAspect* _get(type<SpecAspect>);
126 
128  template <class T>
129  const T* _get(type<T>) const;
130 
132  const SpecAspect* _get(type<SpecAspect>) const;
133 
138  template <class T>
139  void _set(type<T>, const T* aspect);
140 
142  void _set(type<SpecAspect>, const SpecAspect* aspect);
143 
148  template <class T>
149  void _set(type<T>, std::unique_ptr<T>&& aspect);
150 
152  void _set(type<SpecAspect>, std::unique_ptr<SpecAspect>&& aspect);
153 
155  template <class T, typename... Args>
156  T* _createAspect(type<T>, Args&&... args);
157 
159  template <typename... Args>
160  SpecAspect* _createAspect(type<SpecAspect>, Args&&... args);
161 
163  template <class T>
164  void _removeAspect(type<T>);
165 
167  void _removeAspect(type<SpecAspect>);
168 
170  template <class T>
171  std::unique_ptr<T> _releaseAspect(type<T>);
172 
174  std::unique_ptr<SpecAspect> _releaseAspect(type<SpecAspect>);
175 
177  template <class T>
178  static constexpr bool _isSpecializedFor(type<T>);
179 
181  static constexpr bool _isSpecializedFor(type<SpecAspect>);
182 
185 };
187 
188 //==============================================================================
192 template <class SpecAspect1, class... OtherSpecAspects>
193 class SpecializedForAspect<SpecAspect1, OtherSpecAspects...>
194  : public CompositeJoiner<
195  Virtual<SpecializedForAspect<SpecAspect1> >,
196  Virtual<SpecializedForAspect<OtherSpecAspects...> > >
197 {
198 public:
199  virtual ~SpecializedForAspect() = default;
200 };
201 
202 } // namespace common
203 } // namespace dart
204 
206 
207 #endif // DART_COMMON_SPECIALIZEDFORASPECT_HPP_
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_END
Definition: ClassWithVirtualBase.hpp:44
#define DART_DECLARE_CLASS_WITH_VIRTUAL_BASE_BEGIN
Definition: ClassWithVirtualBase.hpp:43
std::string type
Definition: SdfParser.cpp:82
Terminator for the variadic template.
Definition: CompositeJoiner.hpp:45
Composite is a base class that should be virtually inherited by any class that wants to be able to ma...
Definition: Composite.hpp:53
Composite::AspectMap::iterator mSpecAspectIterator
Iterator that points to the Aspect of this SpecializedForAspect.
Definition: SpecializedForAspect.hpp:184
Declaration of the variadic template.
Definition: SpecializedForAspect.hpp:46
virtual ~SpecializedForAspect()=default
std::multimap< dart::dynamics::Shape *, SimpleFrameShapeDnD * >::iterator iterator
Definition: Viewer.cpp:620
Definition: BulletCollisionDetector.cpp:65