1 #ifndef __DALI_PROPERTY_VALUE_H__
2 #define __DALI_PROPERTY_VALUE_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.
25 #include <dali/public-api/object/property.h>
26 #include <dali/public-api/math/rect.h>
40 * @brief A value-type representing a property value.
42 class DALI_IMPORT_API Property::Value
47 * @brief Default constructor.
49 * This creates a property with type Property::NONE.
54 * @brief Create a boolean property value.
56 * @param [in] boolValue A boolean value.
58 Value( bool boolValue );
61 * @brief Create an integer property value.
63 * @param [in] integerValue An integer value.
65 Value( int integerValue );
68 * @brief Create a float property value.
70 * @param [in] floatValue A floating-point value.
72 Value( float floatValue );
75 * @brief Create a Vector2 property value.
77 * @param [in] vectorValue A vector of 2 floating-point values.
79 Value( const Vector2& vectorValue );
82 * @brief Create a Vector3 property value.
84 * @param [in] vectorValue A vector of 3 floating-point values.
86 Value( const Vector3& vectorValue );
89 * @brief Create a Vector4 property value.
91 * @param [in] vectorValue A vector of 4 floating-point values.
93 Value( const Vector4& vectorValue );
96 * @brief Create a Matrix3 property value.
98 * @param [in] matrixValue A matrix of 3x3 floating-point values.
100 Value( const Matrix3& matrixValue );
103 * @brief Create a Matrix property value.
105 * @param [in] matrixValue A matrix of 4x4 floating-point values.
107 Value( const Matrix& matrixValue );
110 * @brief Create a Vector4 property value.
112 * @param [in] vectorValue A vector of 4 integer values.
114 Value( const Rect<int>& vectorValue );
117 * @brief Create an orientation property value.
119 * @param [in] angleAxis An angle-axis representing the rotation.
121 Value( const AngleAxis& angleAxis );
124 * @brief Create an orientation property value.
126 * @param [in] quaternion A quaternion representing the rotation.
128 Value( const Quaternion& quaternion );
131 * @brief Create an string property value.
133 * @param [in] stringValue A string.
135 Value( const std::string& stringValue );
138 * @brief Create an string property value.
140 * @param [in] stringValue A string.
142 Value( const char* stringValue );
145 * @brief Create an array property value.
147 * @param [in] arrayValue An array
149 Value( Property::Array& arrayValue );
152 * @brief Create a map property value.
154 * @param [in] mapValue An array
156 Value( Property::Map& mapValue );
159 * @brief Explicitly set a type and initialize it.
161 * @param [in] type The property value type.
163 explicit Value( Type type );
166 * @brief Copy constructor
168 * @param [in] value The property value to copy.
170 Value( const Value& value );
173 * @brief Assign a property value.
175 * @param [in] value The property value to assign from.
176 * @return a reference to this
178 Value& operator=( const Value& value );
181 * @brief Non-virtual destructor.
183 * This class is not a base class.
188 * @brief Query the type of this property value.
190 * @return The type ID.
192 Type GetType() const;
195 * @brief Retrieve a specific value.
197 * Works on a best-effort approach; if value type is not convertible returns a default value of the type
199 * @return A value of type T.
201 template <typename T>
202 T DALI_INTERNAL Get() const
204 T temp = T(); // value (zero) initialize
210 * @brief Retrieve a boolean value.
212 * @pre GetType() returns Property::BOOLEAN.
213 * @param [out] boolValue On return, a boolean value.
214 * @return true if the value is successfully retrieved, false if the type is not convertible
216 bool Get( bool& boolValue ) const;
219 * @brief Retrieve a floating-point value.
221 * @pre GetType() returns Property::FLOAT.
222 * @param [out] floatValue On return, a floating-point value.
223 * @return true if the value is successfully retrieved, false if the type is not convertible
225 bool Get( float& floatValue ) const;
228 * @brief Retrieve an integer value.
230 * @pre GetType() returns Property::INTEGER.
231 * @param [out] integerValue On return, an integer value.
232 * @return true if the value is successfully retrieved, false if the type is not convertible
234 bool Get( int& integerValue ) const;
237 * @brief Retrieve an integer rectangle.
239 * @pre GetType() returns Property::RECTANGLE.
240 * @param [out] rect On return, an integer rectangle.
241 * @return true if the value is successfully retrieved, false if the type is not convertible
243 bool Get( Rect<int>& rect ) const;
246 * @brief Retrieve a vector value.
248 * @pre GetType() returns Property::VECTOR2.
249 * @param [out] vectorValue On return, a vector value.
250 * @return true if the value is successfully retrieved, false if the type is not convertible
252 bool Get( Vector2& vectorValue ) const;
255 * @brief Retrieve a vector value.
257 * @pre GetType() returns Property::VECTOR3.
258 * @param [out] vectorValue On return, a vector value.
259 * @return true if the value is successfully retrieved, false if the type is not convertible
261 bool Get( Vector3& vectorValue ) const;
264 * @brief Retrieve a vector value.
266 * @pre GetType() returns Property::VECTOR4.
267 * @param [out] vectorValue On return, a vector value.
268 * @return true if the value is successfully retrieved, false if the type is not convertible
270 bool Get( Vector4& vectorValue ) const;
273 * @brief Retrieve a matrix3 value.
275 * @pre GetType() returns Property::MATRIX3.
276 * @param [out] matrixValue On return, a matrix3 value.
277 * @return true if the value is successfully retrieved, false if the type is not convertible
279 bool Get( Matrix3& matrixValue ) const;
282 * @brief Retrieve a matrix value.
284 * @pre GetType() returns Property::MATRIX.
285 * @param [out] matrixValue On return, a matrix value.
286 * @return true if the value is successfully retrieved, false if the type is not convertible
288 bool Get( Matrix& matrixValue ) const;
291 * @brief Retrieve an angle-axis value.
293 * @pre GetType() returns Property::ROTATION.
294 * @param [out] angleAxisValue On return, a angle-axis value.
295 * @return true if the value is successfully retrieved, false if the type is not convertible
297 bool Get( AngleAxis& angleAxisValue ) const;
300 * @brief Retrieve a quaternion value.
302 * @pre GetType() returns Property::ROTATION.
303 * @param [out] quaternionValue On return, a quaternion value.
304 * @return true if the value is successfully retrieved, false if the type is not convertible
306 bool Get( Quaternion& quaternionValue ) const;
309 * @brief Retrieve an string property value.
311 * @pre GetType() returns Property::STRING.
312 * @param [out] stringValue A string.
313 * @return true if the value is successfully retrieved, false if the type is not convertible
315 bool Get( std::string& stringValue ) const;
318 * @brief Retrieve an array property value.
320 * @pre GetType() returns Property::ARRAY.
321 * @param [out] arrayValue The array as a vector Property Values
322 * @return true if the value is successfully retrieved, false if the type is not convertible
324 bool Get( Property::Array& arrayValue ) const;
327 * @brief Retrieve an map property value.
329 * @pre GetType() returns Property::MAP.
330 * @param [out] mapValue The map as vector of string and Property Value pairs
331 * @return true if the value is successfully retrieved, false if the type is not convertible
333 bool Get( Property::Map& mapValue ) const;
336 * @brief Retrieve the Array API of the Property::Value without copying the contents of the map
338 * @return the Array API of the Property::Value or NULL if not a Property::Array
340 Property::Array* GetArray() const;
343 * @brief Retrieve the Map API of the Property::Value without copying the contents of the map
345 * @return the Map API of the Property::Value or NULL if not a Property::Map
347 Property::Map* GetMap() const;
352 friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
356 struct DALI_INTERNAL Impl;
357 Impl* mImpl; ///< Pointer to the implementation
362 * @brief Convert the value of the property into a string and append to an output stream.
364 * @param [in] ouputStream The output stream operator.
365 * @param [in] value The value to insert
366 * @return The output stream operator.
368 DALI_IMPORT_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
372 #endif // __DALI_PROPERTY_VALUE_H__