Go to the documentation of this file.
7 #ifndef CNOID_UTIL_EASYSCANNER_H_INCLUDED
8 #define CNOID_UTIL_EASYSCANNER_H_INCLUDED
10 #include <unordered_map>
14 #include "exportdecl.h"
34 std::string getFullMessage()
const;
38 T_NONE = 0, T_SPACE, T_ALPHABET, T_INTEGER, T_DOUBLE,
T_WORD,
42 typedef std::unordered_map<std::string, int>
SymbolMap;
59 this->symbols = symbols;
63 SymbolMap::iterator p = symbols->find(symbol);
64 return (p != symbols->end()) ? p->second : 0;
68 void setCommentChar(
char cc);
70 void setLineOriented(
bool on);
71 void setQuoteChar(
char qc);
72 void setWhiteSpaceChar(
char ws);
74 void loadFile(
const std::string& filename);
76 void setText(
const char* text,
size_t len);
78 void setLineNumberOffset(
int offset);
81 defaultErrorMessage = message;
94 bool readChar(
int chara);
112 return readString0(delimiterChar);
115 bool readString(
const char*
str);
118 return readString(
str.c_str());
121 bool readQuotedString(
bool allowNoQuotedWord =
false);
123 bool readUnquotedTextBlock();
126 bool readSymbol(
int id);
130 return (*text ==
'\0');
141 return readLF0() ? true : (*text ==
'\0');
148 bool skipBlankLines();
149 void skipToLineEnd();
153 void throwException(
const char* message);
154 void throwException(
const std::string& message);
161 if(!readInt()) throwException(message);
169 if(!readDouble()) throwException(message);
177 if(!readFloat()) throwException(message);
186 throwException(message);
193 if(!readChar(chara)) throwException(message);
199 inline const std::string&
readWordEx(
const char* message = 0) {
200 if(!readWord()) throwException(message);
205 if(!readString(
str)) throwException(message);
213 if(!readString()) throwException(message);
218 if(!readQuotedString()) throwException(message);
226 if(!readSymbol()) throwException(message);
233 if(!readLF()) throwException(message);
237 if(!readLFEOF()) throwException(message);
256 bool extractQuotedString();
260 bool readString0(
const int delimiterChar);
265 int lineNumberOffset;
270 std::vector<int> whiteSpaceChars;
272 std::shared_ptr<SymbolMap> symbols;
void setDefaultErrorMessage(const std::string &message)
Definition: EasyScanner.h:80
double readDoubleEx(const char *message=0)
Definition: EasyScanner.h:168
Endl endl
Definition: EasyScanner.h:45
std::string filename
Definition: EasyScanner.h:32
bool isEOF()
Definition: EasyScanner.h:128
std::pair< std::string, int > SymbolPair
Definition: EasyScanner.h:43
int lineNumber
Definition: EasyScanner.h:248
int readCharEx(const char *message=0)
Definition: EasyScanner.h:184
bool readString(const int delimiterChar=',')
Definition: EasyScanner.h:110
std::string str(const Vector3 &v)
Definition: EigenUtil.cpp:206
void readLFex(const char *message=0)
Definition: EasyScanner.h:232
float floatValue
Definition: EasyScanner.h:242
std::unordered_map< std::string, int > SymbolMap
Definition: EasyScanner.h:42
bool readWord()
Definition: EasyScanner.h:101
std::string defaultErrorMessage
Definition: EasyScanner.h:247
bool readLF()
reading a line feed
Definition: EasyScanner.h:134
bool readLFEOF()
Definition: EasyScanner.h:139
char * text
Definition: EasyScanner.h:250
const std::string & readStringEx(const char *message=0)
Definition: EasyScanner.h:212
void registerSymbol(int id, const std::string &symbol)
Definition: EasyScanner.h:54
float readFloatEx(const char *message=0)
Definition: EasyScanner.h:176
std::string stringValue
Definition: EasyScanner.h:243
char charValue
Definition: EasyScanner.h:244
Definition: EasyScanner.h:21
@ T_WORD
Definition: EasyScanner.h:38
const std::string & readWordEx(const char *message=0)
Definition: EasyScanner.h:199
Definition: AbstractSceneLoader.h:11
TokenType
Definition: EasyScanner.h:37
Definition: EasyScanner.h:25
int intValue
Definition: EasyScanner.h:240
void readCharEx(int chara, const char *message=0)
Definition: EasyScanner.h:192
@ T_STRING
Definition: EasyScanner.h:39
int symbolValue
Definition: EasyScanner.h:245
std::string message
Definition: EasyScanner.h:31
std::string filename
Definition: EasyScanner.h:252
Definition: EasyScanner.h:29
void setSymbols(std::shared_ptr< SymbolMap > symbols)
Definition: EasyScanner.h:58
bool readString(const std::string &str)
Definition: EasyScanner.h:117
int readIntEx(const char *message=0)
Definition: EasyScanner.h:160
int readSymbolEx(const char *message=0)
Definition: EasyScanner.h:225
void readLFEOFex(const char *message=0)
Definition: EasyScanner.h:236
void checkStringEx(const char *str, const char *message=0)
Definition: EasyScanner.h:204
int getSymbolID(const std::string &symbol)
Definition: EasyScanner.h:62
CNOID_EXPORT EasyScanner & operator>>(EasyScanner &scanner, double &value)
Definition: EasyScanner.cpp:681
const std::string & readQuotedStringEx(const char *message=0)
Definition: EasyScanner.h:217
double doubleValue
Definition: EasyScanner.h:241
int lineNumber
Definition: EasyScanner.h:33