williamr@2: /* williamr@2: * Copyright (c) 2003-2005 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@4: * under the terms of "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@4: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: Variant data type for AIW generic parameters. williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: #ifndef AIW_VARIANT_H williamr@2: #define AIW_VARIANT_H williamr@2: williamr@2: // INCLUDES williamr@2: #include williamr@2: #include williamr@2: #include williamr@4: #include "AiwVariantType.hrh" williamr@2: williamr@2: // FORWARD DECLARATIONS williamr@2: williamr@2: // CLASS DECLARATION williamr@2: williamr@2: /** williamr@2: * Variant data class to hold a value of a TAiwGenericParam instance. williamr@2: * The variant contains a data type and a value. This class is attached to williamr@2: * TAiwGenericParam instance which holds the semantic type of the value. williamr@2: * williamr@2: * @lib ServiceHandler.lib williamr@2: * @since Series 60 2.6 williamr@2: * @see TAiwGenericParam williamr@2: */ williamr@2: class TAiwVariant williamr@2: { williamr@2: public: // Constructors williamr@2: /** williamr@2: * Default constructor. Initializes this variant to be empty. williamr@2: * williamr@2: * @post IsEmpty() williamr@2: */ williamr@2: inline TAiwVariant(); williamr@2: williamr@2: /** williamr@2: * Constructor from a value. williamr@2: * williamr@2: * @param aValue The value to set for this variant object. williamr@2: */ williamr@2: inline TAiwVariant(TInt32 aValue); williamr@2: williamr@2: /** williamr@2: * Constructor from a value. williamr@2: * williamr@2: * @param aValue The value to set for this variant object. williamr@2: */ williamr@2: inline TAiwVariant(const TUid& aValue); williamr@2: williamr@2: /** williamr@2: * Constructor from a value. williamr@2: * williamr@2: * @param aValue The value to set for this variant object. williamr@2: */ williamr@2: inline TAiwVariant(const TTime& aValue); williamr@2: williamr@2: /** williamr@2: * Constructor from a value. williamr@2: * williamr@2: * @param aValue The value to set for this variant object. williamr@2: */ williamr@2: inline TAiwVariant(const TDesC& aValue); williamr@2: williamr@2: /** williamr@2: * Constructor from a value. williamr@2: * williamr@2: * @param aValue The value to set for this variant object. williamr@2: */ williamr@2: inline TAiwVariant(const HBufC* aValue); williamr@2: williamr@2: /** williamr@2: * Constructor from a value. williamr@2: * williamr@2: * @param aValue The value to set for this variant object. williamr@2: */ williamr@2: inline TAiwVariant(const TDesC8& aValue); williamr@2: williamr@2: /** williamr@2: * Constructor from a value. williamr@2: * williamr@2: * @param aValue The value to set for this variant object. williamr@2: */ williamr@2: inline TAiwVariant(const RFile& aValue); williamr@2: williamr@2: /** williamr@2: * Copy constructor. Does not take ownership of data. williamr@2: * williamr@2: * @param aSrc The source object. williamr@2: */ williamr@2: IMPORT_C TAiwVariant(const TAiwVariant& aSrc); williamr@2: williamr@2: /** williamr@2: * Assignment operator. Does not take ownership of data. williamr@2: * williamr@2: * @param aValue The source object. williamr@2: */ williamr@2: IMPORT_C TAiwVariant& TAiwVariant::operator=(const TAiwVariant& aValue); williamr@2: williamr@2: // This class does not need a destructor because memory allocation williamr@2: // policy for variant class has been implemented by TAiwGenericParam williamr@2: // class. williamr@2: williamr@2: public: // Interface williamr@2: /** williamr@2: * Returns the type id of data this variant object is holding. williamr@2: */ williamr@2: inline TVariantTypeId TypeId() const; williamr@2: williamr@2: /** williamr@2: * Returns ETrue if this variant is empty (it does not hold any value). williamr@2: */ williamr@2: inline TBool IsEmpty() const; williamr@2: williamr@2: /** williamr@2: * Retrieves the value held by this variant. williamr@2: * williamr@2: * @param aValue If this variant's type does not match the williamr@2: * parameter type, the parameter will not be modified. williamr@2: * @return ETrue if aValue was set, EFalse if types did not match. williamr@2: */ williamr@2: IMPORT_C TBool Get(TInt32& aValue) const; williamr@2: williamr@2: /** williamr@2: * Retrieves the value held by this variant. williamr@2: * williamr@2: * @param aValue If this variant's type does not match the williamr@2: * parameter type, the parameter will not be modified. williamr@2: * @return ETrue if aValue was set, EFalse if types did not match. williamr@2: */ williamr@2: IMPORT_C TBool Get(TUid& aValue) const; williamr@2: williamr@2: /** williamr@2: * Retrieves the value held by this variant. williamr@2: * williamr@2: * @param aValue If this variant's type does not match the williamr@2: * parameter type, the parameter will not be modified. williamr@2: * @return ETrue if aValue was set, EFalse if types did not match. williamr@2: */ williamr@2: IMPORT_C TBool Get(TPtrC& aValue) const; williamr@2: williamr@2: /** williamr@2: * Retrieves the value held by this variant. williamr@2: * williamr@2: * @param aValue If this variant's type does not match the williamr@2: * parameter type, the parameter will not be modified. williamr@2: * @return ETrue if aValue was set, EFalse if types did not match. williamr@2: */ williamr@2: IMPORT_C TBool Get(TTime& aValue) const; williamr@2: williamr@2: /** williamr@2: * Retrieves the value held by this variant. williamr@2: * williamr@2: * @param aValue If this variant's type does not match the williamr@2: * parameter type, the parameter will not be modified. williamr@2: * @return ETrue if aValue was set, EFalse if types did not match. williamr@2: */ williamr@2: IMPORT_C TBool Get(TPtrC8& aValue) const; williamr@2: williamr@2: /** williamr@2: * Retrieves the value held by this variant. williamr@2: * williamr@2: * @param aValue If this variant's type does not match the williamr@2: * parameter type, the parameter will not be modified. williamr@2: * @return ETrue if aValue was set, EFalse if types did not match. williamr@2: */ williamr@2: IMPORT_C TBool Get(RFile& aValue) const; williamr@2: williamr@2: /** williamr@2: * Returns the value held by this variant. williamr@2: * williamr@2: * @return The value held by this variant. If the data type does not williamr@2: * match the function, the default initialized data is returned. williamr@2: */ williamr@2: IMPORT_C TInt32 AsTInt32() const; williamr@2: williamr@2: /** williamr@2: * Returns the value held by this variant. williamr@2: * williamr@2: * @return The value held by this variant. If the data type does not williamr@2: * match the function, the default initialized data is returned. williamr@2: */ williamr@2: IMPORT_C TUid AsTUid() const; williamr@2: williamr@2: /** williamr@2: * Returns the value held by this variant. williamr@2: * williamr@2: * @return The value held by this variant. If the data type does not williamr@2: * match the function, the default initialized data is returned. williamr@2: */ williamr@2: IMPORT_C TPtrC AsDes() const; williamr@2: williamr@2: /** williamr@2: * Returns the value held by this variant. williamr@2: * williamr@2: * @return The value held by this variant. If the data type does not williamr@2: * match the function, the default initialized data is returned. williamr@2: */ williamr@2: IMPORT_C TTime AsTTime() const; williamr@2: williamr@2: /** williamr@2: * Returns the value held by this variant. williamr@2: * williamr@2: * @return The value held by this variant. If the data type does not williamr@2: * match the function, the default initialized data is returned. williamr@2: */ williamr@2: IMPORT_C TPtrC8 AsData() const; williamr@2: williamr@2: /** williamr@2: * Returns the value held by this variant. williamr@2: * williamr@2: * @return The value held by this variant. If the data type does not williamr@2: * match the function, the default initialized data is returned. williamr@2: */ williamr@2: IMPORT_C RFile AsFileHandle() const; williamr@2: williamr@2: /** williamr@2: * Deletes possibly set value and resets this variant to empty. williamr@2: * williamr@2: * @post IsEmpty() williamr@2: */ williamr@2: IMPORT_C void Reset(); williamr@2: williamr@2: /** williamr@2: * Sets integer value to this variant. The previous value is overwritten. williamr@2: * williamr@2: * @param aValue Value for this variant object to hold. williamr@2: * @post *this == aValue williamr@2: */ williamr@2: IMPORT_C void Set(TInt32 aValue); williamr@2: williamr@2: /** williamr@2: * Sets unique ID value to this variant. The previous value is overwritten. williamr@2: * williamr@2: * @param aValue Value for this variant object to hold. williamr@2: * @post *this == aValue williamr@2: */ williamr@2: IMPORT_C void Set(const TUid& aValue); williamr@2: williamr@2: /** williamr@2: * Sets date and time value to this variant. The previous value is overwritten. williamr@2: * williamr@2: * @param aValue Value for this variant object to hold. williamr@2: * @post *this == aValue williamr@2: */ williamr@2: IMPORT_C void Set(const TTime& aValue); williamr@2: williamr@2: /** williamr@2: * Sets constant text reference to this variant. williamr@2: * williamr@2: * @param aValue Text value for this variant object to hold. williamr@2: * @post *this == aValue williamr@2: */ williamr@2: IMPORT_C void Set(const TDesC& aValue); williamr@2: williamr@2: /** williamr@2: * Sets constant text reference to this variant. williamr@2: * williamr@2: * @param aValue Text value for this variant object to hold. williamr@2: * Ownership is not taken. williamr@2: */ williamr@2: inline void Set(const HBufC* aValue); williamr@2: williamr@2: /** williamr@2: * Sets constant 8-bit text reference to this variant. williamr@2: * williamr@2: * @param aValue Text value for this variant object to hold. williamr@2: * @post *this == aValue williamr@2: */ williamr@2: IMPORT_C void Set(const TDesC8& aValue); williamr@2: williamr@2: /** williamr@2: * Sets RFile file handle to this variant. williamr@2: * williamr@2: * @param aValue File handle for this variant object to hold. williamr@2: * @post *this == aValue williamr@2: */ williamr@2: IMPORT_C void Set(const RFile& aValue); williamr@2: williamr@2: /** williamr@2: * Assignment operator for the variant. williamr@2: * williamr@2: * @param aValue The source object. williamr@2: */ williamr@2: inline TAiwVariant& operator=(const TTime& aValue); williamr@2: williamr@2: /** williamr@2: * Assignment operator for the variant. williamr@2: * williamr@2: * @param aValue The source object. williamr@2: */ williamr@2: inline TAiwVariant& operator=(const TUid& aValue); williamr@2: williamr@2: /** williamr@2: * Assignment operator for the variant. williamr@2: * williamr@2: * @param aValue The source object. williamr@2: */ williamr@2: inline TAiwVariant& operator=(TInt32 aValue); williamr@2: williamr@2: /** williamr@2: * Assignment operator for the variant. williamr@2: * williamr@2: * @param aValue The source object. williamr@2: */ williamr@2: inline TAiwVariant& operator=(const TDesC& aValue); williamr@2: williamr@2: /** williamr@2: * Assignment operator for the variant. williamr@2: * williamr@2: * @param aValue The source object. williamr@2: */ williamr@2: inline TAiwVariant& operator=(const HBufC* aValue); williamr@2: williamr@2: /** williamr@2: * Assignment operator for the variant. williamr@2: * williamr@2: * @param aValue The source object. williamr@2: */ williamr@2: inline TAiwVariant& operator=(const TDesC8& aValue); williamr@2: williamr@2: /** williamr@2: * Assignment operator for the variant. williamr@2: * williamr@2: * @param aValue The source object. williamr@2: */ williamr@2: inline TAiwVariant& operator=(const RFile& aValue); williamr@2: williamr@2: private: williamr@2: /** williamr@2: * Streaming support for TAiwGenericParam. williamr@2: * Internalizes this variant from a stream. williamr@2: */ williamr@2: void InternalizeL(RReadStream& aStream); williamr@2: williamr@2: /** williamr@2: * Streaming support for TAiwGenericParam. williamr@2: * Externalizes this variant to a stream. williamr@2: */ williamr@2: void ExternalizeL(RWriteStream& aStream) const; williamr@2: williamr@2: /** williamr@2: * Streaming support for TAiwGenericParam. williamr@2: * Returns the maximum externalized size of this variant in bytes. williamr@2: */ williamr@2: TInt Size() const; williamr@2: williamr@2: /** williamr@2: * Data copying support for TAiwGenericParam. williamr@2: * Sets the copy of given variant value to this variant williamr@2: * @param aValue variant value for this variant object to hold. williamr@2: * @post *this == aValue williamr@2: */ williamr@2: void SetL(const TAiwVariant& aValue); williamr@2: williamr@2: /** williamr@2: * Destroys any dynamic resource owned by this variant. williamr@2: */ williamr@2: void Destroy(); williamr@2: williamr@2: /// Debug invariant williamr@2: void __DbgTestInvariant() const; williamr@2: williamr@2: private: // Data williamr@2: /// Type of the data this variant is holding williamr@2: TUint8 iTypeId; williamr@2: williamr@2: /// POD storage for a 64-bit integer williamr@2: struct SInt64 williamr@2: { williamr@2: TInt32 iLow; williamr@2: TInt32 iHigh; williamr@2: void InternalizeL(RReadStream& aStream); williamr@2: void ExternalizeL(RWriteStream& aStream) const; williamr@2: void Set(const TInt64& aTInt64); williamr@2: operator TInt64() const; williamr@2: TBool operator==(const SInt64& aRhs) const; williamr@2: }; williamr@2: williamr@2: // Data value stored in this variant. williamr@2: // One of these are effective at a time depending on the iTypeId williamr@2: // williamr@2: union UData williamr@2: { williamr@2: TInt32 iInt32; // 32-bit integer williamr@2: SInt64 iInt64; // 64-bit integer williamr@2: HBufC* iBufC; // owned string pointer williamr@2: HBufC8* iBufC8; // owned 8-bit data pointer williamr@2: }; williamr@2: williamr@2: UData iData; // Data union williamr@2: TPtrC iPtrC; // Pointer to string williamr@2: TPtrC8 iPtrC8; // Pointer to 8-bit data williamr@2: williamr@2: private: // friend declarations williamr@2: friend IMPORT_C TBool operator==(const TAiwVariant& aLhs, const TAiwVariant& aRhs); williamr@2: /// TAiwGenericParam needs access to private streaming and copying methods. williamr@2: friend class TAiwGenericParam; williamr@2: williamr@2: }; williamr@2: williamr@2: williamr@2: // FUNCTIONS williamr@2: williamr@2: /** williamr@2: * Returns ETrue if two variants are equal. williamr@2: * williamr@2: * @param aLhs Left hand side. williamr@2: * @param aRhs Right hand side. williamr@2: * @return ETrue if equal, EFalse otherwise. williamr@2: */ williamr@2: IMPORT_C TBool operator==(const TAiwVariant& aLhs, const TAiwVariant& aRhs); williamr@2: williamr@2: /** williamr@2: * Returns ETrue if two variants are not equal. williamr@2: * williamr@2: * @param aLhs Left hand side. williamr@2: * @param aRhs Right hand side. williamr@2: * @return ETrue if not equal, EFalse otherwise. williamr@2: */ williamr@2: inline TBool operator!=(const TAiwVariant& aLhs, const TAiwVariant& aRhs); williamr@2: williamr@2: /** williamr@2: * Dumps the contents of aVariant to debug output. Available only in debug builds. williamr@2: * williamr@2: * @param aVariant The object to be dumped. williamr@2: */ williamr@2: void Dump(const TAiwVariant& aVariant); williamr@2: williamr@2: williamr@2: // INLINE FUNCTIONS williamr@4: #include "AiwVariant.inl" williamr@2: williamr@2: #endif // AIW_VARIANT_H williamr@2: williamr@2: // End of File