secureswitools/swisistools/source/sisxlibrary/basefile.h
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 * Note: This file may contain code to generate corrupt files for test purposes.
       
    16 * Such code is excluded from production builds by use of compiler defines;
       
    17 * it is recommended that such code should be removed if this code is ever published publicly.
       
    18 * These streams use memory for storage. If data becomes huge, they will need amending to use temporary files.
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 /**
       
    24  @file 
       
    25  @internalComponent
       
    26  @released
       
    27 */
       
    28 
       
    29 #ifndef __BASEFILE_H__
       
    30 #define __BASEFILE_H__
       
    31 
       
    32 #include "utility_interface.h"
       
    33 
       
    34 
       
    35 #include <sstream>
       
    36 
       
    37 #include "basetype.h"
       
    38 
       
    39 
       
    40 
       
    41 class TSISStream
       
    42 	{
       
    43 public:
       
    44 	typedef unsigned int	size_type;
       
    45 	typedef int				pos_type;
       
    46 
       
    47 public:
       
    48 	/**
       
    49 	 * Default constructor
       
    50 	 */
       
    51 	TSISStream ();
       
    52 	/**
       
    53 	 * Destructor
       
    54 	 */
       
    55 	~TSISStream ();
       
    56 	
       
    57 public:
       
    58 	/**
       
    59 	 * Read the content from the stream.
       
    60 	 * @param aBuffer buffer to which data needs to be read.
       
    61 	 * @param aSize size of data to be read.
       
    62 	 */
       
    63 	void read (TUint8* aBuffer, const size_type aSize);
       
    64 	/**
       
    65 	 * Write the content into the stream
       
    66 	 * @param aBuffer from which the data needs to be written to the stream
       
    67 	 * @param aSize amount of data needs to be written.
       
    68 	 */
       
    69 	void write (const TUint8* aBuffer, const size_type aSize);
       
    70 
       
    71 	/**
       
    72 	 * @return returns the current stream pointer.
       
    73 	 */
       
    74 	pos_type tell () const;
       
    75 	/**
       
    76 	 * Seek the stream pointer.
       
    77 	 * @param aPos offset by which the pointer needs to be moved.
       
    78 	 * @param aRel From where the offset needs to be moved.
       
    79 	 */
       
    80 	void seek (const pos_type aPos, const std::ios_base::seekdir aRel = std::ios_base::beg);
       
    81 
       
    82 	/**
       
    83 	 * @return stream length
       
    84 	 */
       
    85 	size_type length () const;
       
    86 
       
    87 	/**
       
    88 	 * Write the content of the stream into the file.
       
    89 	 * @param aFile file handle.
       
    90 	 */
       
    91 	bool exportfile (HANDLE aFile);
       
    92 	/**
       
    93 	 * Read the content from the file and write it into the stream
       
    94 	 * @param aFile file handle
       
    95 	 * @param filesize file size to be read.
       
    96 	 */
       
    97 	bool import (HANDLE aFile, TUint64* filesize = NULL);
       
    98 
       
    99 	/**
       
   100 	 * Reset all read-write pointers
       
   101 	 */
       
   102 	void reset ();
       
   103 	/**
       
   104 	 * @return buffer pointed by the stream.
       
   105 	 */
       
   106 	const TUint8* data () const;
       
   107 
       
   108 	/**
       
   109 	 * @return Maximum buffer size allocated to this stream
       
   110 	 */
       
   111 	static TUint64 MaxBufferSize ();
       
   112 
       
   113 private:
       
   114 	void reserve (const size_type aSize);
       
   115 
       
   116 private:
       
   117 	TUint8*				iBuffer;
       
   118 	size_type			iSize;
       
   119 	size_type			iDataLength;
       
   120 	pos_type			iOffset;
       
   121 	static size_type 	iChunk;
       
   122 	};
       
   123 
       
   124 
       
   125 
       
   126 
       
   127 inline TSISStream::pos_type TSISStream::tell () const
       
   128 	{
       
   129 	return iOffset;
       
   130 	}
       
   131 
       
   132 inline TSISStream::size_type TSISStream::length () const
       
   133 	{
       
   134 	return iDataLength;
       
   135 	}
       
   136 
       
   137 inline const TUint8* TSISStream::data () const
       
   138 	{
       
   139 	return iBuffer;
       
   140 	}
       
   141 
       
   142 inline TUint64 TSISStream::MaxBufferSize ()
       
   143 	{
       
   144 	return UINT_MAX;
       
   145 	}
       
   146 	
       
   147 
       
   148 
       
   149 
       
   150 
       
   151 inline TSISStream& operator >> (TSISStream& aFile, TUint8& aValue)
       
   152 	{
       
   153 	aFile.read (reinterpret_cast <TUint8*> (&aValue), sizeof (TUint8));
       
   154 	return aFile;
       
   155 	}
       
   156 
       
   157 inline TSISStream& operator << (TSISStream& aFile, const TUint8 aValue)
       
   158 	{
       
   159 	aFile.write (reinterpret_cast <const TUint8*> (&aValue), sizeof (TUint8));
       
   160 	return aFile;
       
   161 	}
       
   162 
       
   163 inline TSISStream& operator >> (TSISStream& aFile, TUint16& aValue)
       
   164 	{
       
   165 	aFile.read (reinterpret_cast <TUint8*> (&aValue), sizeof (TUint16));
       
   166 	return aFile;
       
   167 	}
       
   168 
       
   169 inline TSISStream& operator << (TSISStream& aFile, const TUint16 aValue)
       
   170 	{
       
   171 	aFile.write (reinterpret_cast <const TUint8*> (&aValue), sizeof (TUint16));
       
   172 	return aFile;
       
   173 	}
       
   174 
       
   175 inline TSISStream& operator >> (TSISStream& aFile, TUint32& aValue)
       
   176 	{
       
   177 	aFile.read (reinterpret_cast <TUint8*> (&aValue), sizeof (TUint32));
       
   178 	return aFile;
       
   179 	}
       
   180 
       
   181 inline TSISStream& operator << (TSISStream& aFile, const TUint32 aValue)
       
   182 	{
       
   183 	aFile.write (reinterpret_cast <const TUint8*> (&aValue), sizeof (TUint32));
       
   184 	return aFile;
       
   185 	}
       
   186 
       
   187 inline TSISStream& operator >> (TSISStream& aFile, TInt32& aValue)
       
   188 	{
       
   189 	aFile.read (reinterpret_cast <TUint8*> (&aValue), sizeof (TInt32));
       
   190 	return aFile;
       
   191 	}
       
   192 
       
   193 inline TSISStream& operator << (TSISStream& aFile, const TInt32 aValue)
       
   194 	{
       
   195 	aFile.write (reinterpret_cast <const TUint8*> (&aValue), sizeof (TInt32));
       
   196 	return aFile;
       
   197 	}
       
   198 
       
   199 inline TSISStream& operator >> (TSISStream& aFile, TUint64& aValue)
       
   200 	{
       
   201 	aFile.read (reinterpret_cast <TUint8*> (&aValue), sizeof (TUint64));
       
   202 	return aFile;
       
   203 	}
       
   204 
       
   205 inline TSISStream& operator << (TSISStream& aFile, const TUint64 aValue)
       
   206 	{
       
   207 	aFile.write (reinterpret_cast <const TUint8*> (&aValue), sizeof (TUint64));
       
   208 	return aFile;
       
   209 	}
       
   210 
       
   211 
       
   212 
       
   213 #endif // __BASEFILE_H__
       
   214