mbxmlutils  1.3.0
Multi-Body XML Utils
preprocess.h
1 #ifndef _MBXMLUTILS_PREPROCESS_H_
2 #define _MBXMLUTILS_PREPROCESS_H_
3 
4 #include <fmatvec/atom.h>
5 #include <mbxmlutilshelper/dom.h>
6 #include <mbxmlutils/eval.h>
7 
8 namespace MBXMLUtils {
9 
10 class Preprocess : virtual public fmatvec::Atom {
11  public:
12  using ParamSet = std::map<std::string, Eval::Value>;
13 
16  Preprocess(const boost::filesystem::path &inputFile, // a filename of a XML file used as input
17  std::variant<
18  std::shared_ptr<MBXMLUtils::DOMParser>, // a direct parser OR
19  xercesc::DOMElement*, // the root element of a DOM tree of a XML catalog file to create a parser OR
20  boost::filesystem::path // a filename of a XML catalog file to create a parser
21  > parserVariant
22  );
25  Preprocess(const std::shared_ptr<xercesc::DOMDocument> &inputDoc);
26 
28  void setParam(const std::shared_ptr<ParamSet>& param_);
30  std::shared_ptr<ParamSet> getParam() const;
31 
33  std::shared_ptr<Eval> getEvaluator() const;
34 
36  const std::vector<boost::filesystem::path>& getDependencies() const;
37 
39  std::shared_ptr<xercesc::DOMDocument> processAndGetDocument();
40 
41  private:
42  std::shared_ptr<xercesc::DOMDocument> document;
43  std::vector<boost::filesystem::path> dependencies;
44  std::shared_ptr<Eval> eval;
45  std::shared_ptr<ParamSet> param;
46 
47  bool preprocessed { false };
48 
49  std::map<boost::filesystem::path, std::shared_ptr<xercesc::DOMDocument>> parsedFiles;
50  std::shared_ptr<xercesc::DOMDocument> parseCached(const std::shared_ptr<DOMParser> &parser,
51  const boost::filesystem::path &inputFile,
52  std::vector<boost::filesystem::path> &dependencies,
53  const std::string &msg);
54 
55  void extractEvaluator();
56 
57  using PositionMap = std::map<FQN, int>;
58  void preprocess(xercesc::DOMElement *&e, // in: element to process; out: e changes only if e is itself a Embed element
59  // in: root level parameters to overwrite; out: root level parameters
60  const std::shared_ptr<ParamSet>& param=std::shared_ptr<ParamSet>(),
61 
62  // internal: XPath expression of parent element
63  const std::string &parentXPath="",
64  // internal: XPath expression of parent element
65  int embedXPathCount=1,
66  // internal: XPath position count of the element e
67  const std::shared_ptr<PositionMap>& position=std::make_shared<PositionMap>()
68  );
69 };
70 
71 }
72 
73 #endif
std::shared_ptr< Eval > getEvaluator() const
Get the evaluator.
Definition: preprocess.cc:47
void setParam(const std::shared_ptr< ParamSet > &param_)
Set top level parameters to overwrite before processAndGetDocument is called.
Definition: preprocess.cc:51
Preprocess(const boost::filesystem::path &inputFile, std::variant< std::shared_ptr< MBXMLUtils::DOMParser >, xercesc::DOMElement *, boost::filesystem::path > parserVariant)
const std::vector< boost::filesystem::path > & getDependencies() const
Get all dependencies found during processAndGetDocument.
Definition: preprocess.cc:41
Definition: preprocess.h:10
std::shared_ptr< xercesc::DOMDocument > processAndGetDocument()
Start preprocessing and return the preprocessed DOMDocument.
Definition: preprocess.cc:84
std::shared_ptr< ParamSet > getParam() const
Get available top level parameters after processAndGetDocument is called.
Definition: preprocess.cc:55