DART 6.10.1
Loading...
Searching...
No Matches
Aspect.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_ASPECT_HPP_
34#define DART_COMMON_ASPECT_HPP_
35
36#include <string>
37
41
42namespace dart {
43namespace common {
44
45class Composite;
46
47class Aspect
48{
49public:
50 friend class Composite;
51
64 class State : public Cloneable<State>
65 {
66 };
67
70 template <class Mixin>
72
85 class Properties : public Cloneable<Properties>
86 {
87 };
88
91 template <class Mixin>
93
95 virtual ~Aspect() = default;
96
98 virtual std::unique_ptr<Aspect> cloneAspect() const = 0;
99
101 virtual void setAspectState(const State& otherState);
102
105 virtual const State* getAspectState() const;
106
108 virtual void setAspectProperties(const Properties& someProperties);
109
112 virtual const Properties* getAspectProperties() const;
113
114protected:
120 virtual void setComposite(Composite* newComposite);
121
126 virtual void loseComposite(Composite* oldComposite);
127};
128
129//==============================================================================
130template <class CompositeType>
132{
133public:
136
138 CompositeType* getComposite();
139
141 const CompositeType* getComposite() const;
142
144 bool hasComposite() const;
145
146protected:
148 void setComposite(Composite* newComposite) override;
149
151 void loseComposite(Composite* oldComposite) override;
152
154 CompositeType* mComposite;
155};
156
157} // namespace common
158} // namespace dart
159
160//==============================================================================
161#define DART_COMMON_ASPECT_PROPERTY_CONSTRUCTOR( \
162 ClassName, UpdatePropertiesMacro) \
163 ClassName(const ClassName&) = delete; \
164 inline ClassName(const PropertiesData& properties = PropertiesData()) \
165 : AspectWithVersionedProperties< \
166 Base, \
167 Derived, \
168 PropertiesData, \
169 CompositeType, \
170 UpdatePropertiesMacro>(properties) \
171 { \
172 }
173
174//==============================================================================
175#define DART_COMMON_ASPECT_STATE_PROPERTY_CONSTRUCTORS(ClassName) \
176 ClassName(const ClassName&) = delete; \
177 inline ClassName( \
178 const StateData& state = StateData(), \
179 const PropertiesData& properties = PropertiesData()) \
180 : AspectImpl(state, properties) \
181 { \
182 } \
183 inline ClassName( \
184 const PropertiesData& properties, const StateData state = StateData()) \
185 : AspectImpl(properties, state) \
186 { \
187 }
188
189//==============================================================================
190#define DART_COMMON_SET_ASPECT_PROPERTY_CUSTOM(Type, Name, Update) \
191 inline void set##Name(const Type& value) \
192 { \
193 mProperties.m##Name = value; \
194 Update(); \
195 }
196
197//==============================================================================
198#define DART_COMMON_SET_ASPECT_PROPERTY(Type, Name) \
199 DART_COMMON_SET_ASPECT_PROPERTY_CUSTOM(Type, Name, notifyPropertiesUpdated)
200
201//==============================================================================
202#define DART_COMMON_GET_ASPECT_PROPERTY(Type, Name) \
203 inline const Type& get##Name() const \
204 { \
205 return mProperties.m##Name; \
206 }
207
208//==============================================================================
209#define DART_COMMON_SET_GET_ASPECT_PROPERTY(Type, Name) \
210 DART_COMMON_SET_ASPECT_PROPERTY(Type, Name) \
211 DART_COMMON_GET_ASPECT_PROPERTY(Type, Name)
212
214
215#endif // DART_COMMON_ASPECT_HPP_
If your Aspect has Properties, then that Properties class should inherit this Aspect::Properties clas...
Definition Aspect.hpp:86
If your Aspect has a State, then that State class should inherit this Aspect::State class.
Definition Aspect.hpp:65
Definition Aspect.hpp:48
virtual void setAspectProperties(const Properties &someProperties)
Set the Properties of this Aspect. By default, this does nothing.
Definition Aspect.cpp:56
virtual const State * getAspectState() const
Get the State of this Aspect.
Definition Aspect.cpp:50
virtual std::unique_ptr< Aspect > cloneAspect() const =0
Clone this Aspect into a new composite.
virtual void setAspectState(const State &otherState)
Set the State of this Aspect. By default, this does nothing.
Definition Aspect.cpp:44
virtual const Properties * getAspectProperties() const
Get the Properties of this Aspect.
Definition Aspect.cpp:62
virtual ~Aspect()=default
Virtual destructor.
virtual void setComposite(Composite *newComposite)
This function will be triggered (1) after the Aspect has been created [transfer will be false] and (2...
Definition Aspect.cpp:68
virtual void loseComposite(Composite *oldComposite)
This function will be triggered if your Aspect is about to be removed from its Composite.
Definition Aspect.cpp:74
Cloneable is a CRTP base class that provides an interface for easily creating data structures that ar...
Definition Cloneable.hpp:54
Definition Aspect.hpp:132
CompositeTrackingAspect()
Default constructor.
Definition Aspect.hpp:46
void setComposite(Composite *newComposite) override
Grab the new Composite.
Definition Aspect.hpp:77
CompositeType * getComposite()
Get the Composite of this Aspect.
Definition Aspect.hpp:55
CompositeType * mComposite
Pointer to the current Composite of this Aspect.
Definition Aspect.hpp:154
bool hasComposite() const
Returns true if this Aspect has a Composite that matches CompositeType.
Definition Aspect.hpp:70
void loseComposite(Composite *oldComposite) override
Clear the old Composite.
Definition Aspect.hpp:90
Composite is a base class that should be virtually inherited by any class that wants to be able to ma...
Definition Composite.hpp:53
The MakeCloneable class is used to easily create an Cloneable (such as Node::State) which simply take...
Definition Cloneable.hpp:84
Definition BulletCollisionDetector.cpp:65