Public Member Functions | |
FWConfiguration * | config (void) |
virtual void | data (const std::string &data) |
virtual void | endElement (const std::string &tag) |
FWXMLConfigParser (istream &f) | |
void | pushConfig (Attributes &attributes) |
virtual void | startElement (const std::string &tag, Attributes &attributes) |
Private Types | |
enum | STATES { IN_BEGIN_DOCUMENT, IN_PUSHED_CONFIG, IN_POPPED_CONFIG, IN_BEGIN_STRING, IN_STORED_STRING } |
Private Attributes | |
std::vector< std::pair < std::string, FWConfiguration * > > | m_configs |
std::string | m_currentConfigName |
std::auto_ptr< FWConfiguration > | m_first |
enum STATES | m_state |
Helper class which reads the XML configuration and constructs the FWConfiguration classes.
State machine for the parser can be found by cut and pasting the following in graphviz.
digraph { IN_BEGIN_DOCUMENT->IN_PUSHED_CONFIG [label = "beginElement(config)"]
IN_PUSHED_CONFIG->IN_PUSHED_CONFIG [label = "beginElement(config)"] IN_PUSHED_CONFIG->IN_POPPED_CONFIG [label = "endElement(config)"] IN_PUSHED_CONFIG->IN_BEGIN_STRING [label = "beginElement(string)"]
IN_POPPED_CONFIG->IN_PUSHED_CONFIG [label = "beginElement(config)"] IN_POPPED_CONFIG->IN_POPPED_CONFIG [label = "endElement(config)"] IN_POPPED_CONFIG->DONE [label = "top level config popped"]
IN_BEGIN_STRING->IN_STORED_STRING [label = "data()"]; IN_BEGIN_STRING->IN_PUSHED_CONFIG [label = "endElement(string)"]
IN_STORED_STRING->IN_PUSHED_CONFIG [label = "endElement(string)"] }
Definition at line 200 of file FWConfigurationManager.cc.
enum FWXMLConfigParser::STATES [private] |
Definition at line 202 of file FWConfigurationManager.cc.
FWXMLConfigParser::FWXMLConfigParser | ( | istream & | f | ) | [inline] |
Definition at line 211 of file FWConfigurationManager.cc.
: SimpleSAXParser(f), m_state(IN_BEGIN_DOCUMENT), m_first(0) {}
FWConfiguration* FWXMLConfigParser::config | ( | void | ) | [inline] |
The parsed configuration. Notice that the parser owns it and destroys it when destroyed.
Definition at line 331 of file FWConfigurationManager.cc.
References m_first.
{ return m_first.get(); }
virtual void FWXMLConfigParser::data | ( | const std::string & | data | ) | [inline, virtual] |
Executes any transaction in the state machine which happens when the xml parser finds some data (i.e. text) between tags This is mainly used to handle <string> element contents but also whitespace between tags.
Reimplemented from SimpleSAXParser.
Definition at line 314 of file FWConfigurationManager.cc.
References debug_config_state_machine(), IN_BEGIN_STRING, IN_STORED_STRING, m_configs, and m_state.
{ debug_config_state_machine("data", data, m_state); // We ignore whitespace but complain about any text which is not // in the <string> tag. if (m_state == IN_BEGIN_STRING) { m_configs.back().second->addValue(data); m_state = IN_STORED_STRING; } else if (strspn(data.c_str(), " \t\n") != data.size()) throw ParserError("Unexpected text " + data); }
virtual void FWXMLConfigParser::endElement | ( | const std::string & | tag | ) | [inline, virtual] |
Executes any transaction in the state machine which happens when the xml parser closes an element.
Notice that we need to do addKeyValue on endElement (and carry around the FWConfigutation name) because of the "copy by value" policy of addKeyValue addition which would add empty FWConfiguration objects if done on startElement.
Reimplemented from SimpleSAXParser.
Definition at line 283 of file FWConfigurationManager.cc.
References cond::rpcobimon::current, debug_config_state_machine(), IN_BEGIN_STRING, IN_POPPED_CONFIG, IN_PUSHED_CONFIG, IN_STORED_STRING, combine::key, m_configs, and m_state.
{ debug_config_state_machine("end", tag, m_state); if (m_state == IN_PUSHED_CONFIG || m_state == IN_POPPED_CONFIG) { if (tag != "config") throw ParserError("Wrong closing tag found " + tag); FWConfiguration *current = m_configs.back().second; std::string key = m_configs.back().first; m_configs.pop_back(); if (!m_configs.empty()) m_configs.back().second->addKeyValue(key, *current); m_state = IN_POPPED_CONFIG; } else if (m_state == IN_BEGIN_STRING && tag == "string") { m_configs.back().second->addValue(""); m_state = IN_PUSHED_CONFIG; } else if (m_state == IN_STORED_STRING && tag == "string") m_state = IN_PUSHED_CONFIG; else throw ParserError("Wrong closing tag found " + tag); }
void FWXMLConfigParser::pushConfig | ( | Attributes & | attributes | ) | [inline] |
Pushes the configuration on stack eventually
Definition at line 218 of file FWConfigurationManager.cc.
References asciidump::attr, alignCSCRings::e, i, SimpleSAXParser::Attribute::key, m_configs, mergeVDriftHistosByStation::name, SimpleSAXParser::Attribute::value, and BeamSplash_cfg::version.
Referenced by startElement().
{ std::string name; int version = 0; for (size_t i = 0, e = attributes.size(); i != e; ++i) { Attribute &attr = attributes[i]; if (attr.key == "name") name = attr.value; else if (attr.key == "version") { char *endptr; version = strtol(attr.value.c_str(), &endptr, 10); if (endptr == attr.value.c_str()) throw ParserError("Version must be an integer."); } else throw ParserError("Unexpected attribute " + attr.key); } m_configs.push_back(std::make_pair(name, new FWConfiguration(version))); }
virtual void FWXMLConfigParser::startElement | ( | const std::string & | tag, |
Attributes & | attributes | ||
) | [inline, virtual] |
Executes any transaction in the state machine which happens when the xml parser finds an new element.
Reimplemented from SimpleSAXParser.
Definition at line 244 of file FWConfigurationManager.cc.
References debug_config_state_machine(), IN_BEGIN_DOCUMENT, IN_BEGIN_STRING, IN_POPPED_CONFIG, IN_PUSHED_CONFIG, m_configs, m_first, m_state, and pushConfig().
{ debug_config_state_machine("start", tag, m_state); if (m_state == IN_BEGIN_DOCUMENT) { if (tag != "config") throw ParserError("Expecting toplevel <config> tag"); pushConfig(attributes); m_first.reset(m_configs.back().second); m_state = IN_PUSHED_CONFIG; } else if (m_state == IN_PUSHED_CONFIG) { if (tag == "config") pushConfig(attributes); else if (tag == "string") m_state = IN_BEGIN_STRING; else throw ParserError("Unexpected element " + tag); } else if (m_state == IN_POPPED_CONFIG) { if (tag != "config") throw ParserError("Unexpected element " + tag); pushConfig(attributes); m_state = IN_PUSHED_CONFIG; } else throw ParserError("Wrong opening tag found " + tag); }
std::vector<std::pair<std::string, FWConfiguration *> > FWXMLConfigParser::m_configs [private] |
Definition at line 337 of file FWConfigurationManager.cc.
Referenced by data(), endElement(), pushConfig(), and startElement().
std::string FWXMLConfigParser::m_currentConfigName [private] |
Definition at line 341 of file FWConfigurationManager.cc.
std::auto_ptr<FWConfiguration> FWXMLConfigParser::m_first [private] |
Definition at line 339 of file FWConfigurationManager.cc.
Referenced by config(), and startElement().
enum STATES FWXMLConfigParser::m_state [private] |
Definition at line 338 of file FWConfigurationManager.cc.
Referenced by data(), endElement(), and startElement().