[dali_2.3.26] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / public-api / object / base-object.h
1 #ifndef DALI_BASE_OBJECT_H
2 #define DALI_BASE_OBJECT_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
21 // EXTERNAL INCLUDES
22 #include <memory>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/object/base-handle.h>
26 #include <dali/public-api/object/property.h>
27 #include <dali/public-api/object/ref-object.h>
28 #include <dali/public-api/signals/functor-delegate.h>
29
30 namespace Dali
31 {
32 /**
33  * @addtogroup dali_core_object
34  * @{
35  */
36
37 class BaseHandle;
38
39 /**
40  * @brief A base class for objects.
41  * @SINCE_1_0.0
42  */
43 class DALI_CORE_API BaseObject : public Dali::RefObject
44 {
45 public:
46   /**
47    * @brief Connects a void() functor to a specified signal.
48    *
49    * @SINCE_1_0.0
50    * @param[in] connectionTracker A connection tracker which can be used to disconnect
51    * @param[in] signalName Name of the signal to connect to
52    * @param[in] functor The functor to copy
53    * @return True if the signal was available
54    * @pre The signal must be available in this object.
55    */
56   template<class T>
57   bool ConnectSignal(ConnectionTrackerInterface* connectionTracker, const std::string& signalName, const T& functor)
58   {
59     return DoConnectSignal(connectionTracker, signalName, FunctorDelegate::New(functor));
60   }
61
62   /**
63    * @copydoc Dali::BaseHandle::DoAction
64    */
65   bool DoAction(const std::string& actionName, const Property::Map& attributes);
66
67   /**
68    * @copydoc Dali::BaseHandle::GetTypeName
69    */
70   const std::string& GetTypeName() const;
71
72   /**
73    * @copydoc Dali::BaseHandle::GetTypeInfo
74    */
75   bool GetTypeInfo(Dali::TypeInfo& info) const;
76
77 public: // Not intended for application developers
78   /**
79    * @brief Not intended for application developers.
80    *
81    * @SINCE_1_0.0
82    * @param[in] connectionTracker A connection tracker which can be used to disconnect
83    * @param[in] signalName Name of the signal to connect to
84    * @param[in] functorDelegate A newly allocated functor delegate (takes ownership)
85    * @return True if the signal was available
86    */
87   bool DoConnectSignal(ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functorDelegate);
88
89 protected:
90   /**
91    * @brief Default constructor.
92    * @SINCE_1_0.0
93    */
94   BaseObject();
95
96   /**
97    * @brief A reference counted object may only be deleted by calling Unreference().
98    * @SINCE_1_0.0
99    */
100   ~BaseObject() override;
101
102   /**
103    * @brief Registers the object as created with the Object registry.
104    * @SINCE_1_0.0
105    */
106   void RegisterObject();
107
108   /**
109    * @brief Unregisters the object from Object registry.
110    * @SINCE_1_0.0
111    */
112   void UnregisterObject();
113
114   // Not copyable or movable
115
116   BaseObject(const BaseObject& rhs) = delete;            ///< Deleted copy constructor
117   BaseObject(BaseObject&& rhs)      = delete;            ///< Deleted move constructor
118   BaseObject& operator=(const BaseObject& rhs) = delete; ///< Deleted copy assignment operator
119   BaseObject& operator=(BaseObject&& rhs) = delete;      ///< Deleted move assignment operator
120
121 public:
122   class DALI_INTERNAL Impl;
123
124 private:
125   std::unique_ptr<Impl> mImpl;
126 };
127
128 // Helpers for public-api forwarding methods
129
130 /**
131  * @brief Gets the implementation of a handle.
132  *
133  * @SINCE_1_0.0
134  * @param[in] handle The handle
135  * @return A reference to the object the handle points at
136  */
137 inline BaseObject& GetImplementation(Dali::BaseHandle& handle)
138 {
139   DALI_ASSERT_ALWAYS(handle && "BaseObject handle is empty");
140
141   return handle.GetBaseObject();
142 }
143
144 /**
145  * @brief Gets the implementation of a handle.
146  *
147  * @SINCE_1_0.0
148  * @param[in] handle The handle
149  * @return A reference to the object the handle points at
150  */
151 inline const BaseObject& GetImplementation(const Dali::BaseHandle& handle)
152 {
153   DALI_ASSERT_ALWAYS(handle && "BaseObject handle is empty");
154
155   return handle.GetBaseObject();
156 }
157
158 /**
159  * @}
160  */
161 } // namespace Dali
162
163 #endif // __DALI_BASE_OBJECT_H__