DART 6.7.3
Loading...
Searching...
No Matches
ProxyAspect.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_DETAIL_PROXYASPECT_HPP_
34#define DART_COMMON_DETAIL_PROXYASPECT_HPP_
35
37
38namespace dart {
39namespace common {
40namespace detail {
41
42//==============================================================================
43template <class BaseT, class CompositeT, typename StateT>
44class ProxyStateAspect : public BaseT
45{
46public:
47
48 using Base = BaseT;
49 using CompositeType = CompositeT;
50 using State = StateT;
51
52 virtual ~ProxyStateAspect() = default;
53
55 template <typename... Args>
56 ProxyStateAspect(Args&&... args)
57 : Base(std::forward<Args>(args)...),
59 {
60 // Do nothing
61 }
62
63 // Documentation inherited
64 void setAspectState(const Aspect::State& state) override final
65 {
66 mProxyState.set(static_cast<const State&>(state));
67 }
68
69 // Documentation inherited
70 const Aspect::State* getAspectState() const override final
71 {
72 return &mProxyState;
73 }
74
75 // Documentation inherited
76 std::unique_ptr<Aspect> cloneAspect() const override
77 {
78 return make_unique<ProxyStateAspect>();
79 }
80
81protected:
82
84 void setComposite(Composite* newComposite) override
85 {
86 Base::setComposite(newComposite);
87
88 // Check if the Composite is the correct Owner type
89 typename State::Owner* owner =
90 dynamic_cast<typename State::Owner*>(newComposite);
91
92 if(owner && mProxyState.getOwner() != owner)
93 {
94 // Link the ProxyState to its new owner
95 mProxyState = State(owner, mProxyState.get());
96 }
97 }
98
100 void loseComposite(Composite* oldComposite) override
101 {
103 Base::loseComposite(oldComposite);
104 }
105
108
109};
110
111//==============================================================================
112template <class BaseT, class CompositeT, typename PropertiesT>
113class ProxyPropertiesAspect : public BaseT
114{
115public:
116
117 using Base = BaseT;
118 using CompositeType = CompositeT;
119 using Properties = PropertiesT;
120
121 virtual ~ProxyPropertiesAspect() = default;
122
124 template <typename... Args>
125 ProxyPropertiesAspect(Args&&... args)
126 : Base(std::forward<Args>(args)...),
128 {
129 // Do nothing
130 }
131
132 // Documentation inherited
134 {
135 mProxyProperties.set(static_cast<const Properties&>(properties));
136 }
137
138 // Documentation inherited
139 const Aspect::Properties* getAspectProperties() const override final
140 {
141 return &mProxyProperties;
142 }
143
144 // Documentation inherited
145 std::unique_ptr<Aspect> cloneAspect() const override
146 {
147 return make_unique<ProxyPropertiesAspect>();
148 }
149
150protected:
151
153 void setComposite(Composite* newComposite) override
154 {
155 Base::setComposite(newComposite);
156 typename Properties::Owner* owner =
157 dynamic_cast<typename Properties::Owner*>(newComposite);
158
159 if(owner && mProxyProperties.getOwner() != owner)
160 {
161 // Link the ProxyProperties to its new owner
163 }
164 }
165
167 void loseComposite(Composite* oldComposite) override
168 {
170 Base::loseComposite(oldComposite);
171 }
172
175
176};
177
178} // namespace detail
179} // namespace common
180} // namespace dart
181
182#endif // DART_COMMON_DETAIL_PROXYASPECT_HPP_
BodyPropPtr properties
Definition SdfParser.cpp:80
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
Composite is a base class that should be virtually inherited by any class that wants to be able to ma...
Definition Composite.hpp:52
Definition ProxyAspect.hpp:114
ProxyPropertiesAspect(Args &&... args)
General constructor.
Definition ProxyAspect.hpp:125
CompositeT CompositeType
Definition ProxyAspect.hpp:118
PropertiesT Properties
Definition ProxyAspect.hpp:119
std::unique_ptr< Aspect > cloneAspect() const override
Definition ProxyAspect.hpp:145
void setAspectProperties(const Aspect::Properties &properties) override final
Definition ProxyAspect.hpp:133
Properties mProxyProperties
Proxy properties for this Aspect.
Definition ProxyAspect.hpp:174
void loseComposite(Composite *oldComposite) override
Reconfigure the Aspect to unlink it from this Aspect's old Composite.
Definition ProxyAspect.hpp:167
const Aspect::Properties * getAspectProperties() const override final
Definition ProxyAspect.hpp:139
BaseT Base
Definition ProxyAspect.hpp:117
void setComposite(Composite *newComposite) override
Reconfigure the Aspect to link it to this Aspect's new Composite.
Definition ProxyAspect.hpp:153
Definition ProxyAspect.hpp:45
const Aspect::State * getAspectState() const override final
Definition ProxyAspect.hpp:70
ProxyStateAspect(Args &&... args)
General constructor.
Definition ProxyAspect.hpp:56
void setAspectState(const Aspect::State &state) override final
Definition ProxyAspect.hpp:64
void setComposite(Composite *newComposite) override
Reconfigure the Aspect to link it to this Aspect's new Composite.
Definition ProxyAspect.hpp:84
void loseComposite(Composite *oldComposite) override
Reconfigure the Aspect to unlink it from this Aspect's old Composite.
Definition ProxyAspect.hpp:100
BaseT Base
Definition ProxyAspect.hpp:48
CompositeT CompositeType
Definition ProxyAspect.hpp:49
std::unique_ptr< Aspect > cloneAspect() const override
Definition ProxyAspect.hpp:76
StateT State
Definition ProxyAspect.hpp:50
State mProxyState
Proxy state for this Aspect.
Definition ProxyAspect.hpp:107
Definition BulletCollisionDetector.cpp:63
Definition SharedLibraryManager.hpp:43