1 #ifndef DALI_INTERNAL_OBJECT_CONNECTOR_H
2 #define DALI_INTERNAL_OBJECT_CONNECTOR_H
5 * Copyright (c) 2015 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>
31 * @brief Wrapper class which helps managing intrusive pointer assignments and Connect / Disconnect.
33 * Should be used with objects that implement Dali::Internal::Connectable
35 template<typename Object>
39 typedef IntrusivePtr<Object> ObjectPtr;
42 * @brief Default constructor.
52 * @brief Copy constructor
54 ObjectConnector( const ObjectConnector& connector )
55 : mObject( connector.mObject )
60 * @brief Assignment operator
62 ObjectConnector& operator=( const ObjectConnector& connector )
64 this->mObject = connector.mObject;
69 * @brief Returns a smart pointer to the object
70 * @return a smart pointer to the object
78 * @brief Assigns the object, calling Connect and Disconnect methods accordingly, taking onStage into account.
79 * @param [in] object smart pointer to a object
80 * @param [in] onStage whether the object is used on stage or not
82 void Set( Object& object, bool onStage )
84 if ( mObject.Get() != &object )
86 // Disconnect from old object
87 if ( mObject && onStage )
89 mObject->Disconnect();
94 // Connect to new object
95 if ( mObject && onStage )
103 * @brief Manages connection reference count.
105 * Must be called from owner when connected to stage.
107 void OnStageConnect()
116 * @brief Manages connection reference count.
118 * Must be called from owner when disconnecting from stage.
120 void OnStageDisconnect()
124 mObject->Disconnect();
129 ObjectPtr mObject; ///< intrusive pointer to the Object. ObjectConnector owns this.
133 } // namespace Internal
137 #endif // DALI_INTERNAL_OBJECT_CONNECTOR_H