libFAUDES

Sections

Index

faudes::Token Class Reference

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

#include <cfl_token.h>

List of all members.

Public Types

enum  TokenType {
  None, Begin, End, String,
  Option, Integer, Integer16, Float,
  Binary
}
 

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 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 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.
TokenType Type (void) const
 Get token Type.
int Read (std::istream *pStream)
 Read Token from input stream.
void Write (std::ostream *pStream)
 Write Token to output stream.

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.

Private Member Functions

void WriteString (std::ostream *pStream, char stop)
 Write a std::string value to an output stream.
void WriteBinary (std::ostream *pStream)
 Write my binary data as base64 string to output stream.
bool ReadNumber (std::istream *pStream)
 Read a number from an input file stream.
int ReadString (std::istream *pStream, char stop)
 Read a std::string value from 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

TokenType mType
 Token type.
std::string mStringValue
 Token std::string value (if Token is of type Name, Begein or End).
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).

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
mIntegerValue Token value as C++-type long integer
mFloatValue Token value of C++-type double

Definition at line 52 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 

"name" (the name may not contain a quote (") )

Option 

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

Integer 

1234 (non-negative)

Integer16 

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

Float 

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

Binary 

=ABhlkjj= (base64 encoded binary data)

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

faudes::Token::~Token ( void   ) 

Token destructor.

Definition at line 57 of file cfl_token.cpp.


Member Function Documentation

double faudes::Token::FloatValue ( void   )  const [inline]

Get float value of a numeric token.

Returns:
Token float value

Definition at line 181 of file cfl_token.h.

long int faudes::Token::IntegerValue ( void   )  const [inline]

Get integer value of a numeric token.

Returns:
Token's integer value

Definition at line 171 of file cfl_token.h.

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

Assignment operator.

Definition at line 48 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)

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

bool faudes::Token::ReadNumber ( std::istream *  pStream  )  [private]

Read a number from an input file stream.

Parameters:
pStream Reference to std::istream
Returns:
Success

Definition at line 108 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 484 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 read allready.

Parameters:
pStream Reference to std::istream
stop Stop character
Returns:
Line count or -1 for error

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

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

Definition at line 306 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 71 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 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 76 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 96 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 86 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 91 of file cfl_token.cpp.

void faudes::Token::SetNone ( void   ) 

Initialize None token.

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

const std::string& faudes::Token::StringValue ( void   )  const [inline]

Get string value of a name token.

Returns:
Token's name value

Definition at line 191 of file cfl_token.h.

TokenType faudes::Token::Type ( void   )  const [inline]

Get token Type.

Returns:
Token's TokenType

Definition at line 201 of file cfl_token.h.

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

Write Token to output stream.

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

Definition at line 183 of file cfl_token.cpp.

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

Write my binary data as base64 string to output stream.

Parameters:
pStream Reference to std::ostream

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

void faudes::Token::WriteString ( std::ostream *  pStream,
char  stop 
) [private]

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

This method writes the string enclosed by a signle stop character, typically '"'. Any stop character within the string is excaped by a preceeding "". If the string comtains a "\", it will also be escaped by another "\". Control codes are replaced by a single blanc.

Parameters:
pStream Reference to std::ostream
stop Character to escape by prepending "\\"

Definition at line 229 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 Character to escap eby prepending "\\"

Definition at line 290 of file cfl_token.cpp.


Member Data Documentation

double faudes::Token::mFloatValue [private]

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

Definition at line 262 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 259 of file cfl_token.h.

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

Token std::string value (if Token is of type Name, Begein or End).

Definition at line 256 of file cfl_token.h.

Token type.

Definition at line 253 of file cfl_token.h.


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

libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3