Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

tnstream Class Reference

The interface for all kinds of IO stream. More...

#include <basestreaminterface.h>

Inheritance diagram for tnstream:

Inheritance graph
[legend]
List of all members.

Public Types

enum  IOMode { uninitialized, reading, writing, appending }
 the modes in which a stream can operate More...

Public Member Functions

 tnstream ()
virtual void writedata (const void *buf, int size)=0
 writes data to the stream
virtual int readdata (void *buf, int size, bool excpt=true)=0
 Reads data from the stream.
virtual void readpchar (char **pc, int maxlength=0)
 Reads a string.
virtual void readpnchar (char **pc, int maxlength=0)
 Reads a string.
virtual bool readTextString (ASCString &s, bool includeCR=false)
 Reads a string.
virtual ASCString readString (bool includeCR=false)
 Reads and returns a string.
virtual void writepchar (const char *pc)
 write the C-String pc to the stream
virtual void writeString (const string &pc, bool binary=true)
 writes the C++ String pc to the stream.
virtual int readInt (void)
 Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is performed, if necessary.
virtual int readWord (void)
 Reads a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is performed, if necessary.
virtual char readChar (void)
 Reads a 8 bit unsigned Integer.
template<size_t N>
void writeBitset (const std::bitset< N > &bs)
template<size_t N>
void readBitset (std::bitset< N > &bs)
virtual float readFloat (void)
 Reads a flaot variable.
virtual void writeInt (int i)
 Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is performed, if necessary.
virtual void writeInt (unsigned int i)
void writeInt (bool b)
virtual void writeWord (int w)
 Writes a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is performed, if necessary.
virtual void writeChar (char c)
 Writes a 8 bit unsigned Integer.
virtual void writeFloat (float f)
 Write a floating point variable.
virtual void writerlepict (const void *buf)
 Writes an image to the stream and compresses it using RLE.
virtual void writeImage (const void *buf, bool compress=true)
 Writes an image to the stream.
virtual void readrlepict (void **pnter, bool allocated, int *size)
 Writes an RLE compressed or uncompressed image from the stream.
virtual ASCString getDeviceName (void)
 returns the name of the stream.
virtual ASCString getLocation (void)
 returns the location of the stream.
virtual void seek (int newpos)
 Sets the stream pointer to a new location. An exception is thrown if the stream does not support seeking.
virtual int getSize (void)
 returns the size of the stream or -1 if the stream does not have a size
virtual ~tnstream ()

Protected Attributes

ASCString devicename

Detailed Description

The interface for all kinds of IO stream.

Because ASC was originally written in Pascal, the streams don't have any relation to the C++ streams

Definition at line 36 of file basestreaminterface.h.


Member Enumeration Documentation

enum tnstream::IOMode
 

the modes in which a stream can operate

Enumeration values:
uninitialized 
reading 
writing 
appending 

Definition at line 41 of file basestreaminterface.h.


Constructor & Destructor Documentation

tnstream::tnstream  ) 
 

Definition at line 202 of file basestrm.cpp.

virtual tnstream::~tnstream  )  [inline, virtual]
 

Definition at line 188 of file basestreaminterface.h.


Member Function Documentation

ASCString tnstream::getDeviceName void   )  [virtual]
 

returns the name of the stream.

Definition at line 277 of file basestrm.cpp.

References devicename.

Referenced by tn_file_buf_stream::get_time(), PropertyWritingContainer::getFileName(), tn_file_buf_stream::getstreamsize(), MemoryStreamCopy::MemoryStreamCopy(), Building::newFromStream(), PropertyWritingContainer::PropertyWritingContainer(), Technology::read(), TechAdapterDependency::read(), TechAdapter::read(), TechDependency::read(), Bi3MapTranslationTable::Terrain2id::read(), tfindfile::FileInfo::read(), tn_file_buf_stream::readbuffer(), tnbufstream::readdata(), MemoryStreamCopy::readdata(), TextFormatParser::run(), tn_file_buf_stream::seek(), MemoryStreamCopy::seek(), seek(), tn_c_lzw_filestream::tn_c_lzw_filestream(), tn_file_buf_stream::writebuffer(), tnbufstream::writedata(), MemoryStreamCopy::writedata(), and tn_file_buf_stream::~tn_file_buf_stream().

ASCString tnstream::getLocation void   )  [virtual]
 

returns the location of the stream.

This may be a complete english sentence describing how the stream (usually a file) can be found. Should only be used for informing the user.

Reimplemented in MemoryStreamCopy, and tn_c_lzw_filestream.

Definition at line 282 of file basestrm.cpp.

References devicename.

Referenced by TextFormatParser::error(), PropertyWritingContainer::getLocation(), PropertyWritingContainer::PropertyWritingContainer(), Poly_gon::read(), ItemRepositoryLoader< T >::read(), BuildingType::read(), Research::read_struct(), readClassContainer(), readOldEventLists(), readSDLPixelFormat(), readString(), TextFormatParser::run(), and versionTest().

virtual int tnstream::getSize void   )  [inline, virtual]
 

returns the size of the stream or -1 if the stream does not have a size

Reimplemented in MemoryStreamCopy, tn_c_lzw_filestream, and tn_file_buf_stream.

Definition at line 186 of file basestreaminterface.h.

template<size_t N>
void tnstream::readBitset std::bitset< N > &  bs  )  [inline]
 

Definition at line 126 of file basestreaminterface.h.

References assert, N, readChar(), and readInt().

Referenced by ContainerBaseType::read().

char tnstream::readChar void   )  [virtual]
 

Reads a 8 bit unsigned Integer.

Definition at line 301 of file basestrm.cpp.

References readdata2.

Referenced by checkFileLoadability(), Vehicle::newFromStream(), Building::newFromStream(), TerrainType::Weather::read(), TerrainType::MoveMalus::read(), tpcxheader::read(), GameMap::read(), BuildingType::read(), Research::read_struct(), readBitset(), tspfldloaders::readfields(), readLegacyNetworkData(), trunreplay::readnextaction(), readrlepict(), and trunreplay::run().

virtual int tnstream::readdata void *  buf,
int  size,
bool  excpt = true
[pure virtual]
 

Reads data from the stream.

Parameters:
buf the buffer which the data is written to
size the number of bytes which should be read
excpt If true the operation will throw an exception if the desired number of bytes cannot be read.
Returns:
the number of bytes which were read.

Implemented in MemoryStreamCopy, tmemorystream, tn_lzw_file_buf_stream, tn_c_lzw_filestream, and tnbufstream.

Referenced by MemoryStreamCopy::MemoryStreamCopy(), tpcxheader::read(), GameMap::read(), readOldEvent(), readpchar(), readpnchar(), readrlepict(), and readTextString().

float tnstream::readFloat void   )  [virtual]
 

Reads a flaot variable.

Definition at line 324 of file basestrm.cpp.

References readdata2, and SwapFloat().

Referenced by WeatherSystem::read().

int tnstream::readInt void   )  [virtual]
 

Reads a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is performed, if necessary.

Definition at line 287 of file basestrm.cpp.

References readdata2.

Referenced by AutoProgressBar::AutoProgressBar(), trunreplay::execnextreplaymove(), Reinforcements::execute(), FileCache::FileCache(), findNextCampaignMap(), getGraphicSetIdFromFilename(), trunreplay::getnextreplayinfo(), GraphicSetManager_Base::loadData(), tsavegameloaders::loadgame(), tnetworkloaders::loadnwgame(), loadreplay(), Vehicle::newFromStream(), Building::newFromStream(), ClipBoardBase::pasteUnit(), ClipBoardBase::place(), WeatherSystem::read(), MapCoordinate3D::read(), Resources::read(), TerrainBits::read(), TerrainType::Weather::read(), TerrainType::MoveMalus::read(), Technology::read(), TechAdapterDependency::read(), TechAdapter::read(), TechDependency::read(), Player::read(), Password::read(), GameTransferMechanism::read(), MusicPlayList::read(), Poly_gon::read(), tpcxheader::read(), BI3TranslationTableLoader::read(), Bi3MapTranslationTable::read(), Bi3MapTranslationTable::Terrain2id::read(), ItemRepositoryLoader< T >::read(), GameMap::ReplayInfo::read(), GameMap::read(), Event::read(), ContainerBaseType::read(), BuildingType::read(), tfindfile::FileInfo::read(), AI::read(), Research::read_struct(), readBitset(), FileTransfer::readChildData(), readClassContainer(), AllEnemyBuildingsDestroyed::readData(), AllEnemyUnitsDestroyed::readData(), AllUnitsLost::readData(), AllBuildingsLost::readData(), Reinforcements::readData(), SetViewSharing::readData(), ChangePlayerState::readData(), AddProductionCapability::readData(), DisplayImmediateMessage::readData(), ChangeBuildingOwner::readData(), DisplayEllipse::readData(), NextMap::readData(), AddObject::readData(), MapChange::readData(), DisplayMessage::readData(), Action_Nothing::readData(), AnyUnitEntersPolygon::readData(), SpecificUnitEntersPolygon::readData(), UnitTrigger::readData(), tspfldloaders::readdissections(), tspfldloaders::readfields(), readLegacyNetworkData(), FieldAddressing::readMapModificationData(), tspfldloaders::readmessagelist(), tspfldloaders::readmessages(), readOldEvent(), readOldEventLists(), tspfldloaders::readoldevents(), readPointerContainer(), readSDLPixelFormat(), tncontainerstream::tncontainerstream(), validateemlfile(), validatemapfile(), validatesavfile(), and versionTest().

void tnstream::readpchar char **  pc,
int  maxlength = 0
[virtual]
 

Reads a string.

All bytes of the files are stored in the allocated memory until either a 0 Byte is read or the maximum number of character have been reached. The string will always be 0 terminated in both cases.

Parameters:
pc pointer to an uninitialized pointer which will contain the string. The memory will be allocated using new char[length of string] .
maxlength The maximum number of bytes that will be read. If zero, the maximum length is not limited.

Definition at line 381 of file basestrm.cpp.

References CharBuf::buf, and readdata().

Referenced by findNextCampaignMap(), tnetworkloaders::loadnwgame(), tncontainerstream::tncontainerstream(), validateemlfile(), validatemapfile(), and validatesavfile().

void tnstream::readpnchar char **  pc,
int  maxlength = 0
[virtual]
 

Reads a string.

All bytes of the files are stored in the allocated memory until either a 0 Byte or a newline character is read or the maximum number of character have been reached. The string will always be 0 terminated. Carriage return bytes will be filtered out.

Parameters:
pc pointer to an uninitialized pointer which will contain the string. The memory will be allocated using new char[length of string] .
maxlength The maximum number of bytes that will be read. If zero, the maximum length is not limited.

Definition at line 431 of file basestrm.cpp.

References CharBuf::buf, readdata(), red, and strdup().

void tnstream::readrlepict void **  pnter,
bool  allocated,
int *  size
[virtual]
 

Writes an RLE compressed or uncompressed image from the stream.

Parameters:
pnter Pointer to a void* , which will contain the new image.
allocated If false, a sufficient amount of memory will be allocated for the image. If true it is assumed that a sufficiently large amount of memory has already been allocated.
size Will contain the size of the image. Must not be NULL.

Definition at line 210 of file basestrm.cpp.

References trleheader::id, readChar(), readdata(), readWord(), trleheader::rle, trleheader::size, trleheader::x, and trleheader::y.

Referenced by UnitPropertyEditor::init(), and loadcursor().

ASCString tnstream::readString bool  includeCR = false  )  [virtual]
 

Reads and returns a string.

Carriage Return character will be filtered. If the very first read operation fails because the end of the stream was already reached, a readafterend exception will be thrown. If some data could be read before the end was reached, this data will be returned.

Parameters:
includeCR if true, the reading will stop only at 0 Bytes or the end of stream, so all newline character will be part of the text string. Useful for binary files. If false reading will stop at 0 Bytes and newline characters. The newline character will not be part of the resulting string.

Definition at line 526 of file basestrm.cpp.

References getLocation(), and readTextString().

Referenced by checkFileVersion(), tsavegameloaders::loadgame(), loadsinglemessagefile(), Technology::read(), TechAdapterDependency::read(), TechAdapter::read(), GameTransferMechanism::read(), MusicPlayList::read(), Bi3MapTranslationTable::read(), ItemRepositoryLoader< T >::read(), GameMap::read(), Event::read(), ContainerBaseType::read(), BuildingType::read(), tfindfile::FileInfo::read(), FileTransfer::readChildData(), DisplayImmediateMessage::readData(), readLegacyNetworkData(), TextFormatParser::readLine(), and tspfldloaders::readmessages().

bool tnstream::readTextString ASCString s,
bool  includeCR = false
[virtual]
 

Reads a string.

Carriage Return character will be filtered.

Parameters:
s The ASCString which will contain the data read.
includeCR if true, the reading will stop only a 0 Bytes or the end of stream, so all newline character will be part of the text string. Useful for binary files. If false reading will stop and 0 Bytes and newline characters. The newline character will not be part of the resulting string.
Returns:
true if there is remaining data after the string, false if the reading was ended because the end of the stream was reached.

Definition at line 502 of file basestrm.cpp.

References readdata(), and red.

Referenced by MailOptionsDialog::MailOptionsDialog(), SingleUnitSet::read(), readString(), and readtextmessage().

int tnstream::readWord void   )  [virtual]
 

Reads a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is performed, if necessary.

Definition at line 294 of file basestrm.cpp.

References readdata2.

Referenced by findNextCampaignMap(), tsavegameloaders::loadgame(), tnetworkloaders::loadnwgame(), Vehicle::newFromStream(), Building::newFromStream(), TerrainType::Weather::read(), tpcxheader::read(), GameMap::read(), Research::read_struct(), tspfldloaders::readfields(), readrlepict(), validateemlfile(), validatemapfile(), and validatesavfile().

void tnstream::seek int  newpos  )  [virtual]
 

Sets the stream pointer to a new location. An exception is thrown if the stream does not support seeking.

Reimplemented in MemoryStreamCopy, and tn_file_buf_stream.

Definition at line 205 of file basestrm.cpp.

References getDeviceName().

template<size_t N>
void tnstream::writeBitset const std::bitset< N > &  bs  )  [inline]
 

Definition at line 118 of file basestreaminterface.h.

References N, writeChar(), and writeInt().

Referenced by ContainerBaseType::TransportationIO::write().

void tnstream::writeChar char  c  )  [virtual]
 

Writes a 8 bit unsigned Integer.

Definition at line 371 of file basestrm.cpp.

References writedata2.

Referenced by logtoreplayinfo(), Vehicletype::write(), Vehicle::write(), Surface::write(), tpcxheader::write(), GameMap::write(), Building::write(), writeBitset(), tspfldloaders::writefields(), writeImage(), and writepcx().

virtual void tnstream::writedata const void *  buf,
int  size
[pure virtual]
 

writes data to the stream

Parameters:
buf pointer to the buffer
size the number of bytes which are going to be written

Implemented in MemoryStreamCopy, tmemorystream, tn_lzw_file_buf_stream, tn_c_lzw_filestream, and tnbufstream.

Referenced by Surface::write(), tpcxheader::write(), writeImage(), writepchar(), and writeString().

void tnstream::writeFloat float  f  )  [virtual]
 

Write a floating point variable.

Definition at line 376 of file basestrm.cpp.

References writedata2.

Referenced by WeatherSystem::write(), and ResourceMatrix::write().

void tnstream::writeImage const void *  buf,
bool  compress = true
[virtual]
 

Writes an image to the stream.

Definition at line 249 of file basestrm.cpp.

References compressrle(), trleheader::id, trleheader::rle, trleheader::size, writeChar(), writedata(), writeWord(), trleheader::x, and trleheader::y.

Referenced by writerlepict().

void tnstream::writeInt bool  b  ) 
 

Definition at line 352 of file basestrm.cpp.

References writedata2.

void tnstream::writeInt unsigned int  i  )  [virtual]
 

Definition at line 346 of file basestrm.cpp.

References writedata2.

void tnstream::writeInt int  i  )  [virtual]
 

Writes a 32 bit signed Integer. In the stream little-endian byte order is used and a translation is performed, if necessary.

Definition at line 359 of file basestrm.cpp.

References writedata2.

Referenced by ClipBoardBase::addBuilding(), ClipBoardBase::addUnit(), AutoProgressBar::close(), logtoreplayinfo(), ReinforcementSelector::mark(), Event::read(), tsavegameloaders::savegame(), tmaploaders::savemap(), tnetworkloaders::savenwgame(), savereplay(), WeatherSystem::write(), Vehicletype::HeightChangeMethod::write(), Vehicletype::write(), Vehicle::write(), MapCoordinate::write(), IntRange::write(), Resources::write(), ResourceMatrix::write(), TerrainBits::write(), TerrainType::MoveMalus::write(), Surface::write(), Technology::write(), TechAdapterDependency::write(), TechDependency::write(), Player::write(), Password::write(), ObjectType::write(), MusicPlayList::write(), Poly_gon::write(), tpcxheader::write(), BI3TranslationTableLoader::write(), Bi3MapTranslationTable::write(), Bi3MapTranslationTable::Terraincombixlat::write(), Bi3MapTranslationTable::Terrain2id::write(), ItemFiltrationSystem::DataLoader::write(), ItemFiltrationSystem::ItemFilter::write(), FileCache::write(), ItemRepositoryLoader< T >::write(), AiValue::write(), AiThreat::write(), GameMap::write(), ContainerBaseType::TransportationIO::write(), Building::write(), tfindfile::FileInfo::write(), AI::write(), tgameloaders::writeAI(), writeBitset(), FileTransfer::writeChildData(), writeClassContainer(), AllEnemyBuildingsDestroyed::writeData(), AllEnemyUnitsDestroyed::writeData(), AllUnitsLost::writeData(), AllBuildingsLost::writeData(), SetViewSharing::writeData(), ChangePlayerState::writeData(), ChangeDiplomaticStatus::writeData(), DisplayImmediateMessage::writeData(), DisplayEllipse::writeData(), NextMap::writeData(), RemoveAllObjects::writeData(), AddObject::writeData(), MapChange::writeData(), WeatherChange::writeData(), DisplayMessage::writeData(), ChangeGameParameter::writeData(), WindChange::writeData(), Action_Nothing::writeData(), AnyUnitEntersPolygon::writeData(), SpecificUnitEntersPolygon::writeData(), EventTriggered::writeData(), UnitTrigger::writeData(), TurnPassed::writeData(), TriggerNothing::writeData(), writeDefaultPixelFormat(), tspfldloaders::writedissections(), tspfldloaders::writefields(), FieldAddressing::writeMapModificationData(), tspfldloaders::writemessagelist(), tspfldloaders::writemessages(), and writePointerContainer().

void tnstream::writepchar const char *  pc  )  [virtual]
 

write the C-String pc to the stream

Definition at line 545 of file basestrm.cpp.

References writedata().

Referenced by tsavegameloaders::savegame(), tmaploaders::savemap(), tnetworkloaders::savenwgame(), and writeString().

void tnstream::writerlepict const void *  buf  )  [virtual]
 

Writes an image to the stream and compresses it using RLE.

Definition at line 244 of file basestrm.cpp.

References writeImage().

void tnstream::writeString const string &  pc,
bool  binary = true
[virtual]
 

writes the C++ String pc to the stream.

Parameters:
binary If true, all bytes (including 0 bytes) of the string will be written to the stream. Note that a string containing one or more 0 bytes cannot be read with a single stream reading operation. If false, writing will stop at the first 0 character of the string (or its end of course)

Definition at line 536 of file basestrm.cpp.

References writedata(), and writepchar().

Referenced by PropertyWritingContainer::closeBracket(), generateTechTree(), PropertyWritingContainer::openBracket(), TextRenderer::saveText(), Vehicletype::write(), Vehicle::write(), Technology::write(), TechAdapterDependency::write(), MusicPlayList::write(), Bi3MapTranslationTable::write(), ItemFiltrationSystem::ItemFilter::write(), GameMap::write(), Building::write(), tfindfile::FileInfo::write(), FileTransfer::writeChildData(), DisplayImmediateMessage::writeData(), TechDependency::writeInvertTreeOutput(), tspfldloaders::writemessages(), PropertyWritingContainer::writeProperty(), and TechDependency::writeTreeOutput().

void tnstream::writeWord int  w  )  [virtual]
 

Writes a 16 bit unsigned Integer. In the stream little-endian byte order is used and a translation is performed, if necessary.

Definition at line 365 of file basestrm.cpp.

References writedata2.

Referenced by tsavegameloaders::savegame(), tmaploaders::savemap(), tnetworkloaders::savenwgame(), Vehicletype::write(), Vehicle::write(), Surface::write(), tpcxheader::write(), GameMap::write(), Building::write(), and writeImage().


Member Data Documentation

ASCString tnstream::devicename [protected]
 

Definition at line 188 of file basestreaminterface.h.

Referenced by getDeviceName(), MemoryStreamCopy::getLocation(), getLocation(), MemoryStreamCopy::MemoryStreamCopy(), tn_c_lzw_filestream::tn_c_lzw_filestream(), and tn_file_buf_stream::tn_file_buf_stream().


The documentation for this class was generated from the following files:
Generated on Tue Jun 24 02:21:44 2008 for Advanced Strategic Command by  doxygen 1.4.2