latest version v1.9 - last update 10 Apr 2010 |
Binary stream handler. More...
#include <ltiBinaryStreamHandler.h>
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 |
binaryStreamHandler & | copy (const binaryStreamHandler &other) |
virtual ioHandler * | clone () 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 |
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.
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();
enum lti::binaryStreamHandler::eTokenId [protected] |
Tokens.
This system requires a complete revision!
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
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.
other | the functor to be copied |
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
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...
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] |
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] |
virtual bool lti::binaryStreamHandler::writeSymbol | ( | const std::string & | data | ) | [virtual] |
write a std::string
Implements lti::ioHandler.
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
bool lti::binaryStreamHandler::supressSpaces [protected] |
flag to control spaces supression (for example, there is no need for spaces between parenthesis)
bool lti::binaryStreamHandler::tryEOL [protected] |
flag to indicate if an EOL is needed