Choreonoid  1.8
Classes | Public Types | Public Member Functions | Public Attributes | Friends | List of all members
cnoid::EasyScanner Class Reference

#include <EasyScanner.h>

Classes

class  Endl
 
class  Exception
 

Public Types

enum  TokenType {
  T_NONE = 0, T_SPACE, T_ALPHABET, T_INTEGER,
  T_DOUBLE, T_WORD, T_STRING, T_SIGLUM,
  T_LF, T_EOF
}
 
typedef std::unordered_map< std::string, int > SymbolMap
 
typedef std::pair< std::string, int > SymbolPair
 

Public Member Functions

 EasyScanner ()
 
 EasyScanner (std::string filename)
 
 EasyScanner (const EasyScanner &org, bool copyText=false)
 
virtual ~EasyScanner ()
 
void putSymbols ()
 
void registerSymbol (int id, const std::string &symbol)
 
void setSymbols (std::shared_ptr< SymbolMap > symbols)
 
int getSymbolID (const std::string &symbol)
 
void setCommentChar (char cc)
 if 0, comment is disabled More...
 
void setLineOriented (bool on)
 
void setQuoteChar (char qc)
 
void setWhiteSpaceChar (char ws)
 
void loadFile (const std::string &filename)
 
void setText (const char *text, size_t len)
 
void setLineNumberOffset (int offset)
 
void setDefaultErrorMessage (const std::string &message)
 
void moveToHead ()
 
int readToken ()
 
void toLower ()
 
bool readFloat ()
 
bool readDouble ()
 
bool readInt ()
 
bool readChar ()
 
bool readChar (int chara)
 
int peekChar ()
 
bool readWord ()
 
bool readString (const int delimiterChar=',')
 
bool readString (const char *str)
 
bool readString (const std::string &str)
 
bool readQuotedString (bool allowNoQuotedWord=false)
 
bool readUnquotedTextBlock ()
 
bool readSymbol ()
 
bool readSymbol (int id)
 
bool isEOF ()
 
bool readLF ()
 reading a line feed More...
 
bool readLFEOF ()
 
bool checkLF ()
 
bool readLine ()
 
bool skipLine ()
 
bool skipBlankLines ()
 
void skipToLineEnd ()
 
void skipSpace ()
 
void throwException (const char *message)
 
void throwException (const std::string &message)
 
int readIntEx (const char *message=0)
 
double readDoubleEx (const char *message=0)
 
float readFloatEx (const char *message=0)
 
int readCharEx (const char *message=0)
 
void readCharEx (int chara, const char *message=0)
 
const std::string & readWordEx (const char *message=0)
 
void checkStringEx (const char *str, const char *message=0)
 
const std::string & readStringEx (const char *message=0)
 
const std::string & readQuotedStringEx (const char *message=0)
 
int readSymbolEx (const char *message=0)
 
void readLFex (const char *message=0)
 
void readLFEOFex (const char *message=0)
 

Public Attributes

Endl endl
 
int intValue
 
double doubleValue
 
float floatValue
 
std::string stringValue
 
char charValue
 
int symbolValue
 
std::string defaultErrorMessage
 
int lineNumber
 
char * text
 
std::string filename
 

Friends

CNOID_EXPORT EasyScanneroperator>> (EasyScanner &scanner, double &value)
 
CNOID_EXPORT EasyScanneroperator>> (EasyScanner &scanner, int &value)
 
CNOID_EXPORT EasyScanneroperator>> (EasyScanner &scanner, const char *matchString)
 
CNOID_EXPORT EasyScanneroperator>> (EasyScanner &scanner, char matchChar)
 
CNOID_EXPORT EasyScanneroperator>> (EasyScanner &scanner, std::string &str)
 
CNOID_EXPORT EasyScanneroperator>> (EasyScanner &scanner, EasyScanner::Endl endl)
 

Detailed Description

Member Typedef Documentation

◆ SymbolMap

typedef std::unordered_map<std::string, int> cnoid::EasyScanner::SymbolMap

◆ SymbolPair

typedef std::pair<std::string, int> cnoid::EasyScanner::SymbolPair

Member Enumeration Documentation

◆ TokenType

Enumerator
T_NONE 
T_SPACE 
T_ALPHABET 
T_INTEGER 
T_DOUBLE 
T_WORD 
T_STRING 
T_SIGLUM 
T_LF 
T_EOF 

Constructor & Destructor Documentation

◆ EasyScanner() [1/3]

EasyScanner::EasyScanner ( )

◆ EasyScanner() [2/3]

EasyScanner::EasyScanner ( std::string  filename)
Parameters
filenamefile to read.

◆ EasyScanner() [3/3]

EasyScanner::EasyScanner ( const EasyScanner org,
bool  copyText = false 
)

Copy Constructor. New object inherits another's propety and symbols.

Parameters
orgoriginal object
copyTextIf true, new object has same text as original

◆ ~EasyScanner()

EasyScanner::~EasyScanner ( )
virtual

Member Function Documentation

◆ checkLF()

bool EasyScanner::checkLF ( )

◆ checkStringEx()

void cnoid::EasyScanner::checkStringEx ( const char *  str,
const char *  message = 0 
)
inline

◆ getSymbolID()

int cnoid::EasyScanner::getSymbolID ( const std::string &  symbol)
inline

◆ isEOF()

bool cnoid::EasyScanner::isEOF ( )
inline

◆ loadFile()

void EasyScanner::loadFile ( const std::string &  filename)

This function loads a text from a given file. The function thorws EasyScanner::Exception when the file cannot be loaded.

◆ moveToHead()

void EasyScanner::moveToHead ( )

◆ peekChar()

int EasyScanner::peekChar ( )

◆ putSymbols()

void EasyScanner::putSymbols ( )

◆ readChar() [1/2]

bool EasyScanner::readChar ( )

◆ readChar() [2/2]

bool EasyScanner::readChar ( int  chara)

◆ readCharEx() [1/2]

int cnoid::EasyScanner::readCharEx ( const char *  message = 0)
inline

The exception version of readChar().

Returns
Scanned char value.

◆ readCharEx() [2/2]

void cnoid::EasyScanner::readCharEx ( int  chara,
const char *  message = 0 
)
inline

The exception version of readChar().

◆ readDouble()

bool EasyScanner::readDouble ( )

◆ readDoubleEx()

double cnoid::EasyScanner::readDoubleEx ( const char *  message = 0)
inline

The exception version of readDouble().

Returns
Scanned double value.

◆ readFloat()

bool EasyScanner::readFloat ( )

◆ readFloatEx()

float cnoid::EasyScanner::readFloatEx ( const char *  message = 0)
inline

The exception version of readDouble().

Returns
Scanned double value.

◆ readInt()

bool EasyScanner::readInt ( )

◆ readIntEx()

int cnoid::EasyScanner::readIntEx ( const char *  message = 0)
inline

The exception version of readInt().

Returns
Scanned int value.

◆ readLF()

bool cnoid::EasyScanner::readLF ( )
inline

reading a line feed

◆ readLFEOF()

bool cnoid::EasyScanner::readLFEOF ( )
inline

◆ readLFEOFex()

void cnoid::EasyScanner::readLFEOFex ( const char *  message = 0)
inline

◆ readLFex()

void cnoid::EasyScanner::readLFex ( const char *  message = 0)
inline

The exception version of readLF().

◆ readLine()

bool EasyScanner::readLine ( )

◆ readQuotedString()

bool EasyScanner::readQuotedString ( bool  allowNoQuotedWord = false)

read a quoted string. If 'allowNoQuotedWord' is true, the function read a word without quotations.

◆ readQuotedStringEx()

const std::string& cnoid::EasyScanner::readQuotedStringEx ( const char *  message = 0)
inline

◆ readString() [1/3]

bool EasyScanner::readString ( const char *  str)

◆ readString() [2/3]

bool cnoid::EasyScanner::readString ( const int  delimiterChar = ',')
inline

In contrast to readWord(), this function allows a string to include siglums such as !,",#,$,%,&,...

◆ readString() [3/3]

bool cnoid::EasyScanner::readString ( const std::string &  str)
inline

◆ readStringEx()

const std::string& cnoid::EasyScanner::readStringEx ( const char *  message = 0)
inline

The exception version of readString().

Returns
Scanned word string.

◆ readSymbol() [1/2]

bool EasyScanner::readSymbol ( )

◆ readSymbol() [2/2]

bool EasyScanner::readSymbol ( int  id)

◆ readSymbolEx()

int cnoid::EasyScanner::readSymbolEx ( const char *  message = 0)
inline

The exception version of readSymbol().

Returns
ID of the scanned symbol.

◆ readToken()

int EasyScanner::readToken ( )

◆ readUnquotedTextBlock()

bool EasyScanner::readUnquotedTextBlock ( )

◆ readWord()

bool cnoid::EasyScanner::readWord ( )
inline

In contrast to readString(), this function does not recognize siglums except '_' as a part of a word.

◆ readWordEx()

const std::string& cnoid::EasyScanner::readWordEx ( const char *  message = 0)
inline

The exception version of readWord().

Returns
Scanned word string.

◆ registerSymbol()

void cnoid::EasyScanner::registerSymbol ( int  id,
const std::string &  symbol 
)
inline

◆ setCommentChar()

void EasyScanner::setCommentChar ( char  cc)

if 0, comment is disabled

This function sets the identifier character of comment beginning.

Parameters
ccIdentifier character. Default is '#'. If you want no comment, set 0.

◆ setDefaultErrorMessage()

void cnoid::EasyScanner::setDefaultErrorMessage ( const std::string &  message)
inline

◆ setLineNumberOffset()

void EasyScanner::setLineNumberOffset ( int  offset)

◆ setLineOriented()

void EasyScanner::setLineOriented ( bool  on)

◆ setQuoteChar()

void EasyScanner::setQuoteChar ( char  qs)

If you want to read quoted string, set quote character by this function. In default, this is unset.

◆ setSymbols()

void cnoid::EasyScanner::setSymbols ( std::shared_ptr< SymbolMap symbols)
inline

◆ setText()

void EasyScanner::setText ( const char *  text,
size_t  len 
)

This function directly sets a text in the main memory

◆ setWhiteSpaceChar()

void EasyScanner::setWhiteSpaceChar ( char  ws)

If there is a character to ignore, you can set it by this function

◆ skipBlankLines()

bool EasyScanner::skipBlankLines ( )

◆ skipLine()

bool EasyScanner::skipLine ( )

◆ skipSpace()

void EasyScanner::skipSpace ( )

◆ skipToLineEnd()

void EasyScanner::skipToLineEnd ( )

move the current position to just before the end (LF or EOF) of a line

◆ throwException() [1/2]

void EasyScanner::throwException ( const char *  message)

◆ throwException() [2/2]

void EasyScanner::throwException ( const std::string &  message)

◆ toLower()

void EasyScanner::toLower ( )

This function makes all the characters in stringValue lower case

Friends And Related Function Documentation

◆ operator>> [1/6]

CNOID_EXPORT EasyScanner& operator>> ( EasyScanner scanner,
char  matchChar 
)
friend

◆ operator>> [2/6]

CNOID_EXPORT EasyScanner& operator>> ( EasyScanner scanner,
const char *  matchString 
)
friend

◆ operator>> [3/6]

CNOID_EXPORT EasyScanner& operator>> ( EasyScanner scanner,
double &  value 
)
friend

◆ operator>> [4/6]

CNOID_EXPORT EasyScanner& operator>> ( EasyScanner scanner,
EasyScanner::Endl  endl 
)
friend

◆ operator>> [5/6]

CNOID_EXPORT EasyScanner& operator>> ( EasyScanner scanner,
int &  value 
)
friend

◆ operator>> [6/6]

CNOID_EXPORT EasyScanner& operator>> ( EasyScanner scanner,
std::string &  str 
)
friend

Member Data Documentation

◆ charValue

char cnoid::EasyScanner::charValue

◆ defaultErrorMessage

std::string cnoid::EasyScanner::defaultErrorMessage

◆ doubleValue

double cnoid::EasyScanner::doubleValue

◆ endl

Endl cnoid::EasyScanner::endl

◆ filename

std::string cnoid::EasyScanner::filename

◆ floatValue

float cnoid::EasyScanner::floatValue

◆ intValue

int cnoid::EasyScanner::intValue

◆ lineNumber

int cnoid::EasyScanner::lineNumber

◆ stringValue

std::string cnoid::EasyScanner::stringValue

◆ symbolValue

int cnoid::EasyScanner::symbolValue

◆ text

char* cnoid::EasyScanner::text

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