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