74e5940cdc137fbeaa42e90617dbc2294910b052
[platform/core/uifw/dali-core.git] / capi / dali / public-api / object / base-object.h
1 #ifndef __DALI_BASE_OBJECT_H__
2 #define __DALI_BASE_OBJECT_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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  * @addtogroup CAPI_DALI_OBJECT_MODULE
22  * @{
23  */
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/object/base-handle.h>
28 #include <dali/public-api/object/property.h>
29 #include <dali/public-api/signals/functor-delegate.h>
30
31 namespace Dali DALI_IMPORT_API
32 {
33
34 class BaseHandle;
35
36 /**
37  * @brief A base class for objects.
38  */
39 class BaseObject : public Dali::RefObject
40 {
41 public:
42
43   /**
44    * @brief Connects a void() functor to a specified signal.
45    *
46    * @pre The signal must be available in this object.
47    * @param [in] connectionTracker A connection tracker which can be used to disconnect.
48    * @param [in] signalName Name of the signal to connect to.
49    * @param [in] functor The functor to copy.
50    * @return True if the signal was available.
51    */
52   template <class T>
53   bool ConnectSignal( ConnectionTrackerInterface* connectionTracker, const std::string& signalName, const T& functor )
54   {
55     return DoConnectSignal( connectionTracker, signalName, FunctorDelegate::New( functor ) );
56   }
57
58   /**
59    * @copydoc Dali::BaseHandle::DoAction
60    */
61   bool DoAction(const std::string& actionName, const std::vector<Property::Value>& attributes);
62
63   /**
64    * @copydoc Dali::BaseHandle::GetTypeName
65    */
66   const std::string& GetTypeName() const;
67
68 public: // Not intended for application developers
69
70   /**
71    * @copydoc Dali::BaseHandle::DoConnectSignal
72    */
73   bool DoConnectSignal( ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functorDelegate );
74
75 protected:
76
77   /**
78    * @brief Default constructor.
79    */
80   BaseObject();
81
82   /**
83    * @brief A reference counted object may only be deleted by calling Unreference().
84    */
85   virtual ~BaseObject();
86
87   /**
88    * @brief Registers the object as created with the Object registry.
89    */
90   void RegisterObject();
91
92   /**
93    * @brief Unregisters the object from Object registry.
94    */
95   void UnregisterObject();
96
97 private:
98
99   // Not implemented
100   DALI_INTERNAL BaseObject(const BaseObject& rhs);
101
102   // Not implemented
103   DALI_INTERNAL BaseObject& operator=(const BaseObject& rhs);
104 };
105
106 // Helpers for public-api forwarding methods
107
108 /**
109  * @brief Get the implementation of a handle.
110  *
111  * @param[in] handle The handle
112  * @return A reference to the object the handle points at.
113  */
114 inline BaseObject& GetImplementation(Dali::BaseHandle& handle)
115 {
116   DALI_ASSERT_ALWAYS( handle && "BaseObject handle is empty" );
117
118   return handle.GetBaseObject();
119 }
120
121 /**
122  * @brief Get the implementation of a handle.
123  *
124  * @param[in] handle The handle
125  * @return A reference to the object the handle points at.
126  */
127 inline const BaseObject& GetImplementation(const Dali::BaseHandle& handle)
128 {
129   DALI_ASSERT_ALWAYS( handle && "BaseObject handle is empty" );
130
131   return handle.GetBaseObject();
132 }
133
134 } // namespace Dali
135
136 /**
137  * @}
138  */
139 # endif // __DALI_BASE_OBJECT_H__