Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-core.git] / dali / internal / update / animation / property-accessor.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/internal/update/common/animatable-property.h>
24
25 namespace Dali
26 {
27
28 namespace Internal
29 {
30
31 /**
32  * A wrapper class for getting/setting a property.
33  * Animators use this instead of accessing properties directly.
34  */
35 template < typename PropertyType >
36 class PropertyAccessor
37 {
38 public:
39
40   /**
41    * Create a property component.
42    * @param [in] property The property to access.
43    */
44   PropertyAccessor( SceneGraph::PropertyBase* property )
45   : mProperty( dynamic_cast< SceneGraph::AnimatableProperty<PropertyType>* >(property) )
46   {
47   }
48
49   /**
50    * Non-virtual destructor; PropertyAccessor is not suitable as a base class.
51    */
52   ~PropertyAccessor()
53   {
54   }
55
56   /**
57    * Query whether the accessor is set.
58    * @return True if set.
59    */
60   bool IsSet() const
61   {
62     return mProperty != NULL;
63   }
64
65   /**
66    * Reset the property accessor
67    * @post Calling any other PropertyAccessor is invalid.
68    */
69   void Reset()
70   {
71     mProperty = NULL;
72   }
73
74   /**
75    * @copydoc Dali::Internal::SceneGraph::PropertyBase::IsClean()
76    */
77   bool IsClean() const
78   {
79     return mProperty->IsClean();
80   }
81
82   /**
83    * Read access to the property.
84    * @param [in] bufferIndex The current update buffer index.
85    */
86   const PropertyType& Get( BufferIndex bufferIndex ) const
87   {
88     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Get() mProperty was NULL" );
89     return mProperty->Get( bufferIndex );
90   }
91
92   /**
93    * @copydoc AnimatableProperty<float>::Set()
94    */
95   void Set( BufferIndex bufferIndex, const PropertyType& value ) const
96   {
97     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Set() mProperty was NULL" );
98     mProperty->Set( bufferIndex, value );
99   }
100
101   /**
102    * @copydoc AnimatableProperty<float>::Bake()
103    */
104   void Bake( BufferIndex bufferIndex, const PropertyType& value ) const
105   {
106     DALI_ASSERT_DEBUG( NULL != mProperty && "PropertyAccessor::Bake() mProperty was NULL" );
107     mProperty->Bake( bufferIndex, value );
108   }
109
110 private:
111
112   // Undefined
113   PropertyAccessor(const PropertyAccessor& property);
114
115   // Undefined
116   PropertyAccessor& operator=(const PropertyAccessor& rhs);
117
118 private:
119
120   SceneGraph::AnimatableProperty<PropertyType>* mProperty; ///< The real property
121 };
122
123 } // namespace Internal
124
125 } // namespace Dali
126
127 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_ACCESSOR_H__