uiservicetabsettings/inc/cvimpstsettingskeyvaluepair.h
branchRCL_3
changeset 22 3104fc151679
parent 21 2b7283837edb
child 23 9a48e301e94b
equal deleted inserted replaced
21:2b7283837edb 22:3104fc151679
     1 /*
       
     2 * Copyright (c) 2004 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:  Key - value container.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef __CVIMPSTSETTINGSKEYVALUEPAIR_H
       
    19 #define __CVIMPSTSETTINGSKEYVALUEPAIR_H
       
    20 
       
    21 //  INCLUDES
       
    22 #include <e32base.h>
       
    23 #include <s32strm.h>
       
    24 
       
    25 // CLASS DECLARATION
       
    26 /**
       
    27  * Key - value container.
       
    28  * Can be derived to expand services.
       
    29  *
       
    30  * @since 3.0
       
    31  **/
       
    32 NONSHARABLE_CLASS( CVIMPSTSettingsKeyValuePair ): public CBase
       
    33     {
       
    34     public:  // Enumerations
       
    35 
       
    36         /**
       
    37          * Data type enumeration.
       
    38          * List supported value data types.
       
    39          * @since 3.0
       
    40          **/
       
    41         enum TValueType
       
    42             {
       
    43             EValueTypeNone = 0,            
       
    44             EValueTypeDesC16
       
    45             };
       
    46 
       
    47 
       
    48     public:  // Constructors and destructor
       
    49 
       
    50         /**
       
    51          * Non leaving two phased constructor.
       
    52          *
       
    53          * If object allocation fails, returns NULL.
       
    54          *
       
    55          * @since 3.0
       
    56          * @param aKey The key.
       
    57          */
       
    58         static CVIMPSTSettingsKeyValuePair* New( const TDesC& aKey );
       
    59         /**
       
    60          * Two phased constructor initializing object state
       
    61          * from given flat descriptor.
       
    62          *
       
    63          * @since 3.0
       
    64          * @param aKeyValuePairFlat The flat representation of key-value pair
       
    65          */
       
    66 
       
    67 		static CVIMPSTSettingsKeyValuePair* NewLC( const TDesC& aKeyValuePairFlat );
       
    68 
       
    69         /**
       
    70          * Destructor.
       
    71          */
       
    72         virtual ~CVIMPSTSettingsKeyValuePair();
       
    73 
       
    74 
       
    75     protected:  // Constructor
       
    76 
       
    77         /**
       
    78          * C++ default constructor.
       
    79          */
       
    80         CVIMPSTSettingsKeyValuePair();
       
    81 
       
    82 
       
    83         /**
       
    84          * Symbian OS constructor.
       
    85          * Initializes object state from given stream.
       
    86          *
       
    87          * @since 3.0
       
    88          * @param aStream The stream to read object state.
       
    89          */
       
    90         void ConstructL( RReadStream& aStream );
       
    91 
       
    92 
       
    93     public:  //Data access
       
    94 
       
    95         /**
       
    96          * Key accessor.
       
    97          *
       
    98          * Gets the key associated with key-value object.
       
    99          * Virtual to allow derived classes to expand behaviour.
       
   100          *
       
   101          * @since 3.0
       
   102          * @return The key.
       
   103          */
       
   104         virtual const TDesC& Key() const;
       
   105 
       
   106 
       
   107         /**
       
   108          * Data setters.
       
   109          *
       
   110          *
       
   111          * @since 3.0
       
   112          * @param aValue The value to assign for key-value object.
       
   113          * @return Error code. One of following:
       
   114          * KErrNone: Value assigned/updated succesfully.
       
   115          * KErrGeneral: Different data type already assigned.
       
   116          * KErrNoMemory: No memory to allocate the new value.
       
   117          * Original value remains if assigning new value fails.
       
   118          */
       
   119         TInt SetValue( const TDesC16& aValue );
       
   120 
       
   121 
       
   122         /**
       
   123          * Data getters.
       
   124          *
       
   125          *
       
   126          * @since 3.0
       
   127          * @param aValue The value to get.
       
   128          * @return Error code. One of following:
       
   129          * KErrNone: Value read succesfully.
       
   130          * KErrNotFound: No value yet assigned.
       
   131          * KErrGeneral: Different data type assigned.
       
   132          * Given aValue isn't changed if reading fails.
       
   133          */    
       
   134         TInt GetValue( TPtrC16& aValue ) const;
       
   135 
       
   136 
       
   137 		/**
       
   138          * Key-Value pair flat representation
       
   139          *
       
   140          * Creates flat representation of the key-value pair
       
   141          * and pushes it in cleanup stack.
       
   142          * Ownership is transferred to calling method.
       
   143          *
       
   144          * @since 3.0
       
   145          * @return The flat representation of key-value pair
       
   146          */
       
   147 
       
   148 		HBufC* KeyValuePairFlatLC();
       
   149 		
       
   150 		/**
       
   151 		 * Checks if the data fits in the flat
       
   152 		 * descriptor
       
   153 		 *
       
   154 		 * @since 3.0
       
   155 		 * @return ETrue if data is too big.
       
   156 		 */
       
   157 		TBool IsDataTooBig() const;
       
   158 		
       
   159 		/**
       
   160 		 * Approximates the value pair data size
       
   161 		 * in decimal textual representation
       
   162 		 *
       
   163 		 * @since 3.0
       
   164 		 * @return The value pair data size.
       
   165 		 */
       
   166 		TInt DataSizeDec() const;
       
   167   
       
   168     private:    // Help functions
       
   169 
       
   170         /**
       
   171          * Resets the value pair data.
       
   172          * @since 3.0
       
   173          */
       
   174         void Reset();
       
   175         
       
   176         /**
       
   177          * Parses value pair data from flat descriptor.
       
   178          * @param aKeyValuePairFlat flat descriptor to parse
       
   179          * @since 3.0
       
   180          */
       
   181         void ParseFlatKeyValuePairL( const TDesC& aKeyValuePairFlat );
       
   182 
       
   183 
       
   184     private:    // Data
       
   185 
       
   186 
       
   187         HBufC16*        iKey;           //OWN: The key.
       
   188 
       
   189         TValueType      iValueType;     //OWN: The value type.
       
   190 
       
   191         union                           //OWN: The value. Value type is determined from iValueType.
       
   192             {
       
   193             TInt        iInt;
       
   194             HBufC8*     iBuf8;
       
   195             HBufC16*    iBuf16;
       
   196             };
       
   197 
       
   198     };
       
   199 
       
   200 #endif      // __CVIMPSTSETTINGSKEYVALUEPAIR_H
       
   201 
       
   202 
       
   203 //  End of File
       
   204