[dali_1.1.35] Merge branch 'devel/master'
[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) 2016 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 value type field should be queried, before accessing the scene-graph property:
43  *
44  * @code
45  * void Example(PropertyEntry entry)
46  * {
47  *   if (entry.value.GetType() == 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   : value(),
64     componentIndex(Property::INVALID_COMPONENT_INDEX),
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   : value(), // value is held by newProperty
75     componentIndex(Property::INVALID_COMPONENT_INDEX),
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   : value(newValue),
87     componentIndex(Property::INVALID_COMPONENT_INDEX),
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   /*
122    * @return type of the held property value
123    */
124   inline Property::Type GetType() const { return value.GetType(); }
125
126   Property::Value value;  ///< The property value for a non animatable and custom property
127   int componentIndex;     ///< The index of the property component
128
129 protected:
130
131   // Not implemented
132   PropertyMetadata( const PropertyMetadata& );
133   PropertyMetadata& operator=( const PropertyMetadata& );
134
135   const SceneGraph::PropertyBase* mProperty; ///< A pointer to a scene-graph property; should not be modified from actor-thread.
136 };
137
138
139 /**
140  * An entry in an animatable property metadata lookup.
141  * The value type field should be queried, before accessing the animatable property:
142  */
143 class AnimatablePropertyMetadata : public PropertyMetadata
144 {
145 public:
146
147   /**
148    * Constructor for metadata of animatable property
149    * @param [in] newIndex The index of the animatable property.
150    * @param [in] newType The type ID of the animatable property.
151    * @param [in] newProperty A pointer to the scene-graph owned property.
152    */
153   AnimatablePropertyMetadata( Property::Index newIndex,
154                         int newComponentIndex,
155                         Property::Type newType,
156                         const SceneGraph::PropertyBase* newProperty )
157   : index(newIndex)
158   {
159     componentIndex = newComponentIndex;
160     value = Property::Value(newType);
161     mProperty = newProperty;
162     DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property");
163   }
164
165   /**
166    * Constructor for metadata of animatable property
167    * @param [in] newIndex The index of the animatable property.
168    * @param [in] newValue The value of the scene-graph owned property.
169    */
170   AnimatablePropertyMetadata( Property::Index newIndex,
171                         int newComponentIndex,
172                         Property::Value newValue )
173   : index(newIndex)
174   {
175     componentIndex = newComponentIndex;
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     childPropertyIndex(Property::INVALID_INDEX),
212     mAccessMode(Property::ANIMATABLE)
213   {
214     value = Property::Value(newType);
215     mProperty = newProperty;
216     DALI_ASSERT_DEBUG(mProperty && "Uninitialized scenegraph property");
217   }
218
219   /**
220    * Constructor for metadata of event side only properties
221    * @param [in] newName The name of the custom property.
222    * @param [in] newValue The value of the custom property.
223    * @param [in] accessMode The access mode of the custom property (writable, animatable etc).
224    */
225   CustomPropertyMetadata( const std::string& newName,
226                           Property::Value newValue,
227                           Property::AccessMode accessMode )
228   : name(newName),
229     childPropertyIndex(Property::INVALID_INDEX),
230     mAccessMode(accessMode)
231   {
232     value = newValue;
233     DALI_ASSERT_DEBUG(accessMode != Property::ANIMATABLE && "Animatable must have scenegraph property");
234   }
235
236   /**
237    * @return true if the property can be written to
238    */
239   virtual bool IsWritable(void) const
240   {
241     return (mAccessMode == Property::ANIMATABLE) || (mAccessMode == Property::READ_WRITE);
242   }
243
244   std::string name;       ///< The name of the property
245   Property::Index childPropertyIndex; ///< The index as a child property
246
247 private:
248
249   // Not implemented
250   CustomPropertyMetadata();
251   CustomPropertyMetadata( const CustomPropertyMetadata& );
252   CustomPropertyMetadata& operator=( const CustomPropertyMetadata& );
253
254 private:
255   Property::AccessMode mAccessMode; ///< The mode of the property
256 };
257
258 } // namespace Internal
259
260 } // namespace Dali
261
262 #endif // __DALI_INTERNAL_PROPERTY_METADATA_H__