|
latest version v1.9 - last update 24 Nov 2005 |
|
#include <ltiLispStreamHandler.h>
Inheritance diagram for lti::lispStreamHandler:


Public Member Functions | |
| lispStreamHandler () | |
| lispStreamHandler (std::ostream &aStream) | |
| lispStreamHandler (std::istream &aStream) | |
| lispStreamHandler (const char *aStream) | |
| lispStreamHandler (const lispStreamHandler &other) | |
| virtual | ~lispStreamHandler () |
| void | use (std::ostream &aStream) |
| void | use (std::istream &aStream) |
| void | clear () |
| virtual const char * | getTypeName () const |
| lispStreamHandler & | copy (const lispStreamHandler &other) |
| lispStreamHandler & | operator= (const lispStreamHandler &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 () |
| virtual void | appendContextStatus () const |
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 | |
| typedef std::map< std::string, std::string > | cacheType |
| enum | eTokenId { BeginToken, EndToken, SymbolToken, StringToken, ErrorToken } |
Protected Member Functions | |
| eTokenId | getNextToken (std::string &token, const bool justTry=false) |
| eTokenId | getNextTokenFromString (std::string &src, std::string::size_type &srcPos, std::string &token, const bool justTry=false) |
| void | getNextLine (std::string &newline) |
| bool | commentFilter () |
| bool | isTokenDelimiter (const char &c) |
| bool | completeLevel (std::string &restOfLevel) |
Protected Attributes | |
| std::istream * | inStream |
| std::string | inString |
| std::string::size_type | inStringPos |
| std::ostream * | outStream |
| bool | supressSpaces |
| bool | tryEOL |
| std::list< stackElement > | stack |
Static Protected Attributes | |
| static const char | openChar |
| static const char | closeChar |
| static const char | separator |
| static const char | commentChar |
| static const char | stringChar |
| static const char | quoteChar |
Classes | |
| struct | stackElement |
| type for each element of the stack More... | |
This is the LTI-lib standard ioHandler.
If the standard functions atof() and operator<< for numbers consider the locale settings (this occurs in MS-VC++ or newer glibc and gcc with Linux), then the read() and write() methods will also be localed. A typical problem with this "feature" is that if you have a file saved with "LANG=C", the decimal point is a point (e.g. 1.532), and when you try to read it in another locale (for example LANG=de_DE.ISO-8859-1), then all numbers with a decimal point won't be readed correctly, because the method will be expecting a decimal comma (e.g. 1,532).
See also the read and write methods for the basic types for more information
// the lisp stream formatting object lti::lispStreamHandler lsh; // Write example: // open a stream in text mode std::ofstream out("testfile.bin"); // tell the lisp stream handler to use the given stream lsh.use(out); lti::write(lsh,"anInteger",5); lti::write(lsh,"aString","hello world"); out.close(); // Read example // Open a stream in lisp mode std::ifstream in("testfile.bin"); lsh.use(in); int i; lti::read(lsh,"anInteger",i); std::string str; lti::read(lsh,"aString",str); in.close();
|
|
type for the cache of each level, where the value for each symbol is stored
|
|
|
Types of tokens.
|
|
|
default constructor
|
|
|
default constructor
|
|
|
default constructor
|
|
|
default constructor. This constructor uses the given string as input, as if read from a stread.
|
|
|
copy constructor
|
|
|
destructor
|
|
|
Overload of context status information. This function should help the users to find errors in their files. It just inserts some contextual information into the status string to help localizing wrong data. It is useful for streams that can be edited by hand, because the users will make errors! Reimplemented from lti::ioHandler. |
|
|
This method resets all internal state variables (for input and output streams as well) in a way that the next operations behave as if this handler were used for the first time. This allows the use of the same handler instance after reopening a stream. Alternativelly, you can just call the use(std::istream&) or use(std::ostream&) members to clear the input or output state variables only. If you use this method "within" a read/write process, the behaviour will be unpredictable. |
|
|
returns a pointer to a clone of this functor.
Implements lti::ioHandler. |
|
|
this filter eliminates all comments at the beginning of inString
|
|
|
complete actual level reads the data from the input string and input stream until the actual level has been readed.
|
|
|
copy data of "other" functor.
|
|
|
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.
|
|
|
get the next "garbageThreshold" characters from the given stream, and ensures that the last readed character is a delimiter
|
|
||||||||||||
|
read next token from the input string or from the input stream
|
|
||||||||||||||||||||
|
read next token from the given string this member get the next token into the given string Following tokens are recognized: beginToken := '(' endToken := ')' symbolToken := {alpha | digit} | float stringToken := quote {alpha | digit | other | escape quote} quote ErrorToken where alpha = "A" | "B" | ... "Z" | "a" | "b" | ... "z" digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | other = "!" | "," | "$" | "%" | "&" | "/" | "[" | "]" | "{" | "}" | "?" | "'" | "#" | "+" | "*" | "-" | "." | "," | ":" | ";" quote = '"' escape = '\' float = ['+' | '-'] {digit} '.' {digit} [exponent] exponent = eid ['+' | '-'] digit {digit} eid = 'E' | 'e' comments will be ignored! They begin with a ';' The ErrorToken is not a real token. This is the way to signalized that no other token could be readed! If justTry = true the source string will remain untouched |
|
|
returns the name of this type ("lispStreamHandler")
Reimplemented from lti::ioHandler. |
|
|
returns true if the given char can indicate the end of a token
|
|
|
copy data of "other" functor.
|
|
|
read an unsigned short
Implements lti::ioHandler. |
|
|
read a short
Implements lti::ioHandler. |
|
|
read an unsigned long
Implements lti::ioHandler. |
|
|
read a long
Implements lti::ioHandler. |
|
|
read a boolan
Implements lti::ioHandler. |
|
|
read an unsigned byte value
Implements lti::ioHandler. |
|
|
read a signed byte value
Implements lti::ioHandler. |
|
|
Read a char value. The char can be given in two ways:
Implements lti::ioHandler. |
|
|
read an unsigned int value
Implements lti::ioHandler. |
|
|
read an integer value
Implements lti::ioHandler. |
|
|
read a float value
Implements lti::ioHandler. |
|
|
read a double value
Implements lti::ioHandler. |
|
|
read a std::string The string should be quoted (i.e. between '"' and '"'), expect if its a single word. The two-char sequences '\"' and '\' will be replaced by '"' and '\' respectivelly. Implements lti::ioHandler. |
|
|
the begin token or tokens: here a "("
Reimplemented from lti::ioHandler. |
|
|
write key/value separator A space is expected
Implements lti::ioHandler. |
|
|
the end token or tokens: here a ")"
Reimplemented from lti::ioHandler. |
|
|
write key/value separator A space is expected
Implements lti::ioHandler. |
|
|
read a symbol in the given std::string
Implements lti::ioHandler. |
|
|
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. |
|
|
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... This is useful in trees or other complicated data structures. Implements lti::ioHandler. |
|
|
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. |
|
|
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...
Implements lti::ioHandler. |
|
|
indicate the input stream to be used Calling this method you will reinitialize the state of the parser (see also clear()). Implements lti::ioHandler. |
|
|
indicate the output stream to be used Calling this method you will reinitialize the state of the parser (see also clear()). Implements lti::ioHandler. |
|
|
write an unsigned short
Implements lti::ioHandler. |
|
|
write a short
Implements lti::ioHandler. |
|
|
write an unsigned long
Implements lti::ioHandler. |
|
|
write a long
Implements lti::ioHandler. |
|
|
write a boolean
Implements lti::ioHandler. |
|
|
write a unsigned 8-bit value
Implements lti::ioHandler. |
|
|
write an 8-bit signed value
Implements lti::ioHandler. |
|
|
write a char The char is writen as numerical code if there is no standard ASCII representation. If there is an ASCII representation (i.e. its value is greater or equal 32 (' ') and smaller or equal 127 ('~'), then the ASCII character will be writen enclosed in single quotes. Implements lti::ioHandler. |
|
|
write an unsigned integer value
Implements lti::ioHandler. |
|
|
write an integer value
Implements lti::ioHandler. |
|
|
write a float value
Implements lti::ioHandler. |
|
|
write a double value.
Implements lti::ioHandler. |
|
|
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. |
|
|
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. |
|
|
the begin token or tokens: here a "(".
Reimplemented from lti::ioHandler. |
|
|
write comment writes the input data without any preprocessing, just ensuring that the comment format is given
Implements lti::ioHandler. |
|
|
write comment writes the input data without any preprocessing, just ensuring that the comment format is given
Implements lti::ioHandler. |
|
|
write key/value separator. In this case the data separator is a space Implements lti::ioHandler. |
|
|
the end token or tokens: here a ")".
Reimplemented from lti::ioHandler. |
|
|
write end of line
Implements lti::ioHandler. |
|
|
write key/value separator. In this case the key/value separator is a space Implements lti::ioHandler. |
|
|
write spaces (default value 1). A space-token is a char with value 32. Implements lti::ioHandler. |
|
|
write a std::string
Implements lti::ioHandler. |
|
|
closing char. Usually ")" |
|
|
comment char. Usually ';' |
|
|
pointer to the input stream
|
|
|
the input stream will be cached into this string
|
|
|
actual reading position in the input string
|
|
|
opening char. Usually "(" |
|
|
pointer to the output stream
|
|
|
quote char. Usually "'" |
|
|
separator char. Usually a space |
|
|
the data stack. All readed symbols and their values are stored here temporarly to allow different sorting of the symbols in the stream |
|
|
string char. Usually '"' |
|
|
flag to control spaces supression (for example, there is no need for spaces between parenthesis)
|
|
|
flag to indicate if an EOL is needed
|