epoc32/include/mw/aiwvariant.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2 * Copyright (c) 2003-2005 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:     Variant data type for AIW generic parameters.
    15 *
    16 */
    17 
    18 
    19 
    20 
    21 
    22 #ifndef AIW_VARIANT_H
    23 #define AIW_VARIANT_H
    24 
    25 // INCLUDES
    26 #include <e32std.h>
    27 #include <s32strm.h>
    28 #include <f32file.h>
    29 #include "AiwVariantType.hrh"
    30 
    31 // FORWARD DECLARATIONS
    32 
    33 // CLASS DECLARATION
    34 
    35 /**
    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.
    39 *
    40 * @lib ServiceHandler.lib
    41 * @since Series 60 2.6
    42 * @see TAiwGenericParam
    43 */
    44 class TAiwVariant
    45     {
    46     public:  // Constructors
    47         /**
    48         * Default constructor. Initializes this variant to be empty.
    49         *
    50         * @post IsEmpty()
    51         */
    52         inline TAiwVariant();
    53         
    54         /**
    55         * Constructor from a value.
    56         *
    57         * @param aValue The value to set for this variant object.
    58         */
    59         inline TAiwVariant(TInt32 aValue);
    60         
    61         /**
    62         * Constructor from a value.
    63         *
    64         * @param aValue The value to set for this variant object.
    65         */        
    66         inline TAiwVariant(const TUid& aValue);
    67         
    68         /**
    69         * Constructor from a value.
    70         *
    71         * @param aValue The value to set for this variant object.
    72         */        
    73         inline TAiwVariant(const TTime& aValue);
    74         
    75         /**
    76         * Constructor from a value.
    77         *
    78         * @param aValue The value to set for this variant object.
    79         */        
    80         inline TAiwVariant(const TDesC& aValue);
    81         
    82         /**
    83         * Constructor from a value.
    84         *
    85         * @param aValue The value to set for this variant object.
    86         */        
    87         inline TAiwVariant(const HBufC* aValue);
    88         
    89         /**
    90         * Constructor from a value.
    91         *
    92         * @param aValue The value to set for this variant object.
    93         */        
    94         inline TAiwVariant(const TDesC8& aValue);
    95         
    96         /**
    97         * Constructor from a value.
    98         *
    99         * @param aValue The value to set for this variant object.
   100         */        
   101         inline TAiwVariant(const RFile& aValue);
   102 
   103         /**
   104         * Copy constructor. Does not take ownership of data.
   105         *
   106         * @param aSrc The source object.
   107         */
   108         IMPORT_C TAiwVariant(const TAiwVariant& aSrc);
   109                 
   110         /**
   111         * Assignment operator. Does not take ownership of data.
   112         *
   113         * @param aValue The source object.
   114         */
   115         IMPORT_C TAiwVariant& TAiwVariant::operator=(const TAiwVariant& aValue);
   116 
   117         // This class does not need a destructor because memory allocation
   118         // policy for variant class has been implemented by TAiwGenericParam
   119         // class.
   120 
   121     public:  // Interface
   122         /**
   123         * Returns the type id of data this variant object is holding.
   124         */
   125         inline TVariantTypeId TypeId() const;
   126 
   127         /**
   128         * Returns ETrue if this variant is empty (it does not hold any value).
   129         */
   130         inline TBool IsEmpty() const;
   131 
   132         /**
   133         * Retrieves the value held by this variant.
   134         *
   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.
   138         */
   139         IMPORT_C TBool Get(TInt32& aValue) const;
   140         
   141         /**
   142         * Retrieves the value held by this variant.
   143         *
   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.
   147         */        
   148         IMPORT_C TBool Get(TUid& aValue)   const;
   149         
   150         /**
   151         * Retrieves the value held by this variant.
   152         *
   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.
   156         */        
   157         IMPORT_C TBool Get(TPtrC& aValue)  const;
   158         
   159         /**
   160         * Retrieves the value held by this variant.
   161         *
   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.
   165         */        
   166         IMPORT_C TBool Get(TTime& aValue)  const;
   167         
   168         /**
   169         * Retrieves the value held by this variant.
   170         *
   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.
   174         */        
   175         IMPORT_C TBool Get(TPtrC8& aValue) const;
   176         
   177         /**
   178         * Retrieves the value held by this variant.
   179         *
   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.
   183         */        
   184         IMPORT_C TBool Get(RFile& aValue) const;
   185 
   186         /**
   187         * Returns the value held by this variant.
   188         *
   189         * @return The value held by this variant. If the data type does not
   190         *         match the function, the default initialized data is returned.
   191         */
   192         IMPORT_C TInt32 AsTInt32() const;
   193         
   194         /**
   195         * Returns the value held by this variant.
   196         *
   197         * @return The value held by this variant. If the data type does not
   198         *         match the function, the default initialized data is returned.
   199         */        
   200         IMPORT_C TUid AsTUid() const;
   201         
   202         /**
   203         * Returns the value held by this variant.
   204         *
   205         * @return The value held by this variant. If the data type does not
   206         *         match the function, the default initialized data is returned.
   207         */        
   208         IMPORT_C TPtrC AsDes() const;
   209         
   210         /**
   211         * Returns the value held by this variant.
   212         *
   213         * @return The value held by this variant. If the data type does not
   214         *         match the function, the default initialized data is returned.
   215         */        
   216         IMPORT_C TTime AsTTime() const;
   217         
   218         /**
   219         * Returns the value held by this variant.
   220         *
   221         * @return The value held by this variant. If the data type does not
   222         *         match the function, the default initialized data is returned.
   223         */        
   224         IMPORT_C TPtrC8 AsData() const; 
   225         
   226         /**
   227         * Returns the value held by this variant.
   228         *
   229         * @return The value held by this variant. If the data type does not
   230         *         match the function, the default initialized data is returned.
   231         */        
   232         IMPORT_C RFile AsFileHandle() const;
   233 
   234         /**
   235         * Deletes possibly set value and resets this variant to empty.
   236         *
   237         * @post IsEmpty()
   238         */
   239         IMPORT_C void Reset();
   240 
   241         /**
   242         * Sets integer value to this variant. The previous value is overwritten.
   243         *
   244         * @param aValue Value for this variant object to hold.
   245         * @post *this == aValue
   246         */
   247         IMPORT_C void Set(TInt32 aValue);
   248 
   249         /**
   250         * Sets unique ID value to this variant. The previous value is overwritten.
   251         *
   252         * @param aValue Value for this variant object to hold.
   253         * @post *this == aValue
   254         */
   255         IMPORT_C void Set(const TUid& aValue);
   256         
   257         /**
   258         * Sets date and time value to this variant. The previous value is overwritten.
   259         *
   260         * @param aValue Value for this variant object to hold.
   261         * @post *this == aValue
   262         */
   263         IMPORT_C void Set(const TTime& aValue);
   264 
   265         /**
   266         * Sets constant text reference to this variant. 
   267         *
   268         * @param aValue Text value for this variant object to hold.
   269         * @post *this == aValue
   270         */
   271         IMPORT_C void Set(const TDesC& aValue);
   272 
   273         /**
   274         * Sets constant text reference to this variant. 
   275         *
   276         * @param aValue Text value for this variant object to hold. 
   277         *               Ownership is not taken.
   278         */
   279         inline void Set(const HBufC* aValue);
   280 
   281         /**
   282         * Sets constant 8-bit text reference to this variant.
   283         * 
   284         * @param aValue Text value for this variant object to hold.
   285         * @post *this == aValue
   286         */
   287         IMPORT_C void Set(const TDesC8& aValue);
   288 
   289         /**
   290         * Sets RFile file handle to this variant.
   291         *
   292         * @param aValue File handle for this variant object to hold.
   293         * @post *this == aValue
   294         */
   295         IMPORT_C void Set(const RFile& aValue);
   296 
   297         /**
   298         * Assignment operator for the variant.
   299         *
   300         * @param aValue The source object.
   301         */
   302         inline TAiwVariant& operator=(const TTime& aValue);
   303 
   304         /**
   305         * Assignment operator for the variant.
   306         *
   307         * @param aValue The source object.
   308         */        
   309         inline TAiwVariant& operator=(const TUid& aValue);
   310         
   311         /**
   312         * Assignment operator for the variant.
   313         *
   314         * @param aValue The source object.
   315         */        
   316         inline TAiwVariant& operator=(TInt32 aValue);
   317         
   318         /**
   319         * Assignment operator for the variant.
   320         *
   321         * @param aValue The source object.
   322         */        
   323         inline TAiwVariant& operator=(const TDesC& aValue);
   324         
   325         /**
   326         * Assignment operator for the variant.
   327         *
   328         * @param aValue The source object.
   329         */        
   330         inline TAiwVariant& operator=(const HBufC* aValue);
   331         
   332         /**
   333         * Assignment operator for the variant.
   334         *
   335         * @param aValue The source object.
   336         */        
   337         inline TAiwVariant& operator=(const TDesC8& aValue);
   338         
   339         /**
   340         * Assignment operator for the variant.
   341         *
   342         * @param aValue The source object.
   343         */        
   344         inline TAiwVariant& operator=(const RFile& aValue);
   345         
   346     private:
   347         /**
   348         * Streaming support for TAiwGenericParam.
   349         * Internalizes this variant from a stream.
   350         */
   351         void InternalizeL(RReadStream& aStream);
   352 
   353         /**
   354         * Streaming support for TAiwGenericParam.
   355         * Externalizes this variant to a stream.
   356         */
   357         void ExternalizeL(RWriteStream& aStream) const;
   358 
   359         /**
   360         * Streaming support for TAiwGenericParam.
   361         * Returns the maximum externalized size of this variant in bytes.
   362         */
   363         TInt Size() const; 
   364 
   365         /**
   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
   370         */
   371         void SetL(const TAiwVariant& aValue);
   372 
   373         /**
   374         * Destroys any dynamic resource owned by this variant.
   375         */
   376         void Destroy();
   377 
   378         /// Debug invariant
   379         void __DbgTestInvariant() const;
   380         
   381     private:  // Data
   382         /// Type of the data this variant is holding
   383         TUint8 iTypeId;
   384 
   385         /// POD storage for a 64-bit integer
   386         struct SInt64
   387             {
   388             TInt32 iLow;
   389             TInt32 iHigh;
   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;
   395             };
   396 
   397         // Data value stored in this variant.
   398         // One of these are effective at a time depending on the iTypeId
   399         //
   400         union UData
   401             {
   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 
   406             };
   407 
   408         UData  iData;  // Data union
   409         TPtrC  iPtrC;  // Pointer to string
   410         TPtrC8 iPtrC8; // Pointer to 8-bit data 
   411 
   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;
   416         
   417     };
   418 
   419 
   420 // FUNCTIONS
   421 
   422 /**
   423 * Returns ETrue if two variants are equal.
   424 *
   425 * @param aLhs Left hand side.
   426 * @param aRhs Right hand side.
   427 * @return ETrue if equal, EFalse otherwise.
   428 */
   429 IMPORT_C TBool operator==(const TAiwVariant& aLhs, const TAiwVariant& aRhs);
   430 
   431 /**
   432 * Returns ETrue if two variants are not equal.
   433 *
   434 * @param aLhs Left hand side.
   435 * @param aRhs Right hand side.
   436 * @return ETrue if not equal, EFalse otherwise.
   437 */
   438 inline TBool operator!=(const TAiwVariant& aLhs, const TAiwVariant& aRhs);
   439 
   440 /**
   441 * Dumps the contents of aVariant to debug output. Available only in debug builds.
   442 *
   443 * @param aVariant The object to be dumped.
   444 */
   445 void Dump(const TAiwVariant& aVariant);
   446 
   447 
   448 // INLINE FUNCTIONS
   449 #include "AiwVariant.inl"
   450 
   451 #endif // AIW_VARIANT_H
   452 
   453 // End of File