CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Types | Private Attributes
FWXMLConfigParser Class Reference
Inheritance diagram for FWXMLConfigParser:
SimpleSAXParser

Public Member Functions

FWConfigurationconfig (void)
 
virtual void data (const std::string &data) override
 
virtual void endElement (const std::string &tag) override
 
 FWXMLConfigParser (istream &f)
 
void pushConfig (Attributes &attributes)
 
virtual void startElement (const std::string &tag, Attributes &attributes) override
 
- Public Member Functions inherited from SimpleSAXParser
void parse (void)
 
 SimpleSAXParser (std::istream &f)
 
virtual ~SimpleSAXParser ()
 

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< FWConfigurationm_first
 
enum STATES m_state
 

Additional Inherited Members

- Public Types inherited from SimpleSAXParser
typedef std::vector< AttributeAttributes
 
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
}
 

Detailed Description

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 199 of file FWConfigurationManager.cc.

Member Enumeration Documentation

Constructor & Destructor Documentation

FWXMLConfigParser::FWXMLConfigParser ( istream &  f)
inline

Definition at line 210 of file FWConfigurationManager.cc.

211  : SimpleSAXParser(f),
213  m_first(0)
214  {}
std::auto_ptr< FWConfiguration > m_first
double f[11][100]
SimpleSAXParser(std::istream &f)

Member Function Documentation

FWConfiguration* FWXMLConfigParser::config ( void  )
inline

The parsed configuration. Notice that the parser owns it and destroys it when destroyed.

Definition at line 330 of file FWConfigurationManager.cc.

References m_first.

331  {
332  return m_first.get();
333  }
std::auto_ptr< FWConfiguration > m_first
virtual void FWXMLConfigParser::data ( const std::string &  data)
inlineoverridevirtual

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 313 of file FWConfigurationManager.cc.

References debug_config_state_machine(), IN_BEGIN_STRING, IN_STORED_STRING, m_configs, and m_state.

Referenced by cuy.FindIssue::__init__().

314  {
316  // We ignore whitespace but complain about any text which is not
317  // in the <string> tag.
318  if (m_state == IN_BEGIN_STRING)
319  {
320  m_configs.back().second->addValue(data);
322  }
323  else if (strspn(data.c_str(), " \t\n") != data.size())
324  throw ParserError("Unexpected text " + data);
325  }
std::vector< std::pair< std::string, FWConfiguration * > > m_configs
void debug_config_state_machine(const char *where, const std::string &tag, int state)
virtual void data(const std::string &data) override
virtual void FWXMLConfigParser::endElement ( const std::string &  tag)
inlineoverridevirtual

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 282 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, m_state, and AlCaHLTBitMon_QueryRunRegistry::string.

283  {
286  {
287  if (tag != "config")
288  throw ParserError("Wrong closing tag found " + tag);
289 
290  FWConfiguration *current = m_configs.back().second;
291  std::string key = m_configs.back().first;
292  m_configs.pop_back();
293  if (!m_configs.empty())
294  m_configs.back().second->addKeyValue(key, *current);
296  }
297  else if (m_state == IN_BEGIN_STRING && tag == "string")
298  {
299  m_configs.back().second->addValue("");
301  }
302  else if (m_state == IN_STORED_STRING && tag == "string")
304  else
305  throw ParserError("Wrong closing tag found " + tag);
306  }
std::vector< std::pair< std::string, FWConfiguration * > > m_configs
void debug_config_state_machine(const char *where, const std::string &tag, int state)
list key
Definition: combine.py:13
void FWXMLConfigParser::pushConfig ( Attributes attributes)
inline

Pushes the configuration on stack eventually

Definition at line 217 of file FWConfigurationManager.cc.

References asciidump::attr, alignCSCRings::e, i, SimpleSAXParser::Attribute::key, m_configs, mergeVDriftHistosByStation::name, AlCaHLTBitMon_QueryRunRegistry::string, SimpleSAXParser::Attribute::value, and BeamSplash_cfg::version.

Referenced by startElement().

218  {
220  int version = 0;
221  for (size_t i = 0, e = attributes.size(); i != e; ++i)
222  {
223  Attribute &attr = attributes[i];
224  if (attr.key == "name")
225  name = attr.value;
226  else if (attr.key == "version")
227  {
228  char *endptr;
229  version = strtol(attr.value.c_str(), &endptr, 10);
230  if (endptr == attr.value.c_str())
231  throw ParserError("Version must be an integer.");
232  }
233  else
234  throw ParserError("Unexpected attribute " + attr.key);
235  }
236  m_configs.push_back(std::make_pair(name, new FWConfiguration(version)));
237  }
int i
Definition: DBlmapReader.cc:9
std::vector< std::pair< std::string, FWConfiguration * > > m_configs
list attributes
Definition: asciidump.py:415
tuple attr
Definition: asciidump.py:432
virtual void FWXMLConfigParser::startElement ( const std::string &  tag,
Attributes attributes 
)
inlineoverridevirtual

Executes any transaction in the state machine which happens when the xml parser finds an new element.

Reimplemented from SimpleSAXParser.

Definition at line 243 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().

244  {
246  if (m_state == IN_BEGIN_DOCUMENT)
247  {
248  if (tag != "config")
249  throw ParserError("Expecting toplevel <config> tag");
251  m_first.reset(m_configs.back().second);
253  }
254  else if (m_state == IN_PUSHED_CONFIG)
255  {
256  if (tag == "config")
258  else if (tag == "string")
260  else
261  throw ParserError("Unexpected element " + tag);
262  }
263  else if (m_state == IN_POPPED_CONFIG)
264  {
265  if (tag != "config")
266  throw ParserError("Unexpected element " + tag);
269  }
270  else
271  throw ParserError("Wrong opening tag found " + tag);
272  }
std::auto_ptr< FWConfiguration > m_first
std::vector< std::pair< std::string, FWConfiguration * > > m_configs
void debug_config_state_machine(const char *where, const std::string &tag, int state)
void pushConfig(Attributes &attributes)
list attributes
Definition: asciidump.py:415

Member Data Documentation

std::vector<std::pair<std::string, FWConfiguration *> > FWXMLConfigParser::m_configs
private

Definition at line 336 of file FWConfigurationManager.cc.

Referenced by data(), endElement(), pushConfig(), and startElement().

std::string FWXMLConfigParser::m_currentConfigName
private

Definition at line 340 of file FWConfigurationManager.cc.

std::auto_ptr<FWConfiguration> FWXMLConfigParser::m_first
private

Definition at line 338 of file FWConfigurationManager.cc.

Referenced by config(), and startElement().

enum STATES FWXMLConfigParser::m_state
private

Definition at line 337 of file FWConfigurationManager.cc.

Referenced by data(), endElement(), and startElement().