1 #ifndef DALI_INTERNAL_OBJECT_CONNECTOR_H
2 #define DALI_INTERNAL_OBJECT_CONNECTOR_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/intrusive-ptr.h>
29 * @brief Wrapper class which helps managing intrusive pointer assignments and Connect / Disconnect.
31 * Should be used with objects that implement Dali::Internal::Connectable
33 template<typename Object>
37 using ObjectPtr = IntrusivePtr<Object>;
40 * @brief Default constructor.
42 ObjectConnector() = default;
47 ~ObjectConnector() = default;
50 * @brief Copy constructor
52 ObjectConnector(const ObjectConnector& connector)
53 : mObject(connector.mObject)
58 * @brief Assignment operator
60 ObjectConnector& operator=(const ObjectConnector& connector)
62 this->mObject = connector.mObject;
67 * @brief Returns a smart pointer to the object
68 * @return a smart pointer to the object
76 * @brief Assigns the object, calling Connect and Disconnect methods accordingly, taking onScene into account.
77 * @param [in] object smart pointer to a object
78 * @param [in] onScene whether the object is used on stage or not
80 void Set(Object& object, bool onScene)
82 if(mObject.Get() != &object)
84 // Disconnect from old object
85 if(mObject && onScene)
87 mObject->Disconnect();
92 // Connect to new object
93 if(mObject && onScene)
101 * @brief Manages connection reference count.
103 * Must be called from owner when connected to the scene.
105 void OnSceneConnect()
114 * @brief Manages connection reference count.
116 * Must be called from owner when disconnecting from the scene.
118 void OnSceneDisconnect()
122 mObject->Disconnect();
127 ObjectPtr mObject; ///< intrusive pointer to the Object. ObjectConnector owns this.
130 } // namespace Internal
134 #endif // DALI_INTERNAL_OBJECT_CONNECTOR_H