|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Handle declaration |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 3 % |
|
20 */ |
|
21 |
|
22 #ifndef WLANHANDLE_H |
|
23 #define WLANHANDLE_H |
|
24 |
|
25 #include "wlanobject.h" |
|
26 |
|
27 /** |
|
28 * Just another handle in the handle body idiom |
|
29 * |
|
30 * |
|
31 * @lib wlanosa.lib |
|
32 * @since S60 v3.2 |
|
33 */ |
|
34 template<class T> |
|
35 class Handle : public DBase, public WlanObject |
|
36 { |
|
37 typedef Handle<T> Self; |
|
38 |
|
39 friend TBool operator== ( const Self& aLhs, const Self& aRhs); |
|
40 |
|
41 public: |
|
42 |
|
43 /** |
|
44 * ctor |
|
45 * NOTE: call IsValid() member from super class |
|
46 * to validate object after ctor |
|
47 * |
|
48 * @since S60 v3.2 |
|
49 * @param aElem data to be handled |
|
50 */ |
|
51 explicit inline Handle( T& aElem ); |
|
52 |
|
53 /** |
|
54 * delete data to be handled if this is the last owner |
|
55 * |
|
56 * @since S60 v3.2 |
|
57 */ |
|
58 virtual ~Handle(); |
|
59 |
|
60 /** |
|
61 * copy ctor (one more owner for the data) |
|
62 * |
|
63 * @since S60 v3.2 |
|
64 * @param aElem me, myself and I |
|
65 */ |
|
66 inline Handle( const Self& aElem ); |
|
67 |
|
68 /** |
|
69 * assignment operator (unshare old and share the new value) |
|
70 * |
|
71 * @since S60 v3.2 |
|
72 * @param aElem me, myself and I |
|
73 * @return me, myself and I |
|
74 */ |
|
75 inline Self& operator=( const Self& aElem ); |
|
76 |
|
77 /** |
|
78 * operator -> |
|
79 * |
|
80 * @since S60 v3.2 |
|
81 * @return representation |
|
82 */ |
|
83 inline T* operator->(); |
|
84 |
|
85 /** |
|
86 * extract data that is handled |
|
87 * |
|
88 * @since S60 v3.2 |
|
89 * @return data that is handled |
|
90 */ |
|
91 inline T* Data(); |
|
92 |
|
93 /** |
|
94 * extract data that is handled |
|
95 * |
|
96 * @since S60 v3.2 |
|
97 * @return data that is handled |
|
98 */ |
|
99 inline const T* Data() const; |
|
100 |
|
101 /** |
|
102 * rebind handle to a new representation |
|
103 * |
|
104 * @since S60 v3.2 |
|
105 * @param aElem data to be handled |
|
106 * @return ETrue for success any other failure |
|
107 */ |
|
108 inline TBool Bind( T& aElem ); |
|
109 |
|
110 private: |
|
111 |
|
112 /** |
|
113 * removes the reference to the representation |
|
114 * |
|
115 * @since S60 v3.2 |
|
116 */ |
|
117 inline void Dispose(); |
|
118 |
|
119 private: // data |
|
120 |
|
121 /** |
|
122 * data to be handled |
|
123 */ |
|
124 T* iData; |
|
125 |
|
126 /** |
|
127 * reference count for the data to be handled |
|
128 */ |
|
129 TInt* iRefCount; |
|
130 }; |
|
131 |
|
132 template<class T> |
|
133 inline TBool operator== ( const Handle<T>& aLhs, const Handle<T>& aRhs) |
|
134 { |
|
135 return ( *(aLhs.iData) == *(aRhs.iData) ); |
|
136 } |
|
137 |
|
138 #include "osahandle.inl" |
|
139 |
|
140 #endif // WLANHANDLE_H |