libFAUDES

Sections

Index

faudes::Token Class Reference
[Faudes object serialization.]

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

#include <cfl_token.h>

List of all members.

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,
  Float = 0x080, Binary = 0x100
}
 

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 long int number)
 Initialize as Integer token.
void SetInteger16 (const long int number)
 Initialize as Integer16 token.
void SetBoolean (const long int number)
 Initialize as Boolean token.
void SetFloat (const double number)
 Initialize as Float token.
void SetBinary (const char *data, long int len)
 Initialize Binary token.
long int IntegerValue (void) const
 Get integer value of a numeric token.
double 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 IsEnd (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, long int value)
 Insert named attribute with integer value.
void InsAttributeInteger16 (const std::string &name, long int value)
 Insert named attribute with integer value.
void InsAttributeBoolean (const std::string &name, long int value)
 Insert named attribute with boolean value.
void InsAttributeFloat (const std::string &name, double 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.
long int AttributeIntegerValue (const std::string &name)
 Access attribute value.
double 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, long int 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.

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, long int &ival, double &fval)
 Interpret string a s number.
bool InterpretNumber (void)
 Interpret token as 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).
long int mIntegerValue
 Token integer value (if Token is of type Integer or Integer16).
double mFloatValue
 Token float value (if Token is of type Float or Integer).
std::map< std::string,
AttributeValue
mAttributes
 Attribute value map.
int mAttributeCount
 Attribute sort index (for nice output only).

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:
mType faudes::TokenType of the Token
mStringValue Token value as C++-type std::string
mOptionValue Token value as interpreted option token
mIntegerValue Token value as C++-type long integer
mFloatValue Token value of C++-type double

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 578 of file cfl_token.h.

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

Definition at line 579 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.

Float 

-12.34 ("-" or "." makes a number a float)

Binary 

=ABhlkjj= (base64 encoded binary data)

Definition at line 81 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 40 of file cfl_token.cpp.

faudes::Token::~Token ( void   ) 

Token destructor.

Definition at line 65 of file cfl_token.cpp.


Member Function Documentation

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

Access attribute value.

Parameters:
name Attribute name
Returns:
String value of specified attribute

Definition at line 365 of file cfl_token.cpp.

long int faudes::Token::AttributeIntegerValue ( const std::string &  name  ) 

Access attribute value.

Parameters:
name Attribute name
Returns:
String value of specified attribute

Definition at line 355 of file cfl_token.cpp.

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

Access attribute value.

Parameters:
name Attribute name
Returns:
String value of specified attribute

Definition at line 344 of file cfl_token.cpp.

void faudes::Token::ClearAttributes ( void   ) 

Clear all attributes.

Definition at line 251 of file cfl_token.cpp.

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

Clear attribute.

Parameters:
name Attribute name

Definition at line 244 of file cfl_token.cpp.

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

Test attibute existence.

Parameters:
name Attribute name
Returns:
True is attribute exists and matches type.

Definition at line 334 of file cfl_token.cpp.

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

Test attibute existence.

Parameters:
name Attribute name
Returns:
True is attribute exists and matches type.

Definition at line 324 of file cfl_token.cpp.

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

Test attibute existence.

Parameters:
name Attribute name
Returns:
True is attribute exists and matches type.

Definition at line 314 of file cfl_token.cpp.

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

Get float value of a numeric token.

Returns:
Token float value

Definition at line 162 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:
name Attribute name
value Attribute value

Definition at line 258 of file cfl_token.cpp.

void faudes::Token::InsAttributeBoolean ( const std::string &  name,
long 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 295 of file cfl_token.cpp.

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

Insert named attribute with integer value.

Note: only begin tags can have attributes.

Parameters:
name Attribute name
value Attribute value

Definition at line 305 of file cfl_token.cpp.

void faudes::Token::InsAttributeInteger ( const std::string &  name,
long 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 277 of file cfl_token.cpp.

void faudes::Token::InsAttributeInteger16 ( const std::string &  name,
long 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 286 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:
name Attribute name
value Attribute value

Definition at line 268 of file cfl_token.cpp.

long int faudes::Token::IntegerValue ( void   )  const

Get integer value of a numeric token.

Returns:
Token's integer value

Definition at line 156 of file cfl_token.cpp.

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

Interpret attribute value from string.

Definition at line 620 of file cfl_token.cpp.

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

Interpret token as number.

Parameters:
numstr String to interpret
Returns:
Success

Definition at line 629 of file cfl_token.cpp.

bool faudes::Token::InterpretNumber ( const std::string &  numstr,
int &  type,
long int &  ival,
double &  fval 
) [private]

Interpret string a s number.

Definition at line 634 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 233 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 228 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 208 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 238 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 213 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 198 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 203 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 193 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 218 of file cfl_token.cpp.

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

Test token Type.

Returns:
True on match

Definition at line 223 of file cfl_token.cpp.

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

Assignment operator.

Definition at line 53 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 173 of file cfl_token.cpp.

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

Read Token from input stream.

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

Definition at line 1108 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:
pStream Reference to std::istream
Returns:
Line count or -1 for error

Definition at line 886 of file cfl_token.cpp.

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 505 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:
pStream Reference to std::istream
stop Stop character
rString Reference to result.
Returns:
Line count or -1 for error

Definition at line 831 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:
pStream Reference to std::istream
Returns:
Line count or -1 for error

Definition at line 962 of file cfl_token.cpp.

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

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

Parameters:
pStream Reference to std::istream
Returns:
Number of lines read

Definition at line 581 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:
pStream Reference to std::istream
stop Stop character
Returns:
Line count or -1 for error

Definition at line 823 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:
pStream Reference to std::istream
Returns:
Line count or -1 for error

Definition at line 391 of file cfl_token.cpp.

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

Initialize as Begin token.

Parameters:
rName Title of section to fill the Token

Definition at line 87 of file cfl_token.cpp.

void faudes::Token::SetBinary ( const char *  data,
long int  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 148 of file cfl_token.cpp.

void faudes::Token::SetBoolean ( const long int  number  ) 

Initialize as Boolean token.

Parameters:
number Number to fill the Token

Definition at line 132 of file cfl_token.cpp.

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 101 of file cfl_token.cpp.

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

Initialize as End token.

Parameters:
rName Title of section to fill the Token

Definition at line 94 of file cfl_token.cpp.

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

Initialize as Float token.

Parameters:
number Number to fill the Token

Definition at line 140 of file cfl_token.cpp.

void faudes::Token::SetInteger ( const long int  number  ) 

Initialize as Integer token.

Parameters:
number Number to fill the Token

Definition at line 116 of file cfl_token.cpp.

void faudes::Token::SetInteger16 ( const long int  number  ) 

Initialize as Integer16 token.

Parameters:
number Number to fill the Token

Definition at line 124 of file cfl_token.cpp.

void faudes::Token::SetNone ( void   ) 

Initialize None token.

Definition at line 69 of file cfl_token.cpp.

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

Initialize as Option token.

Parameters:
rName Option to fill the Token

Definition at line 108 of file cfl_token.cpp.

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

Initialize as String token.

Parameters:
rName String to fill the Token

Definition at line 80 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 1203 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 167 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 178 of file cfl_token.cpp.

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

Write Token to output stream.

Parameters:
pStream Pointer to ostream
Exceptions:
Exception 
  • ios exceptions (eg file io error,)

Definition at line 725 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:
pStream Reference to std::ostream

Definition at line 498 of file cfl_token.cpp.

void faudes::Token::WriteBinary ( std::ostream *  pStream,
const char *  pData,
long int  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 437 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:
pStream Reference to std::ostream
outstr String to stream
Returns:
Number of characters written.

Definition at line 784 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:
pStream Reference to std::ostream
delim Delimiter

Definition at line 810 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:
pStream Reference to std::ostream
rString String to write

Definition at line 375 of file cfl_token.cpp.


Member Data Documentation

Attribute sort index (for nice output only).

Definition at line 575 of file cfl_token.h.

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

Attribute value map.

Definition at line 572 of file cfl_token.h.

double faudes::Token::mFloatValue [private]

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

Definition at line 558 of file cfl_token.h.

long int faudes::Token::mIntegerValue [private]

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

Definition at line 555 of file cfl_token.h.

std::string faudes::Token::mOptionValue [private]

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

Definition at line 552 of file cfl_token.h.

std::string faudes::Token::mStringValue [private]

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

Definition at line 549 of file cfl_token.h.

int faudes::Token::mType [private]

Token type.

Definition at line 546 of file cfl_token.h.


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

libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3