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 <utility> // std::pair
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
41 namespace PropertyBufferMetadata
44 } // namespace PropertyBufferMetadata
46 } // namespace SceneGraph
49 typedef IntrusivePtr<PropertyBuffer> PropertyBufferPtr;
52 * PropertyBuffer is an object that contains an array of structures of values that
53 * can be accessed as properties.
55 class PropertyBuffer : public Object, public Connectable
60 * @copydoc PropertBuffer::New()
62 static PropertyBufferPtr New();
65 * @copydoc PropertBuffer::SetSize()
67 void SetSize( std::size_t size );
70 * @copydoc PropertBuffer::GetSize()
72 std::size_t GetSize() const;
75 * @copydoc PropertBuffer::SetData()
77 void SetData( const void* data );
80 * @copydoc PropertBuffer::GetPropertyIndex()
82 Dali::Property::Index GetPropertyIndex( const std::string name, std::size_t index );
85 * @brief Get the propertyBuffer scene object
87 * @return the propertyBuffer scene object
89 const SceneGraph::PropertyBuffer* GetPropertyBufferSceneObject() const;
92 * @brief Set the type of PropertyBuffer
94 * @pre Has not been set yet
96 * @param[in] type of PropertyBuffer
98 void SetType( Dali::PropertyBuffer::Type type );
101 * @brief Set the format of the PropertyBuffer
103 * @pre Has not been set yet
105 * @param[in] format of the PropertyBuffer
107 void SetFormat( Dali::Property::Map& format );
109 public: // Default property extensions from Object
112 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
114 virtual unsigned int GetDefaultPropertyCount() const;
117 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
119 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
122 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
124 virtual const char* GetDefaultPropertyName(Property::Index index) const;
127 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
129 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
132 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
134 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
137 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
139 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
142 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
144 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
147 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
149 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
152 * @copydoc Dali::Internal::Object::SetDefaultProperty()
154 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
157 * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
159 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
162 * @copydoc Dali::Internal::Object::GetDefaultProperty()
164 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
167 * @copydoc Dali::Internal::Object::GetPropertyOwner()
169 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
172 * @copydoc Dali::Internal::Object::GetSceneObject()
174 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
177 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
179 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
182 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
184 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
187 * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
189 virtual int GetPropertyComponentIndex( Property::Index index ) const;
191 public: // Functions from Connectable
193 * @copydoc Dali::Internal::Connectable::OnStage()
195 virtual bool OnStage() const;
198 * @copydoc Dali::Internal::Connectable::Contnect()
200 virtual void Connect();
203 * @copydoc Dali::Internal::Connectable::Disconnect()
205 virtual void Disconnect();
213 private: // implementation
215 * @brief Default constructor
220 * Second stage initialization
225 * Update the buffer when the format changes
227 void FormatChanged();
230 * Update the buffer when the size changes
234 private: // unimplemented methods
235 PropertyBuffer( const PropertyBuffer& );
236 PropertyBuffer& operator=( const PropertyBuffer& );
239 SceneGraph::PropertyBuffer* mSceneObject; ///< Update side object
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
247 bool mOnStage; ///< Flag to know if the object is on stage
251 * Get the implementation type from a Property::Type
253 template<Property::Type type> struct PropertyImplementationType
255 // typedef ... Type; not defined, only support types declared bellow
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; };
269 unsigned int GetPropertyImplementationSize( Property::Type& propertyType );
271 } // namespace Internal
273 // Helpers for public-api forwarding methods
274 inline Internal::PropertyBuffer& GetImplementation(Dali::PropertyBuffer& handle)
276 DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
278 BaseObject& object = handle.GetBaseObject();
280 return static_cast<Internal::PropertyBuffer&>(object);
283 inline const Internal::PropertyBuffer& GetImplementation(const Dali::PropertyBuffer& handle)
285 DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
287 const BaseObject& object = handle.GetBaseObject();
289 return static_cast<const Internal::PropertyBuffer&>(object);
294 #endif // DALI_INTERNAL_PROPERTY_BUFFER_H