2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FUi_SharedPtr.h
19 * @brief This is the header file for the _SharedPtr class.
21 * This file contains the declarations of the _SharedPtr class.
24 #ifndef _FUI_INTERNAL_SHARED_PTR_H_
25 #define _FUI_INTERNAL_SHARED_PTR_H_
29 namespace Tizen { namespace Ui
32 template<typename BaseType>
37 unsigned int* _useCount;
46 explicit _SharedPtr(BaseType* pInstance)
47 : _pInstance(pInstance)
48 , _useCount(new (std::nothrow) unsigned int (1))
52 _SharedPtr(const _SharedPtr& refInstance)
56 _pInstance = refInstance._pInstance;
57 _useCount = refInstance._useCount;
63 virtual ~_SharedPtr(void)
68 _SharedPtr& operator =(const _SharedPtr& refInstance)
70 if (_pInstance == refInstance._pInstance)
77 _pInstance = refInstance._pInstance;
78 _useCount = refInstance._useCount;
88 inline BaseType& operator *(void) const
90 // assert(_pInstance);
94 inline BaseType* operator ->(void) const
99 inline BaseType* Get(void) const
104 void Bind(BaseType* rep)
106 if (!_pInstance && !_useCount)
108 _useCount = new (std::nothrow) unsigned int(1);
113 inline bool Unique(void) const
115 return (_useCount) ? (*_useCount == 1) : true;
118 inline unsigned int UseCount() const
120 return (_useCount) ? *_useCount : 0;
123 inline unsigned int* UseCountPointer(void) const
128 inline bool IsNull(void) const
130 return (_pInstance == 0);
133 inline void SetNull(void)
144 inline void _Release(void)
148 if (--(*_useCount) == 0)
155 virtual void _Destroy(void)
162 template<typename BaseType1, typename BaseType2> inline bool
163 operator ==(_SharedPtr <BaseType1> const& a, _SharedPtr <BaseType2> const& b)
165 return a.Get() == b.Get();
168 template<typename BaseType1, typename BaseType2> inline bool
169 operator !=(_SharedPtr <BaseType1> const& a, _SharedPtr <BaseType2> const& b)
171 return a.Get() != b.Get();
177 #endif // _FUI_INTERNAL_SHARED_PTR_H_