1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/internal/update/common/animatable-property.h>
24 #include <dali/internal/update/manager/transform-manager-property.h>
33 * A wrapper class for getting/setting a property.
34 * Animators use this instead of accessing properties directly.
36 template < typename PropertyType >
37 class PropertyAccessor
42 * Create a property component.
43 * @param [in] property The property to access.
45 PropertyAccessor( SceneGraph::PropertyBase* property )
46 : mProperty( static_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) ) // we know the type
51 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
53 ~PropertyAccessor() = default;
56 * Query whether the accessor is set.
57 * @return True if set.
61 return mProperty != nullptr;
65 * Reset the property accessor
66 * @post Calling any other PropertyAccessor is invalid.
74 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
78 return mProperty->IsClean();
82 * Read access to the property.
83 * @param [in] bufferIndex The current update buffer index.
85 const PropertyType& Get( BufferIndex bufferIndex ) const
87 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
88 return mProperty->Get( bufferIndex );
92 * @copydoc AnimatableProperty<float>::Set()
94 void Set( BufferIndex bufferIndex, const PropertyType& value ) const
96 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
97 mProperty->Set( bufferIndex, value );
101 * @copydoc AnimatableProperty<float>::Bake()
103 void Bake( BufferIndex bufferIndex, const PropertyType& value ) const
105 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
106 mProperty->Bake( bufferIndex, value );
112 PropertyAccessor() = delete;
113 PropertyAccessor(const PropertyAccessor& property) = delete;
114 PropertyAccessor& operator=(const PropertyAccessor& rhs) = delete;
118 SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
123 * A wrapper class for getting/setting a transform manager property
124 * Animators use this instead of accessing properties directly.
126 template <typename T>
127 class TransformManagerPropertyAccessor
132 * Create a property component.
133 * @param [in] property The property to access.
135 TransformManagerPropertyAccessor( SceneGraph::PropertyBase* property )
136 : mProperty( static_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) ) // we know the type
141 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
143 ~TransformManagerPropertyAccessor() = default;
146 * Query whether the accessor is set.
147 * @return True if set.
151 return mProperty != nullptr;
155 * Reset the property accessor
156 * @post Calling any other PropertyAccessor is invalid.
164 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
168 return mProperty->IsClean();
172 * Read access to the property.
173 * @param [in] bufferIndex The current update buffer index.
174 * @return The value of the property
176 const T& Get( BufferIndex bufferIndex ) const
178 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
179 return mProperty->Get( bufferIndex );
183 * @copydoc AnimatableProperty<float>::Set()
185 void Set( BufferIndex bufferIndex, const T& value ) const
187 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
188 mProperty->Set( bufferIndex, value );
192 * @copydoc AnimatableProperty<float>::Bake()
194 void Bake( BufferIndex bufferIndex, const T& value ) const
196 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
197 mProperty->Bake( bufferIndex, value );
203 TransformManagerPropertyAccessor() = delete;
204 TransformManagerPropertyAccessor(const TransformManagerPropertyAccessor& property) = delete;
205 TransformManagerPropertyAccessor& operator=(const TransformManagerPropertyAccessor& rhs) = delete;
209 SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
214 * A wrapper class for getting/setting a transform manager property component
215 * Animators use this instead of accessing properties directly.
217 template <typename T, uint32_t COMPONENT>
218 class TransformManagerPropertyComponentAccessor
223 * Create a property component.
224 * @param [in] property The property to access.
226 TransformManagerPropertyComponentAccessor( SceneGraph::PropertyBase* property )
227 : mProperty( static_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) ) // we know the type
232 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
234 ~TransformManagerPropertyComponentAccessor() = default;
237 * Query whether the accessor is set.
238 * @return True if set.
242 return mProperty != nullptr;
246 * Reset the property accessor
247 * @post Calling any other PropertyAccessor is invalid.
255 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
259 return mProperty->IsClean();
263 * Read access to the property.
264 * @param [in] bufferIndex The current update buffer index.
265 * @return The value of the component of the property
267 float Get( BufferIndex bufferIndex ) const
269 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
270 return mProperty->GetFloatComponent( COMPONENT );
274 * @copydoc AnimatableProperty<float>::Set()
276 void Set( BufferIndex bufferIndex, float value ) const
278 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
279 mProperty->SetFloatComponent( value, COMPONENT );
283 * @copydoc AnimatableProperty<float>::Bake()
285 void Bake( BufferIndex bufferIndex, float value ) const
287 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
288 mProperty->BakeFloatComponent( value, COMPONENT );
294 TransformManagerPropertyComponentAccessor() = delete;
295 TransformManagerPropertyComponentAccessor(const TransformManagerPropertyComponentAccessor& property) = delete;
296 TransformManagerPropertyComponentAccessor& operator=(const TransformManagerPropertyComponentAccessor& rhs) = delete;
300 SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
304 } // namespace Internal
308 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H