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 #ifndef _FUI_INTERNAL_SHARED_PTR_H_
19 #define _FUI_INTERNAL_SHARED_PTR_H_
23 namespace Tizen { namespace Ui
26 template<typename BaseType>
31 unsigned int* _useCount;
40 explicit _SharedPtr(BaseType* pInstance)
41 : _pInstance(pInstance)
42 , _useCount(new (std::nothrow) unsigned int (1))
46 _SharedPtr(const _SharedPtr& refInstance)
50 _pInstance = refInstance._pInstance;
51 _useCount = refInstance._useCount;
57 virtual ~_SharedPtr(void)
62 _SharedPtr& operator =(const _SharedPtr& refInstance)
64 if (_pInstance == refInstance._pInstance)
71 _pInstance = refInstance._pInstance;
72 _useCount = refInstance._useCount;
82 inline BaseType& operator *(void) const
84 // assert(_pInstance);
88 inline BaseType* operator ->(void) const
93 inline BaseType* Get(void) const
98 void Bind(BaseType* rep)
100 if (!_pInstance && !_useCount)
102 _useCount = new (std::nothrow) unsigned int(1);
107 inline bool Unique(void) const
109 return (_useCount) ? (*_useCount == 1) : true;
112 inline unsigned int UseCount() const
114 return (_useCount) ? *_useCount : 0;
117 inline unsigned int* UseCountPointer(void) const
122 inline bool IsNull(void) const
124 return (_pInstance == 0);
127 inline void SetNull(void)
138 inline void _Release(void)
142 if (--(*_useCount) == 0)
149 virtual void _Destroy(void)
156 template<typename BaseType1, typename BaseType2> inline bool
157 operator ==(_SharedPtr <BaseType1> const& a, _SharedPtr <BaseType2> const& b)
159 return a.Get() == b.Get();
162 template<typename BaseType1, typename BaseType2> inline bool
163 operator !=(_SharedPtr <BaseType1> const& a, _SharedPtr <BaseType2> const& b)
165 return a.Get() != b.Get();
171 #endif // _FUI_INTERNAL_SHARED_PTR_H_