Making DALi core internals typesafe using guaranteed types; uint8_t, uint32_t
[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) 2018 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 // INTERNAL INCLUDES
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/base-object.h>
25 #include <dali/public-api/object/property-map.h> // Dali::Property::Map
26 #include <dali/internal/event/common/event-thread-services.h>
27 #include <dali/internal/render/renderers/render-property-buffer.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33
34 class PropertyBuffer;
35 typedef IntrusivePtr<PropertyBuffer> PropertyBufferPtr;
36
37 /**
38  * PropertyBuffer is an object that contains an array of structures of values that
39  * can be accessed as properties.
40  */
41 class PropertyBuffer : public BaseObject
42 {
43 public:
44
45   /**
46    * @copydoc PropertBuffer::New()
47    */
48   static PropertyBufferPtr New( Dali::Property::Map& format );
49
50   /**
51    * @copydoc PropertBuffer::SetData()
52    */
53   void SetData( const void* data, uint32_t size );
54
55   /**
56    * @copydoc PropertBuffer::GetSize()
57    */
58   uint32_t GetSize() const;
59
60 public: // Default property extensions from Object
61
62   /**
63    * @brief Get the render thread side of the PropertyBuffer
64    *
65    * @return The render thread side of this PropertyBuffer
66    */
67   const Render::PropertyBuffer* GetRenderObject() const;
68
69 protected:
70   /**
71    * @brief Destructor
72    */
73   ~PropertyBuffer();
74
75 private: // implementation
76   /**
77    * @brief Default constructor
78    */
79   PropertyBuffer();
80
81   /**
82    * Second stage initialization
83    */
84   void Initialize( Dali::Property::Map& format );
85
86 private: // unimplemented methods
87   PropertyBuffer( const PropertyBuffer& );
88   PropertyBuffer& operator=( const PropertyBuffer& );
89
90 private: // data
91   EventThreadServices& mEventThreadServices;    ///<Used to send messages to the render thread via update thread
92   Render::PropertyBuffer* mRenderObject;        ///<Render side object
93   uint32_t mBufferFormatSize;
94   uint32_t mSize; ///< Number of elements in the buffer
95 };
96
97 /**
98  * Get the implementation type from a Property::Type
99  */
100 template<Property::Type type> struct PropertyImplementationType
101 {
102   // typedef ... Type; not defined, only support types declared bellow
103 };
104 template<> struct PropertyImplementationType< Property::BOOLEAN > { typedef bool Type; };
105 template<> struct PropertyImplementationType< Property::FLOAT > { typedef float Type; };
106 template<> struct PropertyImplementationType< Property::INTEGER > { typedef int Type; };
107 template<> struct PropertyImplementationType< Property::VECTOR2 > { typedef Vector2 Type; };
108 template<> struct PropertyImplementationType< Property::VECTOR3 > { typedef Vector3 Type; };
109 template<> struct PropertyImplementationType< Property::VECTOR4 > { typedef Vector4 Type; };
110 template<> struct PropertyImplementationType< Property::MATRIX3 > { typedef Matrix3 Type; };
111 template<> struct PropertyImplementationType< Property::MATRIX > { typedef Matrix Type; };
112 template<> struct PropertyImplementationType< Property::RECTANGLE > { typedef Rect<int> Type; };
113 template<> struct PropertyImplementationType< Property::ROTATION > { typedef Quaternion Type; };
114
115 uint32_t GetPropertyImplementationSize( Property::Type& propertyType );
116
117 } // namespace Internal
118
119 // Helpers for public-api forwarding methods
120 inline Internal::PropertyBuffer& GetImplementation(Dali::PropertyBuffer& handle)
121 {
122   DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
123
124   BaseObject& object = handle.GetBaseObject();
125
126   return static_cast<Internal::PropertyBuffer&>(object);
127 }
128
129 inline const Internal::PropertyBuffer& GetImplementation(const Dali::PropertyBuffer& handle)
130 {
131   DALI_ASSERT_ALWAYS(handle && "PropertyBuffer handle is empty");
132
133   const BaseObject& object = handle.GetBaseObject();
134
135   return static_cast<const Internal::PropertyBuffer&>(object);
136 }
137
138 } // namespace Dali
139
140 #endif // DALI_INTERNAL_PROPERTY_BUFFER_H