Merge remote-tracking branch 'origin/tizen' into devel/new_mesh
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-metadata.h
1 #ifndef __DALI_INTERNAL_PROPERTY_METADATA_H__
2 #define __DALI_INTERNAL_PROPERTY_METADATA_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 // EXTERNAL INCLUDES
22 #include <algorithm>
23 #include <utility>
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/common/constants.h>
27 #include <dali/public-api/object/property.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace SceneGraph
36 {
37 class PropertyBase;
38 }
39
40 /**
41  * An entry in a property metadata lookup.
42  * The type field should be queried, before accessing the scene-graph property:
43  *
44  * @code
45  * void Example(PropertyEntry entry)
46  * {
47  *   if (entry.type == Property::VECTOR3)
48  *   {
49  *     SceneGraph::AnimatableProperty<Vector3>* property = dynamic_cast< SceneGraph::AnimatableProperty<Vector3>* >( entry.property );
50  *     ...
51  *   }
52  * @endcode
53  *
54  */
55 class PropertyMetadata
56 {
57 public:
58
59   /**
60    * Constructor for an uninitalized property metadata
61    */
62   PropertyMetadata()
63   : type(Property::NONE),
64     value(),
65     mProperty(NULL)
66   {
67   }
68
69   /**
70    * Constructor for property metadata
71    * @param [in] newProperty A pointer to the property metadata.
72    */
73   PropertyMetadata(const SceneGraph::PropertyBase* newProperty)
74   : type(Property::NONE),
75     value(), // value is held by newProperty
76     mProperty(newProperty)
77   {
78     DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
79   }
80
81   /**
82    * Constructor for property metadata
83    * @param [in] newValue The value of the scene-graph owned property.
84    */
85   PropertyMetadata(Property::Value newValue)
86   : type(newValue.GetType()),
87     value(newValue),
88     mProperty(NULL)
89   {
90   }
91
92   /**
93    * Destructor for property metadata
94    */
95   virtual ~PropertyMetadata()
96   {
97   }
98
99   /**
100    * @return true if the property is animatable (i.e. if its a scene graph property)
101    */
102   bool IsAnimatable(void) const
103   {
104     return NULL != mProperty;
105   }
106
107   /**
108    * @return true if the property can be written to
109    */
110   virtual bool IsWritable(void) const = 0;
111
112   /**
113    * @return the scene graph property
114    */
115   const SceneGraph::PropertyBase* GetSceneGraphProperty() const
116   {
117     DALI_ASSERT_DEBUG(mProperty && "Accessing uninitialized SceneGraph property") ;
118     return mProperty;
119   }
120
121   Property::Type type;    ///< The type of the property
122   Property::Value value;  ///< The property value for a non animatable and custom property
123
124 protected:
125
126   // Not implemented
127   PropertyMetadata( const PropertyMetadata& );
128   PropertyMetadata& operator=( const PropertyMetadata& );
129
130   const SceneGraph::PropertyBase* mProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread.
131 };
132
133
134 /**
135  * An entry in an animatable property metadata lookup.
136  * The type field should be queried, before accessing the animatable property:
137  */
138 class AnimatablePropertyMetadata : public PropertyMetadata
139 {
140 public:
141
142   /**
143    * Constructor for metadata of animatable property
144    * @param [in] newIndex The index of the animatable property.
145    * @param [in] newType The type ID of the animatable property.
146    * @param [in] newProperty A pointer to the scene-graph owned property.
147    */
148   AnimatablePropertyMetadata( Property::Index newIndex,
149                         Property::Type newType,
150                         const SceneGraph::PropertyBase* newProperty )
151   : index(newIndex)
152   {
153     type = newType;
154     mProperty = newProperty;
155     DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
156   }
157
158   /**
159    * Constructor for metadata of animatable property
160    * @param [in] newIndex The index of the animatable property.
161    * @param [in] newValue The value of the scene-graph owned property.
162    */
163   AnimatablePropertyMetadata( Property::Index newIndex,
164                         Property::Value newValue )
165   : index(newIndex)
166   {
167     type = newValue.GetType();
168     value = newValue;
169   }
170
171   /**
172    * @return true if the property can be written to
173    */
174   virtual bool IsWritable(void) const
175   {
176     return true ;
177   }
178
179   Property::Index index;       ///< The index of the property
180
181 private:
182
183   // Not implemented
184   AnimatablePropertyMetadata();
185   AnimatablePropertyMetadata( const AnimatablePropertyMetadata& );
186   AnimatablePropertyMetadata& operator=( const AnimatablePropertyMetadata& );
187 };
188
189 class CustomPropertyMetadata : public PropertyMetadata
190 {
191 public:
192
193   /**
194    * Constructor for metadata of scene graph based properties
195    * @param [in] newName The name of the custom property.
196    * @param [in] newType The type ID of the custom property.
197    * @param [in] newProperty A pointer to the scene-graph owned property.
198    */
199   CustomPropertyMetadata( const std::string& newName,
200                           Property::Type newType,
201                           const SceneGraph::PropertyBase* newProperty)
202   : name(newName),
203     mAccessMode(Property::ANIMATABLE)
204   {
205     type = newType;
206     mProperty = newProperty;
207     DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
208   }
209
210   /**
211    * Constructor for metadata of event side only properties
212    * @param [in] newName The name of the custom property.
213    * @param [in] newValue The value of the custom property.
214    * @param [in] accessMode The access mode of the custom property (writable, animatable etc).
215    */
216   CustomPropertyMetadata( const std::string& newName,
217                           Property::Value newValue,
218                           Property::AccessMode accessMode )
219   : name(newName),
220     mAccessMode(accessMode)
221   {
222     type = newValue.GetType();
223     value = newValue;
224     DALI_ASSERT_DEBUG(accessMode != Property::ANIMATABLE && "Animatable must have scenegraph property") ;
225   }
226
227   /**
228    * @return true if the property can be written to
229    */
230   virtual bool IsWritable(void) const
231   {
232     return (mAccessMode == Property::ANIMATABLE) || (mAccessMode == Property::READ_WRITE) ;
233   }
234
235   std::string name;       ///< The name of the property
236
237 private:
238
239   // Not implemented
240   CustomPropertyMetadata();
241   CustomPropertyMetadata( const CustomPropertyMetadata& );
242   CustomPropertyMetadata& operator=( const CustomPropertyMetadata& );
243
244 private:
245   Property::AccessMode mAccessMode; ///< The mode of the property
246 };
247
248 } // namespace Internal
249
250 } // namespace Dali
251
252 #endif // __DALI_INTERNAL_PROPERTY_METADATA_H__