00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __DOLPHIN_H__
00030 #define __DOLPHIN_H__
00031
00032 #include <fsmpp/fsm.h>
00033 #include <fsmpp/action.h>
00034 #include <fsmpp/strparser.h>
00035 #include <seal/list.h>
00036 #include <fstream>
00037 #include <string>
00038
00039 class DolphinStartErrorAction;
00040 class DolphinAttribErrorAction;
00041 class DolphinAssignErrorAction;
00042
00046 class AttributeValuePair
00047 {
00048 public:
00051 std::string attrib;
00052
00055 std::string value;
00056 };
00057
00060 class Dolphin : public fsm::FSM<char>
00061 {
00062
00063 friend class DolphinDirectiveEndAction;
00064 friend class DolphinValueEndAction;
00065 friend class DolphinStartErrorAction;
00066 friend class DolphinAttribErrorAction;
00067 friend class DolphinAssignErrorAction;
00068
00069 static const char NL = 10;
00070 static const char CR = 0xD;
00071 static const char BS = 0x7;
00072 static const char US = '_';
00073 static const char SPACE = ' ';
00074 static const char TAB = '\t';
00075 static const char DOT = '.';
00076 static const char EQL = '=';
00077
00080 typedef enum
00081 {
00082 ATTRIBUTE = 1000,
00083 DIRECTIVE,
00084 END,
00085 ASSIGN,
00086 ERROR,
00087 SPACE_1,
00088 SPACE_2,
00089 SPACE_3,
00090 START,
00091 VALUE,
00092 STR_PARSER_1,
00093 STR_PARSER_2,
00094 COMMENT
00095 } StateID;
00096
00097 public:
00098
00102 typedef enum
00103 {
00104 NO_ERROR = 2000,
00105 START_ERROR,
00106 DIRECTIVE_ERROR,
00107 ATTRIB_ERROR,
00108 ASSIGN_ERROR
00109 } ErrorType;
00110
00113 typedef enum
00114 {
00121 ARGUMENT = 3000,
00122
00128 ATTRIB_VALUE,
00129
00135 EMPTY,
00136
00139 NONE
00140 } DirectiveType;
00141
00144 class ErrorInfo
00145 {
00146 public:
00149 ErrorType type;
00150
00153 unsigned int position;
00154
00157 std::string message;
00158 };
00159
00160 public:
00163 Dolphin(void);
00164
00167 virtual ~Dolphin(void);
00168
00173 bool parse(std::string &str);
00174
00178 Dolphin::ErrorInfo getErrorInfo(void);
00179
00182 DirectiveType getDirectiveType(void) { return _directiveType; }
00183
00186 std::string getDirectiveName(void) { return _directiveName; }
00187
00190 std::string getArgumentValue(void) { return _argumentValue; }
00191
00194 seal::LinkedList<AttributeValuePair> getAttributeValuePairList(void)
00195 { return _attributeValuePairList; }
00196
00201 static bool isDot(const std::string &str);
00202
00203 private:
00204
00206
00208
00209 class ValueEndAction : public fsm::Action<char>
00210 {
00211 public:
00212 ValueEndAction(Dolphin *parent);
00213 virtual ~ValueEndAction() {}
00214
00215 virtual void perform(const char &);
00216
00217 private:
00218 Dolphin *_parent;
00219 };
00220
00221 class DirectiveEndAction : public fsm::Action<char>
00222 {
00223 public:
00224 DirectiveEndAction(Dolphin *parent);
00225 virtual ~DirectiveEndAction() {}
00226
00227 virtual void perform(const char &);
00228
00229 private:
00230 Dolphin *_parent;
00231 };
00232
00233 class ArgumentEndAction : public fsm::Action<char>
00234 {
00235 public:
00236 ArgumentEndAction(Dolphin *parent);
00237 virtual ~ArgumentEndAction() {}
00238
00239 virtual void perform(const char &c);
00240
00241 private:
00242 Dolphin *_parent;
00243 };
00244
00246
00248
00249 class StartErrorAction : public fsm::Action<char>
00250 {
00251 public:
00252 StartErrorAction(Dolphin *parent)
00253 : fsm::Action<char>(parent), _parent(parent)
00254 {}
00255
00256 virtual ~StartErrorAction() {}
00257 virtual void perform(const char &);
00258
00259 private:
00260 Dolphin *_parent;
00261 };
00262
00263 class DirectiveErrorAction : public fsm::Action<char>
00264 {
00265 public:
00266 DirectiveErrorAction(Dolphin *parent)
00267 : fsm::Action<char>(parent), _parent(parent)
00268 {}
00269
00270 virtual ~DirectiveErrorAction() {}
00271 virtual void perform(const char &c);
00272
00273 private:
00274 Dolphin *_parent;
00275 };
00276
00277 class Space1ErrorAction : public fsm::Action<char>
00278 {
00279 public:
00280 Space1ErrorAction(Dolphin *parent)
00281 : fsm::Action<char>(parent), _parent(parent)
00282 {}
00283
00284 virtual ~Space1ErrorAction() {}
00285 virtual void perform(const char &c);
00286
00287 private:
00288 Dolphin *_parent;
00289 };
00290
00291 class Space2ErrorAction : public fsm::Action<char>
00292 {
00293 public:
00294 Space2ErrorAction(Dolphin *parent)
00295 : fsm::Action<char>(parent), _parent(parent)
00296 {}
00297
00298 virtual ~Space2ErrorAction() {}
00299 virtual void perform(const char &c);
00300
00301 private:
00302 Dolphin *_parent;
00303 };
00304
00305 class AssignErrorAction : public fsm::Action<char>
00306 {
00307 public:
00308 AssignErrorAction(Dolphin *parent)
00309 : fsm::Action<char>(parent), _parent(parent)
00310 {}
00311
00312 virtual ~AssignErrorAction() {}
00313 virtual void perform(const char &c);
00314
00315 private:
00316 Dolphin *_parent;
00317 };
00318
00319 private:
00320 void onValueEnd(void);
00321 void onDirectiveEnd(void);
00322 void onArgumentEnd(void);
00323 void setErrorType(ErrorType state) { _errorType = state; }
00324 void setErrorString(std::string &str) { _errorString = str; }
00325
00326 DirectiveType _directiveType;
00327 std::string _directiveName;
00328 std::string _argumentValue;
00329 std::string _errorString;
00330 unsigned int _charPosition;
00331
00332 seal::LinkedList<AttributeValuePair> _attributeValuePairList;
00333
00334 fsm::State<char> *start, *space1, *space2, *space3, *direct, *attrib, *error, *assign,
00335 *value, *end, *comment;
00336
00337 fsm::StringParser *strparser1, *strparser2;
00338
00339 ErrorType _errorType;
00340 };
00341
00342 #endif // __DOLPHIN_H__