sync with tizen_2.0
[platform/framework/native/appfw.git] / src / base / inc / FBase_HandleT.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FBase_HandleT.h
20  * @brief       This is the header file for the %_HandleT class.
21  *
22  * This file contains the declarations of the %_HandleT class.
23  */
24
25 #ifndef _FBASE_INTERNAL_HANDLE_TEMPLATE_H_
26 #define _FBASE_INTERNAL_HANDLE_TEMPLATE_H_
27
28 #include <FBaseObject.h>
29 #include "FBase_ObjectManagerImpl.h"
30
31 namespace Tizen { namespace Base
32 {
33
34 template<typename T>
35 class _ObjectManagerT;
36
37 template<typename T>
38 class _HandleT
39         : public Tizen::Base::Object
40 {
41 public:
42         /**
43          * This is the default constructor for this class.
44          *
45          * @since 2.0
46          */
47         _HandleT(void)
48                 : __handle(0), __pObjectManagerImpl(null)
49         {
50         }
51
52         /**
53          * This is the destructor for this class.
54          *
55          * @since 2.0
56          */
57         virtual ~_HandleT(void)
58         {
59         }
60
61         /**
62          * Checks whether the handle is initialized or not.
63          *
64          * @since 2.0
65          * @return              @c true if the handle is not initialized, @n
66          else @c false
67          */
68         bool IsNull(void) const
69         {
70                 return __handle == 0;
71         }
72
73         /**
74          * Checks whether the handle is valid or not.
75          *
76          * @since 2.0
77          * return @c true if the handle is valid, @n else @c false
78          */
79         bool IsValid(void) const
80         {
81                 if (__handle == 0 || __pObjectManagerImpl == null)
82                 {
83                         return false;
84                 }
85
86                 return __pObjectManagerImpl->IsValidHandle(__handle);
87         }
88
89         /**
90          * Get the signed @c int equivalent of the current instance.
91          *
92          * @since 2.0
93          * @return Signed @c int equivalent of the current instance
94          */
95         int ToInt(void) const
96         {
97                 return (int)__handle;
98         }
99
100         /**
101          * Checks whether the two instances of _HandleT are equal.
102          *
103          * @since 2.0
104          * @return              @c true if the values of the two instances of _HandleT are similar, @n
105          *                      else @c false
106          * @param[in]   rhs             An instance of %_HandleT
107          */
108         inline bool operator ==(const _HandleT <T>& rhs) const
109         {
110                 return __handle == rhs.__handle;
111         }
112
113         /**
114          * Checks whether the two instances of _HandleT are not equal.
115          *
116          * @since 2.0
117          * @return              @c true if the values of the two instances of _HandleT are not similar, @n
118          *                      else @c false
119          * @param[in]   rhs             An instance of %_HandleT
120          *
121          */
122         inline bool operator !=(const _HandleT <T>& rhs) const
123         {
124                 return !(*this == rhs);
125         }
126
127         _HandleT(const _HandleT<T>& handle)
128         {
129                 this->__handle = handle.__handle;
130                 this->__pObjectManagerImpl = handle.__pObjectManagerImpl;
131         }
132
133         _HandleT<T>& operator = (const _HandleT& handle)
134         {
135                 if (this == &handle)
136                 {
137                         return *this;
138                 }
139
140                 this->__handle = handle.__handle;
141                 this->__pObjectManagerImpl = handle.__pObjectManagerImpl;
142
143                 return *this;
144         }
145
146 private:
147         void Initialize(unsigned int handle, _ObjectManagerImpl* pObjectManagerImpl)
148         {
149                 __handle = handle;
150                 __pObjectManagerImpl = pObjectManagerImpl;
151         }
152
153 private:
154         unsigned int __handle;
155         _ObjectManagerImpl* __pObjectManagerImpl;
156
157         friend class _ObjectManagerT <T>;
158 }; // _HandleT
159
160 }} // Tizen::Base
161
162 #endif // _FBASE_RT_INTERNAL_HANDLE_TEMPLATE_H_