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