use modern construct 'override' in the derive class.
[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   ~BaseObject() override;
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   // Not copyable or movable
118
119   BaseObject(const BaseObject& rhs) = delete; ///< Deleted copy constructor
120   BaseObject(BaseObject&& rhs) = delete; ///< Deleted move constructor
121   BaseObject& operator=(const BaseObject& rhs) = delete; ///< Deleted copy assignment operator
122   BaseObject& operator=(BaseObject&& rhs) = delete; ///< Deleted move assignment operator
123
124 public:
125
126   class DALI_INTERNAL Impl;
127
128 private:
129
130   std::unique_ptr<Impl> mImpl;
131 };
132
133 // Helpers for public-api forwarding methods
134
135 /**
136  * @brief Gets the implementation of a handle.
137  *
138  * @SINCE_1_0.0
139  * @param[in] handle The handle
140  * @return A reference to the object the handle points at
141  */
142 inline BaseObject& GetImplementation(Dali::BaseHandle& handle)
143 {
144   DALI_ASSERT_ALWAYS( handle && "BaseObject handle is empty" );
145
146   return handle.GetBaseObject();
147 }
148
149 /**
150  * @brief Gets the implementation of a handle.
151  *
152  * @SINCE_1_0.0
153  * @param[in] handle The handle
154  * @return A reference to the object the handle points at
155  */
156 inline const BaseObject& GetImplementation(const Dali::BaseHandle& handle)
157 {
158   DALI_ASSERT_ALWAYS( handle && "BaseObject handle is empty" );
159
160   return handle.GetBaseObject();
161 }
162
163 /**
164  * @}
165  */
166 } // namespace Dali
167
168 # endif // __DALI_BASE_OBJECT_H__