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>
31 * @addtogroup dali_core_object
44 * @brief A value-type representing a property value.
47 class DALI_IMPORT_API Property::Value
52 * @brief Default constructor.
54 * This creates a property with type Property::NONE.
60 * @brief Create a boolean property value.
63 * @param [in] boolValue A boolean value.
65 Value( bool boolValue );
68 * @brief Create an integer property value.
71 * @param [in] integerValue An integer value.
73 Value( int integerValue );
76 * @brief Create a float property value.
79 * @param [in] floatValue A floating-point value.
81 Value( float floatValue );
84 * @brief Create a Vector2 property value.
87 * @param [in] vectorValue A vector of 2 floating-point values.
89 Value( const Vector2& vectorValue );
92 * @brief Create a Vector3 property value.
95 * @param [in] vectorValue A vector of 3 floating-point values.
97 Value( const Vector3& vectorValue );
100 * @brief Create a Vector4 property value.
103 * @param [in] vectorValue A vector of 4 floating-point values.
105 Value( const Vector4& vectorValue );
108 * @brief Create a Matrix3 property value.
111 * @param [in] matrixValue A matrix of 3x3 floating-point values.
113 Value( const Matrix3& matrixValue );
116 * @brief Create a Matrix property value.
119 * @param [in] matrixValue A matrix of 4x4 floating-point values.
121 Value( const Matrix& matrixValue );
124 * @brief Create a Vector4 property value.
127 * @param [in] vectorValue A vector of 4 integer values.
129 Value( const Rect<int>& vectorValue );
132 * @brief Create an orientation property value.
135 * @param [in] angleAxis An angle-axis representing the rotation.
137 Value( const AngleAxis& angleAxis );
140 * @brief Create an orientation property value.
143 * @param [in] quaternion A quaternion representing the rotation.
145 Value( const Quaternion& quaternion );
148 * @brief Create an string property value.
151 * @param [in] stringValue A string.
153 Value( const std::string& stringValue );
156 * @brief Create an string property value.
159 * @param [in] stringValue A string.
161 Value( const char* stringValue );
164 * @brief Create an array property value.
167 * @param [in] arrayValue An array
169 Value( Property::Array& arrayValue );
172 * @brief Create a map property value.
175 * @param [in] mapValue An array
177 Value( Property::Map& mapValue );
180 * @brief Explicitly set a type and initialize it.
183 * @param [in] type The property value type.
185 explicit Value( Type type );
188 * @brief Copy constructor
191 * @param [in] value The property value to copy.
193 Value( const Value& value );
196 * @brief Assign a property value.
199 * @param [in] value The property value to assign from.
200 * @return a reference to this
202 Value& operator=( const Value& value );
205 * @brief Non-virtual destructor.
207 * This class is not a base class.
213 * @brief Query the type of this property value.
216 * @return The type ID.
218 Type GetType() const;
221 * @brief Retrieve a specific value.
223 * Works on a best-effort approach; if value type is not convertible returns a default value of the type
226 * @return A value of type T.
228 template <typename T>
229 T DALI_INTERNAL Get() const
231 T temp = T(); // value (zero) initialize
237 * @brief Retrieve a boolean value.
240 * @param [out] boolValue On return, a boolean value.
241 * @return true if the value is successfully retrieved, false if the type is not convertible
242 * @pre GetType() is a type convertible to bool.
244 bool Get( bool& boolValue ) const;
247 * @brief Retrieve a floating-point value.
250 * @param [out] floatValue On return, a floating-point value.
251 * @return true if the value is successfully retrieved, false if the type is not convertible
252 * @pre GetType() is a type convertible to float.
254 bool Get( float& floatValue ) const;
257 * @brief Retrieve an integer value.
260 * @param [out] integerValue On return, an integer value.
261 * @return true if the value is successfully retrieved, false if the type is not convertible
262 * @pre GetType() is a type convertible to int.
264 bool Get( int& integerValue ) const;
267 * @brief Retrieve an integer rectangle.
270 * @param [out] rect On return, an integer rectangle.
271 * @return true if the value is successfully retrieved, false if the type is not convertible
272 * @pre GetType() is a type convertible to Rect<int>.
274 bool Get( Rect<int>& rect ) const;
277 * @brief Retrieve a vector value.
280 * @param [out] vectorValue On return, a vector value.
281 * @return true if the value is successfully retrieved, false if the type is not convertible
282 * @pre GetType() is a type convertible to Vector2.
284 bool Get( Vector2& vectorValue ) const;
287 * @brief Retrieve a vector value.
290 * @param [out] vectorValue On return, a vector value.
291 * @return true if the value is successfully retrieved, false if the type is not convertible
292 * @pre GetType() is a type convertible to Vector3.
294 bool Get( Vector3& vectorValue ) const;
297 * @brief Retrieve a vector value.
300 * @param [out] vectorValue On return, a vector value.
301 * @return true if the value is successfully retrieved, false if the type is not convertible
302 * @pre GetType() is a type convertible to Vector4.
304 bool Get( Vector4& vectorValue ) const;
307 * @brief Retrieve a matrix3 value.
310 * @param [out] matrixValue On return, a matrix3 value.
311 * @return true if the value is successfully retrieved, false if the type is not convertible
312 * @pre GetType() is a type convertible to Matrix3.
314 bool Get( Matrix3& matrixValue ) const;
317 * @brief Retrieve a matrix value.
320 * @param [out] matrixValue On return, a matrix value.
321 * @return true if the value is successfully retrieved, false if the type is not convertible
322 * @pre GetType() is a type convertible to Matrix.
324 bool Get( Matrix& matrixValue ) const;
327 * @brief Retrieve an angle-axis value.
330 * @param [out] angleAxisValue On return, a angle-axis value.
331 * @return true if the value is successfully retrieved, false if the type is not convertible
332 * @pre GetType() is a type convertible to AngleAxis.
334 bool Get( AngleAxis& angleAxisValue ) const;
337 * @brief Retrieve a quaternion value.
340 * @param [out] quaternionValue On return, a quaternion value.
341 * @return true if the value is successfully retrieved, false if the type is not convertible
342 * @pre GetType() is a type convertible to Quaternion.
344 bool Get( Quaternion& quaternionValue ) const;
347 * @brief Retrieve an string property value.
350 * @param [out] stringValue A string.
351 * @return true if the value is successfully retrieved, false if the type is not convertible
352 * @pre GetType() is a type convertible to string.
354 bool Get( std::string& stringValue ) const;
357 * @brief Retrieve an array property value.
360 * @param [out] arrayValue The array as a vector Property Values
361 * @return true if the value is successfully retrieved, false if the type is not convertible
362 * @pre GetType() returns Property::ARRAY.
364 bool Get( Property::Array& arrayValue ) const;
367 * @brief Retrieve an map property value.
370 * @param [out] mapValue The map as vector of string and Property Value pairs
371 * @return true if the value is successfully retrieved, false if the type is not convertible
372 * @pre GetType() returns Property::MAP.
374 bool Get( Property::Map& mapValue ) const;
377 * @brief Retrieve the Array API of the Property::Value without copying the contents of the map
380 * @return the Array API of the Property::Value or NULL if not a Property::Array
382 Property::Array* GetArray() const;
385 * @brief Retrieve the Map API of the Property::Value without copying the contents of the map
388 * @return the Map API of the Property::Value or NULL if not a Property::Map
390 Property::Map* GetMap() const;
393 * @brief output to stream
396 friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
400 struct DALI_INTERNAL Impl;
401 Impl* mImpl; ///< Pointer to the implementation
406 * @brief Convert the value of the property into a string and append to an output stream.
409 * @param [in] ouputStream The output stream operator.
410 * @param [in] value The value to insert
411 * @return The output stream operator.
413 DALI_IMPORT_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
420 #endif // __DALI_PROPERTY_VALUE_H__