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