LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::binaryStreamHandler Class Reference
[Storable Interface]

Binary stream handler. More...

#include <ltiBinaryStreamHandler.h>

Inheritance diagram for lti::binaryStreamHandler:
Inheritance graph
[legend]
Collaboration diagram for lti::binaryStreamHandler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 binaryStreamHandler ()
 binaryStreamHandler (std::ostream &aStream)
 binaryStreamHandler (std::istream &aStream)
 binaryStreamHandler (const char *aStream)
 binaryStreamHandler (const binaryStreamHandler &other)
virtual ~binaryStreamHandler ()
void use (std::ostream &aStream)
void use (std::istream &aStream)
virtual const char * getTypeName () const
binaryStreamHandlercopy (const binaryStreamHandler &other)
virtual ioHandlerclone () const
virtual bool writeBegin ()
virtual bool writeEnd ()
virtual bool readBegin ()
virtual bool readEnd ()
virtual bool writeSymbol (const std::string &data)
virtual bool readSymbol (std::string &data)
virtual bool trySymbol (const std::string &data)
virtual bool writeComment (const std::string &data)
virtual bool writeComment (const char *data)
virtual bool tryBegin ()
virtual bool tryEnd ()
virtual bool writeSpaces (const int &s=1)
virtual bool writeEOL ()
virtual bool writeKeyValueSeparator ()
virtual bool writeDataSeparator ()
virtual bool readKeyValueSeparator ()
virtual bool readDataSeparator ()
virtual bool eof ()
virtual bool restoreLevel ()
write members



virtual bool write (const std::string &data)
virtual bool write (const char *data)
virtual bool write (const double &data)
virtual bool write (const float &data)
virtual bool write (const int &data)
virtual bool write (const unsigned int &data)
virtual bool write (const char &data)
virtual bool write (const byte &data)
virtual bool write (const ubyte &data)
virtual bool write (const bool &data)
virtual bool write (const long &data)
virtual bool write (const unsigned long &data)
virtual bool write (const short &data)
virtual bool write (const unsigned short &data)
read members



virtual bool read (std::string &data)
virtual bool read (double &data)
virtual bool read (float &data)
virtual bool read (int &data)
virtual bool read (unsigned int &data)
virtual bool read (char &data)
virtual bool read (byte &data)
virtual bool read (ubyte &data)
virtual bool read (bool &data)
virtual bool read (long &data)
virtual bool read (unsigned long &data)
virtual bool read (short &data)
virtual bool read (unsigned short &data)

Protected Types

enum  eTokenId

Protected Member Functions

eTokenId getNextToken (const bool justTry=false)

Protected Attributes

std::istream * inStream
std::string inString
std::string::size_type inStringPos
std::ostream * outStream
bool supressSpaces
bool tryEOL

Detailed Description

Binary stream handler.

The binaryStreamHandler class offer an interface for the functor parameters and other classes to read() and write() them in a binary format.

The advantage of the binary format is that the produced files are smaller, which at the same time implies shorter times to read or write the data.

The disadvange is that the produced files cannot be easily edited. If you need this, you should still use the lti::lispStreamHandler.

Warning:
Do not forget to open your streams in binary mode. If you create them as ASCII streams, the data can be corrupted.

Example:

 // the binary stream formatting object
 lti::binaryStreamHandler bsh;

 // Write example:

 // open a stream in binary mode
 std::ofstream out("testfile.bin",std::ios_base::binary);
 
 // tell the binary stream handler to use the given stream
 bsh.use(out);

 lti::write(bsh,"anInteger",5);
 lti::write(bsh,"aString","hello world");

 out.close();
 
 // Read example

 // Open a stream in binary mode
 std::ifstream in("testfile.bin",std::ios_base::binary);

 bsh.use(in);
 int i;
 lti::read(bsh,"anInteger",i);

 std::string str;
 lti::read(bsh,"aString",str);

 in.close();
Bug:
: An intrinsic bug for the binary stream handler was found (2004-02-03). There are some cases in which the tryXXX methods will success (return true), even if the searched token is not present. Some rules need to be defined to avoid problems (indirectly the currently used formats avoid these cases), but a more detailed revision of the whole handler has to be done.

Member Enumeration Documentation

Tokens.

This system requires a complete revision!


Constructor & Destructor Documentation

lti::binaryStreamHandler::binaryStreamHandler (  ) 

default constructor

lti::binaryStreamHandler::binaryStreamHandler ( std::ostream &  aStream  ) 

default constructor.

Please ensure that the given stream was opened with the std::ios_base::binary flag!

lti::binaryStreamHandler::binaryStreamHandler ( std::istream &  aStream  ) 

default constructor.

Please ensure that the given stream was opened with the std::ios_base::binary flag!

lti::binaryStreamHandler::binaryStreamHandler ( const char *  aStream  ) 

default constructor.

This constructor uses the given string as input. Note that the given string is NOT a filename, but a string containing the data "stream". This is useful especially for the JNI.

lti::binaryStreamHandler::binaryStreamHandler ( const binaryStreamHandler other  ) 

copy constructor

virtual lti::binaryStreamHandler::~binaryStreamHandler (  )  [virtual]

destructor


Member Function Documentation

virtual ioHandler* lti::binaryStreamHandler::clone (  )  const [virtual]

returns a pointer to a clone of this functor.

Implements lti::ioHandler.

binaryStreamHandler& lti::binaryStreamHandler::copy ( const binaryStreamHandler other  ) 

copy data of "other" functor.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

Reimplemented from lti::ioHandler.

virtual bool lti::binaryStreamHandler::eof (  )  [virtual]

if the input stream is at the end of file return true, otherwise false if the stream hasn't been set yet, this function also returns true.

eTokenId lti::binaryStreamHandler::getNextToken ( const bool  justTry = false  )  [protected]

read next token from the input string or from the input stream

See also:
getNextTokenFromString.
virtual const char* lti::binaryStreamHandler::getTypeName (  )  const [virtual]

returns the name of this type ("binaryStreamHandler")

Reimplemented from lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( unsigned short &  data  )  [virtual]

read an unsigned short

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( short &  data  )  [virtual]

read a short

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( unsigned long &  data  )  [virtual]

read an unsigned long

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( long &  data  )  [virtual]

read a long

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( bool &  data  )  [virtual]

read a boolan

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( ubyte data  )  [virtual]

read an ubyte value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( byte data  )  [virtual]

read a char value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( char &  data  )  [virtual]

read a char value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( unsigned int &  data  )  [virtual]

read an unsigned int value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( int &  data  )  [virtual]

read an integer value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( float &  data  )  [virtual]

read a float value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( double &  data  )  [virtual]

read a double value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::read ( std::string &  data  )  [virtual]

read a std::string

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::readBegin (  )  [virtual]

the begin token or tokens: here a "("

Reimplemented from lti::ioHandler.

virtual bool lti::binaryStreamHandler::readDataSeparator (  )  [virtual]

write key/value separator A space is expected

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::readEnd (  )  [virtual]

the end token or tokens: here a ")"

Reimplemented from lti::ioHandler.

virtual bool lti::binaryStreamHandler::readKeyValueSeparator (  )  [virtual]

write key/value separator A space is expected

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::readSymbol ( std::string &  data  )  [virtual]

read a symbol in the given std::string

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::restoreLevel (  )  [virtual]

restore all the information in the handler taken in the actual level.

If "complete" is true, the begin-token is also restored

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::tryBegin (  )  [virtual]

try to read the begin token from the handler.

If present, returns true and the token is removed from the handler, if not present returns false and leaves the handle as it was before calling this member...

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::tryEnd (  )  [virtual]

try to read the end token from the handler.

If present, returns true and the token is removed from the handler, if not present returns false and leaves the handle as it was before calling this member... This is usually used when reading lists of data, where the number of elements is unknown.

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::trySymbol ( const std::string &  data  )  [virtual]

try to read the given symbol from the handler.

If present, returns true and the token is removed from the handler, if not present returns false and leaves the stream as is...

Parameters:
data the symbol to be readed

Implements lti::ioHandler.

void lti::binaryStreamHandler::use ( std::istream &  aStream  )  [virtual]

indicate the input stream to be used.

Please ensure that the given stream was opened with the std::ios_base::binary flag!

Implements lti::ioHandler.

void lti::binaryStreamHandler::use ( std::ostream &  aStream  )  [virtual]

indicate the output stream to be used.

Please ensure that the given stream was opened with the std::ios_base::binary flag!

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const unsigned short &  data  )  [virtual]

write an unsigned short

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const short &  data  )  [virtual]

write a short

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const unsigned long &  data  )  [virtual]

write an unsigned long

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const long &  data  )  [virtual]

write a long

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const bool &  data  )  [virtual]

write a boolean

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const ubyte data  )  [virtual]

write a unsigned 8-bit value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const byte data  )  [virtual]

write an 8-bit signed value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const char &  data  )  [virtual]

write a char

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const unsigned int &  data  )  [virtual]

write an unsigned integer value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const int &  data  )  [virtual]

write an integer value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const float &  data  )  [virtual]

write a float value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const double &  data  )  [virtual]

write a double value

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const char *  data  )  [virtual]

write a character string.

This method will write just the string if it does not contain spaces. Otherwise the string will be enclosed by quotes.

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::write ( const std::string &  data  )  [virtual]

write a std::string.

This method will write just the string if it does not contain spaces. Otherwise the string will be enclosed by quotes.

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::writeBegin (  )  [virtual]

the begin token or tokens: here a "(".

Reimplemented from lti::ioHandler.

virtual bool lti::binaryStreamHandler::writeComment ( const char *  data  )  [virtual]

write comment writes the input data without any preprocessing, just ensuring that the comment format is given

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::writeComment ( const std::string &  data  )  [virtual]

write comment writes the input data without any preprocessing, just ensuring that the comment format is given

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::writeDataSeparator (  )  [virtual]

write key/value separator.

In this case the data separator is a space

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::writeEnd (  )  [virtual]

the end token or tokens: here a ")".

Reimplemented from lti::ioHandler.

virtual bool lti::binaryStreamHandler::writeEOL (  )  [virtual]

write end of line

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::writeKeyValueSeparator (  )  [virtual]

write key/value separator.

In this case the key/value separator is a space

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::writeSpaces ( const int &  s = 1  )  [virtual]

write spaces (default value 1).

A space-token is a char with value 32.

Implements lti::ioHandler.

virtual bool lti::binaryStreamHandler::writeSymbol ( const std::string &  data  )  [virtual]

write a std::string

Implements lti::ioHandler.


Member Data Documentation

std::istream* lti::binaryStreamHandler::inStream [protected]

pointer to the input stream

std::string lti::binaryStreamHandler::inString [protected]

the input stream will be cached into this string

std::string::size_type lti::binaryStreamHandler::inStringPos [protected]

actual reading position in the input string

std::ostream* lti::binaryStreamHandler::outStream [protected]

pointer to the output stream

flag to control spaces supression (for example, there is no need for spaces between parenthesis)

flag to indicate if an EOL is needed


The documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:28:08 2010 for LTI-Lib by Doxygen 1.6.1