DART 6.7.3
Loading...
Searching...
No Matches
SpecializedForAspect.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_COMMON_SPECIALIZEDFORASPECT_HPP_
34#define DART_COMMON_SPECIALIZEDFORASPECT_HPP_
35
39
40namespace dart {
41namespace common {
42
44template <class... OtherSpecAspects>
46{
47public:
48 virtual ~SpecializedForAspect() = default;
49};
50
51//==============================================================================
54template <class SpecAspect>
55class SpecializedForAspect<SpecAspect> : public virtual Composite
56{
57public:
58
61
62 virtual ~SpecializedForAspect() = default;
63
65 template <class T>
66 bool has() const;
67
69 template <class T>
70 T* get();
71
73 template <class T>
74 const T* get() const;
75
79 template <class T>
80 void set(const T* aspect);
81
85 template <class T>
86 void set(std::unique_ptr<T>&& aspect);
87
89 template <class T, typename ...Args>
90 T* createAspect(Args&&... args);
91
93 template <class T>
94 void removeAspect();
95
99 template <class T>
100 std::unique_ptr<T> releaseAspect();
101
103 template <class T>
104 static constexpr bool isSpecializedFor();
105
106protected:
107
108 template <class T> struct type { };
109
111 template <class T>
112 bool _has(type<T>) const;
113
115 bool _has(type<SpecAspect>) const;
116
118 template <class T>
119 T* _get(type<T>);
120
122 SpecAspect* _get(type<SpecAspect>);
123
125 template <class T>
126 const T* _get(type<T>) const;
127
129 const SpecAspect* _get(type<SpecAspect>) const;
130
135 template <class T>
136 void _set(type<T>, const T* aspect);
137
139 void _set(type<SpecAspect>, const SpecAspect* aspect);
140
145 template <class T>
146 void _set(type<T>, std::unique_ptr<T>&& aspect);
147
149 void _set(type<SpecAspect>, std::unique_ptr<SpecAspect>&& aspect);
150
152 template <class T, typename ...Args>
153 T* _createAspect(type<T>, Args&&... args);
154
156 template <typename ...Args>
157 SpecAspect* _createAspect(type<SpecAspect>, Args&&... args);
158
160 template <class T>
161 void _removeAspect(type<T>);
162
164 void _removeAspect(type<SpecAspect>);
165
167 template <class T>
168 std::unique_ptr<T> _releaseAspect(type<T>);
169
171 std::unique_ptr<SpecAspect> _releaseAspect(type<SpecAspect>);
172
174 template <class T>
175 static constexpr bool _isSpecializedFor(type<T>);
176
178 static constexpr bool _isSpecializedFor(type<SpecAspect>);
179
181 Composite::AspectMap::iterator mSpecAspectIterator;
182
183};
184
185//==============================================================================
189template <class SpecAspect1, class... OtherSpecAspects>
190class SpecializedForAspect<SpecAspect1, OtherSpecAspects...> :
191 public CompositeJoiner< Virtual< SpecializedForAspect<SpecAspect1> >,
192 Virtual< SpecializedForAspect<OtherSpecAspects...> > >
193{
194public:
195 virtual ~SpecializedForAspect() = default;
196};
197
198} // namespace common
199} // namespace dart
200
202
203#endif // DART_COMMON_SPECIALIZEDFORASPECT_HPP_
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:52
Composite::AspectMap::iterator mSpecAspectIterator
Iterator that points to the Aspect of this SpecializedForAspect.
Definition SpecializedForAspect.hpp:181
Declaration of the variadic template.
Definition SpecializedForAspect.hpp:46
virtual ~SpecializedForAspect()=default
Definition BulletCollisionDetector.cpp:63