1.1 --- a/epoc32/include/mw/aiwvariant.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/mw/aiwvariant.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,453 @@
1.4 -aiwvariant.h
1.5 +/*
1.6 +* Copyright (c) 2003-2005 Nokia Corporation and/or its subsidiary(-ies).
1.7 +* All rights reserved.
1.8 +* This component and the accompanying materials are made available
1.9 +* 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
1.10 +* which accompanies this distribution, and is available
1.11 +* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.12 +*
1.13 +* Initial Contributors:
1.14 +* Nokia Corporation - initial contribution.
1.15 +*
1.16 +* Contributors:
1.17 +*
1.18 +* Description: Variant data type for AIW generic parameters.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +
1.24 +
1.25 +
1.26 +#ifndef AIW_VARIANT_H
1.27 +#define AIW_VARIANT_H
1.28 +
1.29 +// INCLUDES
1.30 +#include <e32std.h>
1.31 +#include <s32strm.h>
1.32 +#include <f32file.h>
1.33 +#include "aiwvarianttype.hrh"
1.34 +
1.35 +// FORWARD DECLARATIONS
1.36 +
1.37 +// CLASS DECLARATION
1.38 +
1.39 +/**
1.40 +* Variant data class to hold a value of a TAiwGenericParam instance.
1.41 +* The variant contains a data type and a value. This class is attached to
1.42 +* TAiwGenericParam instance which holds the semantic type of the value.
1.43 +*
1.44 +* @lib ServiceHandler.lib
1.45 +* @since Series 60 2.6
1.46 +* @see TAiwGenericParam
1.47 +*/
1.48 +class TAiwVariant
1.49 + {
1.50 + public: // Constructors
1.51 + /**
1.52 + * Default constructor. Initializes this variant to be empty.
1.53 + *
1.54 + * @post IsEmpty()
1.55 + */
1.56 + inline TAiwVariant();
1.57 +
1.58 + /**
1.59 + * Constructor from a value.
1.60 + *
1.61 + * @param aValue The value to set for this variant object.
1.62 + */
1.63 + inline TAiwVariant(TInt32 aValue);
1.64 +
1.65 + /**
1.66 + * Constructor from a value.
1.67 + *
1.68 + * @param aValue The value to set for this variant object.
1.69 + */
1.70 + inline TAiwVariant(const TUid& aValue);
1.71 +
1.72 + /**
1.73 + * Constructor from a value.
1.74 + *
1.75 + * @param aValue The value to set for this variant object.
1.76 + */
1.77 + inline TAiwVariant(const TTime& aValue);
1.78 +
1.79 + /**
1.80 + * Constructor from a value.
1.81 + *
1.82 + * @param aValue The value to set for this variant object.
1.83 + */
1.84 + inline TAiwVariant(const TDesC& aValue);
1.85 +
1.86 + /**
1.87 + * Constructor from a value.
1.88 + *
1.89 + * @param aValue The value to set for this variant object.
1.90 + */
1.91 + inline TAiwVariant(const HBufC* aValue);
1.92 +
1.93 + /**
1.94 + * Constructor from a value.
1.95 + *
1.96 + * @param aValue The value to set for this variant object.
1.97 + */
1.98 + inline TAiwVariant(const TDesC8& aValue);
1.99 +
1.100 + /**
1.101 + * Constructor from a value.
1.102 + *
1.103 + * @param aValue The value to set for this variant object.
1.104 + */
1.105 + inline TAiwVariant(const RFile& aValue);
1.106 +
1.107 + /**
1.108 + * Copy constructor. Does not take ownership of data.
1.109 + *
1.110 + * @param aSrc The source object.
1.111 + */
1.112 + IMPORT_C TAiwVariant(const TAiwVariant& aSrc);
1.113 +
1.114 + /**
1.115 + * Assignment operator. Does not take ownership of data.
1.116 + *
1.117 + * @param aValue The source object.
1.118 + */
1.119 + IMPORT_C TAiwVariant& TAiwVariant::operator=(const TAiwVariant& aValue);
1.120 +
1.121 + // This class does not need a destructor because memory allocation
1.122 + // policy for variant class has been implemented by TAiwGenericParam
1.123 + // class.
1.124 +
1.125 + public: // Interface
1.126 + /**
1.127 + * Returns the type id of data this variant object is holding.
1.128 + */
1.129 + inline TVariantTypeId TypeId() const;
1.130 +
1.131 + /**
1.132 + * Returns ETrue if this variant is empty (it does not hold any value).
1.133 + */
1.134 + inline TBool IsEmpty() const;
1.135 +
1.136 + /**
1.137 + * Retrieves the value held by this variant.
1.138 + *
1.139 + * @param aValue If this variant's type does not match the
1.140 + * parameter type, the parameter will not be modified.
1.141 + * @return ETrue if aValue was set, EFalse if types did not match.
1.142 + */
1.143 + IMPORT_C TBool Get(TInt32& aValue) const;
1.144 +
1.145 + /**
1.146 + * Retrieves the value held by this variant.
1.147 + *
1.148 + * @param aValue If this variant's type does not match the
1.149 + * parameter type, the parameter will not be modified.
1.150 + * @return ETrue if aValue was set, EFalse if types did not match.
1.151 + */
1.152 + IMPORT_C TBool Get(TUid& aValue) const;
1.153 +
1.154 + /**
1.155 + * Retrieves the value held by this variant.
1.156 + *
1.157 + * @param aValue If this variant's type does not match the
1.158 + * parameter type, the parameter will not be modified.
1.159 + * @return ETrue if aValue was set, EFalse if types did not match.
1.160 + */
1.161 + IMPORT_C TBool Get(TPtrC& aValue) const;
1.162 +
1.163 + /**
1.164 + * Retrieves the value held by this variant.
1.165 + *
1.166 + * @param aValue If this variant's type does not match the
1.167 + * parameter type, the parameter will not be modified.
1.168 + * @return ETrue if aValue was set, EFalse if types did not match.
1.169 + */
1.170 + IMPORT_C TBool Get(TTime& aValue) const;
1.171 +
1.172 + /**
1.173 + * Retrieves the value held by this variant.
1.174 + *
1.175 + * @param aValue If this variant's type does not match the
1.176 + * parameter type, the parameter will not be modified.
1.177 + * @return ETrue if aValue was set, EFalse if types did not match.
1.178 + */
1.179 + IMPORT_C TBool Get(TPtrC8& aValue) const;
1.180 +
1.181 + /**
1.182 + * Retrieves the value held by this variant.
1.183 + *
1.184 + * @param aValue If this variant's type does not match the
1.185 + * parameter type, the parameter will not be modified.
1.186 + * @return ETrue if aValue was set, EFalse if types did not match.
1.187 + */
1.188 + IMPORT_C TBool Get(RFile& aValue) const;
1.189 +
1.190 + /**
1.191 + * Returns the value held by this variant.
1.192 + *
1.193 + * @return The value held by this variant. If the data type does not
1.194 + * match the function, the default initialized data is returned.
1.195 + */
1.196 + IMPORT_C TInt32 AsTInt32() const;
1.197 +
1.198 + /**
1.199 + * Returns the value held by this variant.
1.200 + *
1.201 + * @return The value held by this variant. If the data type does not
1.202 + * match the function, the default initialized data is returned.
1.203 + */
1.204 + IMPORT_C TUid AsTUid() const;
1.205 +
1.206 + /**
1.207 + * Returns the value held by this variant.
1.208 + *
1.209 + * @return The value held by this variant. If the data type does not
1.210 + * match the function, the default initialized data is returned.
1.211 + */
1.212 + IMPORT_C TPtrC AsDes() const;
1.213 +
1.214 + /**
1.215 + * Returns the value held by this variant.
1.216 + *
1.217 + * @return The value held by this variant. If the data type does not
1.218 + * match the function, the default initialized data is returned.
1.219 + */
1.220 + IMPORT_C TTime AsTTime() const;
1.221 +
1.222 + /**
1.223 + * Returns the value held by this variant.
1.224 + *
1.225 + * @return The value held by this variant. If the data type does not
1.226 + * match the function, the default initialized data is returned.
1.227 + */
1.228 + IMPORT_C TPtrC8 AsData() const;
1.229 +
1.230 + /**
1.231 + * Returns the value held by this variant.
1.232 + *
1.233 + * @return The value held by this variant. If the data type does not
1.234 + * match the function, the default initialized data is returned.
1.235 + */
1.236 + IMPORT_C RFile AsFileHandle() const;
1.237 +
1.238 + /**
1.239 + * Deletes possibly set value and resets this variant to empty.
1.240 + *
1.241 + * @post IsEmpty()
1.242 + */
1.243 + IMPORT_C void Reset();
1.244 +
1.245 + /**
1.246 + * Sets integer value to this variant. The previous value is overwritten.
1.247 + *
1.248 + * @param aValue Value for this variant object to hold.
1.249 + * @post *this == aValue
1.250 + */
1.251 + IMPORT_C void Set(TInt32 aValue);
1.252 +
1.253 + /**
1.254 + * Sets unique ID value to this variant. The previous value is overwritten.
1.255 + *
1.256 + * @param aValue Value for this variant object to hold.
1.257 + * @post *this == aValue
1.258 + */
1.259 + IMPORT_C void Set(const TUid& aValue);
1.260 +
1.261 + /**
1.262 + * Sets date and time value to this variant. The previous value is overwritten.
1.263 + *
1.264 + * @param aValue Value for this variant object to hold.
1.265 + * @post *this == aValue
1.266 + */
1.267 + IMPORT_C void Set(const TTime& aValue);
1.268 +
1.269 + /**
1.270 + * Sets constant text reference to this variant.
1.271 + *
1.272 + * @param aValue Text value for this variant object to hold.
1.273 + * @post *this == aValue
1.274 + */
1.275 + IMPORT_C void Set(const TDesC& aValue);
1.276 +
1.277 + /**
1.278 + * Sets constant text reference to this variant.
1.279 + *
1.280 + * @param aValue Text value for this variant object to hold.
1.281 + * Ownership is not taken.
1.282 + */
1.283 + inline void Set(const HBufC* aValue);
1.284 +
1.285 + /**
1.286 + * Sets constant 8-bit text reference to this variant.
1.287 + *
1.288 + * @param aValue Text value for this variant object to hold.
1.289 + * @post *this == aValue
1.290 + */
1.291 + IMPORT_C void Set(const TDesC8& aValue);
1.292 +
1.293 + /**
1.294 + * Sets RFile file handle to this variant.
1.295 + *
1.296 + * @param aValue File handle for this variant object to hold.
1.297 + * @post *this == aValue
1.298 + */
1.299 + IMPORT_C void Set(const RFile& aValue);
1.300 +
1.301 + /**
1.302 + * Assignment operator for the variant.
1.303 + *
1.304 + * @param aValue The source object.
1.305 + */
1.306 + inline TAiwVariant& operator=(const TTime& aValue);
1.307 +
1.308 + /**
1.309 + * Assignment operator for the variant.
1.310 + *
1.311 + * @param aValue The source object.
1.312 + */
1.313 + inline TAiwVariant& operator=(const TUid& aValue);
1.314 +
1.315 + /**
1.316 + * Assignment operator for the variant.
1.317 + *
1.318 + * @param aValue The source object.
1.319 + */
1.320 + inline TAiwVariant& operator=(TInt32 aValue);
1.321 +
1.322 + /**
1.323 + * Assignment operator for the variant.
1.324 + *
1.325 + * @param aValue The source object.
1.326 + */
1.327 + inline TAiwVariant& operator=(const TDesC& aValue);
1.328 +
1.329 + /**
1.330 + * Assignment operator for the variant.
1.331 + *
1.332 + * @param aValue The source object.
1.333 + */
1.334 + inline TAiwVariant& operator=(const HBufC* aValue);
1.335 +
1.336 + /**
1.337 + * Assignment operator for the variant.
1.338 + *
1.339 + * @param aValue The source object.
1.340 + */
1.341 + inline TAiwVariant& operator=(const TDesC8& aValue);
1.342 +
1.343 + /**
1.344 + * Assignment operator for the variant.
1.345 + *
1.346 + * @param aValue The source object.
1.347 + */
1.348 + inline TAiwVariant& operator=(const RFile& aValue);
1.349 +
1.350 + private:
1.351 + /**
1.352 + * Streaming support for TAiwGenericParam.
1.353 + * Internalizes this variant from a stream.
1.354 + */
1.355 + void InternalizeL(RReadStream& aStream);
1.356 +
1.357 + /**
1.358 + * Streaming support for TAiwGenericParam.
1.359 + * Externalizes this variant to a stream.
1.360 + */
1.361 + void ExternalizeL(RWriteStream& aStream) const;
1.362 +
1.363 + /**
1.364 + * Streaming support for TAiwGenericParam.
1.365 + * Returns the maximum externalized size of this variant in bytes.
1.366 + */
1.367 + TInt Size() const;
1.368 +
1.369 + /**
1.370 + * Data copying support for TAiwGenericParam.
1.371 + * Sets the copy of given variant value to this variant
1.372 + * @param aValue variant value for this variant object to hold.
1.373 + * @post *this == aValue
1.374 + */
1.375 + void SetL(const TAiwVariant& aValue);
1.376 +
1.377 + /**
1.378 + * Destroys any dynamic resource owned by this variant.
1.379 + */
1.380 + void Destroy();
1.381 +
1.382 + /// Debug invariant
1.383 + void __DbgTestInvariant() const;
1.384 +
1.385 + private: // Data
1.386 + /// Type of the data this variant is holding
1.387 + TUint8 iTypeId;
1.388 +
1.389 + /// POD storage for a 64-bit integer
1.390 + struct SInt64
1.391 + {
1.392 + TInt32 iLow;
1.393 + TInt32 iHigh;
1.394 + void InternalizeL(RReadStream& aStream);
1.395 + void ExternalizeL(RWriteStream& aStream) const;
1.396 + void Set(const TInt64& aTInt64);
1.397 + operator TInt64() const;
1.398 + TBool operator==(const SInt64& aRhs) const;
1.399 + };
1.400 +
1.401 + // Data value stored in this variant.
1.402 + // One of these are effective at a time depending on the iTypeId
1.403 + //
1.404 + union UData
1.405 + {
1.406 + TInt32 iInt32; // 32-bit integer
1.407 + SInt64 iInt64; // 64-bit integer
1.408 + HBufC* iBufC; // owned string pointer
1.409 + HBufC8* iBufC8; // owned 8-bit data pointer
1.410 + };
1.411 +
1.412 + UData iData; // Data union
1.413 + TPtrC iPtrC; // Pointer to string
1.414 + TPtrC8 iPtrC8; // Pointer to 8-bit data
1.415 +
1.416 + private: // friend declarations
1.417 + friend IMPORT_C TBool operator==(const TAiwVariant& aLhs, const TAiwVariant& aRhs);
1.418 + /// TAiwGenericParam needs access to private streaming and copying methods.
1.419 + friend class TAiwGenericParam;
1.420 +
1.421 + };
1.422 +
1.423 +
1.424 +// FUNCTIONS
1.425 +
1.426 +/**
1.427 +* Returns ETrue if two variants are equal.
1.428 +*
1.429 +* @param aLhs Left hand side.
1.430 +* @param aRhs Right hand side.
1.431 +* @return ETrue if equal, EFalse otherwise.
1.432 +*/
1.433 +IMPORT_C TBool operator==(const TAiwVariant& aLhs, const TAiwVariant& aRhs);
1.434 +
1.435 +/**
1.436 +* Returns ETrue if two variants are not equal.
1.437 +*
1.438 +* @param aLhs Left hand side.
1.439 +* @param aRhs Right hand side.
1.440 +* @return ETrue if not equal, EFalse otherwise.
1.441 +*/
1.442 +inline TBool operator!=(const TAiwVariant& aLhs, const TAiwVariant& aRhs);
1.443 +
1.444 +/**
1.445 +* Dumps the contents of aVariant to debug output. Available only in debug builds.
1.446 +*
1.447 +* @param aVariant The object to be dumped.
1.448 +*/
1.449 +void Dump(const TAiwVariant& aVariant);
1.450 +
1.451 +
1.452 +// INLINE FUNCTIONS
1.453 +#include "aiwvariant.inl"
1.454 +
1.455 +#endif // AIW_VARIANT_H
1.456 +
1.457 +// End of File