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