|
Tokens model atomic data for stream IO.
A Token models a string or numeric datum that can be read from a or written to a C++ stream. The class itself implements the representation of the data including its type and parsing from/to C++ streams. For section handling see TokenReader and TokenWriter.
There is no one-to-one correspondence between elementary faudes data types like string or index with a particlular representation. The class Token therefore takes a relaxed approach and indicates possible interpretations when reading from a stream and requiering specific directions when writing.
See TokenType for a list of supported formats/interpretations.
Definition at line 54 of file cfl_token.h.
#include <cfl_token.h>
|
enum | TokenType {
None = 0x000
, Begin = 0x001
, End = 0x002
, String = 0x004
,
Option = 0x008
, Integer = 0x010
, Integer16 =0x020
, Boolean = 0x040
,
Float = 0x080
, Binary = 0x100
, Cdata = 0x200
} |
| Token types: More...
|
|
|
| Token (void) |
| Empty constructor, constructs None token. More...
|
|
| Token (const Token &rToken) |
| Copy constructor. More...
|
|
| ~Token (void) |
| Token destructor. More...
|
|
Token & | operator= (const Token &rOther) |
| Assignment operator. More...
|
|
void | SetNone (void) |
| Initialize None token. More...
|
|
void | SetString (const std::string &rName) |
| Initialize as String token. More...
|
|
void | SetBegin (const std::string &rName) |
| Initialize as Begin token. More...
|
|
void | SetEnd (const std::string &rName) |
| Initialize as End token. More...
|
|
void | SetEmpty (const std::string &rName) |
| Initialize as empty-tag token. More...
|
|
void | SetOption (const std::string &rName) |
| Initialize as Option token. More...
|
|
void | SetInteger (const Int number) |
| Initialize as Integer token. More...
|
|
void | SetInteger16 (const Int number) |
| Initialize as Integer16 token. More...
|
|
void | SetBoolean (const Int number) |
| Initialize as Boolean token. More...
|
|
void | SetFloat (const faudes::Float number) |
| Initialize as Float token. More...
|
|
void | SetBinary (const char *data, std::size_t len) |
| Initialize Binary token. More...
|
|
void | ClrEnd (void) |
| Clear End type (resolve empty section) More...
|
|
Int | IntegerValue (void) const |
| Get integer value of a numeric token. More...
|
|
faudes::Float | FloatValue (void) const |
| Get float value of a numeric token. More...
|
|
const std::string & | StringValue (void) const |
| Get string value of a name token. More...
|
|
const std::string & | OptionValue (void) const |
| Get option value of a name token. More...
|
|
const std::string & | PreceedingSpace (void) const |
| Preceeding space when writing to stream. More...
|
|
void | PreceedingSpace (const std::string &sep) |
| Preceeding space when writing to stream. More...
|
|
TokenType | Type (void) const |
| Get token Type. More...
|
|
bool | IsNone (void) const |
| Test token Type. More...
|
|
bool | IsInteger (void) const |
| Test token Type. More...
|
|
bool | IsInteger16 (void) const |
| Test token Type. More...
|
|
bool | IsBoolean (void) const |
| Test token Type. More...
|
|
bool | IsFloat (void) const |
| Test token Type. More...
|
|
bool | IsOption (void) const |
| Test token Type. More...
|
|
bool | IsString (void) const |
| Test token Type. More...
|
|
bool | IsBinary (void) const |
| Test token Type. More...
|
|
bool | IsCdata (void) const |
| Test token Type. More...
|
|
bool | IsBegin (void) const |
| Test token Type. More...
|
|
bool | IsBegin (const std::string &tag) const |
| Test token Type. More...
|
|
bool | IsEnd (void) const |
| Test token Type. More...
|
|
bool | IsEnd (const std::string &tag) const |
| Test token Type. More...
|
|
bool | IsEmpty (void) const |
| Test token Type. More...
|
|
void | ClearAttributes () |
| Clear all attributes. More...
|
|
void | ClrAttribute (const std::string &name) |
| Clear attribute. More...
|
|
void | InsAttribute (const std::string &name, const std::string &value) |
| Insert named attribute, no type. More...
|
|
void | InsAttributeString (const std::string &name, const std::string &value) |
| Insert named attribute with string value. More...
|
|
void | InsAttributeInteger (const std::string &name, Int value) |
| Insert named attribute with integer value. More...
|
|
void | InsAttributeInteger16 (const std::string &name, Int value) |
| Insert named attribute with integer value. More...
|
|
void | InsAttributeBoolean (const std::string &name, Int value) |
| Insert named attribute with boolean value. More...
|
|
void | InsAttributeFloat (const std::string &name, faudes::Float value) |
| Insert named attribute with integer value. More...
|
|
bool | ExistsAttributeString (const std::string &name) |
| Test attibute existence. More...
|
|
bool | ExistsAttributeInteger (const std::string &name) |
| Test attibute existence. More...
|
|
bool | ExistsAttributeFloat (const std::string &name) |
| Test attibute existence. More...
|
|
const std::string & | AttributeStringValue (const std::string &name) |
| Access attribute value. More...
|
|
Int | AttributeIntegerValue (const std::string &name) |
| Access attribute value. More...
|
|
faudes::Float | AttributeFloatValue (const std::string &name) |
| Access attribute value. More...
|
|
int | Read (std::istream *pStream, bool fcomments=true) |
| Read Token from input stream. More...
|
|
void | Write (std::ostream *pStream) const |
| Write Token to output stream. More...
|
|
std::string | Str (void) const |
| Pretty print string representation. More...
|
|
|
static void | WriteBinary (std::ostream *pStream, const char *pData, std::size_t len) |
| Write specified binary data as base64 string to output stream. More...
|
|
static void | WriteVerbatim (std::ostream *pStream, const std::string &rString, bool lfflag=0) |
| Write a std::string value to an output stream. More...
|
|
static int | WriteEscapedString (std::ostream *pStream, const std::string &outstr) |
| Write a std::string value to an output stream. More...
|
|
static int | ReadEscapedString (std::istream *pStream, char stop, std::string &rString) |
| Read a std::string value from an input file stream. More...
|
|
static int | ReadCharacterData (std::istream *pStream, std::string &rString, bool fcomments) |
| Read chracter data from an input file stream. More...
|
|
◆ aiterator
◆ caiterator
◆ TokenType
Token types:
Enumerator |
---|
None | Invalid/empty token
|
Begin | <label> (begin of section)
|
End | <\label> (end of section)
|
String | any string, space separated or quoted, must start with a letter
|
Option | +xyZ+ (option string, may not contain a "+")
|
Integer | 1234 (non-negative integer)
|
Integer16 | 0x12fff ("0x" makes an integer an Integer16)
|
Boolean | True/False
|
Float | -12.34 ("-" or "." turns an integer to a float)
|
Binary | =ABhlkjj= (base64 encoded binary data)
|
Cdata | ... verbatim markup
|
Definition at line 82 of file cfl_token.h.
◆ Token() [1/2]
faudes::Token::Token |
( |
void |
| ) |
|
Empty constructor, constructs None token.
Definition at line 30 of file cfl_token.cpp.
◆ Token() [2/2]
faudes::Token::Token |
( |
const Token & |
rToken | ) |
|
◆ ~Token()
faudes::Token::~Token |
( |
void |
| ) |
|
◆ AttributeFloatValue()
faudes::Float faudes::Token::AttributeFloatValue |
( |
const std::string & |
name | ) |
|
Access attribute value.
- Parameters
-
- Returns
- String value of specified attribute
Definition at line 407 of file cfl_token.cpp.
◆ AttributeIntegerValue()
Int faudes::Token::AttributeIntegerValue |
( |
const std::string & |
name | ) |
|
Access attribute value.
- Parameters
-
- Returns
- Integer value of specified attribute (return 0 if it does not exist)
Definition at line 397 of file cfl_token.cpp.
◆ AttributeStringValue()
const std::string & faudes::Token::AttributeStringValue |
( |
const std::string & |
name | ) |
|
Access attribute value.
- Parameters
-
- Returns
- String value of specified attribute
Definition at line 386 of file cfl_token.cpp.
◆ ClearAttributes()
void faudes::Token::ClearAttributes |
( |
void |
| ) |
|
◆ ClrAttribute()
void faudes::Token::ClrAttribute |
( |
const std::string & |
name | ) |
|
◆ ClrEnd()
void faudes::Token::ClrEnd |
( |
void |
| ) |
|
Clear End type (resolve empty section)
Definition at line 161 of file cfl_token.cpp.
◆ ExistsAttributeFloat()
bool faudes::Token::ExistsAttributeFloat |
( |
const std::string & |
name | ) |
|
Test attibute existence.
- Parameters
-
- Returns
- True is attribute exists and matches type.
Definition at line 376 of file cfl_token.cpp.
◆ ExistsAttributeInteger()
bool faudes::Token::ExistsAttributeInteger |
( |
const std::string & |
name | ) |
|
Test attibute existence.
- Parameters
-
- Returns
- True is attribute exists and matches type.
Definition at line 366 of file cfl_token.cpp.
◆ ExistsAttributeString()
bool faudes::Token::ExistsAttributeString |
( |
const std::string & |
name | ) |
|
Test attibute existence.
- Parameters
-
- Returns
- True is attribute exists and matches type.
Definition at line 356 of file cfl_token.cpp.
◆ FloatValue()
Get float value of a numeric token.
- Returns
- Token float value
Definition at line 173 of file cfl_token.cpp.
◆ InsAttribute()
void faudes::Token::InsAttribute |
( |
const std::string & |
name, |
|
|
const std::string & |
value |
|
) |
| |
Insert named attribute, no type.
Note: only begin tags can have attributes.
- Parameters
-
name | Attribute name |
value | Attribute value |
Definition at line 300 of file cfl_token.cpp.
◆ InsAttributeBoolean()
void faudes::Token::InsAttributeBoolean |
( |
const std::string & |
name, |
|
|
Int |
value |
|
) |
| |
Insert named attribute with boolean value.
Note: only begin tags can have attributes.
- Parameters
-
name | Attribute name |
value | Attribute value |
Definition at line 337 of file cfl_token.cpp.
◆ InsAttributeFloat()
void faudes::Token::InsAttributeFloat |
( |
const std::string & |
name, |
|
|
faudes::Float |
value |
|
) |
| |
Insert named attribute with integer value.
Note: only begin tags can have attributes.
- Parameters
-
name | Attribute name |
value | Attribute value |
Definition at line 347 of file cfl_token.cpp.
◆ InsAttributeInteger()
void faudes::Token::InsAttributeInteger |
( |
const std::string & |
name, |
|
|
Int |
value |
|
) |
| |
Insert named attribute with integer value.
Note: only begin tags can have attributes.
- Parameters
-
name | Attribute name |
value | Attribute value |
Definition at line 319 of file cfl_token.cpp.
◆ InsAttributeInteger16()
void faudes::Token::InsAttributeInteger16 |
( |
const std::string & |
name, |
|
|
Int |
value |
|
) |
| |
Insert named attribute with integer value.
Note: only begin tags can have attributes.
- Parameters
-
name | Attribute name |
value | Attribute value |
Definition at line 328 of file cfl_token.cpp.
◆ InsAttributeString()
void faudes::Token::InsAttributeString |
( |
const std::string & |
name, |
|
|
const std::string & |
value |
|
) |
| |
Insert named attribute with string value.
Note: only begin tags can have attributes.
- Parameters
-
name | Attribute name |
value | Attribute value |
Definition at line 310 of file cfl_token.cpp.
◆ IntegerValue()
Int faudes::Token::IntegerValue |
( |
void |
| ) |
const |
Get integer value of a numeric token.
- Returns
- Token's integer value
Definition at line 167 of file cfl_token.cpp.
◆ InterpretAttribute()
void faudes::Token::InterpretAttribute |
( |
aiterator |
ait | ) |
|
|
private |
Interpret attribute value from string.
Definition at line 645 of file cfl_token.cpp.
◆ InterpretNumber() [1/2]
bool faudes::Token::InterpretNumber |
( |
const std::string & |
numstr, |
|
|
int & |
type, |
|
|
Int & |
ival, |
|
|
faudes::Float & |
fval |
|
) |
| |
|
private |
◆ InterpretNumber() [2/2]
bool faudes::Token::InterpretNumber |
( |
void |
| ) |
|
|
private |
◆ IsBegin() [1/2]
bool faudes::Token::IsBegin |
( |
const std::string & |
tag | ) |
const |
Test token Type.
- Parameters
-
tag | Section tag to test for |
- Returns
- True on match
Definition at line 264 of file cfl_token.cpp.
◆ IsBegin() [2/2]
bool faudes::Token::IsBegin |
( |
void |
| ) |
const |
◆ IsBinary()
bool faudes::Token::IsBinary |
( |
void |
| ) |
const |
◆ IsBoolean()
bool faudes::Token::IsBoolean |
( |
void |
| ) |
const |
◆ IsCdata()
bool faudes::Token::IsCdata |
( |
void |
| ) |
const |
◆ IsEmpty()
bool faudes::Token::IsEmpty |
( |
void |
| ) |
const |
◆ IsEnd() [1/2]
bool faudes::Token::IsEnd |
( |
const std::string & |
tag | ) |
const |
Test token Type.
- Parameters
-
tag | Section tag to test for |
- Returns
- True on match
Definition at line 275 of file cfl_token.cpp.
◆ IsEnd() [2/2]
bool faudes::Token::IsEnd |
( |
void |
| ) |
const |
◆ IsFloat()
bool faudes::Token::IsFloat |
( |
void |
| ) |
const |
◆ IsInteger()
bool faudes::Token::IsInteger |
( |
void |
| ) |
const |
◆ IsInteger16()
bool faudes::Token::IsInteger16 |
( |
void |
| ) |
const |
◆ IsNone()
bool faudes::Token::IsNone |
( |
void |
| ) |
const |
◆ IsOption()
bool faudes::Token::IsOption |
( |
void |
| ) |
const |
◆ IsString()
bool faudes::Token::IsString |
( |
void |
| ) |
const |
◆ operator=()
Token & faudes::Token::operator= |
( |
const Token & |
rOther | ) |
|
◆ OptionValue()
const std::string & faudes::Token::OptionValue |
( |
void |
| ) |
const |
Get option value of a name token.
- Returns
- Token's option value
Definition at line 184 of file cfl_token.cpp.
◆ PreceedingSpace() [1/2]
void faudes::Token::PreceedingSpace |
( |
const std::string & |
sep | ) |
|
Preceeding space when writing to stream.
- Parameters
-
Definition at line 194 of file cfl_token.cpp.
◆ PreceedingSpace() [2/2]
const std::string & faudes::Token::PreceedingSpace |
( |
void |
| ) |
const |
Preceeding space when writing to stream.
- Returns
- preceeding string
Definition at line 189 of file cfl_token.cpp.
◆ Read()
int faudes::Token::Read |
( |
std::istream * |
pStream, |
|
|
bool |
fcomments = true |
|
) |
| |
Read Token from input stream.
- Parameters
-
pStream | Pointer to std::ifstream |
fcomments | when true, faudes comments are skipped |
- Exceptions
-
- Returns
- line count
Definition at line 1206 of file cfl_token.cpp.
◆ ReadAttributes()
int faudes::Token::ReadAttributes |
( |
std::istream * |
pStream | ) |
|
|
private |
Read and interpret attribute definitions of begin tags from an input file stream.
- Parameters
-
pStream | Reference to std::istream |
- Returns
- Line count or -1 for error
Definition at line 958 of file cfl_token.cpp.
◆ ReadBinary()
int faudes::Token::ReadBinary |
( |
std::istream * |
pStream | ) |
|
|
private |
Read a base64 binary string from an input file stream.
- Parameters
-
pStream | Reference to std::istream |
- Returns
- Line count or -1 for error
Definition at line 514 of file cfl_token.cpp.
◆ ReadCharacterData()
int faudes::Token::ReadCharacterData |
( |
std::istream * |
pStream, |
|
|
std::string & |
rString, |
|
|
bool |
fcomments |
|
) |
| |
|
static |
Read chracter data from an input file stream.
Reads the stream until the next "<" character. The plain character data is returned, no entities re-substituted.
If fcomments is set, faudes-comments are ignored.
- Parameters
-
pStream | Reference to std::istream |
rString | Reference to result. |
fcomments | when true, faudes comments are skipped |
- Returns
- Line count or -1 for error
Definition at line 919 of file cfl_token.cpp.
◆ ReadEscapedString()
int faudes::Token::ReadEscapedString |
( |
std::istream * |
pStream, |
|
|
char |
stop, |
|
|
std::string & |
rString |
|
) |
| |
|
static |
Read a std::string value from an input file stream.
Read an XML escaped string until excluding the specified stop character.
- Parameters
-
pStream | Reference to std::istream |
stop | Stop character |
rString | Reference to result. |
- Returns
- Line count or -1 for error
Definition at line 858 of file cfl_token.cpp.
◆ ReadMarkup()
int faudes::Token::ReadMarkup |
( |
std::istream * |
pStream | ) |
|
|
private |
Read and interpret markup an input file stream.
This method will identify begin and end tags. Any other XML markup is meant to be gracefully ignored.
- Parameters
-
pStream | Reference to std::istream |
- Returns
- Line count or -1 for error
Definition at line 1041 of file cfl_token.cpp.
◆ ReadSpace()
int faudes::Token::ReadSpace |
( |
std::istream * |
pStream, |
|
|
bool |
fcomments = true |
|
) |
| |
|
private |
Read (ignore) spaces on input file stream.
- Parameters
-
pStream | Reference to std::istream |
fcomments | when true, read space swallows fcomments |
- Returns
- Number of lines read
Definition at line 590 of file cfl_token.cpp.
◆ ReadString()
int faudes::Token::ReadString |
( |
std::istream * |
pStream, |
|
|
char |
stop |
|
) |
| |
|
private |
Read a std::string value from an input file stream.
This method assumes that the string was written in the format of WriteString, i.e. either enclosed by single stop characters or with a trailing space as stop character. For practical reasons, it is assumed that the first stop character has been allready read.
- Parameters
-
pStream | Reference to std::istream |
stop | Stop character |
- Returns
- Line count or -1 for error
Definition at line 852 of file cfl_token.cpp.
◆ SetBegin()
void faudes::Token::SetBegin |
( |
const std::string & |
rName | ) |
|
Initialize as Begin token.
- Parameters
-
rName | Title of section to fill the Token |
Definition at line 92 of file cfl_token.cpp.
◆ SetBinary()
void faudes::Token::SetBinary |
( |
const char * |
data, |
|
|
std::size_t |
len |
|
) |
| |
Initialize Binary token.
This method allocates a copy of the data. For writing only, you may use the TokenWriter interface to avoid the local copy.
- Parameters
-
data | Reference to raw data record |
len | Number of bytes in record |
Definition at line 153 of file cfl_token.cpp.
◆ SetBoolean()
void faudes::Token::SetBoolean |
( |
const Int |
number | ) |
|
◆ SetEmpty()
void faudes::Token::SetEmpty |
( |
const std::string & |
rName | ) |
|
Initialize as empty-tag token.
- Parameters
-
rName | Title of section to fill the Token |
Definition at line 106 of file cfl_token.cpp.
◆ SetEnd()
void faudes::Token::SetEnd |
( |
const std::string & |
rName | ) |
|
Initialize as End token.
- Parameters
-
rName | Title of section to fill the Token |
Definition at line 99 of file cfl_token.cpp.
◆ SetFloat()
Initialize as Float token.
- Parameters
-
number | Number to fill the Token |
Definition at line 145 of file cfl_token.cpp.
◆ SetInteger()
void faudes::Token::SetInteger |
( |
const Int |
number | ) |
|
◆ SetInteger16()
void faudes::Token::SetInteger16 |
( |
const Int |
number | ) |
|
Initialize as Integer16 token.
- Parameters
-
number | Number to fill the Token |
Definition at line 129 of file cfl_token.cpp.
◆ SetNone()
void faudes::Token::SetNone |
( |
void |
| ) |
|
◆ SetOption()
void faudes::Token::SetOption |
( |
const std::string & |
rName | ) |
|
Initialize as Option token.
- Parameters
-
rName | Option to fill the Token |
Definition at line 113 of file cfl_token.cpp.
◆ SetString()
void faudes::Token::SetString |
( |
const std::string & |
rName | ) |
|
◆ Str()
std::string faudes::Token::Str |
( |
void |
| ) |
const |
Pretty print string representation.
Convenience functio for inspection/debugging
- Returns
- Printable string representation
Definition at line 1297 of file cfl_token.cpp.
◆ StringValue()
const std::string & faudes::Token::StringValue |
( |
void |
| ) |
const |
Get string value of a name token.
- Returns
- Token's string value
Definition at line 178 of file cfl_token.cpp.
◆ Type()
Get token Type.
This method is for backward compatibility only. It returns a token type with only one bit set to indicate the type as in libfaudes up to version 2.17. To test for possible token interpretations, use the 2.17 interface IsInteger(), IsString() etc. - Returns
- Type of token
Definition at line 199 of file cfl_token.cpp.
◆ Write()
void faudes::Token::Write |
( |
std::ostream * |
pStream | ) |
const |
Write Token to output stream.
- Parameters
-
pStream | Pointer to ostream |
- Exceptions
-
Definition at line 750 of file cfl_token.cpp.
◆ WriteBinary() [1/2]
void faudes::Token::WriteBinary |
( |
std::ostream * |
pStream | ) |
const |
|
private |
Write my binary data as base64 string to output stream.
- Parameters
-
pStream | Reference to std::ostream |
Definition at line 507 of file cfl_token.cpp.
◆ WriteBinary() [2/2]
void faudes::Token::WriteBinary |
( |
std::ostream * |
pStream, |
|
|
const char * |
pData, |
|
|
std::size_t |
len |
|
) |
| |
|
static |
Write specified binary data as base64 string to output stream.
- Parameters
-
pStream | Reference to std::ostream |
len | Number of bytes to write |
pData | Data to write |
Definition at line 446 of file cfl_token.cpp.
◆ WriteEscapedString()
int faudes::Token::WriteEscapedString |
( |
std::ostream * |
pStream, |
|
|
const std::string & |
outstr |
|
) |
| |
|
static |
Write a std::string value to an output stream.
This method replace critical characters by their XML entities and streams the resulting string. No whitespace etc added.
- Parameters
-
pStream | Reference to std::ostream |
outstr | String to stream |
- Returns
- Number of characters written.
Definition at line 813 of file cfl_token.cpp.
◆ WriteString()
void faudes::Token::WriteString |
( |
std::ostream * |
pStream, |
|
|
const std::string & |
delim |
|
) |
| const |
|
private |
Write a std::string value to an output stream.
This method writes the string enclosed by a the specified delimiter, typically '"' or ' '. Relevant XML entities are replaced by references, e.g. < && etc. A single white space is added as a sepqrqtor.
- Parameters
-
pStream | Reference to std::ostream |
delim | Delimiter |
Definition at line 839 of file cfl_token.cpp.
◆ WriteVerbatim()
void faudes::Token::WriteVerbatim |
( |
std::ostream * |
pStream, |
|
|
const std::string & |
rString, |
|
|
bool |
lfflag = 0 |
|
) |
| |
|
static |
Write a std::string value to an output stream.
This method writes a string as verbatim character data using the markup "<[!CDATA[ ... ]]> i.e. incl all control characters. The flag is used to insert extra formating at the begin and the end of the markup.
- Parameters
-
pStream | Reference to std::ostream |
rString | String to write |
lfflag | add extra linefeeds etc |
Definition at line 417 of file cfl_token.cpp.
◆ TokenReader
◆ TokenWriter
◆ mAttributeCount
int faudes::Token::mAttributeCount |
|
private |
Attribute sort index (for nice output only)
Definition at line 666 of file cfl_token.h.
◆ mAttributes
◆ mFloatValue
◆ mIntegerValue
Int faudes::Token::mIntegerValue |
|
private |
◆ mOptionValue
std::string faudes::Token::mOptionValue |
|
private |
Token std::string value (if token is of type Option)
Definition at line 640 of file cfl_token.h.
◆ mPreceedingSpace
std::string faudes::Token::mPreceedingSpace |
|
private |
Preceeding space (cosmetic)
Definition at line 649 of file cfl_token.h.
◆ mStringValue
std::string faudes::Token::mStringValue |
|
private |
◆ mType
The documentation for this class was generated from the following files:
libFAUDES 2.32f
--- 2024.12.22
--- c++ api documentaion by doxygen
|