IMPSengine/datautils/inc/impsdata.h
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2002 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: 
       
    15 *     Interface for CImpsData
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef IMPS_CIMPSDATA_H
       
    21 #define IMPS_CIMPSDATA_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include "impsdataaccessorapi.h"
       
    25 #include "impskey.h"
       
    26 
       
    27 #ifdef _DEBUG
       
    28 #include    <f32file.h>
       
    29 #endif
       
    30 
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class CImpsKey;
       
    34 
       
    35 // CLASS DECLARATION
       
    36 
       
    37 /**
       
    38 *  CImpsElement the key and corresponding value
       
    39 *
       
    40 */
       
    41 class CImpsElement : public CBase
       
    42     {
       
    43     public:  // Constructors and destructor
       
    44 
       
    45         /**
       
    46         * Two-phased constructor
       
    47         */
       
    48         static CImpsElement* NewL( );
       
    49 
       
    50         /**
       
    51         * Destructor.
       
    52         */
       
    53         virtual ~CImpsElement();
       
    54 
       
    55     public: // New functions
       
    56 
       
    57         /**
       
    58         * SetStringL
       
    59         * @param Key in
       
    60         * @param string to store
       
    61         * @return void
       
    62         */
       
    63         void SetStringL( const CImpsKey* aKey, const TDesC& aBuf );
       
    64 
       
    65         /**
       
    66         * SetString8L
       
    67         * @param Key in
       
    68         * @param string to store
       
    69         * @return void
       
    70         */
       
    71         void SetString8L( const CImpsKey* aKey, const TDesC8& aBuf );
       
    72 
       
    73         /**
       
    74         * SetIntL
       
    75         * @param Key in
       
    76         * @param int to store
       
    77         * @return void
       
    78         */
       
    79         void SetIntL( const CImpsKey* aKey, TInt aInt );
       
    80 
       
    81         /**
       
    82         * SetBooleanL
       
    83         * @param Key in
       
    84         * @param boolean to store
       
    85         * @return void
       
    86         */
       
    87         void SetBooleanL( const CImpsKey* aKey, TBool aBool );
       
    88 
       
    89         /**
       
    90         * SetEmptyL
       
    91         * @param Key in
       
    92         * @return void
       
    93         */
       
    94         void SetEmptyL( const CImpsKey* aKey );
       
    95 
       
    96         /**
       
    97         * GetKey
       
    98         * @return Key
       
    99         */
       
   100         inline const CImpsKey* GetKey(  ) const;
       
   101 
       
   102         /**
       
   103         * GetKey
       
   104         * @return Key
       
   105         */
       
   106         inline CImpsKey* GetKey(  );
       
   107 
       
   108         /**
       
   109         * GetInt
       
   110         * @return int
       
   111         */
       
   112         inline TInt GetInt(  ) const;
       
   113 
       
   114         /**
       
   115         * GetString
       
   116         * @return string
       
   117         */
       
   118         inline TDesC* GetString(  ) const;
       
   119 
       
   120         /**
       
   121         * GetString8
       
   122         * @return string
       
   123         */
       
   124         inline TDesC8* GetString8(  ) const;
       
   125 
       
   126         /**
       
   127         * GetBoolean
       
   128         * @return boolean
       
   129         */
       
   130         inline TBool GetBoolean(  ) const;
       
   131 
       
   132         /**
       
   133         * IsEmpty
       
   134         * @return true if empty
       
   135         */
       
   136         inline TBool IsEmpty(  ) const;
       
   137 
       
   138         /**
       
   139         * GetType
       
   140         * @return type of the value
       
   141         */
       
   142         inline TImpsDataType GetType(  ) const;
       
   143 
       
   144         /**
       
   145         * Size
       
   146         * @return the size the data used by this object
       
   147         */
       
   148         TInt Size( ) const;
       
   149 
       
   150         /**
       
   151         * Pack
       
   152         * @param start pointer
       
   153         * @param end pointer
       
   154         * @return KErrNone if ok. error status otherwise
       
   155         */
       
   156         TInt Pack( const TUint8*& aPtrStart ) const;
       
   157 
       
   158         /**
       
   159         * UnPackL
       
   160         * @param Pointer with stream to unpack
       
   161         */
       
   162         void UnPackL( TUint8*& aPtr );
       
   163 
       
   164 #ifdef _DEBUG
       
   165         /**
       
   166         * DumpToFile
       
   167         * @param file where to dump
       
   168         */
       
   169         void DumpToFileL( RFile& aFile ) const;
       
   170 #endif
       
   171 
       
   172         /**
       
   173         * CopyL
       
   174         */
       
   175         CImpsElement* CopyL( ) const;
       
   176 
       
   177     private:
       
   178 
       
   179         /**
       
   180         * By default Symbian OS constructor is private.
       
   181         */
       
   182         CImpsElement();
       
   183 
       
   184         /**
       
   185         * Actual construction.
       
   186         */
       
   187         void ConstructL();
       
   188 
       
   189         // By default, prohibit copy constructor
       
   190         CImpsElement( const CImpsElement& );
       
   191         // Prohibit assigment operator
       
   192         CImpsElement& operator= ( const CImpsElement& );
       
   193 
       
   194     private:            // Data
       
   195         CImpsKey*       iKey;
       
   196         TInt            iInt;
       
   197         TBool           iBool;
       
   198         HBufC*          iString;
       
   199         HBufC8*         iString8;
       
   200         TImpsDataType   iValueType;
       
   201         TBool           iIsEmpty; // If the element doesn't contain any values
       
   202     };
       
   203 
       
   204 
       
   205 // DATA TYPES
       
   206 typedef CArrayPtrFlat<CImpsElement> CImpsElements;
       
   207 
       
   208 /**
       
   209 *  CImpsData contains a vector of CImpsElements
       
   210 *  Container for CImpsElements
       
   211 */
       
   212 class CImpsData : public CBase
       
   213     {
       
   214     public:  // Constructors and destructor
       
   215 
       
   216         /**
       
   217         * Two-phased constructor.
       
   218         */
       
   219         static CImpsData* NewL();
       
   220 
       
   221         /**
       
   222         * Destructor.
       
   223         */
       
   224         virtual ~CImpsData();
       
   225 
       
   226     public: // New functions
       
   227 
       
   228         /**
       
   229         * Stores new key/value pair to the datastore
       
   230         * @param aKey Key to save with the value
       
   231         * @param aBuff String value to store
       
   232         * @return void
       
   233         */
       
   234         void StoreStringL( const CImpsKey *aKey, const TDesC& aBuff );
       
   235 
       
   236         /**
       
   237         * Stores new key/value pair to the datastore
       
   238         * @param aKey Key to save with the value
       
   239         * @param aBuff String value to store
       
   240         * @return void
       
   241         */
       
   242         void StoreString8L( const CImpsKey *aKey, const TDesC8& aBuff );
       
   243 
       
   244         /**
       
   245         * Stores new key/value pair to the datastore
       
   246         * @param aKey Key to save with the value
       
   247         * @param aInt Interger value to store
       
   248         * @return void
       
   249         */
       
   250         void StoreIntL( const CImpsKey *aKey, TInt aInt );
       
   251 
       
   252         /**
       
   253         * Stores new key/value pair to the datastore
       
   254         * @param aKey Key to save with the value
       
   255         * @param aBool Boolean value to store
       
   256         * @return void
       
   257         */
       
   258         void StoreBooleanL( const CImpsKey *aKey, TBool aBool );
       
   259 
       
   260         /**
       
   261         * Stores new key and empty value pair to the datastore
       
   262         * @param aKey Key to save with the value
       
   263         * @return void
       
   264         */
       
   265         void StoreEmptyL( const CImpsKey *aKey );
       
   266 
       
   267         /**
       
   268         * Restores value from the store found by key
       
   269         * @param aKey Key used for selecting from the store
       
   270         * @param aBuff buffer found
       
   271         * @return true if found, false if not
       
   272         */
       
   273         TBool RestoreString( const CImpsKey *aKey, TDesC*& aBuff ) const;
       
   274 
       
   275         /**
       
   276         * Restores value from the store found by key
       
   277         * @param aKey Key used for selecting from the store
       
   278         * @param aBuff buffer found
       
   279         * @return true if found, false if not
       
   280         */
       
   281         TBool RestoreString8( const CImpsKey *aKey, TDesC8*& aBuff );
       
   282 
       
   283         /**
       
   284         * Restores value from the store found by key
       
   285         * @param aKey Key used for selecting from the store
       
   286         * @param aInt integer found
       
   287         * @return true if found, false if not
       
   288         */
       
   289         TBool RestoreInt( const CImpsKey *aKey, TInt& aInt );
       
   290 
       
   291         /**
       
   292         * Restores value from the store found by key
       
   293         * @param aKey Key used for selecting from the store
       
   294         * @param aBool Boolean found
       
   295         * @return true if found, false if not
       
   296         */
       
   297         TBool RestoreBoolean( const CImpsKey *aKey, TBool& aBoolean );
       
   298 
       
   299         /**
       
   300         * Restores value from the store found by key
       
   301         * @param aKey Key used for selecting from the store
       
   302         * @return true if found, false if not
       
   303         */
       
   304         TBool RestoreEmpty( const CImpsKey *aKey );
       
   305 
       
   306         /**
       
   307         * Checks if the key exists in the datastore. Options
       
   308         * are partial
       
   309         * wholekey
       
   310         * @param aKey Key used for finding from the store
       
   311         * @param aOpt Find mode (partial or whole)
       
   312         * @return CImpsKey if found, NULL if not
       
   313         */
       
   314         const CImpsKey* CheckKey( const CImpsKey *aKey, TImpsKeyOptions aOpt = EPartialKey ) const;
       
   315 
       
   316         /**
       
   317         * Finds the element from the list based on a key(no partial key, full key)
       
   318         * @param aKey Key used for finding from the store
       
   319         * @param type of the key.
       
   320         * @return address of the element, NULL if not found
       
   321         */
       
   322         const CImpsElement* Find( const CImpsKey *aKey, TImpsDataType aType ) const;
       
   323 
       
   324         /**
       
   325         * Resets the array to empty array and deletes all elemenst
       
   326         */
       
   327         inline void Reset( );
       
   328 
       
   329         /**
       
   330         * Size
       
   331         * @return the size the data used by this object
       
   332         */
       
   333         TInt Size( ) const;
       
   334 
       
   335         /**
       
   336         * Count
       
   337         * @return the number of elements in the list
       
   338         */
       
   339         inline TInt Count( ) const;
       
   340 
       
   341         /**
       
   342         * Pack
       
   343         * @param start pointer
       
   344         * @param end pointer
       
   345         * @return KErrNone if ok. error status otherwise
       
   346         */
       
   347         TInt Pack( const TUint8*& aPtrStart ) const;
       
   348 
       
   349         /**
       
   350         * UnPackL
       
   351         * @param Pointer with stream to unpack
       
   352         */
       
   353         void UnPackL( TUint8*& aPtr );
       
   354 #ifdef _DEBUG
       
   355         /**
       
   356         * DumpToFileL
       
   357         * @param Filename with path where to dump the object
       
   358         */
       
   359         void DumpToFileL( RFs& aSession, const TDesC& aFileName ) const;
       
   360 #endif
       
   361         /**
       
   362         * Copy
       
   363         * @param All elements which have the key in the beginning are copied
       
   364         * If aKey is NULL everything is copied
       
   365         * @param Source CImpsData
       
   366         */
       
   367         void CopyL( const CImpsKey* aKey, const CImpsData* aSource );
       
   368 
       
   369         /**
       
   370         * SetKeyIndex
       
   371         * This function changes all the entries in this data storage
       
   372         * which have this key. The index of the last key is changed.
       
   373         * @param Partial key ( All found keys are changed )
       
   374         * Cannot be NULL
       
   375         * @param New index for the key element
       
   376         */
       
   377         void SetKeyIndex( const CImpsKey* aKey, TInt aNewIndex );
       
   378 
       
   379     private:
       
   380 
       
   381         /**
       
   382         * By default Symbian OS constructor is private.
       
   383         */
       
   384         CImpsData();
       
   385 
       
   386         /**
       
   387         * Symbian OS second phase construction
       
   388         */
       
   389         void ConstructL();
       
   390 
       
   391         // By default, prohibit copy constructor
       
   392         CImpsData( const CImpsData& );
       
   393         // Prohibit assigment operator
       
   394         CImpsData& operator= ( const CImpsData& );
       
   395 
       
   396     private:    // Data
       
   397         CImpsElements*   iElements;
       
   398 
       
   399     };
       
   400 
       
   401 #include "ImpsData.inl"
       
   402 
       
   403 #endif      // IMPS_CIMPSDATA_H
       
   404 
       
   405 // End of File