1 #ifndef __DALI_PROPERTY_VALUE_H__
2 #define __DALI_PROPERTY_VALUE_H__
5 * Copyright (c) 2017 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>
31 * @addtogroup dali_core_object
45 * @brief A value-type representing a property value.
48 class DALI_IMPORT_API Property::Value
53 * @brief Default constructor.
55 * This creates a property with type Property::NONE.
61 * @brief Creates a boolean property value.
64 * @param[in] boolValue A boolean value
66 Value( bool boolValue );
69 * @brief Creates an integer property value.
72 * @param[in] integerValue An integer value
74 Value( int integerValue );
77 * @brief Creates a float property value.
80 * @param[in] floatValue A floating-point value
82 Value( float floatValue );
85 * @brief Creates a Vector2 property value.
88 * @param[in] vectorValue A vector of 2 floating-point values
90 Value( const Vector2& vectorValue );
93 * @brief Creates a Vector3 property value.
96 * @param[in] vectorValue A vector of 3 floating-point values
98 Value( const Vector3& vectorValue );
101 * @brief Creates a Vector4 property value.
104 * @param[in] vectorValue A vector of 4 floating-point values
106 Value( const Vector4& vectorValue );
109 * @brief Creates a Matrix3 property value.
112 * @param[in] matrixValue A matrix of 3x3 floating-point values
114 Value( const Matrix3& matrixValue );
117 * @brief Creates a Matrix property value.
120 * @param[in] matrixValue A matrix of 4x4 floating-point values
122 Value( const Matrix& matrixValue );
125 * @brief Creates a Vector4 property value.
128 * @param[in] vectorValue A vector of 4 integer values
130 Value( const Rect<int>& vectorValue );
133 * @brief Creates an orientation property value.
136 * @param[in] angleAxis An angle-axis representing the rotation
138 Value( const AngleAxis& angleAxis );
141 * @brief Creates an orientation property value.
144 * @param[in] quaternion A quaternion representing the rotation
146 Value( const Quaternion& quaternion );
149 * @brief Creates an string property value.
152 * @param[in] stringValue A string
154 Value( const std::string& stringValue );
157 * @brief Creates a string property value.
160 * @param[in] stringValue A string
162 Value( const char* stringValue );
165 * @brief Creates an array property value.
168 * @param[in] arrayValue An array
170 Value( Property::Array& arrayValue );
173 * @brief Creates a map property value.
176 * @param[in] mapValue An array
178 Value( Property::Map& mapValue );
181 * @brief Creates an extents property value.
184 * @param[in] extentsValue A collection of 4 uint16_t values
186 Value( const Extents& extentsValue );
189 * @brief Explicitly sets a type and initialize it.
192 * @param[in] type The property value type
194 explicit Value( Type type );
197 * @brief Copy constructor.
200 * @param[in] value The property value to copy
202 Value( const Value& value );
205 * @brief Assigns a property value.
208 * @param[in] value The property value to assign from
209 * @return a reference to this
211 Value& operator=( const Value& value );
214 * @brief Non-virtual destructor.
216 * This class is not a base class.
222 * @brief Queries the type of this property value.
225 * @return The type ID
227 Type GetType() const;
230 * @brief Retrieves a specific value.
232 * Works on a best-effort approach; if value type is not convertible returns a default value of the type.
235 * @return A value of type T
237 template <typename T>
238 T DALI_INTERNAL Get() const
240 T temp = T(); // value (zero) initialize
246 * @brief Retrieves a boolean value.
249 * @param[out] boolValue On return, a boolean value
250 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
251 * @pre GetType() is a type convertible to bool.
253 bool Get( bool& boolValue ) const;
256 * @brief Retrieves a floating-point value.
259 * @param[out] floatValue On return, a floating-point value
260 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
261 * @pre GetType() is a type convertible to float.
263 bool Get( float& floatValue ) const;
266 * @brief Retrieves an integer value.
269 * @param[out] integerValue On return, an integer value
270 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
271 * @pre GetType() is a type convertible to int.
273 bool Get( int& integerValue ) const;
276 * @brief Retrieves an integer rectangle.
279 * @param[out] rect On return, an integer rectangle
280 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
281 * @pre GetType() is a type convertible to Rect<int>.
283 bool Get( Rect<int>& rect ) const;
286 * @brief Retrieves a vector value.
289 * @param[out] vectorValue On return, a vector value
290 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
291 * @pre GetType() is a type convertible to Vector2.
293 bool Get( Vector2& vectorValue ) const;
296 * @brief Retrieves a vector value.
299 * @param[out] vectorValue On return, a vector value
300 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
301 * @pre GetType() is a type convertible to Vector3.
303 bool Get( Vector3& vectorValue ) const;
306 * @brief Retrieves a vector value.
309 * @param[out] vectorValue On return, a vector value
310 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
311 * @pre GetType() is a type convertible to Vector4.
313 bool Get( Vector4& vectorValue ) const;
316 * @brief Retrieves a matrix3 value.
319 * @param[out] matrixValue On return, a matrix3 value
320 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
321 * @pre GetType() is a type convertible to Matrix3.
323 bool Get( Matrix3& matrixValue ) const;
326 * @brief Retrieves a matrix value.
329 * @param[out] matrixValue On return, a matrix value
330 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
331 * @pre GetType() is a type convertible to Matrix.
333 bool Get( Matrix& matrixValue ) const;
336 * @brief Retrieves an angle-axis value.
339 * @param[out] angleAxisValue On return, a angle-axis value
340 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
341 * @pre GetType() is a type convertible to AngleAxis.
343 bool Get( AngleAxis& angleAxisValue ) const;
346 * @brief Retrieves a quaternion value.
349 * @param[out] quaternionValue On return, a quaternion value
350 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
351 * @pre GetType() is a type convertible to Quaternion.
353 bool Get( Quaternion& quaternionValue ) const;
356 * @brief Retrieves an string property value.
359 * @param[out] stringValue A string
360 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
361 * @pre GetType() is a type convertible to string.
363 bool Get( std::string& stringValue ) const;
366 * @brief Retrieves an array property value.
369 * @param[out] arrayValue The array as a vector Property Values
370 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
371 * @pre GetType() returns Property::ARRAY.
373 bool Get( Property::Array& arrayValue ) const;
376 * @brief Retrieves an map property value.
379 * @param[out] mapValue The map as vector of string and Property Value pairs
380 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
381 * @pre GetType() returns Property::MAP.
383 bool Get( Property::Map& mapValue ) const;
386 * @brief Retrieves the Array API of the Property::Value without copying the contents of the map.
389 * @return The Array API of the Property::Value or NULL if not a Property::Array
391 Property::Array* GetArray() const;
394 * @brief Retrieves the Map API of the Property::Value without copying the contents of the map.
397 * @return The Map API of the Property::Value or NULL if not a Property::Map
399 Property::Map* GetMap() const;
402 * @brief Retrieves an extents.
405 * @param[out] extentsValue Extents, a collection of 4 uint16_t
406 * @return @c true if the value is successfully retrieved, @c false if the type is not convertible
407 * @pre GetType() is a type convertible to Extents.
409 bool Get( Extents& extentsValue ) const;
412 * @brief Output to stream.
415 friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
419 struct DALI_INTERNAL Impl;
420 Impl* mImpl; ///< Pointer to the implementation
425 * @brief Converts the value of the property into a string and append to an output stream.
428 * @param[in] ouputStream The output stream operator
429 * @param[in] value The value to insert
430 * @return The output stream operator
432 DALI_IMPORT_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
439 #endif // __DALI_PROPERTY_VALUE_H__