mbxmlutils  1.3.0
Multi-Body XML Utils
 All Classes Functions Typedefs Enumerations
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 
44  std::shared_ptr<xercesc::DOMDocument> getDOMDocument() { return document; }
45 
46  private:
47  std::shared_ptr<xercesc::DOMDocument> document;
48  std::vector<boost::filesystem::path> dependencies;
49  std::shared_ptr<Eval> eval;
50  std::shared_ptr<ParamSet> param;
51  std::shared_ptr<DOMParser> noneValidatingParser;
52  static const FQN embedFileNotFound;
53 
54  bool preprocessed { false };
55 
56  std::map<boost::filesystem::path, std::shared_ptr<xercesc::DOMDocument>> parsedFiles;
57  std::shared_ptr<xercesc::DOMDocument> parseCached(const std::shared_ptr<DOMParser> &parser,
58  const boost::filesystem::path &inputFile,
59  std::vector<boost::filesystem::path> &dependencies,
60  const std::string &msg, bool allowUnknownRootElement=false);
61 
62  void extractEvaluator();
63 
64  using PositionMap = std::map<FQN, int>;
65  bool preprocess(// in: element to process; out: e changes only if e is itself a Embed element
66  xercesc::DOMElement *&e,
67  // 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
68  int &nrElementsEmbeded,
69  // in: root level parameters to overwrite; out: root level parameters
70  const std::shared_ptr<ParamSet>& param=std::shared_ptr<ParamSet>(),
71 
72  // internal: XPath expression of parent element
73  int embedXPathCount=1
74  );
75 };
76 
77 }
78 
79 #endif
Definition: dom.h:109
std::shared_ptr< ParamSet > getParam() const
Get available top level parameters after processAndGetDocument is called.
Definition: preprocess.cc:61
std::shared_ptr< Eval > getEvaluator() const
Get the evaluator.
Definition: preprocess.cc:53
void setParam(const std::shared_ptr< ParamSet > &param_)
Set top level parameters to overwrite before processAndGetDocument is called.
Definition: preprocess.cc:57
const std::vector< boost::filesystem::path > & getDependencies() const
Get all dependencies found during processAndGetDocument.
Definition: preprocess.cc:47
Preprocess(const boost::filesystem::path &inputFile, std::variant< std::shared_ptr< MBXMLUtils::DOMParser >, xercesc::DOMElement *, boost::filesystem::path > parserVariant)
std::shared_ptr< xercesc::DOMDocument > getDOMDocument()
Definition: preprocess.h:44
Definition: preprocess.h:10
std::shared_ptr< xercesc::DOMDocument > processAndGetDocument()
Start preprocessing and return the preprocessed DOMDocument.
Definition: preprocess.cc:90