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>
31 * @addtogroup dali-core-object
44 * @brief A value-type representing a property value.
46 class DALI_IMPORT_API Property::Value
51 * @brief Default constructor.
53 * This creates a property with type Property::NONE.
58 * @brief Create a boolean property value.
60 * @param [in] boolValue A boolean value.
62 Value( bool boolValue );
65 * @brief Create an integer property value.
67 * @param [in] integerValue An integer value.
69 Value( int integerValue );
72 * @brief Create a float property value.
74 * @param [in] floatValue A floating-point value.
76 Value( float floatValue );
79 * @brief Create a Vector2 property value.
81 * @param [in] vectorValue A vector of 2 floating-point values.
83 Value( const Vector2& vectorValue );
86 * @brief Create a Vector3 property value.
88 * @param [in] vectorValue A vector of 3 floating-point values.
90 Value( const Vector3& vectorValue );
93 * @brief Create a Vector4 property value.
95 * @param [in] vectorValue A vector of 4 floating-point values.
97 Value( const Vector4& vectorValue );
100 * @brief Create a Matrix3 property value.
102 * @param [in] matrixValue A matrix of 3x3 floating-point values.
104 Value( const Matrix3& matrixValue );
107 * @brief Create a Matrix property value.
109 * @param [in] matrixValue A matrix of 4x4 floating-point values.
111 Value( const Matrix& matrixValue );
114 * @brief Create a Vector4 property value.
116 * @param [in] vectorValue A vector of 4 integer values.
118 Value( const Rect<int>& vectorValue );
121 * @brief Create an orientation property value.
123 * @param [in] angleAxis An angle-axis representing the rotation.
125 Value( const AngleAxis& angleAxis );
128 * @brief Create an orientation property value.
130 * @param [in] quaternion A quaternion representing the rotation.
132 Value( const Quaternion& quaternion );
135 * @brief Create an string property value.
137 * @param [in] stringValue A string.
139 Value( const std::string& stringValue );
142 * @brief Create an string property value.
144 * @param [in] stringValue A string.
146 Value( const char* stringValue );
149 * @brief Create an array property value.
151 * @param [in] arrayValue An array
153 Value( Property::Array& arrayValue );
156 * @brief Create a map property value.
158 * @param [in] mapValue An array
160 Value( Property::Map& mapValue );
163 * @brief Explicitly set a type and initialize it.
165 * @param [in] type The property value type.
167 explicit Value( Type type );
170 * @brief Copy constructor
172 * @param [in] value The property value to copy.
174 Value( const Value& value );
177 * @brief Assign a property value.
179 * @param [in] value The property value to assign from.
180 * @return a reference to this
182 Value& operator=( const Value& value );
185 * @brief Non-virtual destructor.
187 * This class is not a base class.
192 * @brief Query the type of this property value.
194 * @return The type ID.
196 Type GetType() const;
199 * @brief Retrieve a specific value.
201 * Works on a best-effort approach; if value type is not convertible returns a default value of the type
203 * @return A value of type T.
205 template <typename T>
206 T DALI_INTERNAL Get() const
208 T temp = T(); // value (zero) initialize
214 * @brief Retrieve a boolean value.
216 * @pre GetType() returns Property::BOOLEAN.
217 * @param [out] boolValue On return, a boolean value.
218 * @return true if the value is successfully retrieved, false if the type is not convertible
220 bool Get( bool& boolValue ) const;
223 * @brief Retrieve a floating-point value.
225 * @pre GetType() returns Property::FLOAT.
226 * @param [out] floatValue On return, a floating-point value.
227 * @return true if the value is successfully retrieved, false if the type is not convertible
229 bool Get( float& floatValue ) const;
232 * @brief Retrieve an integer value.
234 * @pre GetType() returns Property::INTEGER.
235 * @param [out] integerValue On return, an integer value.
236 * @return true if the value is successfully retrieved, false if the type is not convertible
238 bool Get( int& integerValue ) const;
241 * @brief Retrieve an integer rectangle.
243 * @pre GetType() returns Property::RECTANGLE.
244 * @param [out] rect On return, an integer rectangle.
245 * @return true if the value is successfully retrieved, false if the type is not convertible
247 bool Get( Rect<int>& rect ) const;
250 * @brief Retrieve a vector value.
252 * @pre GetType() returns Property::VECTOR2.
253 * @param [out] vectorValue On return, a vector value.
254 * @return true if the value is successfully retrieved, false if the type is not convertible
256 bool Get( Vector2& vectorValue ) const;
259 * @brief Retrieve a vector value.
261 * @pre GetType() returns Property::VECTOR3.
262 * @param [out] vectorValue On return, a vector value.
263 * @return true if the value is successfully retrieved, false if the type is not convertible
265 bool Get( Vector3& vectorValue ) const;
268 * @brief Retrieve a vector value.
270 * @pre GetType() returns Property::VECTOR4.
271 * @param [out] vectorValue On return, a vector value.
272 * @return true if the value is successfully retrieved, false if the type is not convertible
274 bool Get( Vector4& vectorValue ) const;
277 * @brief Retrieve a matrix3 value.
279 * @pre GetType() returns Property::MATRIX3.
280 * @param [out] matrixValue On return, a matrix3 value.
281 * @return true if the value is successfully retrieved, false if the type is not convertible
283 bool Get( Matrix3& matrixValue ) const;
286 * @brief Retrieve a matrix value.
288 * @pre GetType() returns Property::MATRIX.
289 * @param [out] matrixValue On return, a matrix value.
290 * @return true if the value is successfully retrieved, false if the type is not convertible
292 bool Get( Matrix& matrixValue ) const;
295 * @brief Retrieve an angle-axis value.
297 * @pre GetType() returns Property::ROTATION.
298 * @param [out] angleAxisValue On return, a angle-axis value.
299 * @return true if the value is successfully retrieved, false if the type is not convertible
301 bool Get( AngleAxis& angleAxisValue ) const;
304 * @brief Retrieve a quaternion value.
306 * @pre GetType() returns Property::ROTATION.
307 * @param [out] quaternionValue On return, a quaternion value.
308 * @return true if the value is successfully retrieved, false if the type is not convertible
310 bool Get( Quaternion& quaternionValue ) const;
313 * @brief Retrieve an string property value.
315 * @pre GetType() returns Property::STRING.
316 * @param [out] stringValue A string.
317 * @return true if the value is successfully retrieved, false if the type is not convertible
319 bool Get( std::string& stringValue ) const;
322 * @brief Retrieve an array property value.
324 * @pre GetType() returns Property::ARRAY.
325 * @param [out] arrayValue The array as a vector Property Values
326 * @return true if the value is successfully retrieved, false if the type is not convertible
328 bool Get( Property::Array& arrayValue ) const;
331 * @brief Retrieve an map property value.
333 * @pre GetType() returns Property::MAP.
334 * @param [out] mapValue The map as vector of string and Property Value pairs
335 * @return true if the value is successfully retrieved, false if the type is not convertible
337 bool Get( Property::Map& mapValue ) const;
340 * @brief Retrieve the Array API of the Property::Value without copying the contents of the map
342 * @return the Array API of the Property::Value or NULL if not a Property::Array
344 Property::Array* GetArray() const;
347 * @brief Retrieve the Map API of the Property::Value without copying the contents of the map
349 * @return the Map API of the Property::Value or NULL if not a Property::Map
351 Property::Map* GetMap() const;
356 friend std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
360 struct DALI_INTERNAL Impl;
361 Impl* mImpl; ///< Pointer to the implementation
366 * @brief Convert the value of the property into a string and append to an output stream.
368 * @param [in] ouputStream The output stream operator.
369 * @param [in] value The value to insert
370 * @return The output stream operator.
372 DALI_IMPORT_API std::ostream& operator<<( std::ostream& ouputStream, const Property::Value& value );
379 #endif // __DALI_PROPERTY_VALUE_H__