Game Development Reference
In-Depth Information
virtual std::string GetFileName() const { return FFileName; }
virtual uint64 GetFilePos() const { return FPosition; }
virtual void Seek( const uint64 Position )
{
#ifdef _WIN32
SetFilePointerEx( FMapFile,
*reinterpret_cast<const LARGE_INTEGER*>( &Position ),
NULL, FILE_BEGIN );
#else
if ( FMapFile != -1 )
{ lseek( FMapFile, Position, SEEK_SET ); }
#endif
FPosition = Position;
}
However, things may get more complex if you decide to support
more operating systems. It can be a good refactoring exercise.
virtual uint64 Write( const void* Buf, const uint64 Size )
{
#ifdef _WIN32
DWORD written;
WriteFile( FMapFile, Buf, DWORD( Size ),
&written, NULL );
#else
if ( FMapFile != -1 ) { write( FMapFile, Buf, Size ); }
#endif
FPosition += Size;
return Size;
}
private:
std::string FFileName;
#ifdef _WIN32
HANDLE FMapFile;
#else
int FMapFile;
#endif
uint64 FPosition;
};
How it works…
Now we can also present an implementation of the iOStream that stores everything in a
memory block. To store arbitrary data in a memory block, we declare the Blob class, as
shown in the following code:
 
Search WWH ::




Custom Search