Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / public-api / object / indirect-value.h
1 #ifndef DALI_INDIRECT_VALUE_H
2 #define DALI_INDIRECT_VALUE_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 #include <dali/public-api/common/intrusive-ptr.h>
21 #include <dali/public-api/object/property-value.h>
22 #include <dali/public-api/object/property.h>
23 #include <dali/public-api/object/ref-object.h>
24
25 namespace Dali
26 {
27 /**
28  * @addtogroup dali_core_object
29  * @{
30  */
31
32 class Handle;
33
34 /**
35  * @brief Dali::IndirectValue is an intermediate object that enables a simpler
36  * syntax for addressing properties.
37  *
38  * @SINCE_1_9.27
39  * object["property"] = value;
40  * float value = object["property"];
41  *
42  * It is not intended to be directly instantiated, instead, any Handle type
43  * will generate a temporary object using the above syntax.
44  */
45 class DALI_CORE_API IndirectValue
46 {
47 public:
48   /**
49    * @brief Assignment operator
50    *
51    * @SINCE_1_9.27
52    * Enables "handle[property] = value" syntax.
53    * @param[in] value The value to assign
54    */
55   void operator=(Property::Value value);
56
57   /**
58    * @brief Explicit cast operator for property value.
59    *
60    * @SINCE_1_9.27
61    * Enables implicit promotion of this to a Property::Value type parameter
62    * @return The property value
63    */
64   operator Property::Value()
65   {
66     return GetProperty();
67   }
68
69   /**
70    * @brief Cast operator
71    *
72    * @SINCE_1_9.27
73    * Enables "value = handle[property]" syntax.
74    * @tparam Type The type of the associated property
75    * @return The associated property cast to the desired type
76    */
77   template<typename Type>
78   inline operator Type()
79   {
80     Property::Value value = GetProperty();
81     return value.Get<Type>();
82   }
83
84 private:
85   /// @cond internal
86
87   /**
88    * @brief Move constructor.
89    *
90    * @SINCE_1_9.27
91    * Making this private to prevent construction of auto type or IndirectValue type.
92    * @param[in] rhs The object to move
93    */
94   DALI_INTERNAL IndirectValue(IndirectValue&& rhs);
95
96   /**
97    * @brief Move assignment operator.
98    *
99    * @SINCE_1_9.27
100    * Making this private to prevent assignment to auto type or IndirectValue type.
101    * @param[in] rhs The object to move
102    */
103   DALI_INTERNAL IndirectValue& operator=(IndirectValue&& rhs);
104
105   /**
106    * @brief Accessor for handle property.
107    *
108    * @SINCE_1_9.27
109    * @return The handle's property value
110    * @note Asserts if the handle is empty
111    */
112   Property::Value GetProperty();
113
114   friend class Handle; ///< Only Handle types can construct this object
115
116   /**
117    * @brief Private constructor
118    *
119    * @SINCE_1_9.27
120    * @param[in] handle A reference to the associated handle
121    * @param[in] index The index to the associated property
122    */
123   DALI_INTERNAL IndirectValue(Handle& handle, Property::Index index);
124
125 private:
126   IntrusivePtr<Dali::RefObject> mHandle; ///< A handle to the property owner
127   Property::Index               mIndex;  ///< Index of the property in the property owner.
128
129   struct Extension;      ///< Reserved for future use
130   Extension* mExtension; ///< Reserved for future use
131
132   /// @endcond
133 };
134
135 /**
136  * @}
137  */
138 } // Namespace Dali
139
140 #endif // DALI_INDIRECT_VALUE_H