mtpfws/mtpfw/datatypes/src/tmtptypeuint128.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @publishedPartner
       
    19 */
       
    20 
       
    21 #include <mtp/mtpdatatypeconstants.h>
       
    22 #include <mtp/tmtptypeuint128.h>
       
    23 
       
    24 /**
       
    25 Default constructor.
       
    26 */
       
    27 EXPORT_C TMTPTypeUint128::TMTPTypeUint128()
       
    28     {
       
    29     iData.FillZ(iData.MaxLength());
       
    30     }
       
    31 
       
    32 /**
       
    33 Conversion constructor.
       
    34 @param aData The initial data value.
       
    35 */
       
    36 EXPORT_C TMTPTypeUint128::TMTPTypeUint128(const TPtrC8& aData) : 
       
    37     iData(aData)
       
    38     {
       
    39     }
       
    40     
       
    41 /**
       
    42 Conversion constructor.
       
    43 @param aUpperGUID the most significant 64 bits: TUint32 and TUint16[2]
       
    44 @param aLowerGUID the lowest  64 bits : TUint8[8]
       
    45 */
       
    46 EXPORT_C TMTPTypeUint128::TMTPTypeUint128(const TUint64 aUpperValue, const TUint64 aLowerValue) 
       
    47     {  
       
    48     iData.FillZ(iData.MaxLength());
       
    49     memcpy(&iData[KMTPTypeUint128OffsetMS], &aUpperValue, sizeof(aUpperValue));
       
    50     memcpy(&iData[KMTPTypeUint128OffsetLS], &aLowerValue, sizeof(aLowerValue));
       
    51     }
       
    52 
       
    53 
       
    54 /**
       
    55 Sets the data type to the specified value.
       
    56 */  
       
    57 EXPORT_C void TMTPTypeUint128::Set(TUint64 aUpperValue, TUint64 aLowerValue)
       
    58 	{   
       
    59     memcpy(&iData[KMTPTypeUint128OffsetMS], &aUpperValue, sizeof(aUpperValue));
       
    60     memcpy(&iData[KMTPTypeUint128OffsetLS], &aLowerValue, sizeof(aLowerValue));
       
    61 	}
       
    62 
       
    63 /**
       
    64 Provides the least significant portion of the data type.
       
    65 @return The least significant 64 bits of the value.
       
    66 */    
       
    67 EXPORT_C TUint64 TMTPTypeUint128::LowerValue() const
       
    68     {    
       
    69     // memcpy the data to avoid alignment errors.
       
    70     TUint64 ret;
       
    71     memcpy(&ret, &iData[KMTPTypeUint128OffsetLS], sizeof(ret));
       
    72     return ret;
       
    73     }
       
    74 
       
    75 /**
       
    76 Provides the most significant portion of type's value.
       
    77 @return The most significant 64 bits of the value.
       
    78 */    
       
    79 EXPORT_C TUint64 TMTPTypeUint128::UpperValue() const
       
    80     {
       
    81     // memcpy the data to avoid alignment errors.
       
    82     TUint64 ret;
       
    83     memcpy(&ret, &iData[KMTPTypeUint128OffsetMS], sizeof(ret));
       
    84     return ret;
       
    85     }
       
    86 
       
    87 	
       
    88 EXPORT_C TInt TMTPTypeUint128::FirstReadChunk(TPtrC8& aChunk) const
       
    89     {
       
    90 	aChunk.Set(iData);
       
    91     return KMTPChunkSequenceCompletion;
       
    92     }
       
    93 	
       
    94 EXPORT_C TInt TMTPTypeUint128::NextReadChunk(TPtrC8& aChunk) const
       
    95     {
       
    96     aChunk.Set(NULL, 0);
       
    97     return KErrNotReady;
       
    98     }
       
    99 	
       
   100 EXPORT_C TInt TMTPTypeUint128::FirstWriteChunk(TPtr8& aChunk)
       
   101     {
       
   102 	aChunk.Set(&iData[0], 0, iData.MaxLength());
       
   103     return KMTPChunkSequenceCompletion;
       
   104     }
       
   105 	
       
   106 EXPORT_C TInt TMTPTypeUint128::NextWriteChunk(TPtr8& aChunk)
       
   107     {
       
   108     aChunk.Set(NULL, 0, 0);
       
   109     return KErrNotReady;
       
   110     }
       
   111 
       
   112 EXPORT_C TUint64 TMTPTypeUint128::Size() const
       
   113     {
       
   114     return iData.MaxLength();
       
   115     }
       
   116     
       
   117 EXPORT_C TUint TMTPTypeUint128::Type() const
       
   118     {
       
   119     return EMTPTypeUINT128;
       
   120     }
       
   121 
       
   122 EXPORT_C TBool TMTPTypeUint128::Equal(const TMTPTypeUint128& aR) const
       
   123     {
       
   124     return ( (this->UpperValue() == aR.UpperValue()) && (this->LowerValue() == aR.LowerValue()) );
       
   125     }
       
   126 
       
   127 EXPORT_C TInt TMTPTypeUint128::Compare(const TMTPTypeUint128& aR) const
       
   128     {  
       
   129     return this->Compare(aR.UpperValue(),aR.LowerValue());
       
   130     }
       
   131 
       
   132 EXPORT_C TInt TMTPTypeUint128::Compare(const TUint64 aRUpper, const TUint64 aRLower) const
       
   133     {
       
   134     TUint64 tmp = this->UpperValue();
       
   135     if( tmp != aRUpper)
       
   136         {
       
   137         return ( tmp > aRUpper ) ? 1 : -1;
       
   138         }
       
   139     
       
   140     tmp = this->LowerValue();
       
   141     if ( tmp != aRLower )
       
   142         {
       
   143         return ( tmp > aRLower ) ? 1 : -1;
       
   144         }
       
   145  
       
   146     return 0;
       
   147     }
       
   148 
       
   149