ximpfw/core/srcutils/ximprbufhelpers.cpp
changeset 0 e6b17d312c8b
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Helpers for handling RBuf.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "ximprbufhelpers.h"
       
    19 
       
    20 // ==================== XIMPRBuf16Helper MEMBER FUNCTIONS ====================
       
    21 
       
    22 // -----------------------------------------------------------------------------
       
    23 // XIMPRBuf16Helper::GrowIfNeededL()
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 EXPORT_C void XIMPRBuf16Helper::GrowIfNeededL( RBuf16& aBuf, const TInt aMaxLength )
       
    27     {
       
    28     if ( aBuf.MaxLength() < aMaxLength )
       
    29         {
       
    30         aBuf.ReAllocL( aMaxLength );
       
    31         }
       
    32     }
       
    33 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // XIMPRBuf16Helper::SetNewValueL()
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 EXPORT_C void XIMPRBuf16Helper::SetNewValueL( RBuf16& aBuf,
       
    40                                               const TDesC16& aValue )
       
    41     {
       
    42     GrowIfNeededL( aBuf, aValue.Length() );
       
    43     aBuf.Copy( aValue );
       
    44     }
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // XIMPRBuf16Helper::ExternalizeL()
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C void XIMPRBuf16Helper::ExternalizeL( const RBuf16& aBuf,
       
    52                                               RWriteStream& aStream )
       
    53     {
       
    54     aStream.WriteInt32L( aBuf.Length() );
       
    55     aStream.WriteL( aBuf );
       
    56     }
       
    57 
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // XIMPRBuf16Helper::InternalizeL()
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C void XIMPRBuf16Helper::InternalizeL( RBuf16& aBuf,
       
    64                                               RReadStream& aStream )
       
    65     {
       
    66     TInt length = aStream.ReadInt32L();
       
    67     GrowIfNeededL( aBuf, length );
       
    68     aStream.ReadL( aBuf, length );
       
    69     }
       
    70 
       
    71 
       
    72 // ==================== XIMPRBuf8Helper MEMBER FUNCTIONS ====================
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // XIMPRBuf8Helper::GrowIfNeededL()
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C void XIMPRBuf8Helper::GrowIfNeededL( RBuf8& aBuf, const TInt aMaxLength )
       
    79     {
       
    80     if ( aBuf.MaxLength() < aMaxLength )
       
    81         {
       
    82         aBuf.ReAllocL( aMaxLength );
       
    83         }
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // XIMPRBuf8Helper::SetNewValueL()
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 EXPORT_C void XIMPRBuf8Helper::SetNewValueL( RBuf8& aBuf,
       
    92                                              const TDesC8& aValue )
       
    93     {
       
    94     GrowIfNeededL( aBuf, aValue.Length() );
       
    95     aBuf.Copy( aValue );
       
    96     }
       
    97 
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // XIMPRBuf8Helper::ExternalizeL()
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C void XIMPRBuf8Helper::ExternalizeL( const RBuf8& aBuf,
       
   104                                              RWriteStream& aStream )
       
   105     {
       
   106     aStream.WriteInt32L( aBuf.Length() );
       
   107     aStream.WriteL( aBuf );
       
   108     }
       
   109 
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // XIMPRBuf8Helper::InternalizeL()
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 EXPORT_C void XIMPRBuf8Helper::InternalizeL( RBuf8& aBuf,
       
   116                                              RReadStream& aStream )
       
   117     {
       
   118     TInt length = aStream.ReadInt32L();
       
   119     GrowIfNeededL( aBuf, length );
       
   120     aStream.ReadL( aBuf, length );
       
   121     }
       
   122 
       
   123