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