1 #ifndef DALI_PROPERTY_VALUE_H
2 #define DALI_PROPERTY_VALUE_H
5 * Copyright (c) 2020 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.
23 #include <type_traits>
25 #include <initializer_list>
28 #include <dali/public-api/object/property.h>
29 #include <dali/public-api/math/rect.h>
35 * @addtogroup dali_core_object
48 typedef std::pair< Property::Key, Property::Value > KeyValuePair;
51 * @brief A value-type representing a property value.
54 class DALI_CORE_API Property::Value
59 * @brief Default constructor.
61 * This creates a property with type Property::NONE.
67 * @brief Creates a boolean property value.
70 * @param[in] boolValue A boolean value
72 Value( bool boolValue );
75 * @brief Creates an integer property value.
78 * @param[in] integerValue An integer value
80 Value( int32_t integerValue );
83 * @brief Creates a float property value.
86 * @param[in] floatValue A floating-point value
88 Value( float floatValue );
91 * @brief Creates a Vector2 property value.
94 * @param[in] vectorValue A vector of 2 floating-point values
96 Value( const Vector2& vectorValue );
99 * @brief Creates a Vector3 property value.
102 * @param[in] vectorValue A vector of 3 floating-point values
104 Value( const Vector3& vectorValue );
107 * @brief Creates a Vector4 property value.
110 * @param[in] vectorValue A vector of 4 floating-point values
112 Value( const Vector4& vectorValue );
115 * @brief Creates a Matrix3 property value.
118 * @param[in] matrixValue A matrix of 3x3 floating-point values
120 Value( const Matrix3& matrixValue );
123 * @brief Creates a Matrix property value.
126 * @param[in] matrixValue A matrix of 4x4 floating-point values
128 Value( const Matrix& matrixValue );
131 * @brief Creates a Vector4 property value.
134 * @param[in] vectorValue A vector of 4 integer values
136 Value( const Rect<int32_t>& vectorValue );
139 * @brief Creates a Vector4 property value.
142 * @param[in] vectorValue A vector of 4 float values
144 Value( const Rect<float>& vectorValue );
147 * @brief Creates an orientation property value.
150 * @param[in] angleAxis An angle-axis representing the rotation
152 Value( const AngleAxis& angleAxis );
155 * @brief Creates an orientation property value.
158 * @param[in] quaternion A quaternion representing the rotation
160 Value( const Quaternion& quaternion );
163 * @brief Creates an string property value.
166 * @param[in] stringValue A string
168 Value( const std::string& stringValue );
171 * @brief Creates a string property value.
174 * @param[in] stringValue A string
176 Value( const char* stringValue );
179 * @brief Creates an array property value.
182 * @param[in] arrayValue An array
184 Value( Property::Array& arrayValue );
187 * @brief Creates an array property value.
190 * @param[in] arrayValue An r-value array
192 Value( Property::Array&& arrayValue );
195 * @brief Creates a map property value.
198 * @param[in] mapValue A map
200 Value( Property::Map& mapValue );
203 * @brief Creates a map property value.
206 * @param[in] mapValue An r-value map
208 Value( Property::Map&& mapValue );
211 * @brief Create a map property value from an initializer_list.
214 * @param [in] values An initializer_list of pairs of index and value.
216 Value( const std::initializer_list< KeyValuePair >& values );
219 * @brief Creates an extents property value.
222 * @param[in] extentsValue A collection of 4 uint16_t values
224 Value( const Extents& extentsValue );
227 * @brief Creates an enumeration property value.
230 * @param[in] enumValue An enumeration value
232 template< typename T, typename std::enable_if< std::is_enum< T >::value >::type* = nullptr >
233 Value( T enumValue ) : Value( static_cast< int32_t >( enumValue ) )
238 * @brief Explicitly sets a type and initialize it.
241 * @param[in] type The property value type
243 explicit Value( Type type );
246 * @brief Copy constructor.
249 * @param[in] value The property value to copy
251 Value( const Value& value );
254 * @brief Move constructor.
256 * A move constructor enables the resources owned by an rvalue object to be moved into an lvalue without copying.
258 * @param[in] value The property value to move from
260 Value( Value&& value );
263 * @brief Assigns a property value.
266 * @param[in] value The property value to assign from
267 * @return a reference to this
269 Value& operator=( const Value& value );
272 * @brief Move assignment operator.
275 * @param[in] value The property value to move from
276 * @return a reference to this
278 Value& operator=( Value&& value );
281 * @brief Non-virtual destructor.
283 * This class is not a base class.
289 * @brief Queries the type of this property value.
292 * @return The type ID
294 Type GetType() const;
297 * @brief Retrieves a specific value.
299 * Works on a best-effort approach; if value type is different returns a default value of the type.
302 * @return A value of type T
304 template< typename T, typename std::enable_if< ! std::is_enum< T >::value >::type* = nullptr >
305 T DALI_INTERNAL Get() const
307 T temp = T(); // value (zero) initialize
313 * @brief Retrieves a specific value.
315 * Works on a best-effort approach; if value type is different returns a default value of the type.
316 * Specialization for enumeration values
319 * @return A value of type T
321 template< typename T, typename std::enable_if< std::is_enum< T >::value >::type* = nullptr >
322 T DALI_INTERNAL Get() const
324 int32_t temp = 0; // value (zero) initialize
326 return static_cast< T >( temp );
330 * @brief Retrieves an enumeration value.
333 * @param[out] enumValue On return, an enumeration value
334 * @return @c true if the value is successfully retrieved, @c false if the type is different
335 * @pre GetType() is any enumeration
337 template< typename T, typename std::enable_if< std::is_enum< T >::value >::type* = nullptr >
338 bool DALI_INTERNAL Get( T& enumValue ) const
345 enumValue = static_cast< T >( temp );
350 * @brief Retrieves a boolean value.
353 * @param[out] boolValue On return, a boolean value
354 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
355 * @pre GetType() is a type convertible to bool.
357 bool Get( bool& boolValue ) const;
360 * @brief Retrieves a floating-point value.
363 * @param[out] floatValue On return, a floating-point value
364 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
365 * @pre GetType() is a type convertible to float.
367 bool Get( float& floatValue ) const;
370 * @brief Retrieves an integer value.
373 * @param[out] integerValue On return, an integer value
374 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
375 * @pre GetType() is a type convertible to int.
377 bool Get( int32_t& integerValue ) const;
380 * @brief Retrieves an integer rectangle.
383 * @param[out] rect On return, an integer rectangle
384 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
385 * @pre GetType() is a type convertible to Rect<int>.
387 bool Get( Rect<int32_t>& rect ) const;
390 * @brief Retrieves a vector value.
393 * @param[out] vectorValue On return, a vector value
394 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
395 * @pre GetType() is a type convertible to Vector2.
397 bool Get( Vector2& vectorValue ) const;
400 * @brief Retrieves a vector value.
403 * @param[out] vectorValue On return, a vector value
404 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
405 * @pre GetType() is a type convertible to Vector3.
407 bool Get( Vector3& vectorValue ) const;
410 * @brief Retrieves a vector value.
413 * @param[out] vectorValue On return, a vector value
414 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
415 * @pre GetType() is a type convertible to Vector4.
417 bool Get( Vector4& vectorValue ) const;
420 * @brief Retrieves a matrix3 value.
423 * @param[out] matrixValue On return, a matrix3 value
424 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
425 * @pre GetType() is a type convertible to Matrix3.
427 bool Get( Matrix3& matrixValue ) const;
430 * @brief Retrieves a matrix value.
433 * @param[out] matrixValue On return, a matrix value
434 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
435 * @pre GetType() is a type convertible to Matrix.
437 bool Get( Matrix& matrixValue ) const;
440 * @brief Retrieves an angle-axis value.
443 * @param[out] angleAxisValue On return, a angle-axis value
444 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
445 * @pre GetType() is a type convertible to AngleAxis.
447 bool Get( AngleAxis& angleAxisValue ) const;
450 * @brief Retrieves a quaternion value.
453 * @param[out] quaternionValue On return, a quaternion value
454 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
455 * @pre GetType() is a type convertible to Quaternion.
457 bool Get( Quaternion& quaternionValue ) const;
460 * @brief Retrieves an string property value.
463 * @param[out] stringValue A string
464 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
465 * @pre GetType() is a type convertible to string.
467 bool Get( std::string& stringValue ) const;
470 * @brief Retrieves an array property value.
473 * @param[out] arrayValue The array as a vector Property Values
474 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
475 * @pre GetType() returns Property::ARRAY.
477 bool Get( Property::Array& arrayValue ) const;
480 * @brief Retrieves an map property value.
483 * @param[out] mapValue The map as vector of string and Property Value pairs
484 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
485 * @pre GetType() returns Property::MAP.
487 bool Get( Property::Map& mapValue ) const;
490 * @brief Retrieves the Array API of the Property::Value without copying the contents of the map.
493 * @return The Array API of the Property::Value or NULL if not a Property::Array
495 Property::Array* GetArray() const;
498 * @brief Retrieves the Map API of the Property::Value without copying the contents of the map.
501 * @return The Map API of the Property::Value or NULL if not a Property::Map
503 Property::Map* GetMap() const;
506 * @brief Retrieves an extents.
509 * @param[out] extentsValue Extents, a collection of 4 uint16_t
510 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
511 * @pre GetType() is a type convertible to Extents.
513 bool Get( Extents& extentsValue ) const;
516 * @brief Output to stream.
519 friend DALI_CORE_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
523 struct DALI_INTERNAL Impl;
524 Impl* mImpl; ///< Pointer to the implementation
529 * @brief Converts the value of the property into a string and append to an output stream.
532 * @param[in] ouputStream The output stream operator
533 * @param[in] value The value to insert
534 * @return The output stream operator
536 DALI_CORE_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
543 #endif // DALI_PROPERTY_VALUE_H