IMPSengine/datautils/src/impsdata.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     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: Container class for stored IMPS engine inner classes
       
    15 * 
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <e32base.h>
       
    21 #include    "impsdata.h"
       
    22 
       
    23 // LOCAL CONSTANTS AND MACROS
       
    24 const TInt KDefaultNumberOfPairs = 10;
       
    25 
       
    26 // C++ default constructor can NOT contain any code, that
       
    27 // might leave.
       
    28 //
       
    29 
       
    30 CImpsElement::CImpsElement( ) :
       
    31 iBool(EFalse),
       
    32 iValueType(EImpsDataTypeNone),
       
    33 iIsEmpty(EFalse)
       
    34     {
       
    35     }
       
    36 
       
    37 // Symbian OS default constructor can leave.
       
    38 void CImpsElement::ConstructL( )
       
    39     {
       
    40     }
       
    41 
       
    42 // Two-phased constructor.
       
    43 CImpsElement* CImpsElement::NewL( )
       
    44     {
       
    45     CImpsElement* self = new (ELeave) CImpsElement;
       
    46     
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( );
       
    49     CleanupStack::Pop( );
       
    50 
       
    51     return self;
       
    52     }
       
    53 
       
    54 // Destructor
       
    55 CImpsElement::~CImpsElement( )
       
    56     {
       
    57     delete iKey;
       
    58     delete iString;
       
    59     delete iString8;
       
    60     }
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CImpsElement::SetStringL
       
    65 // Stores string with given key
       
    66 // ---------------------------------------------------------
       
    67 //
       
    68 void CImpsElement::SetStringL(
       
    69     const CImpsKey* aKey, 
       
    70     const TDesC& aBuf )
       
    71     {
       
    72     iKey = aKey->CopyL(  );
       
    73     HBufC* newString = aBuf.AllocL( );
       
    74     iString = newString;
       
    75     iValueType = EImpsDataTypeDesc;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------
       
    79 // CImpsElement::SetString8L
       
    80 // Stores string8 with given key
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 void CImpsElement::SetString8L(
       
    84     const CImpsKey* aKey, 
       
    85     const TDesC8& aBuf )
       
    86     {
       
    87     iKey = aKey->CopyL(  );
       
    88     HBufC8* newString = aBuf.AllocL( );
       
    89     iString8 = newString;
       
    90     iValueType = EImpsDataTypeDesc8;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // CImpsElement::SetIntL
       
    95 // Stores integervalue with given key
       
    96 // ---------------------------------------------------------
       
    97 //
       
    98 void CImpsElement::SetIntL(
       
    99     const CImpsKey* aKey, 
       
   100     TInt aInt )
       
   101     {
       
   102     iKey = aKey->CopyL(  );
       
   103     iInt = aInt;
       
   104     iValueType = EImpsDataTypeInt;
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------
       
   108 // CImpsElement::SetBooleanL
       
   109 // Stores boolean value with given key
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 void CImpsElement::SetBooleanL(
       
   113     const CImpsKey* aKey, 
       
   114     TBool aBool )
       
   115     {
       
   116     iKey = aKey->CopyL(  );
       
   117     iBool = aBool;
       
   118     iValueType = EImpsDataTypeBoolean;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------
       
   122 // CImpsElement::SetEmptyL
       
   123 // Stores Empty value with given key
       
   124 // ---------------------------------------------------------
       
   125 //
       
   126 void CImpsElement::SetEmptyL(
       
   127     const CImpsKey* aKey )
       
   128     {
       
   129     iKey = aKey->CopyL(  );
       
   130     iIsEmpty = ETrue;
       
   131     iValueType = EImpsDataTypeNone;
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------
       
   135 // CImpsElement::Size
       
   136 // Calculates the size of the element
       
   137 // ---------------------------------------------------------
       
   138 //
       
   139 TInt CImpsElement::Size( ) const
       
   140     {
       
   141     TInt size = 4 * sizeof (TInt); // iInt, iBool, iIsEmpty, iValueType
       
   142     size += iKey->Size( );
       
   143     if( iString )
       
   144         size += iString->Size( ) + sizeof (TInt32);
       
   145     if( iString8 ) 
       
   146         size += iString8->Size( ) + sizeof (TInt32);
       
   147     return size;
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------
       
   151 // CImpsElement::Pack
       
   152 // ---------------------------------------------------------
       
   153 //
       
   154 TInt CImpsElement::Pack(
       
   155     const TUint8*& aPtrStart ) const
       
   156     {
       
   157     Mem::Copy( (void*)aPtrStart, &iInt, sizeof( iInt ) );
       
   158     aPtrStart = aPtrStart + sizeof( iInt );
       
   159 
       
   160     Mem::Copy( (void*)aPtrStart, &iBool, sizeof( iBool ) );
       
   161     aPtrStart = aPtrStart + sizeof( iBool );
       
   162 
       
   163     Mem::Copy( (void*)aPtrStart, &iValueType, sizeof( iValueType ) );
       
   164     aPtrStart = aPtrStart + sizeof( iValueType );
       
   165 
       
   166     Mem::Copy( (void*)aPtrStart, &iIsEmpty, sizeof( iIsEmpty ) );
       
   167     aPtrStart = aPtrStart + sizeof( iIsEmpty );
       
   168 
       
   169     if( iValueType == EImpsDataTypeDesc )
       
   170         {
       
   171         TInt32 tempSize = 0;
       
   172         tempSize = iString->Size();
       
   173         Mem::Copy( (void*)aPtrStart, &tempSize, sizeof( tempSize) );
       
   174         aPtrStart = aPtrStart + sizeof( tempSize );
       
   175         if ( tempSize )
       
   176             {
       
   177             Mem::Copy( (void*)aPtrStart, iString->Ptr(), tempSize);
       
   178             aPtrStart = aPtrStart + tempSize;
       
   179             }
       
   180         }
       
   181     if( iValueType == EImpsDataTypeDesc8 )
       
   182         {
       
   183         TInt32 tempSize = 0;
       
   184 
       
   185         tempSize = iString8->Size();
       
   186         Mem::Copy( (void*)aPtrStart, &tempSize, sizeof( tempSize) );
       
   187         aPtrStart = aPtrStart + sizeof( tempSize );
       
   188         if ( tempSize )
       
   189             {
       
   190             Mem::Copy( (void*)aPtrStart, iString8->Ptr(), tempSize);
       
   191             aPtrStart = aPtrStart + tempSize ;
       
   192             }
       
   193         }
       
   194     TInt ret = iKey->Pack( aPtrStart );
       
   195     return ret;
       
   196     }
       
   197 
       
   198 // ---------------------------------------------------------
       
   199 // CImpsData::UnPack
       
   200 // ---------------------------------------------------------
       
   201 //
       
   202 void CImpsElement::UnPackL(
       
   203     TUint8*& aPtr )
       
   204     { 
       
   205     Mem::Copy( &iInt, aPtr, sizeof( iInt ) );
       
   206     aPtr += sizeof( iInt );
       
   207 
       
   208     Mem::Copy( &iBool, aPtr, sizeof( iBool ) );
       
   209     aPtr += sizeof( iBool );
       
   210 
       
   211     Mem::Copy( &iValueType, aPtr, sizeof( iValueType ) );
       
   212     aPtr += sizeof( iValueType );
       
   213 
       
   214     Mem::Copy( &iIsEmpty, aPtr, sizeof( iIsEmpty ) );
       
   215     aPtr += sizeof( iIsEmpty );
       
   216 
       
   217     if( iValueType == EImpsDataTypeDesc )
       
   218         {
       
   219         const TUint8* textPtr = aPtr;
       
   220         TInt32 tempSize = 0;
       
   221 
       
   222         Mem::Copy( &tempSize, textPtr, sizeof( tempSize) );
       
   223         textPtr = textPtr + sizeof( tempSize );
       
   224         if ( tempSize > 0 )
       
   225             {
       
   226             // No need to put CleanupStack because of other methods do not leave.
       
   227             iString  = HBufC::NewL( tempSize / 2 );  
       
   228             Mem::Copy( (void*)iString->Ptr(), textPtr, tempSize );
       
   229             iString->Des().SetLength( tempSize / 2 ); 
       
   230             textPtr = textPtr + tempSize; 
       
   231             }
       
   232         if ( tempSize < 0 )
       
   233             {
       
   234             User::Leave( KErrCorrupt );
       
   235             }
       
   236 
       
   237         aPtr = (TUint8*) textPtr;
       
   238     
       
   239 
       
   240         }
       
   241     if( iValueType == EImpsDataTypeDesc8 )
       
   242         {
       
   243         const TUint8* textPtr = aPtr;
       
   244         TInt32 tempSize = 0;
       
   245 
       
   246         Mem::Copy( &tempSize, textPtr, sizeof( tempSize) );
       
   247         textPtr = textPtr + sizeof( tempSize );
       
   248         if ( tempSize > 0 )
       
   249             {
       
   250             iString8 = HBufC8::NewL( tempSize );  
       
   251             Mem::Copy( (void*)iString8->Ptr(), textPtr, tempSize );
       
   252             iString8->Des().SetLength( tempSize ); 
       
   253             textPtr = textPtr + tempSize; 
       
   254             }
       
   255         if ( tempSize < 0 )
       
   256             {
       
   257             User::Leave( KErrCorrupt );
       
   258             }
       
   259 
       
   260         aPtr = (TUint8*) textPtr;
       
   261         }
       
   262 
       
   263     iKey = CImpsKey::NewL( );
       
   264     iKey->UnPackL( aPtr );
       
   265     }
       
   266 
       
   267 
       
   268 #ifdef _DEBUG
       
   269 
       
   270 // ---------------------------------------------------------
       
   271 // CImpsElement::DumpToFile
       
   272 // ---------------------------------------------------------
       
   273 //
       
   274 void CImpsElement::DumpToFileL( RFile& aFile ) const
       
   275     {
       
   276     _LIT8( KImpsElementDumpBegin, "  Element dump begin\r\n");
       
   277     aFile.Write( KImpsElementDumpBegin );
       
   278 
       
   279     _LIT8(KIntegerValue,"    Integer value = %d\r\n");
       
   280     _LIT8(KDescStart,"    ");
       
   281     _LIT8(KDescEnd,"\r\n");
       
   282     TBuf8<256> message; 
       
   283     HBufC8* messageString;
       
   284 
       
   285     switch ( iValueType )
       
   286         {
       
   287         case EImpsDataTypeNone:
       
   288             aFile.Write( _L8( "    Impselement type is EImpsDataTypeNone\r\n" ));
       
   289             break;
       
   290         case EImpsDataTypeInt:
       
   291             aFile.Write( _L8( "    Impselement type is EImpsDataTypeInt\r\n" ));
       
   292             message.Format( KIntegerValue, iInt );
       
   293             aFile.Write( message );
       
   294             break;
       
   295         case EImpsDataTypeDesc:
       
   296             aFile.Write( _L8( "    Impselement type is EImpsDataTypeDesc\r\n" ));
       
   297             aFile.Write( KDescStart );
       
   298 //            message.Copy( iString->Des() );
       
   299             messageString = HBufC8::NewL(iString->Length());
       
   300             messageString->Des().Copy(iString->Des());
       
   301             aFile.Write( _L8( "Value: " )  );
       
   302             aFile.Write(messageString->Des());
       
   303             aFile.Write( KDescEnd );
       
   304             delete messageString;
       
   305             break;
       
   306         case EImpsDataTypeDesc8:
       
   307             aFile.Write( _L8( "    Impselement type is EImpsDataTypeDesc8\r\n" ));
       
   308             aFile.Write( KDescStart );
       
   309 //            message.Copy( iString8->Des() );
       
   310             aFile.Write( _L8( "Value: " ) );
       
   311 //            aFile.Write( message );
       
   312             aFile.Write( iString8->Des() );
       
   313             aFile.Write( KDescEnd );
       
   314             break;
       
   315         case EImpsDataTypeBoolean:
       
   316             aFile.Write( _L8( "    Impselement type is EImpsDataTypeBoolean\r\n" ));
       
   317             if( iBool )
       
   318                 aFile.Write( _L8( "    iBool = ETrue\r\n" ));
       
   319             else
       
   320                 aFile.Write( _L8( "    iBool = EFalse\r\n" ));
       
   321             break;
       
   322         case EImpsDataTypeNotSupported:
       
   323             aFile.Write( _L8( "    Impselement type is EImpsDataTypeNotSupported\r\n" ));
       
   324             break;
       
   325         default:
       
   326             aFile.Write( _L8( "    Impselement type is unknown\r\n" ));
       
   327           break;
       
   328         }
       
   329   
       
   330     iKey->DumpToFileL( aFile );
       
   331     
       
   332     _LIT8( KImpsElementDumpEnd, "  Element dump end\r\n");
       
   333     aFile.Write( KImpsElementDumpEnd );
       
   334     }
       
   335 #endif
       
   336 
       
   337 // ---------------------------------------------------------
       
   338 // CImpsElement::CopyL
       
   339 // ---------------------------------------------------------
       
   340 //
       
   341 CImpsElement* CImpsElement::CopyL( ) const
       
   342     {
       
   343     CImpsElement* elem = CImpsElement::NewL( );
       
   344     CleanupStack::PushL( elem );
       
   345     elem->iBool = iBool;
       
   346     elem->iInt = iInt;
       
   347     elem->iValueType = iValueType;
       
   348     elem->iIsEmpty = iIsEmpty;
       
   349     elem->iKey = iKey->CopyL( );
       
   350     if( iString )
       
   351         elem->iString = iString->AllocL( );
       
   352     if( iString8 )
       
   353         elem->iString8 = iString8->AllocL( );
       
   354     CleanupStack::Pop( );
       
   355     return elem;
       
   356     }
       
   357 
       
   358 
       
   359 // ================= MEMBER FUNCTIONS =======================
       
   360 
       
   361 // C++ default constructor can NOT contain any code, that
       
   362 // might leave.
       
   363 //
       
   364 
       
   365 CImpsData::CImpsData()
       
   366     {
       
   367     }
       
   368 
       
   369 // Symbian OS default constructor can leave.
       
   370 void CImpsData::ConstructL( )
       
   371     {
       
   372     iElements = new (ELeave) CImpsElements( KDefaultNumberOfPairs );
       
   373     }
       
   374 
       
   375 // Two-phased constructor.
       
   376 CImpsData* CImpsData::NewL( )
       
   377     {
       
   378     CImpsData* self = new (ELeave) CImpsData;
       
   379     
       
   380     CleanupStack::PushL( self );
       
   381     self->ConstructL( );
       
   382     CleanupStack::Pop( );
       
   383 
       
   384     return self;
       
   385     }
       
   386 
       
   387 // Destructor
       
   388 CImpsData::~CImpsData( )
       
   389     {
       
   390     if ( iElements )
       
   391         {
       
   392         iElements->ResetAndDestroy( );
       
   393         delete iElements;
       
   394         }
       
   395 
       
   396     iElements = NULL;
       
   397     }
       
   398 
       
   399 // ---------------------------------------------------------
       
   400 // CImpsData::StoreStringL
       
   401 // Stores string with given key
       
   402 // ---------------------------------------------------------
       
   403 //
       
   404 void CImpsData::StoreStringL(
       
   405     const CImpsKey *aKey, 
       
   406     const TDesC& aBuff )
       
   407     {
       
   408     CImpsElement* aElement = CImpsElement::NewL( );
       
   409     CleanupStack::PushL( aElement );
       
   410     aElement->SetStringL( aKey, aBuff );
       
   411     iElements->AppendL( aElement );
       
   412     CleanupStack::Pop( );
       
   413     }
       
   414 
       
   415 // ---------------------------------------------------------
       
   416 // CImpsData::StoreString8L
       
   417 // Stores string with given key
       
   418 // ---------------------------------------------------------
       
   419 //
       
   420 void CImpsData::StoreString8L(
       
   421     const CImpsKey *aKey, 
       
   422     const TDesC8& aBuff )
       
   423     {
       
   424     CImpsElement* aElement = CImpsElement::NewL( );
       
   425     CleanupStack::PushL( aElement );
       
   426     aElement->SetString8L( aKey,aBuff );
       
   427     iElements->AppendL( aElement );
       
   428     CleanupStack::Pop( );
       
   429     }
       
   430 
       
   431 // ---------------------------------------------------------
       
   432 // CImpsData::StoreInt
       
   433 // Stores interger value with given key
       
   434 // ---------------------------------------------------------
       
   435 //
       
   436 void CImpsData::StoreIntL(
       
   437     const CImpsKey *aKey, 
       
   438     TInt aInt )
       
   439     {
       
   440     CImpsElement* aElement = CImpsElement::NewL( );
       
   441     CleanupStack::PushL( aElement );
       
   442     aElement->SetIntL( aKey,aInt );
       
   443     iElements->AppendL( aElement );
       
   444     CleanupStack::Pop( );
       
   445     }
       
   446 
       
   447 // ---------------------------------------------------------
       
   448 // CImpsData::StoreBooleanL
       
   449 // Stores boolean value with given key
       
   450 // ---------------------------------------------------------
       
   451 //
       
   452 void CImpsData::StoreBooleanL(
       
   453     const CImpsKey *aKey, 
       
   454     TBool aBool )
       
   455     {
       
   456     CImpsElement* aElement = CImpsElement::NewL( );
       
   457     CleanupStack::PushL( aElement );
       
   458     aElement->SetBooleanL( aKey,aBool );
       
   459     iElements->AppendL( aElement );
       
   460     CleanupStack::Pop( );
       
   461     }
       
   462 
       
   463 // ---------------------------------------------------------
       
   464 // CImpsData::StoreEmptyL
       
   465 // Stores empty value with given key
       
   466 // ---------------------------------------------------------
       
   467 //
       
   468 void CImpsData::StoreEmptyL(
       
   469     const CImpsKey *aKey )
       
   470     {
       
   471     CImpsElement* aElement = CImpsElement::NewL( );
       
   472     CleanupStack::PushL( aElement );
       
   473     aElement->SetEmptyL( aKey );
       
   474     iElements->AppendL( aElement );
       
   475     CleanupStack::Pop( );
       
   476     }
       
   477 
       
   478 // ---------------------------------------------------------
       
   479 // CImpsData::RestoreString
       
   480 // Restores the string with given key
       
   481 // Return EFalse if not found
       
   482 // ---------------------------------------------------------
       
   483 //
       
   484 TBool CImpsData::RestoreString(
       
   485     const CImpsKey *aKey,
       
   486     TDesC*& aBuff ) const
       
   487     {
       
   488     const CImpsElement* aElement = Find( aKey, EImpsDataTypeDesc );
       
   489     if( aElement )
       
   490         {
       
   491         aBuff = aElement->GetString();
       
   492         return ETrue;
       
   493         }
       
   494     return EFalse;
       
   495     }
       
   496 
       
   497 // ---------------------------------------------------------
       
   498 // CImpsData::RestoreString8
       
   499 // Restores the string with given key
       
   500 // Return EFalse if not found
       
   501 // ---------------------------------------------------------
       
   502 //
       
   503 TBool CImpsData::RestoreString8(
       
   504     const CImpsKey *aKey,
       
   505     TDesC8*& aBuff )
       
   506     {
       
   507     const CImpsElement* aElement = Find( aKey, EImpsDataTypeDesc8 );
       
   508     if( aElement )
       
   509         {
       
   510         aBuff = aElement->GetString8();
       
   511         return ETrue;
       
   512         }
       
   513     return EFalse;
       
   514     }
       
   515 
       
   516 // ---------------------------------------------------------
       
   517 // CImpsData::RestoreInt
       
   518 // Restores the integer value with given key
       
   519 // Return EFalse if not found
       
   520 // ---------------------------------------------------------
       
   521 //
       
   522 TBool CImpsData::RestoreInt(
       
   523     const CImpsKey *aKey,
       
   524     TInt& aInt )
       
   525     {
       
   526     const CImpsElement* aElement = Find( aKey, EImpsDataTypeInt );
       
   527     if( aElement )
       
   528         {
       
   529         aInt = aElement->GetInt();
       
   530         return ETrue;
       
   531         }
       
   532     return EFalse;
       
   533     }
       
   534 
       
   535 // ---------------------------------------------------------
       
   536 // CImpsData::RestoreBoolean
       
   537 // Restores the boolean value with given key
       
   538 // Return EFalse if not found
       
   539 // ---------------------------------------------------------
       
   540 //
       
   541 TBool CImpsData::RestoreBoolean(
       
   542     const CImpsKey *aKey,
       
   543     TBool& aBoolean )
       
   544     {
       
   545     const CImpsElement* aElement = Find( aKey, EImpsDataTypeBoolean );
       
   546     if( aElement )
       
   547         {
       
   548         aBoolean = aElement->GetBoolean();
       
   549         return ETrue;
       
   550         }
       
   551     return EFalse;
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------
       
   555 // CImpsData::RestoreEmpty
       
   556 // Return EFalse if not found
       
   557 // ---------------------------------------------------------
       
   558 //
       
   559 TBool CImpsData::RestoreEmpty(
       
   560     const CImpsKey *aKey )
       
   561     {
       
   562     const CImpsElement* aElement = Find( aKey, EImpsDataTypeNone );
       
   563     if( aElement )
       
   564         {
       
   565         return aElement->IsEmpty();
       
   566         }
       
   567     return EFalse;
       
   568     }
       
   569 
       
   570 // ---------------------------------------------------------
       
   571 // CImpsData::CheckKey
       
   572 // Return NULL if not found
       
   573 // ---------------------------------------------------------
       
   574 //
       
   575 const CImpsKey* CImpsData::CheckKey(
       
   576     const CImpsKey *aKey,
       
   577     TImpsKeyOptions aOpt ) const
       
   578     {
       
   579     for( TInt i = 0; i < iElements->Count( ); i++ )
       
   580         {
       
   581         const CImpsElement* aTmp = (*iElements)[i];
       
   582         const CImpsKey* aTmpKey = aTmp->GetKey( );
       
   583         if( aTmpKey->CheckKey( aKey,aOpt ) )
       
   584             return aTmpKey;
       
   585         }
       
   586     return NULL;
       
   587     }
       
   588 
       
   589 // ---------------------------------------------------------
       
   590 // CImpsData::Find
       
   591 // ---------------------------------------------------------
       
   592 //
       
   593 const CImpsElement* CImpsData::Find( const CImpsKey *aKey, TImpsDataType aType) const
       
   594     {
       
   595     for( TInt i = 0; i < iElements->Count(); i++)
       
   596         {
       
   597         const CImpsElement* tmp = (*iElements)[i];
       
   598         if(tmp->GetType( ) == aType) // Check for type little faster
       
   599             {
       
   600             if(*tmp->GetKey()==*aKey)
       
   601                 return tmp;
       
   602             }
       
   603         }
       
   604     return NULL;
       
   605     }
       
   606 
       
   607 // ---------------------------------------------------------
       
   608 // CImpsData::Size
       
   609 // ---------------------------------------------------------
       
   610 //
       
   611 TInt CImpsData::Size( ) const
       
   612     {
       
   613     TInt size = sizeof (TInt); // Count value
       
   614     for( TInt i = 0; i < iElements->Count(); i++)
       
   615         {
       
   616         const CImpsElement* tmp = (*iElements)[i];
       
   617         size += tmp->Size( );
       
   618         }
       
   619     return size;
       
   620     }
       
   621 
       
   622 // ---------------------------------------------------------
       
   623 // CImpsData::Pack
       
   624 // ---------------------------------------------------------
       
   625 //
       
   626 TInt CImpsData::Pack(
       
   627     const TUint8*& aPtrStart ) const
       
   628     {
       
   629     TInt count = Count();
       
   630     Mem::Copy( (void*)aPtrStart, &count, sizeof( count ) );
       
   631     aPtrStart = aPtrStart + sizeof( count );
       
   632   
       
   633     TInt ret = KErrNone;
       
   634     for ( TInt i = 0; i < count; i++)
       
   635         {
       
   636         const CImpsElement* tmp = (*iElements)[i];
       
   637         ret = tmp->Pack( aPtrStart );
       
   638         }
       
   639     return ret;
       
   640     }
       
   641 
       
   642 // ---------------------------------------------------------
       
   643 // CImpsData::UnPack
       
   644 // ---------------------------------------------------------
       
   645 //
       
   646 void CImpsData::UnPackL(
       
   647     TUint8*& aPtr )
       
   648     {
       
   649     TInt elements = 0;   //number of elements in list
       
   650     Mem::Copy( &elements, aPtr, sizeof( elements ) );
       
   651     aPtr += sizeof( elements );
       
   652 
       
   653     for (TInt i = 0; i < elements; i++)
       
   654         {
       
   655         CImpsElement* aElement = CImpsElement::NewL( );
       
   656         CleanupStack::PushL( aElement );
       
   657         aElement->UnPackL( aPtr );
       
   658         iElements->AppendL( aElement );
       
   659         CleanupStack::Pop( );
       
   660         }
       
   661     }
       
   662 
       
   663 #ifdef _DEBUG
       
   664 
       
   665 // ---------------------------------------------------------
       
   666 // CImpsData::DumpToFileL
       
   667 // ---------------------------------------------------------
       
   668 //
       
   669 void CImpsData::DumpToFileL( RFs& aSession, const TDesC& aFileName ) const
       
   670     {
       
   671     RFile file;
       
   672     User::LeaveIfError( file.Replace( aSession, aFileName, EFileWrite ) );
       
   673     _LIT8( KImpsDataDumpBegin, "ImpsData dump begin\r\n");
       
   674     file.Write( KImpsDataDumpBegin );
       
   675 
       
   676     TInt count = Count();
       
   677 
       
   678     _LIT8(KNumberOfElements,"Impsdata number of elements = %d\r\n");
       
   679     _LIT8(KElementNumber,"Element number = %d\r\n");
       
   680     TBuf8<80> message; 
       
   681     message.Format( KNumberOfElements, count );
       
   682     file.Write( message );
       
   683     
       
   684     for ( TInt i = 0; i < count; i++)
       
   685         {
       
   686         const CImpsElement* tmp = (*iElements)[i];
       
   687         message.Format( KElementNumber, i );
       
   688         file.Write( message );
       
   689         tmp->DumpToFileL( file );
       
   690         }
       
   691     
       
   692     _LIT8( KImpsDataDumpEnd, "ImpsData dump end\r\n");
       
   693     file.Write( KImpsDataDumpEnd );
       
   694     file.Close( );
       
   695     }
       
   696 #endif
       
   697 
       
   698 // ---------------------------------------------------------
       
   699 // CImpsData::CopyL
       
   700 // ---------------------------------------------------------
       
   701 //
       
   702 void CImpsData::CopyL( const CImpsKey* aKey, const CImpsData* aSource )
       
   703     {
       
   704     TInt count = aSource->Count();
       
   705     for ( TInt i = 0; i < count; i++)
       
   706         {
       
   707         const CImpsElements* aTmp = aSource->iElements;
       
   708         const CImpsElement* tmpElem = (*aTmp)[i];
       
   709         const CImpsKey* aTmpKey = tmpElem->GetKey( );
       
   710         if( !aKey || aTmpKey->CheckKey( aKey,EPartialKey ) )
       
   711             {
       
   712             CImpsElement* elem = tmpElem->CopyL( );
       
   713             iElements->AppendL( elem );
       
   714             }
       
   715         }
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------
       
   719 // CImpsData::SetKeyIndex
       
   720 // ---------------------------------------------------------
       
   721 //
       
   722 void CImpsData::SetKeyIndex( const CImpsKey* aKey, TInt aNewIndex )
       
   723     {
       
   724     TInt count = Count();
       
   725     for ( TInt i = 0; i < count; i++)
       
   726         {
       
   727         CImpsElement* tmpElem = (*iElements)[i];
       
   728         CImpsKey* aTmpKey = tmpElem->GetKey( );
       
   729         if( aTmpKey->CheckKey( aKey,EPartialKey ) )
       
   730             {
       
   731             aTmpKey->SetElementIndex( aKey->Count( ) - 1 , aNewIndex );
       
   732             }
       
   733         }
       
   734     }
       
   735 
       
   736 //  End of File   
       
   737