Merge branch 'devel/master' 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) 2015 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     componentIndex(Property::INVALID_COMPONENT_INDEX),
66     mProperty(NULL)
67   {
68   }
69
70   /**
71    * Constructor for property metadata
72    * @param [in] newProperty A pointer to the property metadata.
73    */
74   PropertyMetadata(const SceneGraph::PropertyBase* newProperty)
75   : type(Property::NONE),
76     value(), // value is held by newProperty
77     componentIndex(Property::INVALID_COMPONENT_INDEX),
78     mProperty(newProperty)
79   {
80     DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
81   }
82
83   /**
84    * Constructor for property metadata
85    * @param [in] newValue The value of the scene-graph owned property.
86    */
87   PropertyMetadata(Property::Value newValue)
88   : type(newValue.GetType()),
89     value(newValue),
90     componentIndex(Property::INVALID_COMPONENT_INDEX),
91     mProperty(NULL)
92   {
93   }
94
95   /**
96    * Destructor for property metadata
97    */
98   virtual ~PropertyMetadata()
99   {
100   }
101
102   /**
103    * @return true if the property is animatable (i.e. if its a scene graph property)
104    */
105   bool IsAnimatable(void) const
106   {
107     return NULL != mProperty;
108   }
109
110   /**
111    * @return true if the property can be written to
112    */
113   virtual bool IsWritable(void) const = 0;
114
115   /**
116    * @return the scene graph property
117    */
118   const SceneGraph::PropertyBase* GetSceneGraphProperty() const
119   {
120     DALI_ASSERT_DEBUG(mProperty && "Accessing uninitialized SceneGraph property") ;
121     return mProperty;
122   }
123
124   Property::Type type;    ///< The type of the property
125   Property::Value value;  ///< The property value for a non animatable and custom property
126   int componentIndex;     ///< The index of the property component
127
128 protected:
129
130   // Not implemented
131   PropertyMetadata( const PropertyMetadata& );
132   PropertyMetadata& operator=( const PropertyMetadata& );
133
134   const SceneGraph::PropertyBase* mProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread.
135 };
136
137
138 /**
139  * An entry in an animatable property metadata lookup.
140  * The type field should be queried, before accessing the animatable property:
141  */
142 class AnimatablePropertyMetadata : public PropertyMetadata
143 {
144 public:
145
146   /**
147    * Constructor for metadata of animatable property
148    * @param [in] newIndex The index of the animatable property.
149    * @param [in] newType The type ID of the animatable property.
150    * @param [in] newProperty A pointer to the scene-graph owned property.
151    */
152   AnimatablePropertyMetadata( Property::Index newIndex,
153                         int newComponentIndex,
154                         Property::Type newType,
155                         const SceneGraph::PropertyBase* newProperty )
156   : index(newIndex)
157   {
158     componentIndex = newComponentIndex;
159     type = newType;
160     mProperty = newProperty;
161     DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
162   }
163
164   /**
165    * Constructor for metadata of animatable property
166    * @param [in] newIndex The index of the animatable property.
167    * @param [in] newValue The value of the scene-graph owned property.
168    */
169   AnimatablePropertyMetadata( Property::Index newIndex,
170                         int newComponentIndex,
171                         Property::Value newValue )
172   : index(newIndex)
173   {
174     componentIndex = newComponentIndex;
175     type = newValue.GetType();
176     value = newValue;
177   }
178
179   /**
180    * @return true if the property can be written to
181    */
182   virtual bool IsWritable(void) const
183   {
184     return true ;
185   }
186
187   Property::Index index;       ///< The index of the property
188
189 private:
190
191   // Not implemented
192   AnimatablePropertyMetadata();
193   AnimatablePropertyMetadata( const AnimatablePropertyMetadata& );
194   AnimatablePropertyMetadata& operator=( const AnimatablePropertyMetadata& );
195 };
196
197 class CustomPropertyMetadata : public PropertyMetadata
198 {
199 public:
200
201   /**
202    * Constructor for metadata of scene graph based properties
203    * @param [in] newName The name of the custom property.
204    * @param [in] newType The type ID of the custom property.
205    * @param [in] newProperty A pointer to the scene-graph owned property.
206    */
207   CustomPropertyMetadata( const std::string& newName,
208                           Property::Type newType,
209                           const SceneGraph::PropertyBase* newProperty)
210   : name(newName),
211     mAccessMode(Property::ANIMATABLE)
212   {
213     type = newType;
214     mProperty = newProperty;
215     DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property") ;
216   }
217
218   /**
219    * Constructor for metadata of event side only properties
220    * @param [in] newName The name of the custom property.
221    * @param [in] newValue The value of the custom property.
222    * @param [in] accessMode The access mode of the custom property (writable, animatable etc).
223    */
224   CustomPropertyMetadata( const std::string& newName,
225                           Property::Value newValue,
226                           Property::AccessMode accessMode )
227   : name(newName),
228     mAccessMode(accessMode)
229   {
230     type = newValue.GetType();
231     value = newValue;
232     DALI_ASSERT_DEBUG(accessMode != Property::ANIMATABLE && "Animatable must have scenegraph property") ;
233   }
234
235   /**
236    * @return true if the property can be written to
237    */
238   virtual bool IsWritable(void) const
239   {
240     return (mAccessMode == Property::ANIMATABLE) || (mAccessMode == Property::READ_WRITE) ;
241   }
242
243   std::string name;       ///< The name of the property
244
245 private:
246
247   // Not implemented
248   CustomPropertyMetadata();
249   CustomPropertyMetadata( const CustomPropertyMetadata& );
250   CustomPropertyMetadata& operator=( const CustomPropertyMetadata& );
251
252 private:
253   Property::AccessMode mAccessMode; ///< The mode of the property
254 };
255
256 } // namespace Internal
257
258 } // namespace Dali
259
260 #endif // __DALI_INTERNAL_PROPERTY_METADATA_H__