DART  6.6.2
Aspect.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2018, 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 
40 
41 namespace dart {
42 namespace common {
43 
44 class Composite;
45 
46 class Aspect
47 {
48 public:
49 
50  friend class Composite;
51 
64  class State : public Cloneable<State> { };
65 
68  template <class Mixin>
70 
83  class Properties : public Cloneable<Properties> { };
84 
87  template <class Mixin>
89 
91  virtual ~Aspect() = default;
92 
94  virtual std::unique_ptr<Aspect> cloneAspect() const = 0;
95 
97  virtual void setAspectState(const State& otherState);
98 
101  virtual const State* getAspectState() const;
102 
104  virtual void setAspectProperties(const Properties& someProperties);
105 
108  virtual const Properties* getAspectProperties() const;
109 
110 protected:
111 
117  virtual void setComposite(Composite* newComposite);
118 
123  virtual void loseComposite(Composite* oldComposite);
124 };
125 
126 //==============================================================================
127 template <class CompositeType>
129 {
130 public:
131 
134 
136  CompositeType* getComposite();
137 
139  const CompositeType* getComposite() const;
140 
142  bool hasComposite() const;
143 
144 protected:
145 
147  void setComposite(Composite* newComposite) override;
148 
150  void loseComposite(Composite* oldComposite) override;
151 
153  CompositeType* mComposite;
154 
155 };
156 
157 } // namespace common
158 } // namespace dart
159 
160 //==============================================================================
161 #define DART_COMMON_ASPECT_PROPERTY_CONSTRUCTOR( ClassName, UpdatePropertiesMacro )\
162  ClassName (const ClassName &) = delete;\
163  inline ClassName (const PropertiesData& properties = PropertiesData())\
164  : AspectWithVersionedProperties< Base, Derived, PropertiesData, CompositeType, UpdatePropertiesMacro>(properties) { }
165 
166 //==============================================================================
167 #define DART_COMMON_ASPECT_STATE_PROPERTY_CONSTRUCTORS(ClassName)\
168  ClassName (const ClassName &) = delete;\
169  inline ClassName (const StateData& state = StateData(), const PropertiesData& properties = PropertiesData())\
170  : AspectImpl(state, properties) { }\
171  inline ClassName (const PropertiesData& properties, const StateData state = StateData())\
172  : AspectImpl(properties, state) { }
173 
174 //==============================================================================
175 #define DART_COMMON_SET_ASPECT_PROPERTY_CUSTOM( Type, Name, Update )\
176  inline void set ## Name (const Type & value)\
177  { mProperties.m ## Name = value; Update(); }
178 
179 //==============================================================================
180 #define DART_COMMON_SET_ASPECT_PROPERTY( Type, Name )\
181  DART_COMMON_SET_ASPECT_PROPERTY_CUSTOM( Type, Name, notifyPropertiesUpdated )
182 
183 //==============================================================================
184 #define DART_COMMON_GET_ASPECT_PROPERTY( Type, Name )\
185  inline const Type& get ## Name () const\
186  { return mProperties.m ## Name; }
187 
188 //==============================================================================
189 #define DART_COMMON_SET_GET_ASPECT_PROPERTY( Type, Name )\
190  DART_COMMON_SET_ASPECT_PROPERTY( Type, Name )\
191  DART_COMMON_GET_ASPECT_PROPERTY( Type, Name )
192 
194 
195 #endif // DART_COMMON_ASPECT_HPP_
If your Aspect has Properties, then that Properties class should inherit this Aspect::Properties clas...
Definition: Aspect.hpp:83
If your Aspect has a State, then that State class should inherit this Aspect::State class.
Definition: Aspect.hpp:64
Definition: Aspect.hpp:47
virtual std::unique_ptr< Aspect > cloneAspect() const =0
Clone this Aspect into a new composite.
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 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:129
CompositeTrackingAspect()
Default constructor.
Definition: Aspect.hpp:46
void setComposite(Composite *newComposite) override
Grab the new Composite.
Definition: Aspect.hpp:75
CompositeType * getComposite()
Get the Composite of this Aspect.
Definition: Aspect.hpp:54
CompositeType * mComposite
Pointer to the current Composite of this Aspect.
Definition: Aspect.hpp:153
bool hasComposite() const
Returns true if this Aspect has a Composite that matches CompositeType.
Definition: Aspect.hpp:68
void loseComposite(Composite *oldComposite) override
Clear the old Composite.
Definition: Aspect.hpp:87
Composite is a base class that should be virtually inherited by any class that wants to be able to ma...
Definition: Composite.hpp:52
The MakeCloneable class is used to easily create an Cloneable (such as Node::State) which simply take...
Definition: Cloneable.hpp:85
Definition: BulletCollisionDetector.cpp:63