![]() |
![]() |
#include <SimpleSAXParser.h>
Classes | |
struct | Attribute |
class | ParserError |
Public Types | |
typedef std::vector< Attribute > | Attributes |
enum | PARSER_STATES { IN_DOCUMENT, IN_BEGIN_TAG, IN_DONE, IN_BEGIN_ELEMENT, IN_ELEMENT_WHITESPACE, IN_END_ELEMENT, IN_ATTRIBUTE_KEY, IN_END_TAG, IN_DATA, IN_BEGIN_ATTRIBUTE_VALUE, IN_STRING, IN_END_ATTRIBUTE_VALUE, IN_STRING_ENTITY, IN_DATA_ENTITY } |
Public Member Functions | |
virtual void | data (const std::string &) |
virtual void | endElement (const std::string &) |
void | parse (void) |
SimpleSAXParser (std::istream &f) | |
virtual void | startElement (const std::string &, Attributes &) |
virtual | ~SimpleSAXParser () |
Private Member Functions | |
std::string | getToken (const char *delim) |
std::string | getToken (const char delim) |
int | nextChar (void) |
std::string | parseEntity (const std::string &entity) |
bool | skipChar (int c) |
Private Attributes | |
Attributes | m_attributes |
char * | m_buffer |
size_t | m_bufferSize |
std::vector< std::string > | m_elementTags |
std::istream & | m_in |
int | m_nextChar |
A simple SAX parser which is able to parse the configuration.
State machine for the parser can be drawn by cut and pasting the following to graphviz:
digraph { IN_DOCUMENT->IN_BEGIN_TAG [label="nextChar == '<'"]; IN_DOCUMENT->IN_DATA [label="nextChar != '<'"];
IN_BEGIN_TAG->IN_BEGIN_ELEMENT [label="nextChar >= 'a' && nextChar < 'Z'"]; IN_BEGIN_TAG->IN_END_ELEMENT [label= "nextChar == '/'"];
IN_BEGIN_ELEMENT->IN_END_ELEMENT [label="nextChar == '/'"]; IN_BEGIN_ELEMENT->IN_ELEMENT_WHITESPACE [label="nextChar == ' '"]; IN_BEGIN_ELEMENT->IN_END_TAG [label="nextChar == '>'"];
IN_ELEMENT_WHITESPACE->IN_ELEMENT_WHITESPACE [ label = "nextChar == \"\ \t\n""] IN_ELEMENT_WHITESPACE->IN_ATTRIBUTE_KEY [ label = "nextChar >= 'a' && nextChar < 'Z'"] IN_ELEMENT_WHITESPACE->IN_END_ELEMENT [label="nextChar == '/'"]
IN_END_ELEMENT->IN_END_TAG [label = "nextChar == '>'"];
IN_END_TAG->IN_BEGIN_TAG [label="nextChar == '<'"]; IN_END_TAG->IN_DATA [label="nextChar != '<'"]
IN_DATA->IN_BEGIN_TAG [label="nextChar == '<'"]; IN_DATA->IN_DATA_ENTITY [label="nextChar == '&'"]; IN_DATA->IN_DONE [label = "nextChar == EOF"];
IN_DATA_ENTITY->IN_DATA [label="nextChar == ';'"];
IN_ATTRIBUTE_KEY->IN_BEGIN_ATTRIBUTE_VALUE [label = "nextChar == '='"]
IN_BEGIN_ATTRIBUTE_VALUE->IN_STRING [label = "nextChar == '\"' || nextChar == '\'' "]
IN_STRING->IN_END_ATTRIBUTE_VALUE [label = "nextChar == quote"] IN_STRING->IN_STRING_ENTITY [label = "nextChar == '&'"]
IN_END_ATTRIBUTE_VALUE->IN_ELEMENT_WHITESPACE [label = "nextChar == ' '"] IN_END_ATTRIBUTE_VALUE->IN_END_ELEMENT [label = "nextChar == '/'"] IN_END_ATTRIBUTE_VALUE->IN_END_TAG [label = "nextChar == '>'"]
IN_STRING_ENTITY->IN_STRING [label = "nextChar == ';'"] }
Definition at line 71 of file SimpleSAXParser.h.
typedef std::vector<Attribute> SimpleSAXParser::Attributes |
Definition at line 93 of file SimpleSAXParser.h.
Definition at line 106 of file SimpleSAXParser.h.
|
inline |
Definition at line 123 of file SimpleSAXParser.h.
|
virtual |
|
inlinevirtual |
Reimplemented in FWXMLConfigParser.
Definition at line 137 of file SimpleSAXParser.h.
Referenced by parse().
|
inlinevirtual |
Reimplemented in FWXMLConfigParser.
Definition at line 136 of file SimpleSAXParser.h.
Referenced by parse().
|
inlineprivate |
Definition at line 140 of file SimpleSAXParser.h.
References fgettoken(), m_buffer, m_bufferSize, m_in, and m_nextChar.
Referenced by parse().
|
inlineprivate |
Definition at line 146 of file SimpleSAXParser.h.
References fgettoken(), m_buffer, m_bufferSize, m_in, and m_nextChar.
|
inlineprivate |
void SimpleSAXParser::parse | ( | void | ) |
Runs the state machine of the parser, invoking startElement(), setAttribute(), endElement(), data() virtual methods as approppriate. In order have the parser doing something usefull you need to derive from it and specialize the above mentioned virtual methods.
Default implementation is in any case useful to check syntax.
Definition at line 53 of file SimpleSAXParser.cc.
References asciidump::attr, data(), debug_state_machine(), endElement(), getToken(), i, IN_ATTRIBUTE_KEY, IN_BEGIN_ATTRIBUTE_VALUE, IN_BEGIN_ELEMENT, IN_BEGIN_TAG, IN_DATA, IN_DATA_ENTITY, IN_DOCUMENT, IN_DONE, IN_ELEMENT_WHITESPACE, IN_END_ATTRIBUTE_VALUE, IN_END_ELEMENT, IN_END_TAG, IN_STRING, IN_STRING_ENTITY, SimpleSAXParser::Attribute::key, m_attributes, m_elementTags, nextChar(), parseEntity(), skipChar(), startElement(), evf::utils::state, and tmp.
Referenced by FWConfigurationManager::readFromFile().
|
private |
Helper function to handle entities, i.e. characters specified with the "&label;" syntax.
Definition at line 7 of file SimpleSAXParser.cc.
Referenced by parse().
|
inlineprivate |
Definition at line 154 of file SimpleSAXParser.h.
References m_in, and m_nextChar.
Referenced by parse().
|
inlinevirtual |
Reimplemented in FWXMLConfigParser.
Definition at line 134 of file SimpleSAXParser.h.
Referenced by parse().
|
private |
Definition at line 169 of file SimpleSAXParser.h.
Referenced by parse().
|
private |
Definition at line 166 of file SimpleSAXParser.h.
Referenced by getToken(), and ~SimpleSAXParser().
|
private |
Definition at line 165 of file SimpleSAXParser.h.
Referenced by getToken().
|
private |
Definition at line 168 of file SimpleSAXParser.h.
Referenced by parse().
|
private |
Definition at line 164 of file SimpleSAXParser.h.
Referenced by getToken(), and skipChar().
|
private |
Definition at line 167 of file SimpleSAXParser.h.
Referenced by getToken(), nextChar(), and skipChar().