[dali_1.9.20] 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/ref-object.h>
26 #include <dali/public-api/object/base-handle.h>
27 #include <dali/public-api/object/property.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   /**
48    * @brief Connects a void() functor to a specified signal.
49    *
50    * @SINCE_1_0.0
51    * @param[in] connectionTracker A connection tracker which can be used to disconnect
52    * @param[in] signalName Name of the signal to connect to
53    * @param[in] functor The functor to copy
54    * @return True if the signal was available
55    * @pre The signal must be available in this object.
56    */
57   template <class T>
58   bool ConnectSignal( ConnectionTrackerInterface* connectionTracker, const std::string& signalName, const T& functor )
59   {
60     return DoConnectSignal( connectionTracker, signalName, FunctorDelegate::New( functor ) );
61   }
62
63   /**
64    * @copydoc Dali::BaseHandle::DoAction
65    */
66   bool DoAction(const std::string& actionName, const Property::Map& attributes);
67
68   /**
69    * @copydoc Dali::BaseHandle::GetTypeName
70    */
71   const std::string& GetTypeName() const;
72
73   /**
74    * @copydoc Dali::BaseHandle::GetTypeInfo
75    */
76   bool GetTypeInfo(Dali::TypeInfo& info) const;
77
78 public: // Not intended for application developers
79
80   /**
81    * @brief Not intended for application developers.
82    *
83    * @SINCE_1_0.0
84    * @param[in] connectionTracker A connection tracker which can be used to disconnect
85    * @param[in] signalName Name of the signal to connect to
86    * @param[in] functorDelegate A newly allocated functor delegate (takes ownership)
87    * @return True if the signal was available
88    */
89   bool DoConnectSignal( ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functorDelegate );
90
91 protected:
92
93   /**
94    * @brief Default constructor.
95    * @SINCE_1_0.0
96    */
97   BaseObject();
98
99   /**
100    * @brief A reference counted object may only be deleted by calling Unreference().
101    * @SINCE_1_0.0
102    */
103   virtual ~BaseObject();
104
105   /**
106    * @brief Registers the object as created with the Object registry.
107    * @SINCE_1_0.0
108    */
109   void RegisterObject();
110
111   /**
112    * @brief Unregisters the object from Object registry.
113    * @SINCE_1_0.0
114    */
115   void UnregisterObject();
116
117 private:
118
119   // Not implemented
120   DALI_INTERNAL BaseObject(const BaseObject& rhs);
121
122   // Not implemented
123   DALI_INTERNAL BaseObject& operator=(const BaseObject& rhs);
124
125 public:
126
127   class DALI_INTERNAL Impl;
128
129 private:
130
131   std::unique_ptr<Impl> mImpl;
132 };
133
134 // Helpers for public-api forwarding methods
135
136 /**
137  * @brief Gets the implementation of a handle.
138  *
139  * @SINCE_1_0.0
140  * @param[in] handle The handle
141  * @return A reference to the object the handle points at
142  */
143 inline BaseObject& GetImplementation(Dali::BaseHandle& handle)
144 {
145   DALI_ASSERT_ALWAYS( handle && "BaseObject handle is empty" );
146
147   return handle.GetBaseObject();
148 }
149
150 /**
151  * @brief Gets the implementation of a handle.
152  *
153  * @SINCE_1_0.0
154  * @param[in] handle The handle
155  * @return A reference to the object the handle points at
156  */
157 inline const BaseObject& GetImplementation(const Dali::BaseHandle& handle)
158 {
159   DALI_ASSERT_ALWAYS( handle && "BaseObject handle is empty" );
160
161   return handle.GetBaseObject();
162 }
163
164 /**
165  * @}
166  */
167 } // namespace Dali
168
169 # endif // __DALI_BASE_OBJECT_H__