X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=c%2B%2B0x%2Fxml-template.h;h=7cfa0d8dc1a3de85ffc2fdae41e3d41108dc1062;hb=6d6f69fcdf45c3afc82212c5c3d8085c93ec4717;hp=eb132110e8f80604caea2ee12723bce71be26b08;hpb=c29512353e6e683b78ae50587b80e9a8db0797b1;p=xml-template diff --git a/c++0x/xml-template.h b/c++0x/xml-template.h index eb13211..7cfa0d8 100644 --- a/c++0x/xml-template.h +++ b/c++0x/xml-template.h @@ -10,39 +10,71 @@ class Directive { public: + virtual ~Directive(); virtual void process(xmlNode *node, bool clean) = 0; + virtual std::string get_contents(); // Only makes sense for Replace. }; class Replace : public Directive { public: Replace(const std::string &str); virtual void process(xmlNode *node, bool clean); + virtual std::string get_contents(); private: const std::string str; }; +class ReplaceInclude : public Directive { + public: + ReplaceInclude(xmlNodePtr included_node); + ReplaceInclude(xmlDocPtr included_doc); + ~ReplaceInclude(); + virtual void process(xmlNode *node, bool clean); + + private: + xmlNodePtr included_node; + xmlDocPtr included_doc; +}; + +class Substitute; + class Clone : public Directive { public: Clone(const std::vector &subdirectives); + Clone(const std::vector &subdirectives); + Clone(std::initializer_list subdirectives); + ~Clone(); virtual void process(xmlNode *node, bool clean); private: - const std::vector subdirectives; + std::vector subdirectives; }; class Substitute : public Directive { public: Substitute(const std::unordered_map &substitution_map); + Substitute(std::initializer_list> substitution_map); + ~Substitute(); virtual void process(xmlNode *node, bool clean); private: - const std::unordered_map substitution_map; + friend class Alternate; + std::unordered_map substitution_map; +}; + +class Alternate : public Clone { + public: + Alternate(const std::string &attribute, + const std::vector &subdirectives_subs, + const std::vector &alternatives); }; -void process_file(const std::string &input_filename, - const std::string &output_filename, - Directive *root_directive); +xmlDocPtr process_file(const std::string &input_filename, + Directive *root_directive, + bool clean = true); + +void output_to_fd_and_free(xmlDocPtr doc, int fd); #endif // !defined(_XML_TEMPLATE_H)