1 #ifndef DALI_INTERNAL_PROPERTY_BUFFER_H
2 #define DALI_INTERNAL_PROPERTY_BUFFER_H
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
38 namespace PropertyBufferMetadata
41 } // namespace PropertyBufferMetadata
43 } // namespace SceneGraph
46 typedef IntrusivePtr<PropertyBuffer> PropertyBufferPtr;
49 * PropertyBuffer is an object that contains an array of structures of values that
50 * can be accessed as properties.
52 class PropertyBuffer : public Object, public Connectable
57 * @copydoc PropertBuffer::New()
59 static PropertyBufferPtr New();
62 * @copydoc PropertBuffer::SetSize()
64 void SetSize( std::size_t size );
67 * @copydoc PropertBuffer::GetSize()
69 std::size_t GetSize() const;
72 * @copydoc PropertBuffer::SetData()
74 void SetData( const void* data );
77 * @copydoc PropertBuffer::GetPropertyIndex()
79 Dali::Property::Index GetPropertyIndex( const std::string name, std::size_t index );
82 * @brief Get the propertyBuffer scene object
84 * @return the propertyBuffer scene object
86 const SceneGraph::PropertyBuffer* GetPropertyBufferSceneObject() const;
89 * @brief Set the type of PropertyBuffer
91 * @pre Has not been set yet
93 * @param[in] type of PropertyBuffer
95 void SetType( Dali::PropertyBuffer::Type type );
98 * @brief Set the format of the PropertyBuffer
100 * @pre Has not been set yet
102 * @param[in] format of the PropertyBuffer
104 void SetFormat( Dali::Property::Map& format );
106 public: // Default property extensions from Object
109 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
111 virtual unsigned int GetDefaultPropertyCount() const;
114 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
116 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
119 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
121 virtual const char* GetDefaultPropertyName(Property::Index index) const;
124 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
126 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
129 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
131 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
134 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
136 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
139 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
141 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
144 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
146 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
149 * @copydoc Dali::Internal::Object::SetDefaultProperty()
151 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
154 * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
156 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
159 * @copydoc Dali::Internal::Object::GetDefaultProperty()
161 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
164 * @copydoc Dali::Internal::Object::GetPropertyOwner()
166 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
169 * @copydoc Dali::Internal::Object::GetSceneObject()
171 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
174 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
176 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
179 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
181 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
184 * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
186 virtual int GetPropertyComponentIndex( Property::Index index ) const;
188 public: // Functions from Connectable
190 * @copydoc Dali::Internal::Connectable::OnStage()
192 virtual bool OnStage() const;
195 * @copydoc Dali::Internal::Connectable::Contnect()
197 virtual void Connect();
200 * @copydoc Dali::Internal::Connectable::Disconnect()
202 virtual void Disconnect();
210 private: // implementation
212 * @brief Default constructor
217 * Second stage initialization
222 * Update the buffer when the format changes
224 void FormatChanged();
227 * Update the buffer when the size changes
231 private: // unimplemented methods
232 PropertyBuffer( const PropertyBuffer& );
233 PropertyBuffer& operator=( const PropertyBuffer& );
236 SceneGraph::PropertyBuffer* mSceneObject; ///< Update side object
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
244 bool mOnStage; ///< Flag to know if the object is on stage
248 * Get the implementation type from a Property::Type
250 template<Property::Type type> struct PropertyImplementationType
252 // typedef ... Type; not defined, only support types declared bellow
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; };
267 * Get the size of the implementation of a Property::Type
269 * @param[in] propertyType Property::Type used to check the size
271 * @return Size given by sizeof for the implementation this propertyType
273 unsigned int GetPropertyImplementationSize( Property::Type& propertyType );
275 } // namespace Internal
277 // Helpers for public-api forwarding methods
278 inline Internal::PropertyBuffer& GetImplementation(Dali::PropertyBuffer& handle)
280 DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
282 BaseObject& object = handle.GetBaseObject();
284 return static_cast<Internal::PropertyBuffer&>(object);
287 inline const Internal::PropertyBuffer& GetImplementation(const Dali::PropertyBuffer& handle)
289 DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
291 const BaseObject& object = handle.GetBaseObject();
293 return static_cast<const Internal::PropertyBuffer&>(object);
298 #endif // DALI_INTERNAL_PROPERTY_BUFFER_H