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
8namespace MBXMLUtils {
9
10class 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 bool trackDependencies);
25 Preprocess(std::istream &inputStream, // the input stream containing the XML file used as input
26 std::variant<
27 std::shared_ptr<MBXMLUtils::DOMParser>, // a direct parser OR
28 xercesc::DOMElement*, // the root element of a DOM tree of a XML catalog file to create a parser OR
29 boost::filesystem::path // a filename of a XML catalog file to create a parser
30 > parserVariant,
31 bool trackDependencies);
34 Preprocess(const std::shared_ptr<xercesc::DOMDocument> &inputDoc, bool trackDependencies);
35
37
38 void setCheckInterruptFunction(const std::function<void()> &func) {
39 checkInterruptFunc=func;
40 }
41
43 void setParam(const std::shared_ptr<ParamSet>& param_);
45 std::shared_ptr<ParamSet> getParam() const;
46
48 std::shared_ptr<Eval> getEvaluator() const;
49
51 const std::vector<boost::filesystem::path>& getDependencies() const;
52
54 std::shared_ptr<xercesc::DOMDocument> processAndGetDocument();
55
59 std::shared_ptr<xercesc::DOMDocument> getDOMDocument() { return document; }
60
61 private:
62 std::shared_ptr<xercesc::DOMDocument> document;
63 std::unique_ptr<std::vector<boost::filesystem::path>> dependencies;
64 std::shared_ptr<Eval> eval;
65 std::shared_ptr<ParamSet> param;
66 std::shared_ptr<DOMParser> noneValidatingParser;
67 static const FQN embedFileNotFound;
68
69 std::function<void()> checkInterruptFunc;
70 void checkInterrupt() {
71 if(checkInterruptFunc)
72 checkInterruptFunc();
73 }
74
75 bool preprocessed { false };
76
77 std::shared_ptr<DOMParser> initDependenciesAndParser(std::variant<
78 std::shared_ptr<MBXMLUtils::DOMParser>, // a direct parser OR
79 xercesc::DOMElement*, // the root element of a DOM tree of a XML catalog file to create a parser OR
80 boost::filesystem::path // a filename of a XML catalog file to create a parser
81 > parserVariant,
82 bool trackDependencies);
83
84 std::map<boost::filesystem::path, std::shared_ptr<xercesc::DOMDocument>> parsedFiles;//mfmf make this static and check timestemps
85 std::shared_ptr<xercesc::DOMDocument> parseCached(const std::shared_ptr<DOMParser> &parser,
86 const boost::filesystem::path &inputFile,
87 const std::string &msg, bool allowUnknownRootElement=false);
88
89 std::map<size_t, std::shared_ptr<xercesc::DOMDocument>> parsedStream;//mfmf make this static
90 std::shared_ptr<xercesc::DOMDocument> parseCached(const std::shared_ptr<DOMParser> &parser,
91 std::istream &inputStream,
92 const std::string &msg, bool allowUnknownRootElement=false);
93
94 void extractEvaluator();
95
96 bool preprocess(// in: element to process; out: e changes only if e is itself a Embed element
97 xercesc::DOMElement *&e,
98 // out: number of elements added for a Embed element (may be 0), if e is a Embed element or -1 if e is not a Embed element
99 int &nrElementsEmbeded,
100 // in: root level parameters to overwrite; out: root level parameters
101 const std::shared_ptr<ParamSet>& param=std::shared_ptr<ParamSet>(),
102
103 // internal: XPath expression of parent element
104 int embedXPathCount=1
105 );
106};
107
108}
109
110#endif
Definition: dom.h:109
Definition: preprocess.h:10
std::shared_ptr< xercesc::DOMDocument > getDOMDocument()
Definition: preprocess.h:59
Preprocess(const boost::filesystem::path &inputFile, std::variant< std::shared_ptr< MBXMLUtils::DOMParser >, xercesc::DOMElement *, boost::filesystem::path > parserVariant, bool trackDependencies)
std::shared_ptr< ParamSet > getParam() const
Get available top level parameters after processAndGetDocument is called.
Definition: preprocess.cc:106
Preprocess(const std::shared_ptr< xercesc::DOMDocument > &inputDoc, bool trackDependencies)
std::shared_ptr< Eval > getEvaluator() const
Get the evaluator.
Definition: preprocess.cc:98
const std::vector< boost::filesystem::path > & getDependencies() const
Get all dependencies found during processAndGetDocument.
Definition: preprocess.cc:90
Preprocess(std::istream &inputStream, std::variant< std::shared_ptr< MBXMLUtils::DOMParser >, xercesc::DOMElement *, boost::filesystem::path > parserVariant, bool trackDependencies)
void setParam(const std::shared_ptr< ParamSet > &param_)
Set top level parameters to overwrite before processAndGetDocument is called.
Definition: preprocess.cc:102
std::shared_ptr< xercesc::DOMDocument > processAndGetDocument()
Start preprocessing and return the preprocessed DOMDocument.
Definition: preprocess.cc:135