extras/converter/engine/Src/TCnvUnit.cpp
changeset 13 83b3f7c09925
parent 2 c4c2ac0facfd
equal deleted inserted replaced
2:c4c2ac0facfd 13:83b3f7c09925
     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 *	  This is the implementation of the class defined in TCnvUnit.h
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <barsread.h>
       
    22 #include <s32strm.h>
       
    23 
       
    24 #include "TCnvUnit.h"
       
    25 
       
    26 TCnvUnit::TCnvUnit() : 
       
    27 	iFactor( 0 ), iOffset( 0 ), 
       
    28 	iMinimum( 0 ), iId( 0 ), 
       
    29 	iIsTemperatureUnit( EFalse ),
       
    30 	iIsCurrencyUnit ( EFalse )
       
    31 	{
       
    32 	}
       
    33 
       
    34 // Read the data from a resource. If this is a temperature unit we have
       
    35 // a couple extra parameters to read.
       
    36 void TCnvUnit::ReadFromResource( TResourceReader& aReader,
       
    37 								 TBool aIsTemperature, TBool aIsCurrencyUnit )
       
    38 	{
       
    39 	// This flag has been done to avoid storing the two additional TReals in
       
    40 	// resources and streams (they are valid only for temperature units).
       
    41 	iIsTemperatureUnit = aIsTemperature;
       
    42 	iIsCurrencyUnit = aIsCurrencyUnit;
       
    43 
       
    44 	iName.Copy( aReader.ReadTPtrC() );
       
    45 	iFactor = aReader.ReadReal64();
       
    46 	iId = aReader.ReadUint16();
       
    47 
       
    48 	if( iIsTemperatureUnit )
       
    49 		{
       
    50 		iOffset = aReader.ReadReal64();
       
    51 		iMinimum = aReader.ReadReal64();
       
    52 		}
       
    53 	
       
    54 	if(iIsCurrencyUnit)	
       
    55 		{
       
    56 		TUint nameType (aReader.ReadUint8());
       
    57 		iNameType = (TCurrencyType)nameType;
       
    58 		}
       
    59 	}
       
    60 
       
    61 // Store the data in a stream.
       
    62 void TCnvUnit::ExternalizeL( RWriteStream& aStream ) const
       
    63 	{
       
    64 	aStream.WriteUint16L( iName.Length() );
       
    65 	aStream.WriteL( iName );
       
    66 
       
    67 	aStream.WriteReal64L( iFactor );
       
    68 	
       
    69 	aStream.WriteUint16L( iId );
       
    70 
       
    71 	aStream.WriteUint8L( iIsTemperatureUnit );
       
    72 	if( iIsTemperatureUnit )
       
    73 		{
       
    74 		aStream.WriteReal64L( iOffset );
       
    75 		aStream.WriteReal64L( iMinimum );
       
    76 		}
       
    77 		
       
    78 	aStream.WriteUint8L( iIsCurrencyUnit );
       
    79 	if(iIsCurrencyUnit)
       
    80 		{
       
    81 		aStream.WriteUint8L( iNameType );
       
    82 		}
       
    83 	}
       
    84 
       
    85 // Recover the data from a stream.
       
    86 void TCnvUnit::InternalizeL( RReadStream& aStream, TBool aIsCurrencyCategory )
       
    87 	{
       
    88 	iIsCurrencyUnit = aIsCurrencyCategory;
       
    89 	TUint nameLength( aStream.ReadUint16L() );
       
    90 	aStream.ReadL( iName, nameLength );
       
    91 
       
    92 	iFactor = aStream.ReadReal64L();
       
    93 
       
    94 	iId = aStream.ReadUint16L();
       
    95 
       
    96 	iIsTemperatureUnit = aStream.ReadUint8L();
       
    97 
       
    98 	if( iIsTemperatureUnit )
       
    99 		{
       
   100 		iOffset = aStream.ReadReal64L();
       
   101 		iMinimum = aStream.ReadReal64L();
       
   102 		}
       
   103 	
       
   104 	iIsCurrencyUnit = aStream.ReadUint8L();
       
   105 	
       
   106 	if(iIsCurrencyUnit)
       
   107 		{
       
   108 		TUint nameType (aStream.ReadUint8L());
       
   109 		iNameType = (TCurrencyType)nameType;
       
   110 		}
       
   111 	}
       
   112 
       
   113 
       
   114 // End of file