secureswitools/swisistools/source/sisxlibrary/raw.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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 the License "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 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file 
       
    21  @internalComponent
       
    22  @released
       
    23 */
       
    24 
       
    25 #include "raw.h"
       
    26 #include "siswrite.h"
       
    27 
       
    28 CRaw::CRaw (const CRaw& aInitialiser) :
       
    29 		iData (NULL),
       
    30 		iSize (0)
       
    31 	{
       
    32 	assert ((aInitialiser.iData == NULL) == (aInitialiser.iSize == 0));
       
    33 	if (aInitialiser.iSize)
       
    34 		{
       
    35 		Alloc (aInitialiser.iSize);
       
    36 		memcpy (iData, aInitialiser.iData, aInitialiser.iSize);
       
    37 		}
       
    38 	}
       
    39 
       
    40 
       
    41 void CRaw::Alloc (const TFieldSize& aSize)
       
    42 	{
       
    43 	assert (iSize <= UINT_MAX);		// you'll need to rewrite CSISFieldRoot::DoTheCrc and stream I/O to take large sizes
       
    44 	Dispose ();
       
    45 	if (aSize)
       
    46 		{
       
    47 		try
       
    48 			{
       
    49 			iData = new TUint8 [aSize];
       
    50 			}
       
    51 		catch(std::exception& e)
       
    52 			{
       
    53 			SISLogger::Log(L"Error : File Size is too big to process...\n");
       
    54 			throw CSISException (CSISException::EMemory, "File Size is too big to process...");
       
    55 			}
       
    56 
       
    57 		iSize = aSize;
       
    58 		}
       
    59 	}
       
    60 
       
    61 
       
    62 void CRaw::Dispose ()
       
    63 	{
       
    64 	delete iData;
       
    65 	iData = NULL;
       
    66 	iSize = 0;
       
    67 	}
       
    68 
       
    69 	
       
    70 void CRaw::Read (TSISStream& aFile, const TFieldSize& aContainerSize, const CSISFieldRoot::TFieldType aArrayType)
       
    71 	{
       
    72 	assert (aArrayType == CSISFieldRoot::ESISUndefined);	// typing invalid
       
    73 	Alloc (aContainerSize);
       
    74 	if (iSize)
       
    75 		{
       
    76 		aFile.read (iData, static_cast <TSISStream::size_type> (aContainerSize));
       
    77 		}
       
    78 	}
       
    79 
       
    80 
       
    81 void CRaw::Write (TSISStream& aFile, const bool aIsArrayElement) const
       
    82 	{
       
    83 	assert (! aIsArrayElement);	// typing invalid
       
    84 	assert ((iData == NULL) == (iSize == 0));
       
    85 	if (iSize)
       
    86 		{
       
    87 		aFile.write (iData, iSize);
       
    88 		}
       
    89 	}
       
    90 
       
    91 
       
    92 void CRaw::Skip (TSISStream& aFile, const TFieldSize& aContainerSize) const
       
    93 	{
       
    94 	assert (aContainerSize <= aFile.MaxBufferSize ());
       
    95 	if (aContainerSize)
       
    96 		{
       
    97 		aFile.seek (static_cast <TSISStream::pos_type> (aContainerSize), std::ios_base::cur);
       
    98 		}
       
    99 	}
       
   100 
       
   101 
       
   102 CSISFieldRoot::TFieldSize CRaw::ByteCount (const bool aInsideArray) const
       
   103 	{
       
   104 	return iSize;
       
   105 	}
       
   106 
       
   107 
       
   108 void CRaw::SetByteCount (const TFieldSize aSize)
       
   109 	{
       
   110 	Alloc (aSize);
       
   111 	}
       
   112 
       
   113 
       
   114 void CRaw::Dump (std::ostream& aStream, const int aLevel) const
       
   115 	{
       
   116 	aStream << iSize << " bytes:" << std::hex;
       
   117 	TUint64 size = 20;
       
   118 	for (int index = 0; index < std::min (iSize, size); index++)
       
   119 		{
       
   120 		aStream << " " << static_cast <unsigned int> (iData [index]);
       
   121 		}
       
   122 	aStream << std::dec;
       
   123 	}
       
   124 
       
   125 
       
   126 void CRaw::CalculateCrc (TCRC& aCRC, const bool aIsArrayElement) const
       
   127 	{
       
   128 	assert ((iData == NULL) == (iSize == 0));
       
   129 	if (iSize)
       
   130 		{
       
   131 		DoPaddedCrc (aCRC, iData, static_cast <unsigned int> (iSize));
       
   132 		}
       
   133 	}
       
   134 
       
   135 
       
   136 std::string CRaw::Name () const
       
   137 	{
       
   138 	return "raw";
       
   139 	}