PECengine/AttributeLibrary2/SrcWVAttributes/PEngWVAttributeModelDataHelper.inl
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2005 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:  Templated attribute data helpers.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // -----------------------------------------------------------------------------
       
    20 // DoSetDescL()
       
    21 // -----------------------------------------------------------------------------
       
    22 //
       
    23 template< class TBufType, class TDataType >
       
    24 inline void DoSetDescL( TBufType*& aPtr, const TDataType& aData )
       
    25     {
       
    26     TBufType* tmp = aData.AllocL();
       
    27     delete aPtr;
       
    28     aPtr = tmp;
       
    29     }
       
    30 
       
    31 
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // DoGetDesc()
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 template< class TBufType, class TPtrType >
       
    38 inline void DoGetDesc( const TBufType* const& aBuffer, TPtrType& aData )
       
    39     {
       
    40     if( aBuffer )
       
    41         {
       
    42         aData.Set( *aBuffer );
       
    43         }
       
    44     else
       
    45         {
       
    46         aData.Set( NULL, 0 );
       
    47         }
       
    48     }
       
    49 
       
    50 
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // DoGetBufExtSize()
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 template< class TBufType >
       
    57 inline TInt DoGetBufExtSize( const TBufType* const& aBuffer )
       
    58     {
       
    59     TInt size( 4 ); //Buffer length indicator: 4 bytes
       
    60 
       
    61     if( aBuffer && aBuffer->Length() != 0 )
       
    62         {
       
    63         size += aBuffer->Size();
       
    64         }
       
    65 
       
    66     return size;
       
    67     }
       
    68 
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // DoExtrBufL()
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 template< class TBufType >
       
    75 inline void DoExtrBufL( const TBufType* const& aBuffer, RWriteStream& aStream )
       
    76     {
       
    77     if( aBuffer && aBuffer->Length() != 0 )
       
    78         {
       
    79         aStream.WriteInt32L( aBuffer->Length() );
       
    80         aStream.WriteL( *aBuffer );
       
    81         }
       
    82     else
       
    83         {
       
    84         aStream.WriteInt32L( 0 );
       
    85         }
       
    86     }
       
    87 
       
    88 
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // DoIntrBufL()
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 template< class TBufType, class TPtrType >
       
    95 inline void DoIntrBufL( TBufType*& aBufPtr, TPtrType aPtr, RReadStream& aStream )
       
    96     {
       
    97     TBufType* buffer = NULL;
       
    98 
       
    99     TInt length = aStream.ReadInt32L();
       
   100     if( length != 0 )
       
   101         {
       
   102         buffer = TBufType::NewLC( length );
       
   103         aPtr.Set( buffer->Des() );
       
   104         aStream.ReadL( aPtr, length );
       
   105         CleanupStack::Pop(); //buffer
       
   106         }
       
   107 
       
   108     delete aBufPtr;
       
   109     aBufPtr = buffer;
       
   110     }
       
   111 
       
   112 
       
   113 //  End of File
       
   114