phonebookengines/VirtualPhonebook/VPbkSimStoreCommon/src/RVPbkStreamedIntArray.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Streamed sort order array for SIM field types
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "RVPbkStreamedIntArray.h"
       
    22 
       
    23 #include <s32mem.h>
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KSizeTInt = 4;
       
    27 const TInt KTwo = 2;
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // RVPbkStreamedIntArray::ExternalizeL
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C void RVPbkStreamedIntArray::ExternalizeL( 
       
    36     RWriteStream& aWriteStream ) const
       
    37     {
       
    38     TInt count = Count();
       
    39     aWriteStream.WriteInt32L( count );
       
    40     for ( TInt i = 0; i < count; ++i )
       
    41         {
       
    42         aWriteStream.WriteInt32L( iIntArray[i] );
       
    43         }
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // RVPbkStreamedIntArray::ExternalizedSize
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C TInt RVPbkStreamedIntArray::ExternalizedSize() const
       
    51     {
       
    52     // The data stream contains the amount of fields and field types
       
    53     // Let's optimize this sentence for efficiency:
       
    54     // sizeof( TInt ) + Count() * sizeof( TInt )
       
    55     return KSizeTInt + Count() << KTwo;   
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // RVPbkStreamedIntArray::InternalizeL
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 EXPORT_C void RVPbkStreamedIntArray::InternalizeL( 
       
    63     RReadStream& aReadStream )
       
    64     {
       
    65     TInt count = aReadStream.ReadInt32L();
       
    66     for ( TInt i = 0; i < count; ++i )
       
    67         {
       
    68         TInt val = static_cast<TInt>( aReadStream.ReadInt32L() );
       
    69         iIntArray.AppendL( val );
       
    70         }
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // RVPbkStreamedIntArray::RemoveAll
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 EXPORT_C void RVPbkStreamedIntArray::RemoveAll()
       
    78     {
       
    79     // Removes but doesn't free the memory
       
    80     const TInt count = iIntArray.Count();
       
    81     for ( TInt i = count - 1; i >= 0; --i )
       
    82         {
       
    83         iIntArray.Remove( i );
       
    84         }
       
    85     }
       
    86     
       
    87 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // ExternalizeArrayLC
       
    91 // 
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 EXPORT_C HBufC8* ExternalizeArrayLC( 
       
    95     const RVPbkStreamedIntArray& aFieldTypes )
       
    96     {
       
    97     TInt size = aFieldTypes.ExternalizedSize();
       
    98     HBufC8* buf = HBufC8::NewLC( size );
       
    99     TPtr8 ptr( buf->Des() );
       
   100     RDesWriteStream stream( ptr );
       
   101     CleanupClosePushL( stream );
       
   102     stream << aFieldTypes;
       
   103     ptr.SetLength( size );
       
   104     CleanupStack::PopAndDestroy(); // stream
       
   105     return buf;
       
   106     }
       
   107 
       
   108 //  End of File