1 #ifndef __DALI_PROPERTY_VALUE_H__
2 #define __DALI_PROPERTY_VALUE_H__
5 * Copyright (c) 2015 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>
40 * @brief A value-type representing a property value.
42 class DALI_IMPORT_API Property::Value
47 * @brief Default constructor.
49 * This creates a property with type Property::NONE.
54 * @brief Create a boolean property value.
56 * @param [in] boolValue A boolean value.
58 Value( bool boolValue );
61 * @brief Create an integer property value.
63 * @param [in] integerValue An integer value.
65 Value( int integerValue );
68 * @brief Create an unsigned integer property value.
70 * @param [in] unsignedIntegerValue An unsigned integer value.
72 Value( unsigned int unsignedIntegerValue );
75 * @brief Create a float property value.
77 * @param [in] floatValue A floating-point value.
79 Value( float floatValue );
82 * @brief Create a Vector2 property value.
84 * @param [in] vectorValue A vector of 2 floating-point values.
86 Value( const Vector2& vectorValue );
89 * @brief Create a Vector3 property value.
91 * @param [in] vectorValue A vector of 3 floating-point values.
93 Value( const Vector3& vectorValue );
96 * @brief Create a Vector4 property value.
98 * @param [in] vectorValue A vector of 4 floating-point values.
100 Value( const Vector4& vectorValue );
103 * @brief Create a Matrix3 property value.
105 * @param [in] matrixValue A matrix of 3x3 floating-point values.
107 Value( const Matrix3& matrixValue );
110 * @brief Create a Matrix property value.
112 * @param [in] matrixValue A matrix of 4x4 floating-point values.
114 Value( const Matrix& matrixValue );
117 * @brief Create a Vector4 property value.
119 * @param [in] vectorValue A vector of 4 integer values.
121 Value( const Rect<int>& vectorValue );
124 * @brief Create an orientation property value.
126 * @param [in] angleAxis An angle-axis representing the rotation.
128 Value( const AngleAxis& angleAxis );
131 * @brief Create an orientation property value.
133 * @param [in] quaternion A quaternion representing the rotation.
135 Value( const Quaternion& quaternion );
138 * @brief Create an string property value.
140 * @param [in] stringValue A string.
142 Value( const std::string& stringValue );
145 * @brief Create an string property value.
147 * @param [in] stringValue A string.
149 Value( const char* stringValue );
152 * @brief Create an array property value.
154 * @param [in] arrayValue An array
156 Value( Property::Array& arrayValue );
159 * @brief Create a map property value.
161 * @param [in] mapValue An array
163 Value( Property::Map& mapValue );
166 * @brief Explicitly set a type and initialize it.
168 * @param [in] type The property value type.
170 explicit Value( Type type );
173 * @brief Copy constructor
175 * @param [in] value The property value to copy.
177 Value( const Value& value );
180 * @brief Assign a property value.
182 * @param [in] value The property value to assign from.
183 * @return a reference to this
185 Value& operator=( const Value& value );
188 * @brief Non-virtual destructor.
190 * This class is not a base class.
195 * @brief Query the type of this property value.
197 * @return The type ID.
199 Type GetType() const;
202 * @brief Retrieve a specific value.
204 * Works on a best-effort approach; if value type is not convertible returns a default value of the type
206 * @return A value of type T.
208 template <typename T>
209 T DALI_INTERNAL Get() const
211 T temp = T(); // value (zero) initialize
217 * @brief Retrieve a boolean value.
219 * @pre GetType() returns Property::BOOLEAN.
220 * @param [out] boolValue On return, a boolean value.
221 * @return true if the value is successfully retrieved, false if the type is not convertible
223 bool Get( bool& boolValue ) const;
226 * @brief Retrieve a floating-point value.
228 * @pre GetType() returns Property::FLOAT.
229 * @param [out] floatValue On return, a floating-point value.
230 * @return true if the value is successfully retrieved, false if the type is not convertible
232 bool Get( float& floatValue ) const;
235 * @brief Retrieve an integer value.
237 * @pre GetType() returns Property::INTEGER.
238 * @param [out] integerValue On return, an integer value.
239 * @return true if the value is successfully retrieved, false if the type is not convertible
241 bool Get( int& integerValue ) const;
244 * @brief Retrieve an unsigned integer value.
246 * @pre GetType() returns Property::UNSIGNED_INTEGER.
247 * @param [out] unsignedIntegerValue On return, an unsigned integer value.
248 * @return true if the value is successfully retrieved, false if the type is not convertible
250 bool Get( unsigned int& unsignedIntegerValue ) const;
253 * @brief Retrieve an integer rectangle.
255 * @pre GetType() returns Property::RECTANGLE.
256 * @param [out] rect On return, an integer rectangle.
257 * @return true if the value is successfully retrieved, false if the type is not convertible
259 bool Get( Rect<int>& rect ) const;
262 * @brief Retrieve a vector value.
264 * @pre GetType() returns Property::VECTOR2.
265 * @param [out] vectorValue On return, a vector value.
266 * @return true if the value is successfully retrieved, false if the type is not convertible
268 bool Get( Vector2& vectorValue ) const;
271 * @brief Retrieve a vector value.
273 * @pre GetType() returns Property::VECTOR3.
274 * @param [out] vectorValue On return, a vector value.
275 * @return true if the value is successfully retrieved, false if the type is not convertible
277 bool Get( Vector3& vectorValue ) const;
280 * @brief Retrieve a vector value.
282 * @pre GetType() returns Property::VECTOR4.
283 * @param [out] vectorValue On return, a vector value.
284 * @return true if the value is successfully retrieved, false if the type is not convertible
286 bool Get( Vector4& vectorValue ) const;
289 * @brief Retrieve a matrix3 value.
291 * @pre GetType() returns Property::MATRIX3.
292 * @param [out] matrixValue On return, a matrix3 value.
293 * @return true if the value is successfully retrieved, false if the type is not convertible
295 bool Get( Matrix3& matrixValue ) const;
298 * @brief Retrieve a matrix value.
300 * @pre GetType() returns Property::MATRIX.
301 * @param [out] matrixValue On return, a matrix value.
302 * @return true if the value is successfully retrieved, false if the type is not convertible
304 bool Get( Matrix& matrixValue ) const;
307 * @brief Retrieve an angle-axis value.
309 * @pre GetType() returns Property::ROTATION.
310 * @param [out] angleAxisValue On return, a angle-axis value.
311 * @return true if the value is successfully retrieved, false if the type is not convertible
313 bool Get( AngleAxis& angleAxisValue ) const;
316 * @brief Retrieve a quaternion value.
318 * @pre GetType() returns Property::ROTATION.
319 * @param [out] quaternionValue On return, a quaternion value.
320 * @return true if the value is successfully retrieved, false if the type is not convertible
322 bool Get( Quaternion& quaternionValue ) const;
325 * @brief Retrieve an string property value.
327 * @pre GetType() returns Property::STRING.
328 * @param [out] stringValue A string.
329 * @return true if the value is successfully retrieved, false if the type is not convertible
331 bool Get( std::string& stringValue ) const;
334 * @brief Retrieve an array property value.
336 * @pre GetType() returns Property::ARRAY.
337 * @param [out] arrayValue The array as a vector Property Values
338 * @return true if the value is successfully retrieved, false if the type is not convertible
340 bool Get( Property::Array& arrayValue ) const;
343 * @brief Retrieve an map property value.
345 * @pre GetType() returns Property::MAP.
346 * @param [out] mapValue The map as vector of string and Property Value pairs
347 * @return true if the value is successfully retrieved, false if the type is not convertible
349 bool Get( Property::Map& mapValue ) const;
352 * @brief Retrieve the Array API of the Property::Value without copying the contents of the map
354 * @return the Array API of the Property::Value or NULL if not a Property::Array
356 Property::Array* GetArray() const;
359 * @brief Retrieve the Map API of the Property::Value without copying the contents of the map
361 * @return the Map API of the Property::Value or NULL if not a Property::Map
363 Property::Map* GetMap() const;
368 friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
372 struct DALI_INTERNAL Impl;
373 Impl* mImpl; ///< Pointer to the implementation
378 * @brief Convert the value of the property into a string and append to an output stream.
380 * @param [in] ouputStream The output stream operator.
381 * @param [in] value The value to insert
382 * @return The output stream operator.
384 DALI_IMPORT_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
388 #endif // __DALI_PROPERTY_VALUE_H__