Making DALi public API typesafe using guaranteed types; uint8_t, uint32_t
[platform/core/uifw/dali-core.git] / dali / public-api / object / property.h
1 #ifndef __DALI_PROPERTY_H__
2 #define __DALI_PROPERTY_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 // EXTERNAL INCLUDES
22 #include <string>
23 #include <utility>
24 #include <cstdint> // int32_t
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/common/dali-vector.h>
29
30 namespace Dali
31 {
32 /**
33  * @addtogroup dali_core_object
34  * @{
35  */
36
37 class Handle;
38
39 /**
40  * @brief An object + property pair.
41  * @SINCE_1_0.0
42  */
43 struct DALI_CORE_API Property
44 {
45   /**
46    * @brief A valid property index is zero or greater.
47    * @SINCE_1_0.0
48    */
49   typedef int32_t Index;
50
51   static const int32_t INVALID_INDEX; ///< -1 is not a valid property index
52   static const int32_t INVALID_KEY;   ///< -1 is not a valid property key
53   static const int32_t INVALID_COMPONENT_INDEX; ///< -1 is not a valid property index
54
55   typedef Dali::Vector< Index > IndexContainer; ///< A vector of property indices @SINCE_1_0.0
56
57   /**
58    * @brief A value-type representing a property value.
59    */
60   class Value;
61
62   /**
63    * @brief A Key used by Map
64    */
65   struct Key;
66
67   /**
68    * @brief A Map of property values.
69    */
70   class Map;
71
72   /**
73    * @brief An Array of property values.
74    */
75   class Array;
76
77   /**
78    * @brief Enumeration for the property types supported.
79    * @SINCE_1_0.0
80    */
81   enum Type
82   {
83     NONE,            ///< No type @SINCE_1_0.0
84
85     BOOLEAN,         ///< A boolean type @SINCE_1_0.0
86     FLOAT,           ///< A float type @SINCE_1_0.0
87     INTEGER,         ///< An integer type @SINCE_1_0.0
88     VECTOR2,         ///< a vector array of size=2 with float precision @SINCE_1_0.0
89     VECTOR3,         ///< a vector array of size=3 with float precision @SINCE_1_0.0
90     VECTOR4,         ///< a vector array of size=4 with float precision @SINCE_1_0.0
91     MATRIX3,         ///< a 3x3 matrix @SINCE_1_0.0
92     MATRIX,          ///< a 4x4 matrix @SINCE_1_0.0
93     RECTANGLE,       ///< an integer array of size=4 @SINCE_1_0.0
94     ROTATION,        ///< either a quaternion or an axis angle rotation @SINCE_1_0.0
95     STRING,          ///< A string type @SINCE_1_0.0
96     ARRAY,           ///< an array of Property::Value @SINCE_1_0.0
97     MAP,             ///< a string key to Property:value mapping @SINCE_1_0.0
98     EXTENTS          ///< a collection of 4 x uint16_t @SINCE_1_2.62
99   };
100
101   /**
102    * @brief Enumeration for the access mode for custom properties.
103    * @SINCE_1_0.0
104    */
105   enum AccessMode
106   {
107     READ_ONLY,          ///< if the property is read-only @SINCE_1_0.0
108     READ_WRITE,         ///< If the property is read/writeable @SINCE_1_0.0
109     ANIMATABLE,         ///< If the property can be animated or constrained @SINCE_1_0.0
110     ACCESS_MODE_COUNT   ///< The number of access modes @SINCE_1_0.0
111   };
112
113
114   /**
115    * @brief Creates a Property instance.
116    *
117    * @SINCE_1_0.0
118    * @param[in] object A valid handle to the target object
119    * @param[in] propertyIndex The index of a property
120    */
121   Property( Handle& object, Property::Index propertyIndex );
122
123
124   /**
125    * @brief Creates a Property instance.
126    *
127    * @SINCE_1_0.0
128    * @param[in] object A valid handle to the target object.
129    * @param[in] propertyIndex The index of a property.
130    * @param[in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4. -1 for main property (default is -1)
131    */
132   Property( Handle& object, Property::Index propertyIndex, int32_t componentIndex );
133
134   /**
135    * @brief Creates a Property instance.
136    *
137    * @SINCE_1_0.0
138    * @param[in] object A valid handle to the target object
139    * @param[in] propertyName The property name
140    * @note This performs a property index query and is therefore slower than
141    * constructing a Property directly with the index.
142    */
143   Property( Handle& object, const std::string& propertyName );
144
145   /**
146    * @brief Creates a Property instance.
147    *
148    * @SINCE_1_0.0
149    * @param[in] object A valid handle to the target object
150    * @param[in] propertyName The property name
151    * @param[in] componentIndex Index to a sub component of a property, for use with Vector2, Vector3 and Vector4. -1 for main property (default is -1)
152    * @note This performs a property index query and is therefore slower than
153    * constructing a Property directly with the index.
154    */
155   Property( Handle& object, const std::string& propertyName, int32_t componentIndex );
156
157   /**
158    * @brief Non-virtual destructor; Property is not intended as a base class.
159    * @SINCE_1_0.0
160    */
161   ~Property();
162
163   Handle& object; ///< A valid handle to the target object.
164
165   Index propertyIndex; ///< The index of a property provided by object.
166
167   int32_t componentIndex; ///< Index of a property sub component, for use with Vector2, Vector3 and Vector4, -1 if using main property
168 };
169
170 /**
171  * @}
172  */
173 } // namespace Dali
174
175 #endif // __DALI_PROPERTY_H__