Tokens model atomic data for stream IO. More...

#include <cfl_token.h>

Classes

class  AttributeValue
 Attribute value. More...

Public Types

enum  TokenType {
  None = 0x000, Begin = 0x001, End = 0x002, String = 0x004,
  Option = 0x008, Integer = 0x010, Integer16 = 0x020, Boolean = 0x040,
  Number = 0x080, Binary = 0x100, Cdata = 0x200
}
 Token types: More...

Public Member Functions

 Token (void)
 Empty constructor, constructs None token.
 Token (const Token &rToken)
 Copy constructor.
 ~Token (void)
 Token destructor.
Tokenoperator= (const Token &rOther)
 Assignment operator.
void SetNone (void)
 Initialize None token.
void SetString (const std::string &rName)
 Initialize as String token.
void SetBegin (const std::string &rName)
 Initialize as Begin token.
void SetEnd (const std::string &rName)
 Initialize as End token.
void SetEmpty (const std::string &rName)
 Initialize as empty-tag token.
void SetOption (const std::string &rName)
 Initialize as Option token.
void SetInteger (const Int number)
 Initialize as Integer token.
void SetInteger16 (const Int number)
 Initialize as Integer16 token.
void SetBoolean (const Int number)
 Initialize as Boolean token.
void SetFloat (const Float number)
 Initialize as Float token.
void SetBinary (const char *data, std::size_t len)
 Initialize Binary token.
void ClrEnd (void)
 Clear End type (resolve empty section)
Int IntegerValue (void) const
 Get integer value of a numeric token.
Float FloatValue (void) const
 Get float value of a numeric token.
const std::string & StringValue (void) const
 Get string value of a name token.
const std::string & OptionValue (void) const
 Get option value of a name token.
TokenType Type (void) const
 Get token Type.
bool IsNone (void) const
 Test token Type.
bool IsInteger (void) const
 Test token Type.
bool IsInteger16 (void) const
 Test token Type.
bool IsBoolean (void) const
 Test token Type.
bool IsFloat (void) const
 Test token Type.
bool IsOption (void) const
 Test token Type.
bool IsString (void) const
 Test token Type.
bool IsBinary (void) const
 Test token Type.
bool IsBegin (void) const
 Test token Type.
bool IsBegin (const std::string &tag) const
 Test token Type.
bool IsEnd (void) const
 Test token Type.
bool IsEnd (const std::string &tag) const
 Test token Type.
bool IsEmpty (void) const
 Test token Type.
void ClearAttributes ()
 Clear all attributes.
void ClrAttribute (const std::string &name)
 Clear attribute.
void InsAttribute (const std::string &name, const std::string &value)
 Insert named attribute, no type.
void InsAttributeString (const std::string &name, const std::string &value)
 Insert named attribute with string value.
void InsAttributeInteger (const std::string &name, Int value)
 Insert named attribute with integer value.
void InsAttributeInteger16 (const std::string &name, Int value)
 Insert named attribute with integer value.
void InsAttributeBoolean (const std::string &name, Int value)
 Insert named attribute with boolean value.
void InsAttributeFloat (const std::string &name, Float value)
 Insert named attribute with integer value.
bool ExistsAttributeString (const std::string &name)
 Test attibute existence.
bool ExistsAttributeInteger (const std::string &name)
 Test attibute existence.
bool ExistsAttributeFloat (const std::string &name)
 Test attibute existence.
const std::string & AttributeStringValue (const std::string &name)
 Access attribute value.
Int AttributeIntegerValue (const std::string &name)
 Access attribute value.
Float AttributeFloatValue (const std::string &name)
 Access attribute value.
int Read (std::istream *pStream)
 Read Token from input stream.
void Write (std::ostream *pStream) const
 Write Token to output stream.
std::string Str (void) const
 Pretty print string representation.

Static Public Member Functions

static void WriteBinary (std::ostream *pStream, const char *pData, std::size_t len)
 Write specified binary data as base64 string to output stream.
static void WriteVerbatim (std::ostream *pStream, const std::string &rString)
 Write a std::string value to an output stream.
static int WriteEscapedString (std::ostream *pStream, const std::string &outstr)
 Write a std::string value to an output stream.
static int ReadEscapedString (std::istream *pStream, char stop, std::string &rString)
 Read a std::string value from an input file stream.
static int ReadCharacterData (std::istream *pStream, std::string &rString)
 Read chracter data from an input file stream.

Private Types

typedef std::map< std::string,
AttributeValue >::iterator 
aiterator
 Convenience typedef.
typedef std::map< std::string,
AttributeValue >
::const_iterator 
caiterator

Private Member Functions

void InterpretAttribute (aiterator ait)
 Interpret attribute value from string.
bool InterpretNumber (const std::string &numstr, int &type, Int &ival, Float &fval)
 Interpret string a s number.
bool InterpretNumber (void)
 Interpret string a s number.
void WriteString (std::ostream *pStream, const std::string &delim) const
 Write a std::string value to an output stream.
void WriteBinary (std::ostream *pStream) const
 Write my binary data as base64 string to output stream.
int ReadString (std::istream *pStream, char stop)
 Read a std::string value from an input file stream.
int ReadAttributes (std::istream *pStream)
 Read and interpret attribute definitions of begin tags from an input file stream.
int ReadMarkup (std::istream *pStream)
 Read and interpret markup an input file stream.
int ReadVerbatim (std::istream *pStream)
 Read a std::string value from an input file stream.
int ReadBinary (std::istream *pStream)
 Read a base64 binary string from an input file stream.
int ReadSpace (std::istream *pStream)
 Read (ignore) spaces and comments in an input file stream.

Private Attributes

int mType
 Token type.
std::string mStringValue
 Token std::string value (for any token type)
std::string mOptionValue
 Token std::string value (if token is of type Option)
Int mIntegerValue
 Token integer value (if Token is of type Integer or Integer16)
Float mFloatValue
 Token float value (if Token is of type Float or Integer)
bool mPreceedingSpace
 When read from stream, record preceeding space.
bool mPreceedingNewline
 When read from stream, record preceeding space.
std::map< std::string,
AttributeValue
mAttributes
 Attribute value map.
int mAttributeCount
 Attribute sort index (for nice output only)

Friends

class TokenWriter
class TokenReader

Detailed Description

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. For section handling and actual file processing see TokenReader and TokenWriter.

Parameters
mTypefaudes::TokenType of the Token
mStringValueToken value as C++-type std::string
mOptionValueToken value as interpreted option token
mIntegerValueToken value as C++-type integer, faudes typedef Int
mFloatValueToken value of C++-type double, faudes typedef Float

Definition at line 56 of file cfl_token.h.

Member Typedef Documentation

typedef std::map<std::string, AttributeValue>::iterator faudes::Token::aiterator
private

Convenience typedef.

Definition at line 638 of file cfl_token.h.

typedef std::map<std::string, AttributeValue>::const_iterator faudes::Token::caiterator
private

Definition at line 639 of file cfl_token.h.

Member Enumeration Documentation

Token types:

Enumerator:
None 

Invalid/empty token.

Begin 

<label> (begin of section)

End 

<\label> (end of section)

String 

any string, space separated or quoted

Option 

+xyZ+ (option string, may not contain a "+")

Integer 

1234 (non-negative integer)

Integer16 

0x12fff ("0x" makes a number Integer16)

Boolean 

True/False.

Number 

-12.34 ("-" or "." turns an integer to a number)

Binary 

=ABhlkjj= (base64 encoded binary data)

Cdata 

<![CDATA[ ... ]]> markup

Definition at line 84 of file cfl_token.h.

Constructor & Destructor Documentation

faudes::Token::Token ( void  )

Empty constructor, constructs None token.

Definition at line 29 of file cfl_token.cpp.

faudes::Token::Token ( const Token rToken)

Copy constructor.

Definition at line 42 of file cfl_token.cpp.

faudes::Token::~Token ( void  )

Token destructor.

Definition at line 71 of file cfl_token.cpp.

Member Function Documentation

Float faudes::Token::AttributeFloatValue ( const std::string &  name)

Access attribute value.

Parameters
nameAttribute name
Returns
String value of specified attribute

Definition at line 395 of file cfl_token.cpp.

Int faudes::Token::AttributeIntegerValue ( const std::string &  name)

Access attribute value.

Parameters
nameAttribute name
Returns
Integer value of specified attribute (return 0 if it does not exist)

Definition at line 385 of file cfl_token.cpp.

const std::string & faudes::Token::AttributeStringValue ( const std::string &  name)

Access attribute value.

Parameters
nameAttribute name
Returns
String value of specified attribute

Definition at line 374 of file cfl_token.cpp.

void faudes::Token::ClearAttributes ( void  )

Clear all attributes.

Definition at line 281 of file cfl_token.cpp.

void faudes::Token::ClrAttribute ( const std::string &  name)

Clear attribute.

Parameters
nameAttribute name

Definition at line 274 of file cfl_token.cpp.

void faudes::Token::ClrEnd ( void  )

Clear End type (resolve empty section)

Definition at line 164 of file cfl_token.cpp.

bool faudes::Token::ExistsAttributeFloat ( const std::string &  name)

Test attibute existence.

Parameters
nameAttribute name
Returns
True is attribute exists and matches type.

Definition at line 364 of file cfl_token.cpp.

bool faudes::Token::ExistsAttributeInteger ( const std::string &  name)

Test attibute existence.

Parameters
nameAttribute name
Returns
True is attribute exists and matches type.

Definition at line 354 of file cfl_token.cpp.

bool faudes::Token::ExistsAttributeString ( const std::string &  name)

Test attibute existence.

Parameters
nameAttribute name
Returns
True is attribute exists and matches type.

Definition at line 344 of file cfl_token.cpp.

Float faudes::Token::FloatValue ( void  ) const

Get float value of a numeric token.

Returns
Token float value

Definition at line 176 of file cfl_token.cpp.

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
nameAttribute name
valueAttribute value

Definition at line 288 of file cfl_token.cpp.

void faudes::Token::InsAttributeBoolean ( const std::string &  name,
Int  value 
)

Insert named attribute with boolean value.

Note: only begin tags can have attributes.

Parameters
nameAttribute name
valueAttribute value

Definition at line 325 of file cfl_token.cpp.

void faudes::Token::InsAttributeFloat ( const std::string &  name,
Float  value 
)

Insert named attribute with integer value.

Note: only begin tags can have attributes.

Parameters
nameAttribute name
valueAttribute value

Definition at line 335 of file cfl_token.cpp.

void faudes::Token::InsAttributeInteger ( const std::string &  name,
Int  value 
)

Insert named attribute with integer value.

Note: only begin tags can have attributes.

Parameters
nameAttribute name
valueAttribute value

Definition at line 307 of file cfl_token.cpp.

void faudes::Token::InsAttributeInteger16 ( const std::string &  name,
Int  value 
)

Insert named attribute with integer value.

Note: only begin tags can have attributes.

Parameters
nameAttribute name
valueAttribute value

Definition at line 316 of file cfl_token.cpp.

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
nameAttribute name
valueAttribute value

Definition at line 298 of file cfl_token.cpp.

Int faudes::Token::IntegerValue ( void  ) const

Get integer value of a numeric token.

Returns
Token's integer value

Definition at line 170 of file cfl_token.cpp.

void faudes::Token::InterpretAttribute ( aiterator  ait)
private

Interpret attribute value from string.

Definition at line 704 of file cfl_token.cpp.

bool faudes::Token::InterpretNumber ( const std::string &  numstr,
int &  type,
Int ival,
Float fval 
)
private

Interpret string a s number.

Definition at line 718 of file cfl_token.cpp.

bool faudes::Token::InterpretNumber ( void  )
private

Interpret string a s number.

Definition at line 713 of file cfl_token.cpp.

bool faudes::Token::IsBegin ( void  ) const

Test token Type.

Returns
True on match

Definition at line 247 of file cfl_token.cpp.

bool faudes::Token::IsBegin ( const std::string &  tag) const

Test token Type.

Parameters
tagSection tag to test for
Returns
True on match

Definition at line 252 of file cfl_token.cpp.

bool faudes::Token::IsBinary ( void  ) const

Test token Type.

Returns
True on match

Definition at line 242 of file cfl_token.cpp.

bool faudes::Token::IsBoolean ( void  ) const

Test token Type.

Returns
True on match

Definition at line 222 of file cfl_token.cpp.

bool faudes::Token::IsEmpty ( void  ) const

Test token Type.

Returns
True on match

Definition at line 269 of file cfl_token.cpp.

bool faudes::Token::IsEnd ( void  ) const

Test token Type.

Returns
True on match

Definition at line 258 of file cfl_token.cpp.

bool faudes::Token::IsEnd ( const std::string &  tag) const

Test token Type.

Parameters
tagSection tag to test for
Returns
True on match

Definition at line 263 of file cfl_token.cpp.

bool faudes::Token::IsFloat ( void  ) const

Test token Type.

Returns
True on match

Definition at line 227 of file cfl_token.cpp.

bool faudes::Token::IsInteger ( void  ) const

Test token Type.

Returns
True on match

Definition at line 212 of file cfl_token.cpp.

bool faudes::Token::IsInteger16 ( void  ) const

Test token Type.

Returns
True on match

Definition at line 217 of file cfl_token.cpp.

bool faudes::Token::IsNone ( void  ) const

Test token Type.

Returns
True on match

Definition at line 207 of file cfl_token.cpp.

bool faudes::Token::IsOption ( void  ) const

Test token Type.

Returns
True on match

Definition at line 232 of file cfl_token.cpp.

bool faudes::Token::IsString ( void  ) const

Test token Type.

Returns
True on match

Definition at line 237 of file cfl_token.cpp.

Token & faudes::Token::operator= ( const Token rOther)

Assignment operator.

Definition at line 57 of file cfl_token.cpp.

const std::string & faudes::Token::OptionValue ( void  ) const

Get option value of a name token.

Returns
Token's option value

Definition at line 187 of file cfl_token.cpp.

int faudes::Token::Read ( std::istream *  pStream)

Read Token from input stream.

Parameters
pStreamPointer to std::ifstream
Exceptions
Exception
  • ios exceptions (eg file io error)
Returns
line count

Definition at line 1266 of file cfl_token.cpp.

int faudes::Token::ReadAttributes ( std::istream *  pStream)
private

Read and interpret attribute definitions of begin tags from an input file stream.

Parameters
pStreamReference to std::istream
Returns
Line count or -1 for error

Definition at line 1013 of file cfl_token.cpp.

int faudes::Token::ReadBinary ( std::istream *  pStream)
private

Read a base64 binary string from an input file stream.

Parameters
pStreamReference to std::istream
Returns
Line count or -1 for error

Definition at line 572 of file cfl_token.cpp.

int faudes::Token::ReadCharacterData ( std::istream *  pStream,
std::string &  rString 
)
static

Read chracter data from an input file stream.

Reads the stream untion the next "<" character. The plain character data is returned, no enteties substituted etc.

Parameters
pStreamReference to std::istream
rStringReference to result.
Returns
Line count or -1 for error

Definition at line 982 of file cfl_token.cpp.

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 and excl. the specified stop character.

Parameters
pStreamReference to std::istream
stopStop character
rStringReference to result.
Returns
Line count or -1 for error

Definition at line 922 of file cfl_token.cpp.

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 be ignored.

Parameters
pStreamReference to std::istream
Returns
Line count or -1 for error

Definition at line 1088 of file cfl_token.cpp.

int faudes::Token::ReadSpace ( std::istream *  pStream)
private

Read (ignore) spaces and comments in an input file stream.

Parameters
pStreamReference to std::istream
Returns
Number of lines read

Definition at line 648 of file cfl_token.cpp.

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. enclosed by single stop characters. However, for practical reasons, it is assumed that the first stop character has been allready read .

Parameters
pStreamReference to std::istream
stopStop character
Returns
Line count or -1 for error

Definition at line 914 of file cfl_token.cpp.

int faudes::Token::ReadVerbatim ( std::istream *  pStream)
private

Read a std::string value from an input file stream.

This method assumes that the string was written in the format of WriteVerbatim, i.e. enclosed by a start and stop markers "__VERBATIM__" or variations thereof. However, for practical reasons, it is assumed that the first character "_" has been read allready. Note: verbatim sections are in general NOT XML compliant.

Parameters
pStreamReference to std::istream
Returns
Line count or -1 for error

Definition at line 453 of file cfl_token.cpp.

void faudes::Token::SetBegin ( const std::string &  rName)

Initialize as Begin token.

Parameters
rNameTitle of section to fill the Token

Definition at line 95 of file cfl_token.cpp.

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
dataReference to raw data record
lenNumber of bytes in record

Definition at line 156 of file cfl_token.cpp.

void faudes::Token::SetBoolean ( const Int  number)

Initialize as Boolean token.

Parameters
numberNumber to fill the Token

Definition at line 140 of file cfl_token.cpp.

void faudes::Token::SetEmpty ( const std::string &  rName)

Initialize as empty-tag token.

Parameters
rNameTitle of section to fill the Token

Definition at line 109 of file cfl_token.cpp.

void faudes::Token::SetEnd ( const std::string &  rName)

Initialize as End token.

Parameters
rNameTitle of section to fill the Token

Definition at line 102 of file cfl_token.cpp.

void faudes::Token::SetFloat ( const Float  number)

Initialize as Float token.

Parameters
numberNumber to fill the Token

Definition at line 148 of file cfl_token.cpp.

void faudes::Token::SetInteger ( const Int  number)

Initialize as Integer token.

Parameters
numberNumber to fill the Token

Definition at line 124 of file cfl_token.cpp.

void faudes::Token::SetInteger16 ( const Int  number)

Initialize as Integer16 token.

Parameters
numberNumber to fill the Token

Definition at line 132 of file cfl_token.cpp.

void faudes::Token::SetNone ( void  )

Initialize None token.

Definition at line 75 of file cfl_token.cpp.

void faudes::Token::SetOption ( const std::string &  rName)

Initialize as Option token.

Parameters
rNameOption to fill the Token

Definition at line 116 of file cfl_token.cpp.

void faudes::Token::SetString ( const std::string &  rName)

Initialize as String token.

Parameters
rNameString to fill the Token

Definition at line 88 of file cfl_token.cpp.

std::string faudes::Token::Str ( void  ) const

Pretty print string representation.

Convenience functio for inspection/debugging

Returns
Printable string representation

Definition at line 1361 of file cfl_token.cpp.

const std::string & faudes::Token::StringValue ( void  ) const

Get string value of a name token.

Returns
Token's string value

Definition at line 181 of file cfl_token.cpp.

Token::TokenType faudes::Token::Type ( void  ) const

Get token Type.

This method is for backward compatibility only. It returns a token type with only oe 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 192 of file cfl_token.cpp.

void faudes::Token::Write ( std::ostream *  pStream) const

Write Token to output stream.

Parameters
pStreamPointer to ostream
Exceptions
Exception
  • ios exceptions (eg file io error,)

Definition at line 809 of file cfl_token.cpp.

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
pStreamReference to std::ostream
lenNumber of bytes to write
pDataData to write

Definition at line 504 of file cfl_token.cpp.

void faudes::Token::WriteBinary ( std::ostream *  pStream) const
private

Write my binary data as base64 string to output stream.

Parameters
pStreamReference to std::ostream

Definition at line 565 of file cfl_token.cpp.

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
pStreamReference to std::ostream
outstrString to stream
Returns
Number of characters written.

Definition at line 875 of file cfl_token.cpp.

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. &lt; && etc. A single white space is added as a sepqrqtor.

Parameters
pStreamReference to std::ostream
delimDelimiter

Definition at line 901 of file cfl_token.cpp.

void faudes::Token::WriteVerbatim ( std::ostream *  pStream,
const std::string &  rString 
)
static

Write a std::string value to an output stream.

This method writes a string verbatim, i.e. incl all control characters. It is enclosed by a marker which defaults to "__VERBATIM__". If the string contains the marker, a variation is used.

Parameters
pStreamReference to std::ostream
rStringString to write

Definition at line 424 of file cfl_token.cpp.

Friends And Related Function Documentation

friend class TokenReader
friend

Definition at line 60 of file cfl_token.h.

friend class TokenWriter
friend

Definition at line 59 of file cfl_token.h.

Member Data Documentation

int faudes::Token::mAttributeCount
private

Attribute sort index (for nice output only)

Definition at line 635 of file cfl_token.h.

std::map<std::string, AttributeValue> faudes::Token::mAttributes
private

Attribute value map.

Definition at line 632 of file cfl_token.h.

Float faudes::Token::mFloatValue
private

Token float value (if Token is of type Float or Integer)

Definition at line 612 of file cfl_token.h.

Int faudes::Token::mIntegerValue
private

Token integer value (if Token is of type Integer or Integer16)

Definition at line 609 of file cfl_token.h.

std::string faudes::Token::mOptionValue
private

Token std::string value (if token is of type Option)

Definition at line 606 of file cfl_token.h.

bool faudes::Token::mPreceedingNewline
private

When read from stream, record preceeding space.

Definition at line 618 of file cfl_token.h.

bool faudes::Token::mPreceedingSpace
private

When read from stream, record preceeding space.

Definition at line 615 of file cfl_token.h.

std::string faudes::Token::mStringValue
private

Token std::string value (for any token type)

Definition at line 603 of file cfl_token.h.

int faudes::Token::mType
private

Token type.

Definition at line 600 of file cfl_token.h.


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

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen