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.
22 #include <initializer_list>
24 #include <type_traits>
28 #include <dali/public-api/math/rect.h>
29 #include <dali/public-api/object/property.h>
34 * @addtogroup dali_core_object
47 using KeyValuePair = std::pair<Property::Key, Property::Value>;
50 * @brief A value-type representing a property value.
53 class DALI_CORE_API Property::Value
57 * @brief Default constructor.
59 * This creates a property with type Property::NONE.
65 * @brief Creates a boolean property value.
68 * @param[in] boolValue A boolean value
70 Value(bool boolValue);
73 * @brief Creates an integer property value.
76 * @param[in] integerValue An integer value
78 Value(int32_t integerValue);
81 * @brief Creates a float property value.
84 * @param[in] floatValue A floating-point value
86 Value(float floatValue);
89 * @brief Creates a Vector2 property value.
92 * @param[in] vectorValue A vector of 2 floating-point values
94 Value(const Vector2& vectorValue);
97 * @brief Creates a Vector3 property value.
100 * @param[in] vectorValue A vector of 3 floating-point values
102 Value(const Vector3& vectorValue);
105 * @brief Creates a Vector4 property value.
108 * @param[in] vectorValue A vector of 4 floating-point values
110 Value(const Vector4& vectorValue);
113 * @brief Creates a Matrix3 property value.
116 * @param[in] matrixValue A matrix of 3x3 floating-point values
118 Value(const Matrix3& matrixValue);
121 * @brief Creates a Matrix property value.
124 * @param[in] matrixValue A matrix of 4x4 floating-point values
126 Value(const Matrix& matrixValue);
129 * @brief Creates a Vector4 property value.
132 * @param[in] vectorValue A vector of 4 integer values
134 Value(const Rect<int32_t>& vectorValue);
137 * @brief Creates a Vector4 property value.
140 * @param[in] vectorValue A vector of 4 float values
142 Value(const Rect<float>& vectorValue);
145 * @brief Creates an orientation property value.
148 * @param[in] angleAxis An angle-axis representing the rotation
150 Value(const AngleAxis& angleAxis);
153 * @brief Creates an orientation property value.
156 * @param[in] quaternion A quaternion representing the rotation
158 Value(const Quaternion& quaternion);
161 * @brief Creates an string property value.
164 * @param[in] stringValue A string
166 Value(std::string stringValue);
169 * @brief Creates a string property value.
172 * @param[in] stringValue A string
174 Value(const char* stringValue);
177 * @brief Creates an array property value.
180 * @param[in] arrayValue A property array
182 Value(Property::Array arrayValue);
185 * @brief Creates a map property value.
188 * @param[in] mapValue A property map
190 Value(Property::Map mapValue);
193 * @brief Create a map property value from an initializer_list.
196 * @param [in] values An initializer_list of pairs of index and value.
198 Value(const std::initializer_list<KeyValuePair>& values);
201 * @brief Creates an extents property value.
204 * @param[in] extentsValue A collection of 4 uint16_t values
206 Value(const Extents& extentsValue);
209 * @brief Creates an enumeration property value.
212 * @param[in] enumValue An enumeration value
214 template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
216 : Value(static_cast<int32_t>(enumValue))
221 * @brief Explicitly sets a type and initialize it.
224 * @param[in] type The property value type
226 explicit Value(Type type);
229 * @brief Copy constructor.
232 * @param[in] value The property value to copy
234 Value(const Value& value);
237 * @brief Move constructor.
239 * A move constructor enables the resources owned by an rvalue object to be moved into an lvalue without copying.
241 * @param[in] value The property value to move from
243 Value(Value&& value) noexcept;
246 * @brief Assigns a property value.
249 * @param[in] value The property value to assign from
250 * @return a reference to this
252 Value& operator=(const Value& value);
255 * @brief Move assignment operator.
258 * @param[in] value The property value to move from
259 * @return a reference to this
261 Value& operator=(Value&& value) noexcept;
264 * @brief Non-virtual destructor.
266 * This class is not a base class.
272 * @brief Queries the type of this property value.
275 * @return The type ID
277 Type GetType() const;
280 * @brief Retrieves a specific value.
282 * Works on a best-effort approach; if value type is different returns a default value of the type.
285 * @return A value of type T
287 template<typename T, typename std::enable_if<!std::is_enum<T>::value>::type* = nullptr>
288 T DALI_INTERNAL Get() const
290 T temp = T(); // value (zero) initialize
296 * @brief Retrieves a specific value.
298 * Works on a best-effort approach; if value type is different returns a default value of the type.
299 * Specialization for enumeration values
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 int32_t temp = 0; // value (zero) initialize
309 return static_cast<T>(temp);
313 * @brief Retrieves an enumeration value.
316 * @param[out] enumValue On return, an enumeration value
317 * @return @c true if the value is successfully retrieved, @c false if the type is different
318 * @pre GetType() is any enumeration
320 template<typename T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
321 bool DALI_INTERNAL Get(T& enumValue) const
328 enumValue = static_cast<T>(temp);
333 * @brief Retrieves a boolean value.
336 * @param[out] boolValue On return, a boolean 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 bool.
340 bool Get(bool& boolValue) const;
343 * @brief Retrieves a floating-point value.
346 * @param[out] floatValue On return, a floating-point 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 float.
350 bool Get(float& floatValue) const;
353 * @brief Retrieves an integer value.
356 * @param[out] integerValue On return, an integer 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 int.
360 bool Get(int32_t& integerValue) const;
363 * @brief Retrieves an integer rectangle.
366 * @param[out] rect On return, an integer rectangle
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 Rect<int>.
370 bool Get(Rect<int32_t>& rect) const;
373 * @brief Retrieves a vector value.
376 * @param[out] vectorValue On return, a vector 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 Vector2.
380 bool Get(Vector2& vectorValue) const;
383 * @brief Retrieves a vector value.
386 * @param[out] vectorValue On return, a vector value
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 Vector3.
390 bool Get(Vector3& vectorValue) const;
393 * @brief Retrieves a vector value.
396 * @param[out] vectorValue On return, a vector value
397 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
398 * @pre GetType() is a type convertible to Vector4.
400 bool Get(Vector4& vectorValue) const;
403 * @brief Retrieves a matrix3 value.
406 * @param[out] matrixValue On return, a matrix3 value
407 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
408 * @pre GetType() is a type convertible to Matrix3.
410 bool Get(Matrix3& matrixValue) const;
413 * @brief Retrieves a matrix value.
416 * @param[out] matrixValue On return, a matrix value
417 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
418 * @pre GetType() is a type convertible to Matrix.
420 bool Get(Matrix& matrixValue) const;
423 * @brief Retrieves an angle-axis value.
426 * @param[out] angleAxisValue On return, a angle-axis value
427 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
428 * @pre GetType() is a type convertible to AngleAxis.
430 bool Get(AngleAxis& angleAxisValue) const;
433 * @brief Retrieves a quaternion value.
436 * @param[out] quaternionValue On return, a quaternion value
437 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
438 * @pre GetType() is a type convertible to Quaternion.
440 bool Get(Quaternion& quaternionValue) const;
443 * @brief Retrieves an string property value.
446 * @param[out] stringValue A string
447 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
448 * @pre GetType() is a type convertible to string.
450 bool Get(std::string& stringValue) const;
453 * @brief Retrieves an array property value.
456 * @param[out] arrayValue The array as a vector Property Values
457 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
458 * @pre GetType() returns Property::ARRAY.
460 bool Get(Property::Array& arrayValue) const;
463 * @brief Retrieves an map property value.
466 * @param[out] mapValue The map as vector of string and Property Value pairs
467 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
468 * @pre GetType() returns Property::MAP.
470 bool Get(Property::Map& mapValue) const;
473 * @brief Retrieves the Array API of the Property::Value without copying the contents of the map.
476 * @return The Array API of the Property::Value or NULL if not a Property::Array
478 Property::Array* GetArray() const;
481 * @brief Retrieves the Map API of the Property::Value without copying the contents of the map.
484 * @return The Map API of the Property::Value or NULL if not a Property::Map
486 Property::Map* GetMap() const;
489 * @brief Retrieves an extents.
492 * @param[out] extentsValue Extents, a collection of 4 uint16_t
493 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
494 * @pre GetType() is a type convertible to Extents.
496 bool Get(Extents& extentsValue) const;
499 * @brief Output to stream.
502 friend DALI_CORE_API std::ostream& operator<<(std::ostream& ouputStream, const Property::Value& value);
505 struct DALI_INTERNAL Impl;
506 Impl* mImpl; ///< Pointer to the implementation
510 * @brief Converts the value of the property into a string and append to an output stream.
513 * @param[in] ouputStream The output stream operator
514 * @param[in] value The value to insert
515 * @return The output stream operator
517 DALI_CORE_API std::ostream& operator<<(std::ostream& ouputStream, const Property::Value& value);
524 #endif // DALI_PROPERTY_VALUE_H