2 * Copyright (c) 2003-2005 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Variant data type for AIW generic parameters.
29 #include "AiwVariantType.hrh"
31 // FORWARD DECLARATIONS
36 * Variant data class to hold a value of a TAiwGenericParam instance.
37 * The variant contains a data type and a value. This class is attached to
38 * TAiwGenericParam instance which holds the semantic type of the value.
40 * @lib ServiceHandler.lib
41 * @since Series 60 2.6
42 * @see TAiwGenericParam
46 public: // Constructors
48 * Default constructor. Initializes this variant to be empty.
55 * Constructor from a value.
57 * @param aValue The value to set for this variant object.
59 inline TAiwVariant(TInt32 aValue);
62 * Constructor from a value.
64 * @param aValue The value to set for this variant object.
66 inline TAiwVariant(const TUid& aValue);
69 * Constructor from a value.
71 * @param aValue The value to set for this variant object.
73 inline TAiwVariant(const TTime& aValue);
76 * Constructor from a value.
78 * @param aValue The value to set for this variant object.
80 inline TAiwVariant(const TDesC& aValue);
83 * Constructor from a value.
85 * @param aValue The value to set for this variant object.
87 inline TAiwVariant(const HBufC* aValue);
90 * Constructor from a value.
92 * @param aValue The value to set for this variant object.
94 inline TAiwVariant(const TDesC8& aValue);
97 * Constructor from a value.
99 * @param aValue The value to set for this variant object.
101 inline TAiwVariant(const RFile& aValue);
104 * Copy constructor. Does not take ownership of data.
106 * @param aSrc The source object.
108 IMPORT_C TAiwVariant(const TAiwVariant& aSrc);
111 * Assignment operator. Does not take ownership of data.
113 * @param aValue The source object.
115 IMPORT_C TAiwVariant& TAiwVariant::operator=(const TAiwVariant& aValue);
117 // This class does not need a destructor because memory allocation
118 // policy for variant class has been implemented by TAiwGenericParam
123 * Returns the type id of data this variant object is holding.
125 inline TVariantTypeId TypeId() const;
128 * Returns ETrue if this variant is empty (it does not hold any value).
130 inline TBool IsEmpty() const;
133 * Retrieves the value held by this variant.
135 * @param aValue If this variant's type does not match the
136 * parameter type, the parameter will not be modified.
137 * @return ETrue if aValue was set, EFalse if types did not match.
139 IMPORT_C TBool Get(TInt32& aValue) const;
142 * Retrieves the value held by this variant.
144 * @param aValue If this variant's type does not match the
145 * parameter type, the parameter will not be modified.
146 * @return ETrue if aValue was set, EFalse if types did not match.
148 IMPORT_C TBool Get(TUid& aValue) const;
151 * Retrieves the value held by this variant.
153 * @param aValue If this variant's type does not match the
154 * parameter type, the parameter will not be modified.
155 * @return ETrue if aValue was set, EFalse if types did not match.
157 IMPORT_C TBool Get(TPtrC& aValue) const;
160 * Retrieves the value held by this variant.
162 * @param aValue If this variant's type does not match the
163 * parameter type, the parameter will not be modified.
164 * @return ETrue if aValue was set, EFalse if types did not match.
166 IMPORT_C TBool Get(TTime& aValue) const;
169 * Retrieves the value held by this variant.
171 * @param aValue If this variant's type does not match the
172 * parameter type, the parameter will not be modified.
173 * @return ETrue if aValue was set, EFalse if types did not match.
175 IMPORT_C TBool Get(TPtrC8& aValue) const;
178 * Retrieves the value held by this variant.
180 * @param aValue If this variant's type does not match the
181 * parameter type, the parameter will not be modified.
182 * @return ETrue if aValue was set, EFalse if types did not match.
184 IMPORT_C TBool Get(RFile& aValue) const;
187 * Returns the value held by this variant.
189 * @return The value held by this variant. If the data type does not
190 * match the function, the default initialized data is returned.
192 IMPORT_C TInt32 AsTInt32() const;
195 * Returns the value held by this variant.
197 * @return The value held by this variant. If the data type does not
198 * match the function, the default initialized data is returned.
200 IMPORT_C TUid AsTUid() const;
203 * Returns the value held by this variant.
205 * @return The value held by this variant. If the data type does not
206 * match the function, the default initialized data is returned.
208 IMPORT_C TPtrC AsDes() const;
211 * Returns the value held by this variant.
213 * @return The value held by this variant. If the data type does not
214 * match the function, the default initialized data is returned.
216 IMPORT_C TTime AsTTime() const;
219 * Returns the value held by this variant.
221 * @return The value held by this variant. If the data type does not
222 * match the function, the default initialized data is returned.
224 IMPORT_C TPtrC8 AsData() const;
227 * Returns the value held by this variant.
229 * @return The value held by this variant. If the data type does not
230 * match the function, the default initialized data is returned.
232 IMPORT_C RFile AsFileHandle() const;
235 * Deletes possibly set value and resets this variant to empty.
239 IMPORT_C void Reset();
242 * Sets integer value to this variant. The previous value is overwritten.
244 * @param aValue Value for this variant object to hold.
245 * @post *this == aValue
247 IMPORT_C void Set(TInt32 aValue);
250 * Sets unique ID value to this variant. The previous value is overwritten.
252 * @param aValue Value for this variant object to hold.
253 * @post *this == aValue
255 IMPORT_C void Set(const TUid& aValue);
258 * Sets date and time value to this variant. The previous value is overwritten.
260 * @param aValue Value for this variant object to hold.
261 * @post *this == aValue
263 IMPORT_C void Set(const TTime& aValue);
266 * Sets constant text reference to this variant.
268 * @param aValue Text value for this variant object to hold.
269 * @post *this == aValue
271 IMPORT_C void Set(const TDesC& aValue);
274 * Sets constant text reference to this variant.
276 * @param aValue Text value for this variant object to hold.
277 * Ownership is not taken.
279 inline void Set(const HBufC* aValue);
282 * Sets constant 8-bit text reference to this variant.
284 * @param aValue Text value for this variant object to hold.
285 * @post *this == aValue
287 IMPORT_C void Set(const TDesC8& aValue);
290 * Sets RFile file handle to this variant.
292 * @param aValue File handle for this variant object to hold.
293 * @post *this == aValue
295 IMPORT_C void Set(const RFile& aValue);
298 * Assignment operator for the variant.
300 * @param aValue The source object.
302 inline TAiwVariant& operator=(const TTime& aValue);
305 * Assignment operator for the variant.
307 * @param aValue The source object.
309 inline TAiwVariant& operator=(const TUid& aValue);
312 * Assignment operator for the variant.
314 * @param aValue The source object.
316 inline TAiwVariant& operator=(TInt32 aValue);
319 * Assignment operator for the variant.
321 * @param aValue The source object.
323 inline TAiwVariant& operator=(const TDesC& aValue);
326 * Assignment operator for the variant.
328 * @param aValue The source object.
330 inline TAiwVariant& operator=(const HBufC* aValue);
333 * Assignment operator for the variant.
335 * @param aValue The source object.
337 inline TAiwVariant& operator=(const TDesC8& aValue);
340 * Assignment operator for the variant.
342 * @param aValue The source object.
344 inline TAiwVariant& operator=(const RFile& aValue);
348 * Streaming support for TAiwGenericParam.
349 * Internalizes this variant from a stream.
351 void InternalizeL(RReadStream& aStream);
354 * Streaming support for TAiwGenericParam.
355 * Externalizes this variant to a stream.
357 void ExternalizeL(RWriteStream& aStream) const;
360 * Streaming support for TAiwGenericParam.
361 * Returns the maximum externalized size of this variant in bytes.
366 * Data copying support for TAiwGenericParam.
367 * Sets the copy of given variant value to this variant
368 * @param aValue variant value for this variant object to hold.
369 * @post *this == aValue
371 void SetL(const TAiwVariant& aValue);
374 * Destroys any dynamic resource owned by this variant.
379 void __DbgTestInvariant() const;
382 /// Type of the data this variant is holding
385 /// POD storage for a 64-bit integer
390 void InternalizeL(RReadStream& aStream);
391 void ExternalizeL(RWriteStream& aStream) const;
392 void Set(const TInt64& aTInt64);
393 operator TInt64() const;
394 TBool operator==(const SInt64& aRhs) const;
397 // Data value stored in this variant.
398 // One of these are effective at a time depending on the iTypeId
402 TInt32 iInt32; // 32-bit integer
403 SInt64 iInt64; // 64-bit integer
404 HBufC* iBufC; // owned string pointer
405 HBufC8* iBufC8; // owned 8-bit data pointer
408 UData iData; // Data union
409 TPtrC iPtrC; // Pointer to string
410 TPtrC8 iPtrC8; // Pointer to 8-bit data
412 private: // friend declarations
413 friend IMPORT_C TBool operator==(const TAiwVariant& aLhs, const TAiwVariant& aRhs);
414 /// TAiwGenericParam needs access to private streaming and copying methods.
415 friend class TAiwGenericParam;
423 * Returns ETrue if two variants are equal.
425 * @param aLhs Left hand side.
426 * @param aRhs Right hand side.
427 * @return ETrue if equal, EFalse otherwise.
429 IMPORT_C TBool operator==(const TAiwVariant& aLhs, const TAiwVariant& aRhs);
432 * Returns ETrue if two variants are not equal.
434 * @param aLhs Left hand side.
435 * @param aRhs Right hand side.
436 * @return ETrue if not equal, EFalse otherwise.
438 inline TBool operator!=(const TAiwVariant& aLhs, const TAiwVariant& aRhs);
441 * Dumps the contents of aVariant to debug output. Available only in debug builds.
443 * @param aVariant The object to be dumped.
445 void Dump(const TAiwVariant& aVariant);
449 #include "AiwVariant.inl"
451 #endif // AIW_VARIANT_H