Fixes and cleanup.
[platform/core/uifw/dali-core.git] / dali / internal / event / common / property-buffer-impl.h
1 #ifndef DALI_INTERNAL_PROPERTY_BUFFER_H
2 #define DALI_INTERNAL_PROPERTY_BUFFER_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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/public-api/object/property-buffer.h> // Dali::PropertyBuffer
25 #include <dali/public-api/object/property-map.h> // Dali::Property::Map
26 #include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
27 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
28 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 namespace SceneGraph
35 {
36 class PropertyBuffer;
37
38 namespace PropertyBufferMetadata
39 {
40 struct Format;
41 } // namespace PropertyBufferMetadata
42
43 } // namespace SceneGraph
44
45 class PropertyBuffer;
46 typedef IntrusivePtr<PropertyBuffer> PropertyBufferPtr;
47
48 /**
49  * PropertyBuffer is an object that contains an array of structures of values that
50  * can be accessed as properties.
51  */
52 class PropertyBuffer : public Object, public Connectable
53 {
54 public:
55
56   /**
57    * @copydoc PropertBuffer::New()
58    */
59   static PropertyBufferPtr New();
60
61   /**
62    * @copydoc PropertBuffer::SetSize()
63    */
64   void SetSize( std::size_t size );
65
66   /**
67    * @copydoc PropertBuffer::GetSize()
68    */
69   std::size_t GetSize() const;
70
71   /**
72    * @copydoc PropertBuffer::SetData()
73    */
74   void SetData( const void* data );
75
76   /**
77    * @copydoc PropertBuffer::GetPropertyIndex()
78    */
79   Dali::Property::Index GetPropertyIndex( const std::string name, std::size_t index );
80
81   /**
82    * @brief Get the propertyBuffer scene object
83    *
84    * @return the propertyBuffer scene object
85    */
86   const SceneGraph::PropertyBuffer* GetPropertyBufferSceneObject() const;
87
88   /**
89    * @brief Set the type of PropertyBuffer
90    *
91    * @pre Has not been set yet
92    *
93    * @param[in] type of PropertyBuffer
94    */
95   void SetType( Dali::PropertyBuffer::Type type );
96
97   /**
98    * @brief Set the format of the PropertyBuffer
99    *
100    * @pre Has not been set yet
101    *
102    * @param[in] format of the PropertyBuffer
103    */
104   void SetFormat( Dali::Property::Map& format );
105
106 public: // Default property extensions from Object
107
108   /**
109    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
110    */
111   virtual unsigned int GetDefaultPropertyCount() const;
112
113   /**
114    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
115    */
116   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
117
118   /**
119    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
120    */
121   virtual const char* GetDefaultPropertyName(Property::Index index) const;
122
123   /**
124    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
125    */
126   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
127
128   /**
129    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
130    */
131   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
132
133   /**
134    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
135    */
136   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
137
138   /**
139    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
140    */
141   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
142
143   /**
144    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
145    */
146   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
147
148   /**
149    * @copydoc Dali::Internal::Object::SetDefaultProperty()
150    */
151   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
152
153   /**
154    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
155    */
156   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
157
158   /**
159    * @copydoc Dali::Internal::Object::GetDefaultProperty()
160    */
161   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
162
163   /**
164    * @copydoc Dali::Internal::Object::GetPropertyOwner()
165    */
166   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
167
168   /**
169    * @copydoc Dali::Internal::Object::GetSceneObject()
170    */
171   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
172
173   /**
174    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
175    */
176   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
177
178   /**
179    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
180    */
181   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
182
183   /**
184    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
185    */
186   virtual int GetPropertyComponentIndex( Property::Index index ) const;
187
188 public: // Functions from Connectable
189   /**
190    * @copydoc Dali::Internal::Connectable::OnStage()
191    */
192   virtual bool OnStage() const;
193
194   /**
195    * @copydoc Dali::Internal::Connectable::Contnect()
196    */
197   virtual void Connect();
198
199   /**
200    * @copydoc Dali::Internal::Connectable::Disconnect()
201    */
202   virtual void Disconnect();
203
204 protected:
205   /**
206    * @brief Destructor
207    */
208   ~PropertyBuffer();
209
210 private: // implementation
211   /**
212    * @brief Default constructor
213    */
214   PropertyBuffer();
215
216   /**
217    * Second stage initialization
218    */
219   void Initialize();
220
221   /**
222    * Update the buffer when the format changes
223    */
224   void FormatChanged();
225
226   /**
227    * Update the buffer when the size changes
228    */
229   void SizeChanged();
230
231 private: // unimplemented methods
232   PropertyBuffer( const PropertyBuffer& );
233   PropertyBuffer& operator=( const PropertyBuffer& );
234
235 private: // data
236   SceneGraph::PropertyBuffer* mSceneObject; ///< Update side object
237
238   Property::Map mFormat;  ///< Format of the property buffer
239   const SceneGraph::PropertyBufferMetadata::Format* mBufferFormat;  ///< Metadata for the format of the property buffer
240   unsigned int mSize; ///< Number of elements in the buffer
241   Dali::PropertyBuffer::Type mType; ///< Type of propertyBuffer
242   Dali::Vector< char > mBuffer; // Data of the property-buffer
243
244   bool mOnStage;  ///< Flag to know if the object is on stage
245 };
246
247 /**
248  * Get the implementation type from a Property::Type
249  */
250 template<Property::Type type> struct PropertyImplementationType
251 {
252   // typedef ... Type; not defined, only support types declared bellow
253 };
254 template<> struct PropertyImplementationType< Property::BOOLEAN > { typedef bool Type; };
255 template<> struct PropertyImplementationType< Property::FLOAT > { typedef float Type; };
256 template<> struct PropertyImplementationType< Property::INTEGER > { typedef int Type; };
257 template<> struct PropertyImplementationType< Property::UNSIGNED_INTEGER > { typedef unsigned int Type; };
258 template<> struct PropertyImplementationType< Property::VECTOR2 > { typedef Vector2 Type; };
259 template<> struct PropertyImplementationType< Property::VECTOR3 > { typedef Vector3 Type; };
260 template<> struct PropertyImplementationType< Property::VECTOR4 > { typedef Vector4 Type; };
261 template<> struct PropertyImplementationType< Property::MATRIX3 > { typedef Matrix3 Type; };
262 template<> struct PropertyImplementationType< Property::MATRIX > { typedef Matrix Type; };
263 template<> struct PropertyImplementationType< Property::RECTANGLE > { typedef Rect<int> Type; };
264 template<> struct PropertyImplementationType< Property::ROTATION > { typedef Quaternion Type; };
265
266 /**
267  * Get the size of the implementation of a Property::Type
268  *
269  * @param[in] propertyType Property::Type used to check the size
270  *
271  * @return Size given by sizeof for the implementation this propertyType
272  */
273 unsigned int GetPropertyImplementationSize( Property::Type& propertyType );
274
275 } // namespace Internal
276
277 // Helpers for public-api forwarding methods
278 inline Internal::PropertyBuffer& GetImplementation(Dali::PropertyBuffer& handle)
279 {
280   DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
281
282   BaseObject& object = handle.GetBaseObject();
283
284   return static_cast<Internal::PropertyBuffer&>(object);
285 }
286
287 inline const Internal::PropertyBuffer& GetImplementation(const Dali::PropertyBuffer& handle)
288 {
289   DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
290
291   const BaseObject& object = handle.GetBaseObject();
292
293   return static_cast<const Internal::PropertyBuffer&>(object);
294 }
295
296 } // namespace Dali
297
298 #endif // DALI_INTERNAL_PROPERTY_BUFFER_H