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;
222 * @brief Retrieve a specific value.
224 * Works on a best-effort approach; if value type is not convertible returns a default value of the type
227 * @return A value of type T.
229 template <typename T>
230 T DALI_INTERNAL Get() const
232 T temp = T(); // value (zero) initialize
238 * @brief Retrieve a boolean value.
241 * @param [out] boolValue On return, a boolean value.
242 * @return true if the value is successfully retrieved, false if the type is not convertible
243 * @pre GetType() is a type convertible to bool.
245 bool Get( bool& boolValue ) const;
248 * @brief Retrieve a floating-point value.
251 * @param [out] floatValue On return, a floating-point value.
252 * @return true if the value is successfully retrieved, false if the type is not convertible
253 * @pre GetType() is a type convertible to float.
255 bool Get( float& floatValue ) const;
258 * @brief Retrieve an integer value.
261 * @param [out] integerValue On return, an integer value.
262 * @return true if the value is successfully retrieved, false if the type is not convertible
263 * @pre GetType() is a type convertible to int.
265 bool Get( int& integerValue ) const;
268 * @brief Retrieve an integer rectangle.
271 * @param [out] rect On return, an integer rectangle.
272 * @return true if the value is successfully retrieved, false if the type is not convertible
273 * @pre GetType() is a type convertible to Rect<int>.
275 bool Get( Rect<int>& rect ) const;
278 * @brief Retrieve a vector value.
281 * @param [out] vectorValue On return, a vector value.
282 * @return true if the value is successfully retrieved, false if the type is not convertible
283 * @pre GetType() is a type convertible to Vector2.
285 bool Get( Vector2& vectorValue ) const;
288 * @brief Retrieve a vector value.
291 * @param [out] vectorValue On return, a vector value.
292 * @return true if the value is successfully retrieved, false if the type is not convertible
293 * @pre GetType() is a type convertible to Vector3.
295 bool Get( Vector3& vectorValue ) const;
298 * @brief Retrieve a vector value.
301 * @param [out] vectorValue On return, a vector value.
302 * @return true if the value is successfully retrieved, false if the type is not convertible
303 * @pre GetType() is a type convertible to Vector4.
305 bool Get( Vector4& vectorValue ) const;
308 * @brief Retrieve a matrix3 value.
311 * @param [out] matrixValue On return, a matrix3 value.
312 * @return true if the value is successfully retrieved, false if the type is not convertible
313 * @pre GetType() is a type convertible to Matrix3.
315 bool Get( Matrix3& matrixValue ) const;
318 * @brief Retrieve a matrix value.
321 * @param [out] matrixValue On return, a matrix value.
322 * @return true if the value is successfully retrieved, false if the type is not convertible
323 * @pre GetType() is a type convertible to Matrix.
325 bool Get( Matrix& matrixValue ) const;
328 * @brief Retrieve an angle-axis value.
331 * @param [out] angleAxisValue On return, a angle-axis value.
332 * @return true if the value is successfully retrieved, false if the type is not convertible
333 * @pre GetType() is a type convertible to AngleAxis.
335 bool Get( AngleAxis& angleAxisValue ) const;
338 * @brief Retrieve a quaternion value.
341 * @param [out] quaternionValue On return, a quaternion value.
342 * @return true if the value is successfully retrieved, false if the type is not convertible
343 * @pre GetType() is a type convertible to Quaternion.
345 bool Get( Quaternion& quaternionValue ) const;
348 * @brief Retrieve an string property value.
351 * @param [out] stringValue A string.
352 * @return true if the value is successfully retrieved, false if the type is not convertible
353 * @pre GetType() is a type convertible to string.
355 bool Get( std::string& stringValue ) const;
358 * @brief Retrieve an array property value.
361 * @param [out] arrayValue The array as a vector Property Values
362 * @return true if the value is successfully retrieved, false if the type is not convertible
363 * @pre GetType() returns Property::ARRAY.
365 bool Get( Property::Array& arrayValue ) const;
368 * @brief Retrieve an map property value.
371 * @param [out] mapValue The map as vector of string and Property Value pairs
372 * @return true if the value is successfully retrieved, false if the type is not convertible
373 * @pre GetType() returns Property::MAP.
375 bool Get( Property::Map& mapValue ) const;
378 * @brief Retrieve the Array API of the Property::Value without copying the contents of the map
381 * @return the Array API of the Property::Value or NULL if not a Property::Array
383 Property::Array* GetArray() const;
386 * @brief Retrieve the Map API of the Property::Value without copying the contents of the map
389 * @return the Map API of the Property::Value or NULL if not a Property::Map
391 Property::Map* GetMap() const;
394 * @brief output to stream
397 friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
401 struct DALI_INTERNAL Impl;
402 Impl* mImpl; ///< Pointer to the implementation
407 * @brief Convert the value of the property into a string and append to an output stream.
410 * @param [in] ouputStream The output stream operator.
411 * @param [in] value The value to insert
412 * @return The output stream operator.
414 DALI_IMPORT_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
421 #endif // __DALI_PROPERTY_VALUE_H__