1 #ifndef DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
2 #define DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H
5 * Copyright (c) 2020 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 const SceneGraph::AnimatableProperty<PropertyType>* property = mProperty;
89 return property->Get( bufferIndex );
93 * @copydoc AnimatableProperty<float>::Set()
95 void Set( BufferIndex bufferIndex, const PropertyType& value ) const
97 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
98 mProperty->Set( bufferIndex, value );
102 * @copydoc AnimatableProperty<float>::Bake()
104 void Bake( BufferIndex bufferIndex, const PropertyType& value ) const
106 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
107 mProperty->Bake( bufferIndex, value );
113 PropertyAccessor() = delete;
114 PropertyAccessor(const PropertyAccessor& property) = delete;
115 PropertyAccessor& operator=(const PropertyAccessor& rhs) = delete;
119 SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
124 * A wrapper class for getting/setting a transform manager property
125 * Animators use this instead of accessing properties directly.
127 template <typename T>
128 class TransformManagerPropertyAccessor
133 * Create a property component.
134 * @param [in] property The property to access.
136 TransformManagerPropertyAccessor( SceneGraph::PropertyBase* property )
137 : mProperty( static_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) ) // we know the type
142 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
144 ~TransformManagerPropertyAccessor() = default;
147 * Query whether the accessor is set.
148 * @return True if set.
152 return mProperty != nullptr;
156 * Reset the property accessor
157 * @post Calling any other PropertyAccessor is invalid.
165 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
169 return mProperty->IsClean();
173 * Read access to the property.
174 * @param [in] bufferIndex The current update buffer index.
175 * @return The value of the property
177 const T& Get( BufferIndex bufferIndex ) const
179 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
180 const SceneGraph::TransformManagerPropertyHandler<T>* property = mProperty;
181 return property->Get( bufferIndex );
185 * @copydoc AnimatableProperty<float>::Set()
187 void Set( BufferIndex bufferIndex, const T& value ) const
189 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
190 mProperty->Set( bufferIndex, value );
194 * @copydoc AnimatableProperty<float>::Bake()
196 void Bake( BufferIndex bufferIndex, const T& value ) const
198 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
199 mProperty->Bake( bufferIndex, value );
205 TransformManagerPropertyAccessor() = delete;
206 TransformManagerPropertyAccessor(const TransformManagerPropertyAccessor& property) = delete;
207 TransformManagerPropertyAccessor& operator=(const TransformManagerPropertyAccessor& rhs) = delete;
211 SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
216 * A wrapper class for getting/setting a transform manager property component
217 * Animators use this instead of accessing properties directly.
219 template <typename T, uint32_t COMPONENT>
220 class TransformManagerPropertyComponentAccessor
225 * Create a property component.
226 * @param [in] property The property to access.
228 TransformManagerPropertyComponentAccessor( SceneGraph::PropertyBase* property )
229 : mProperty( static_cast< SceneGraph::TransformManagerPropertyHandler<T>* >(property) ) // we know the type
234 * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
236 ~TransformManagerPropertyComponentAccessor() = default;
239 * Query whether the accessor is set.
240 * @return True if set.
244 return mProperty != nullptr;
248 * Reset the property accessor
249 * @post Calling any other PropertyAccessor is invalid.
257 * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
261 return mProperty->IsClean();
265 * Read access to the property.
266 * @param [in] bufferIndex The current update buffer index.
267 * @return The value of the component of the property
269 float Get( BufferIndex bufferIndex ) const
271 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Get() mProperty was nullptr" );
272 const SceneGraph::TransformManagerPropertyHandler<T>* property = mProperty;
273 return property->GetFloatComponent( COMPONENT );
277 * @copydoc AnimatableProperty<float>::Set()
279 void Set( BufferIndex bufferIndex, float value ) const
281 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Set() mProperty was nullptr" );
282 mProperty->SetFloatComponent( value, COMPONENT );
286 * @copydoc AnimatableProperty<float>::Bake()
288 void Bake( BufferIndex bufferIndex, float value ) const
290 DALI_ASSERT_DEBUG( nullptr != mProperty && "PropertyAccessor::Bake() mProperty was nullptr" );
291 mProperty->BakeFloatComponent( value, COMPONENT );
297 TransformManagerPropertyComponentAccessor() = delete;
298 TransformManagerPropertyComponentAccessor(const TransformManagerPropertyComponentAccessor& property) = delete;
299 TransformManagerPropertyComponentAccessor& operator=(const TransformManagerPropertyComponentAccessor& rhs) = delete;
303 SceneGraph::TransformManagerPropertyHandler<T>* mProperty; ///< The real property
307 } // namespace Internal
311 #endif // DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H