diff options
author | Vitaly Stakhovsky <vvs31415@gitlab.org> | 2018-03-04 20:03:57 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-03-09 12:28:49 (GMT) |
commit | 8401b6ac4ebe8bc383f288119af77ef09eb3d62b (patch) | |
tree | ff15e1405414a5da6d515088dd2fe5c1ec9554ef /Source/cmXMLWriter.h | |
parent | 0e362b23e10e0d2b6c3726a94f42ac603304f63a (diff) | |
download | CMake-8401b6ac4ebe8bc383f288119af77ef09eb3d62b.zip CMake-8401b6ac4ebe8bc383f288119af77ef09eb3d62b.tar.gz CMake-8401b6ac4ebe8bc383f288119af77ef09eb3d62b.tar.bz2 |
cmXMLWriter: Add RAII helpers to allow DOM-like syntax
Use RAII for cmXMLWriter::StartElement/EndElement to make nesting
automatic.
Diffstat (limited to 'Source/cmXMLWriter.h')
-rw-r--r-- | Source/cmXMLWriter.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Source/cmXMLWriter.h b/Source/cmXMLWriter.h index 7bae21e..4324873 100644 --- a/Source/cmXMLWriter.h +++ b/Source/cmXMLWriter.h @@ -133,4 +133,56 @@ private: bool IsContent; }; +class cmXMLElement; // IWYU pragma: keep + +class cmXMLDocument +{ +public: + cmXMLDocument(cmXMLWriter& xml) + : xmlwr(xml) + { + xmlwr.StartDocument(); + } + ~cmXMLDocument() { xmlwr.EndDocument(); } +private: + friend class cmXMLElement; + cmXMLWriter& xmlwr; +}; + +class cmXMLElement +{ +public: + cmXMLElement(cmXMLWriter& xml, const char* tag) + : xmlwr(xml) + { + xmlwr.StartElement(tag); + } + cmXMLElement(cmXMLElement const& par, const char* tag) + : xmlwr(par.xmlwr) + { + xmlwr.StartElement(tag); + } + cmXMLElement(cmXMLDocument const& doc, const char* tag) + : xmlwr(doc.xmlwr) + { + xmlwr.StartElement(tag); + } + ~cmXMLElement() { xmlwr.EndElement(); } + + template <typename T> + cmXMLElement& Attribute(const char* name, T const& value) + { + xmlwr.Attribute(name, value); + return *this; + } + template <typename T> + void Content(T const& content) + { + xmlwr.Content(content); + } + +private: + cmXMLWriter& xmlwr; +}; + #endif |