CARMA C++
FaultSystemParser.h
1 /*
2  * Fault System DAG Markup Language XML Parser
3  *
4  * This object is capable of parsing and validating a Fault System DAG ML file,
5  * and then passing the result on to another program.
6  *
7  * Copyright (c) 2010 Ira W. Snyder <iws@ovro.caltech.edu>
8  */
9 
10 #ifndef FAULT_SYSTEM_PARSER_H
11 #define FAULT_SYSTEM_PARSER_H
12 
13 #include <iostream>
14 #include <sstream>
15 #include <cstdio>
16 #include <map>
17 
18 #include <carma/fault/DagMLNode.h>
19 #include <carma/fault/DagMLExpr.h>
20 #include <carma/fault/DOMUtils.h>
21 
22 #include <xercesc/dom/DOM.hpp>
23 #include <xercesc/parsers/XercesDOMParser.hpp>
24 
25 class FaultSystemParser
26 {
27  public:
28  /* Load an XML file into this object, with validation */
29  void load_xml_file(const std::string &name, bool validate = true);
30 
31  /* Write an entire DOM Document to stdout */
32  void write_output_stdout(xercesc::DOMDocument *doc, xercesc::DOMNode *node);
33 
34  /* Write an entire DOM Document to a file */
35  void write_output_file(xercesc::DOMDocument *doc, xercesc::DOMNode *node, const std::string &name);
36 
37  /* Get the DOMDocument */
38  xercesc::DOMDocument* getDOMDocument();
39 
40  /* Get the DagMLNode tree for this document */
41  DagMLNodePtr make_dagmlnode_tree() const;
42 
43  protected:
44  void traverse_all_children(const xercesc::DOMNode *node, unsigned int &num);
45 
46  /* Expand all <range> nodes */
47  void expandRange(xercesc::DOMNode *node);
48 
49  /* Expand all carry-down attributes using the variable map */
50  void expand_attributes(xercesc::DOMNode *node, const VariableMap &parent_varmap);
51 
52  /* Validate a DOM Document against the DTD */
53  void validate_with_dtd(const std::string &name, xercesc::DOMDocument *doc, xercesc::DOMNode *node);
54 
55  /* pre-process the DAG tree into a canonical DAG */
56  void preprocess_tree(xercesc::DOMNode *node, VariableMap &varmap);
57 
58  private:
59  /* Everything is owned by the parser */
60  xercesc::XercesDOMParser parser_;
61  xercesc::DOMDocument *doc_;
62 };
63 
64 #endif /* FAULT_SYSTEM_PARSER_H */