Merge "Revert "Move new mesh API to devel-api"" 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 format of the PropertyBuffer
93    *
94    * @pre Has not been set yet
95    *
96    * @param[in] format of the PropertyBuffer
97    */
98   void SetFormat( Dali::Property::Map& format );
99
100 public: // Default property extensions from Object
101
102   /**
103    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
104    */
105   virtual unsigned int GetDefaultPropertyCount() const;
106
107   /**
108    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
109    */
110   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
111
112   /**
113    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
114    */
115   virtual const char* GetDefaultPropertyName(Property::Index index) const;
116
117   /**
118    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
119    */
120   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
121
122   /**
123    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
124    */
125   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
126
127   /**
128    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
129    */
130   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
131
132   /**
133    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
134    */
135   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
136
137   /**
138    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
139    */
140   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
141
142   /**
143    * @copydoc Dali::Internal::Object::SetDefaultProperty()
144    */
145   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
146
147   /**
148    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
149    */
150   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
151
152   /**
153    * @copydoc Dali::Internal::Object::GetDefaultProperty()
154    */
155   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
156
157   /**
158    * @copydoc Dali::Internal::Object::GetPropertyOwner()
159    */
160   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
161
162   /**
163    * @copydoc Dali::Internal::Object::GetSceneObject()
164    */
165   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
166
167   /**
168    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
169    */
170   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
171
172   /**
173    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
174    */
175   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
176
177   /**
178    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
179    */
180   virtual int GetPropertyComponentIndex( Property::Index index ) const;
181
182 public: // Functions from Connectable
183   /**
184    * @copydoc Dali::Internal::Connectable::OnStage()
185    */
186   virtual bool OnStage() const;
187
188   /**
189    * @copydoc Dali::Internal::Connectable::Contnect()
190    */
191   virtual void Connect();
192
193   /**
194    * @copydoc Dali::Internal::Connectable::Disconnect()
195    */
196   virtual void Disconnect();
197
198 protected:
199   /**
200    * @brief Destructor
201    */
202   ~PropertyBuffer();
203
204 private: // implementation
205   /**
206    * @brief Default constructor
207    */
208   PropertyBuffer();
209
210   /**
211    * Second stage initialization
212    */
213   void Initialize();
214
215   /**
216    * Update the buffer when the format changes
217    */
218   void FormatChanged();
219
220   /**
221    * Update the buffer when the size changes
222    */
223   void SizeChanged();
224
225 private: // unimplemented methods
226   PropertyBuffer( const PropertyBuffer& );
227   PropertyBuffer& operator=( const PropertyBuffer& );
228
229 private: // data
230   SceneGraph::PropertyBuffer* mSceneObject; ///< Update side object
231
232   Property::Map mFormat;  ///< Format of the property buffer
233   const SceneGraph::PropertyBufferMetadata::Format* mBufferFormat;  ///< Metadata for the format of the property buffer
234   unsigned int mSize; ///< Number of elements in the buffer
235   Dali::Vector< char > mBuffer; // Data of the property-buffer
236
237   bool mOnStage;  ///< Flag to know if the object is on stage
238 };
239
240 /**
241  * Get the implementation type from a Property::Type
242  */
243 template<Property::Type type> struct PropertyImplementationType
244 {
245   // typedef ... Type; not defined, only support types declared bellow
246 };
247 template<> struct PropertyImplementationType< Property::BOOLEAN > { typedef bool Type; };
248 template<> struct PropertyImplementationType< Property::FLOAT > { typedef float Type; };
249 template<> struct PropertyImplementationType< Property::INTEGER > { typedef int Type; };
250 template<> struct PropertyImplementationType< Property::UNSIGNED_INTEGER > { typedef unsigned int Type; };
251 template<> struct PropertyImplementationType< Property::VECTOR2 > { typedef Vector2 Type; };
252 template<> struct PropertyImplementationType< Property::VECTOR3 > { typedef Vector3 Type; };
253 template<> struct PropertyImplementationType< Property::VECTOR4 > { typedef Vector4 Type; };
254 template<> struct PropertyImplementationType< Property::MATRIX3 > { typedef Matrix3 Type; };
255 template<> struct PropertyImplementationType< Property::MATRIX > { typedef Matrix Type; };
256 template<> struct PropertyImplementationType< Property::RECTANGLE > { typedef Rect<int> Type; };
257 template<> struct PropertyImplementationType< Property::ROTATION > { typedef Quaternion Type; };
258
259 unsigned int GetPropertyImplementationSize( Property::Type& propertyType );
260
261 } // namespace Internal
262
263 // Helpers for public-api forwarding methods
264 inline Internal::PropertyBuffer& GetImplementation(Dali::PropertyBuffer& handle)
265 {
266   DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
267
268   BaseObject& object = handle.GetBaseObject();
269
270   return static_cast<Internal::PropertyBuffer&>(object);
271 }
272
273 inline const Internal::PropertyBuffer& GetImplementation(const Dali::PropertyBuffer& handle)
274 {
275   DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
276
277   const BaseObject& object = handle.GetBaseObject();
278
279   return static_cast<const Internal::PropertyBuffer&>(object);
280 }
281
282 } // namespace Dali
283
284 #endif // DALI_INTERNAL_PROPERTY_BUFFER_H