1 #ifndef __DALI_PROPERTY_VALUE_H__
2 #define __DALI_PROPERTY_VALUE_H__
5 * Copyright (c) 2016 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>
28 #include <type_traits>
33 * @addtogroup dali_core_object
47 * @brief A value-type representing a property value.
50 class DALI_IMPORT_API Property::Value
55 * @brief Default constructor.
57 * This creates a property with type Property::NONE.
63 * @brief Creates a boolean property value.
66 * @param[in] boolValue A boolean value
68 Value( bool boolValue );
71 * @brief Creates an integer property value.
74 * @param[in] integerValue An integer value
76 Value( int integerValue );
79 * @brief Creates a float property value.
82 * @param[in] floatValue A floating-point value
84 Value( float floatValue );
87 * @brief Creates a Vector2 property value.
90 * @param[in] vectorValue A vector of 2 floating-point values
92 Value( const Vector2& vectorValue );
95 * @brief Creates a Vector3 property value.
98 * @param[in] vectorValue A vector of 3 floating-point values
100 Value( const Vector3& vectorValue );
103 * @brief Creates a Vector4 property value.
106 * @param[in] vectorValue A vector of 4 floating-point values
108 Value( const Vector4& vectorValue );
111 * @brief Creates a Matrix3 property value.
114 * @param[in] matrixValue A matrix of 3x3 floating-point values
116 Value( const Matrix3& matrixValue );
119 * @brief Creates a Matrix property value.
122 * @param[in] matrixValue A matrix of 4x4 floating-point values
124 Value( const Matrix& matrixValue );
127 * @brief Creates a Vector4 property value.
130 * @param[in] vectorValue A vector of 4 integer values
132 Value( const Rect<int>& vectorValue );
135 * @brief Creates an orientation property value.
138 * @param[in] angleAxis An angle-axis representing the rotation
140 Value( const AngleAxis& angleAxis );
143 * @brief Creates an orientation property value.
146 * @param[in] quaternion A quaternion representing the rotation
148 Value( const Quaternion& quaternion );
151 * @brief Creates an string property value.
154 * @param[in] stringValue A string
156 Value( const std::string& stringValue );
159 * @brief Creates a string property value.
162 * @param[in] stringValue A string
164 Value( const char* stringValue );
167 * @brief Creates an array property value.
170 * @param[in] arrayValue An array
172 Value( Property::Array& arrayValue );
175 * @brief Creates a map property value.
178 * @param[in] mapValue An array
180 Value( Property::Map& mapValue );
183 * @brief Creates an extents property value.
186 * @param[in] extentsValue A collection of 4 uint16_t values
188 Value( const Extents& extentsValue );
191 * @brief Creates an enumeration property value.
194 * @param[in] extentsValue A collection of 4 uint16_t values
196 template <typename T, typename std::enable_if<std::is_enum<typename std::remove_reference<typename std::remove_cv<T>::type>::type>::value>::type* = nullptr>
197 Value(T t) : Value(static_cast<int>(t)) { }
200 * @brief Explicitly sets a type and initialize it.
203 * @param[in] type The property value type
205 explicit Value( Type type );
208 * @brief Copy constructor.
211 * @param[in] value The property value to copy
213 Value( const Value& value );
216 * @brief Assigns a property value.
219 * @param[in] value The property value to assign from
220 * @return a reference to this
222 Value& operator=( const Value& value );
225 * @brief Non-virtual destructor.
227 * This class is not a base class.
233 * @brief Queries the type of this property value.
236 * @return The type ID
238 Type GetType() const;
241 * @brief Retrieves a specific value.
243 * Works on a best-effort approach; if value type is different returns a default value of the type.
246 * @return A value of type T
248 template <typename T>
249 T DALI_INTERNAL Get() const
251 T temp = T(); // value (zero) initialize
257 * @brief Retrieves an enumeration value.
260 * @param[out] boolValue On return, an enumeration value
261 * @return @c true if the value is successfully retrieved, @c false if the type is different
262 * @pre GetType() is a type convertible to bool.
264 template <typename T, typename std::enable_if<std::is_enum<typename std::remove_reference<typename std::remove_cv<T>::type>::type>::value>::type* = nullptr>
268 if (!Get(temp)) return false;
269 t = static_cast<T>(temp);
273 * @brief Retrieves a boolean value.
276 * @param[out] boolValue On return, a boolean value
277 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
278 * @pre GetType() is a type convertible to bool.
280 bool Get( bool& boolValue ) const;
283 * @brief Retrieves a floating-point value.
286 * @param[out] floatValue On return, a floating-point value
287 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
288 * @pre GetType() is a type convertible to float.
290 bool Get( float& floatValue ) const;
293 * @brief Retrieves an integer value.
296 * @param[out] integerValue On return, an integer value
297 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
298 * @pre GetType() is a type convertible to int.
300 bool Get( int& integerValue ) const;
303 * @brief Retrieves an integer rectangle.
306 * @param[out] rect On return, an integer rectangle
307 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
308 * @pre GetType() is a type convertible to Rect<int>.
310 bool Get( Rect<int>& rect ) const;
313 * @brief Retrieves a vector value.
316 * @param[out] vectorValue On return, a vector value
317 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
318 * @pre GetType() is a type convertible to Vector2.
320 bool Get( Vector2& vectorValue ) const;
323 * @brief Retrieves a vector value.
326 * @param[out] vectorValue On return, a vector value
327 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
328 * @pre GetType() is a type convertible to Vector3.
330 bool Get( Vector3& vectorValue ) const;
333 * @brief Retrieves a vector value.
336 * @param[out] vectorValue On return, a vector value
337 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
338 * @pre GetType() is a type convertible to Vector4.
340 bool Get( Vector4& vectorValue ) const;
343 * @brief Retrieves a matrix3 value.
346 * @param[out] matrixValue On return, a matrix3 value
347 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
348 * @pre GetType() is a type convertible to Matrix3.
350 bool Get( Matrix3& matrixValue ) const;
353 * @brief Retrieves a matrix value.
356 * @param[out] matrixValue On return, a matrix value
357 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
358 * @pre GetType() is a type convertible to Matrix.
360 bool Get( Matrix& matrixValue ) const;
363 * @brief Retrieves an angle-axis value.
366 * @param[out] angleAxisValue On return, a angle-axis value
367 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
368 * @pre GetType() is a type convertible to AngleAxis.
370 bool Get( AngleAxis& angleAxisValue ) const;
373 * @brief Retrieves a quaternion value.
376 * @param[out] quaternionValue On return, a quaternion value
377 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
378 * @pre GetType() is a type convertible to Quaternion.
380 bool Get( Quaternion& quaternionValue ) const;
383 * @brief Retrieves an string property value.
386 * @param[out] stringValue A string
387 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
388 * @pre GetType() is a type convertible to string.
390 bool Get( std::string& stringValue ) const;
393 * @brief Retrieves an array property value.
396 * @param[out] arrayValue The array as a vector Property Values
397 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
398 * @pre GetType() returns Property::ARRAY.
400 bool Get( Property::Array& arrayValue ) const;
403 * @brief Retrieves an map property value.
406 * @param[out] mapValue The map as vector of string and Property Value pairs
407 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
408 * @pre GetType() returns Property::MAP.
410 bool Get( Property::Map& mapValue ) const;
413 * @brief Retrieves the Array API of the Property::Value without copying the contents of the map.
416 * @return The Array API of the Property::Value or NULL if not a Property::Array
418 Property::Array* GetArray() const;
421 * @brief Retrieves the Map API of the Property::Value without copying the contents of the map.
424 * @return The Map API of the Property::Value or NULL if not a Property::Map
426 Property::Map* GetMap() const;
429 * @brief Retrieves an extents.
432 * @param[out] extentsValue Extents, a collection of 4 uint16_t
433 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
434 * @pre GetType() is a type convertible to Extents.
436 bool Get( Extents& extentsValue ) const;
439 * @brief Output to stream.
442 friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
446 struct DALI_INTERNAL Impl;
447 Impl* mImpl; ///< Pointer to the implementation
452 * @brief Converts the value of the property into a string and append to an output stream.
455 * @param[in] ouputStream The output stream operator
456 * @param[in] value The value to insert
457 * @return The output stream operator
459 DALI_IMPORT_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
466 #endif // __DALI_PROPERTY_VALUE_H__