equal
deleted
inserted
replaced
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 // |
7 // |
8 // Initial Contributors: |
8 // Initial Contributors: |
9 // Nokia Corporation - initial contribution. |
9 // Nokia Corporation - initial contribution. |
10 // |
10 // |
11 // Contributors: |
11 // Contributors: |
17 #define __BABITFLAGS_H__ |
17 #define __BABITFLAGS_H__ |
18 |
18 |
19 // System includes |
19 // System includes |
20 #include <e32std.h> |
20 #include <e32std.h> |
21 |
21 |
22 /////////////////////////////////////////////////////////////////////////////////////// |
22 // |
23 // ----> TBitFlagsT (header) |
23 // ----> TBitFlagsT (header) |
24 /////////////////////////////////////////////////////////////////////////////////////// |
24 // |
25 template <class T> |
25 template <class T> |
26 class TBitFlagsT |
26 class TBitFlagsT |
27 /** |
27 /** |
28 A simple class which manages the process of setting and clearing |
28 A simple class which manages the process of setting and clearing |
29 flags in an abstract fashion. |
29 flags in an abstract fashion. |
30 @publishedAll |
30 @publishedAll |
31 @released |
31 @released |
32 */ |
32 */ |
33 { |
33 { |
34 /////////////////////////////////////////////////////////////////////////////////////// |
34 // |
35 public: // CONSTRUCT |
35 public: // CONSTRUCT |
36 /////////////////////////////////////////////////////////////////////////////////////// |
36 // |
37 |
37 |
38 /** |
38 /** |
39 * Default constructor - initialize all flags to zero |
39 * Default constructor - initialize all flags to zero |
40 */ |
40 */ |
41 inline TBitFlagsT(); |
41 inline TBitFlagsT(); |
49 * Copy constructor - initialize this flag object to mirror |
49 * Copy constructor - initialize this flag object to mirror |
50 * that of aFlags. |
50 * that of aFlags. |
51 */ |
51 */ |
52 inline TBitFlagsT(const TBitFlagsT& aFlags); |
52 inline TBitFlagsT(const TBitFlagsT& aFlags); |
53 |
53 |
54 /////////////////////////////////////////////////////////////////////////////////////// |
54 // |
55 public: // MANIPULATORS |
55 public: // MANIPULATORS |
56 /////////////////////////////////////////////////////////////////////////////////////// |
56 // |
57 |
57 |
58 /** |
58 /** |
59 * Set all the flags |
59 * Set all the flags |
60 */ |
60 */ |
61 inline void SetAll(); |
61 inline void SetAll(); |
87 * Change the state of a particular flag. If the flag at the specified |
87 * Change the state of a particular flag. If the flag at the specified |
88 * index was clear, then it becomes set, otherwise it becomes clear. |
88 * index was clear, then it becomes set, otherwise it becomes clear. |
89 */ |
89 */ |
90 inline void Toggle(TInt aFlagIndex); |
90 inline void Toggle(TInt aFlagIndex); |
91 |
91 |
92 /////////////////////////////////////////////////////////////////////////////////////// |
92 // |
93 public: // OPERATORS |
93 public: // OPERATORS |
94 /////////////////////////////////////////////////////////////////////////////////////// |
94 // |
95 |
95 |
96 /** |
96 /** |
97 * Check if a particular flag is set or not |
97 * Check if a particular flag is set or not |
98 * |
98 * |
99 * @return A boolean indicating whether the specified flag is set or clear |
99 * @return A boolean indicating whether the specified flag is set or clear |
111 * |
111 * |
112 * @return A boolean indicating whether the two flags are identical. |
112 * @return A boolean indicating whether the two flags are identical. |
113 */ |
113 */ |
114 inline TBool operator==(const TBitFlagsT& aFlags); |
114 inline TBool operator==(const TBitFlagsT& aFlags); |
115 |
115 |
116 /////////////////////////////////////////////////////////////////////////////////////// |
116 // |
117 public: // ACCESS |
117 public: // ACCESS |
118 /////////////////////////////////////////////////////////////////////////////////////// |
118 // |
119 |
119 |
120 /** |
120 /** |
121 * Check if a particular flag is set |
121 * Check if a particular flag is set |
122 */ |
122 */ |
123 inline TBool IsSet(TInt aFlagIndex) const; |
123 inline TBool IsSet(TInt aFlagIndex) const; |
136 * Assign a new value (directly) to this flag object. Replaces any |
136 * Assign a new value (directly) to this flag object. Replaces any |
137 * existing individual flag settings. |
137 * existing individual flag settings. |
138 */ |
138 */ |
139 inline void SetValue(T aFlags) { iFlags = aFlags; } |
139 inline void SetValue(T aFlags) { iFlags = aFlags; } |
140 |
140 |
141 /////////////////////////////////////////////////////////////////////////////////////// |
141 // |
142 private: // INTERNAL |
142 private: // INTERNAL |
143 /////////////////////////////////////////////////////////////////////////////////////// |
143 // |
144 |
144 |
145 /** |
145 /** |
146 * Generate a mask for a particular flag |
146 * Generate a mask for a particular flag |
147 */ |
147 */ |
148 inline T FlagMask(TInt aFlagIndex) const; |
148 inline T FlagMask(TInt aFlagIndex) const; |
149 |
149 |
150 /////////////////////////////////////////////////////////////////////////////////////// |
150 // |
151 public: // MEMBER DATA |
151 public: // MEMBER DATA |
152 /////////////////////////////////////////////////////////////////////////////////////// |
152 // |
153 |
153 |
154 // The underlying object container which represents the flags. |
154 // The underlying object container which represents the flags. |
155 T iFlags; |
155 T iFlags; |
156 }; |
156 }; |
157 |
157 |
181 |
181 |
182 |
182 |
183 typedef TBitFlags32 TBitFlags; |
183 typedef TBitFlags32 TBitFlags; |
184 |
184 |
185 |
185 |
186 /////////////////////////////////////////////////////////////////////////////////////// |
186 // |
187 // ----> TBitFlagsT (inlines) |
187 // ----> TBitFlagsT (inlines) |
188 /////////////////////////////////////////////////////////////////////////////////////// |
188 // |
189 template <class T> |
189 template <class T> |
190 inline TBitFlagsT<T>::TBitFlagsT() : iFlags(T(0)) |
190 inline TBitFlagsT<T>::TBitFlagsT() : iFlags(T(0)) |
191 {} |
191 {} |
192 |
192 |
193 template <class T> |
193 template <class T> |
202 inline T TBitFlagsT<T>::FlagMask(TInt aFlagIndex) const |
202 inline T TBitFlagsT<T>::FlagMask(TInt aFlagIndex) const |
203 { return T(T(1)<<aFlagIndex); } |
203 { return T(T(1)<<aFlagIndex); } |
204 |
204 |
205 template <class T> |
205 template <class T> |
206 inline TBool TBitFlagsT<T>::IsSet(TInt aFlagIndex) const |
206 inline TBool TBitFlagsT<T>::IsSet(TInt aFlagIndex) const |
207 { return iFlags & FlagMask(aFlagIndex); } |
207 { |
|
208 // All out-of-range values should return false |
|
209 if(aFlagIndex <= ((sizeof(T)<<3)-1) ) |
|
210 { |
|
211 return iFlags & FlagMask(aFlagIndex); |
|
212 } |
|
213 else |
|
214 { |
|
215 return EFalse; |
|
216 } |
|
217 |
|
218 } |
208 |
219 |
209 template <class T> |
220 template <class T> |
210 inline TBool TBitFlagsT<T>::IsClear(TInt aFlagIndex) const |
221 inline TBool TBitFlagsT<T>::IsClear(TInt aFlagIndex) const |
211 { return !IsSet(aFlagIndex); } |
222 { return !IsSet(aFlagIndex); } |
212 |
223 |