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-map.h> // Dali::Property::Map
28 #include <dali/devel-api/object/property-buffer.h> // Dali::PropertyBuffer
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 format of the PropertyBuffer
94 * @pre Has not been set yet
96 * @param[in] format of the PropertyBuffer
98 void SetFormat( Dali::Property::Map& format );
100 public: // Default property extensions from Object
103 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
105 virtual unsigned int GetDefaultPropertyCount() const;
108 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
110 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
113 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
115 virtual const char* GetDefaultPropertyName(Property::Index index) const;
118 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
120 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
123 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
125 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
128 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
130 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
133 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
135 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
138 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
140 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
143 * @copydoc Dali::Internal::Object::SetDefaultProperty()
145 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
148 * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
150 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
153 * @copydoc Dali::Internal::Object::GetDefaultProperty()
155 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
158 * @copydoc Dali::Internal::Object::GetPropertyOwner()
160 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
163 * @copydoc Dali::Internal::Object::GetSceneObject()
165 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
168 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
170 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
173 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
175 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
178 * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
180 virtual int GetPropertyComponentIndex( Property::Index index ) const;
182 public: // Functions from Connectable
184 * @copydoc Dali::Internal::Connectable::OnStage()
186 virtual bool OnStage() const;
189 * @copydoc Dali::Internal::Connectable::Contnect()
191 virtual void Connect();
194 * @copydoc Dali::Internal::Connectable::Disconnect()
196 virtual void Disconnect();
204 private: // implementation
206 * @brief Default constructor
211 * Second stage initialization
216 * Update the buffer when the format changes
218 void FormatChanged();
221 * Update the buffer when the size changes
225 private: // unimplemented methods
226 PropertyBuffer( const PropertyBuffer& );
227 PropertyBuffer& operator=( const PropertyBuffer& );
230 SceneGraph::PropertyBuffer* mSceneObject; ///< Update side object
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
237 bool mOnStage; ///< Flag to know if the object is on stage
241 * Get the implementation type from a Property::Type
243 template<Property::Type type> struct PropertyImplementationType
245 // typedef ... Type; not defined, only support types declared bellow
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::VECTOR2 > { typedef Vector2 Type; };
251 template<> struct PropertyImplementationType< Property::VECTOR3 > { typedef Vector3 Type; };
252 template<> struct PropertyImplementationType< Property::VECTOR4 > { typedef Vector4 Type; };
253 template<> struct PropertyImplementationType< Property::MATRIX3 > { typedef Matrix3 Type; };
254 template<> struct PropertyImplementationType< Property::MATRIX > { typedef Matrix Type; };
255 template<> struct PropertyImplementationType< Property::RECTANGLE > { typedef Rect<int> Type; };
256 template<> struct PropertyImplementationType< Property::ROTATION > { typedef Quaternion Type; };
258 unsigned int GetPropertyImplementationSize( Property::Type& propertyType );
260 } // namespace Internal
262 // Helpers for public-api forwarding methods
263 inline Internal::PropertyBuffer& GetImplementation(Dali::PropertyBuffer& handle)
265 DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
267 BaseObject& object = handle.GetBaseObject();
269 return static_cast<Internal::PropertyBuffer&>(object);
272 inline const Internal::PropertyBuffer& GetImplementation(const Dali::PropertyBuffer& handle)
274 DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
276 const BaseObject& object = handle.GetBaseObject();
278 return static_cast<const Internal::PropertyBuffer&>(object);
283 #endif // DALI_INTERNAL_PROPERTY_BUFFER_H