|
1 /* |
|
2 * Copyright (c) 2006-2008 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 "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: Definition of ncdattributes interface and |
|
15 * implementation class. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef C_NCDATTRIBUTES_H |
|
21 #define C_NCDATTRIBUTES_H |
|
22 |
|
23 |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "ncdpanics.h" |
|
27 |
|
28 class RWriteStream; |
|
29 class RReadStream; |
|
30 |
|
31 /** |
|
32 * Simple attribute container |
|
33 * |
|
34 * Used for setting, getting, storing and loading simple |
|
35 * attributes. Currently supports 16-bit descriptors and TInt32 |
|
36 */ |
|
37 class CNcdAttributes : public CBase |
|
38 { |
|
39 public: |
|
40 |
|
41 /** |
|
42 * Types of supported attributes |
|
43 */ |
|
44 enum TAttributeType |
|
45 { |
|
46 /** |
|
47 * Attribute type is not set |
|
48 */ |
|
49 EAttributeTypeUndefined = 0, |
|
50 |
|
51 /** |
|
52 * Attribute is TInt32 |
|
53 */ |
|
54 EAttributeTypeInt32, |
|
55 |
|
56 /** |
|
57 * Attribute is a 16-bit descriptor |
|
58 */ |
|
59 EAttributeTypeString16 |
|
60 }; |
|
61 |
|
62 public: |
|
63 |
|
64 /** |
|
65 * @param aUpperLimit Upper attribute limit is NOT included in the range. Must be >= 0 and > aLowerLimit |
|
66 * |
|
67 */ |
|
68 IMPORT_C static CNcdAttributes* NewL( TInt aUpperLimit, TInt aLowerLimit = 0 ); |
|
69 |
|
70 /** |
|
71 * @note If given upperlimit differs from the one read from the stream then |
|
72 * the attribute range is adjusted for the given limit. |
|
73 * @leave KErrArgument if aLowerLimit differs from the lower limit read from the stream |
|
74 */ |
|
75 IMPORT_C static CNcdAttributes* NewL( |
|
76 RReadStream& aStream, |
|
77 TInt aUpperLimit, |
|
78 TInt aLowerLimit = 0 ); |
|
79 |
|
80 /** |
|
81 * Copy constructor |
|
82 */ |
|
83 IMPORT_C static CNcdAttributes* NewL( const CNcdAttributes& aAttributes ); |
|
84 |
|
85 |
|
86 /** |
|
87 * Destructor |
|
88 */ |
|
89 IMPORT_C virtual ~CNcdAttributes(); |
|
90 |
|
91 public: |
|
92 |
|
93 /** |
|
94 * Lower limit getter |
|
95 */ |
|
96 IMPORT_C TInt RangeLowerLimit() const; |
|
97 |
|
98 /** |
|
99 * Upper limit getter |
|
100 */ |
|
101 IMPORT_C TInt RangeUpperLimit() const; |
|
102 |
|
103 /** |
|
104 * TInt32 attribute setter |
|
105 * |
|
106 * @param aAttribute Attribute |
|
107 * @param aValue Value |
|
108 * @panic ENcdPanicIndexOutOfRange if aAttribute is not |
|
109 * RangeLowerLimit() <= aAttribute < RangeUpperLimit() |
|
110 * @panic ENcdPanicInvalidArgument if the attribute type is not |
|
111 * EAttributeTypeInt32 or EAttributeTypeUndefined |
|
112 */ |
|
113 IMPORT_C void SetAttributeL( TInt aAttribute, TInt32 aValue ); |
|
114 |
|
115 /** |
|
116 * 16-bit descriptor attribute setter |
|
117 * |
|
118 * @param aAttribute Attribute |
|
119 * @param aValue Value |
|
120 * @leave KErrNoMemory if memory runs out |
|
121 * @panic ENcdPanicIndexOutOfRange if aAttribute is not |
|
122 * RangeLowerLimit() <= aAttribute < RangeUpperLimit() |
|
123 * @panic ENcdPanicInvalidArgument if the attribute type is not |
|
124 * EAttributeTypeString16 or EAttributeTypeUndefined |
|
125 */ |
|
126 IMPORT_C void SetAttributeL( TInt aAttribute, const TDesC& aValue ); |
|
127 |
|
128 /** |
|
129 * 16-bit descriptor attribute getter |
|
130 * |
|
131 * @param aAttribute Attribute |
|
132 * @return Value of the attribute |
|
133 * @panic ENcdPanicIndexOutOfRange if aAttribute is not |
|
134 * RangeLowerLimit() <= aAttribute < RangeUpperLimit() |
|
135 * @panic ENcdPanicInvalidArgument if the attribute type is not |
|
136 * EAttributeTypeString16 |
|
137 */ |
|
138 IMPORT_C const TDesC& AttributeString16( TInt aAttribute ) const; |
|
139 |
|
140 |
|
141 /** |
|
142 * TInt32 attribute getter |
|
143 * |
|
144 * @param aAttribute Attribute |
|
145 * @return Value of the attribute |
|
146 * @panic ENcdPanicIndexOutOfRange if aAttribute is not |
|
147 * RangeLowerLimit() <= aAttribute < RangeUpperLimit() |
|
148 * @panic ENcdPanicInvalidArgument if the attribute type is not |
|
149 * EAttributeTypeInt32 |
|
150 */ |
|
151 IMPORT_C TInt32 AttributeInt32( TInt aAttribute ) const; |
|
152 |
|
153 |
|
154 /** |
|
155 * Attribute type getter |
|
156 * |
|
157 * @param aAttribute |
|
158 * @return Attribute type |
|
159 * @panic ENcdPanicIndexOutOfRange if aAttribute is not |
|
160 * RangeLowerLimit() <= aAttribute < RangeUpperLimit() |
|
161 */ |
|
162 IMPORT_C TAttributeType AttributeType( TInt aAttribute ) const; |
|
163 |
|
164 public: |
|
165 |
|
166 IMPORT_C void ExternalizeL( RWriteStream& aStream ) const; |
|
167 IMPORT_C void InternalizeL( RReadStream& aStream ); |
|
168 |
|
169 protected: |
|
170 |
|
171 // Union that contains all possible attribute types |
|
172 union TAttributeUnion |
|
173 { |
|
174 HBufC* iString16; |
|
175 TInt32 iInt32; |
|
176 }; |
|
177 |
|
178 // Attribute |
|
179 struct TAttribute |
|
180 { |
|
181 TAttributeType iType; |
|
182 TAttributeUnion iAttribute; |
|
183 |
|
184 TAttribute() : iType( EAttributeTypeUndefined ) |
|
185 { |
|
186 iAttribute.iString16 = NULL; |
|
187 } |
|
188 }; |
|
189 |
|
190 |
|
191 protected: |
|
192 |
|
193 CNcdAttributes( TInt aUpperLimit, TInt aLowerLimit ); |
|
194 void ConstructL(); |
|
195 void ConstructL( const CNcdAttributes& aAttributes ); |
|
196 |
|
197 // Deletes all attributes, array size is reduced to 0 |
|
198 void ClearAttributes(); |
|
199 |
|
200 // Deletes all attributes and resets the array to have |
|
201 // room for the attribute range, array size == ArraySize() |
|
202 void ResetAttributesL(); |
|
203 |
|
204 // Size needed for containing the attribute range |
|
205 TInt ArraySize() const; |
|
206 |
|
207 |
|
208 // Attribute externalization and internalization |
|
209 void ExternalizeAttributeL( |
|
210 const TAttribute& aAttribute, RWriteStream& aStream ) const; |
|
211 |
|
212 TAttribute InternalizeAttributeL( RReadStream& aStream ) const; |
|
213 |
|
214 // Deletes attribute's internals |
|
215 void DeleteAttribute( TAttribute& aAttribute ); |
|
216 |
|
217 // Copies attribute's internals and returns the copy |
|
218 TAttribute CopyAttributeL( const TAttribute& aAttribute ) const; |
|
219 |
|
220 // Indexing methods |
|
221 const TAttribute& Attribute( TInt aAttribute ) const; |
|
222 TAttribute& Attribute( TInt aAttribute ); |
|
223 |
|
224 private: |
|
225 |
|
226 CNcdAttributes( const CNcdAttributes& ); |
|
227 CNcdAttributes& operator=( const CNcdAttributes& ); |
|
228 |
|
229 private: |
|
230 |
|
231 TInt iLowerLimit; |
|
232 TInt iUpperLimit; |
|
233 |
|
234 // Attribute array |
|
235 RArray<TAttribute> iAttributes; |
|
236 }; |
|
237 |
|
238 |
|
239 #endif // M_NCDATTRIBUTES_H |