Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
catch_xmlwriter.h
Go to the documentation of this file.
1/*
2 * Created by Phil on 09/12/2010.
3 * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
4 *
5 * Distributed under the Boost Software License, Version 1.0. (See accompanying
6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 */
8#ifndef TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
9#define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
10
11#include "catch_stream.h"
13
14#include <vector>
15
16namespace Catch {
17
18 class XmlEncode {
19 public:
21
22 XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes );
23
24 void encodeTo( std::ostream& os ) const;
25
26 friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode );
27
28 private:
29 std::string m_str;
30 ForWhat m_forWhat;
31 };
32
33 class XmlWriter {
34 public:
35
37 public:
38 ScopedElement( XmlWriter* writer );
39
40 ScopedElement( ScopedElement&& other ) noexcept;
41 ScopedElement& operator=( ScopedElement&& other ) noexcept;
42
44
45 ScopedElement& writeText( std::string const& text, bool indent = true );
46
47 template<typename T>
48 ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
49 m_writer->writeAttribute( name, attribute );
50 return *this;
51 }
52
53 private:
54 mutable XmlWriter* m_writer = nullptr;
55 };
56
57 XmlWriter( std::ostream& os = Catch::cout() );
58 ~XmlWriter();
59
60 XmlWriter( XmlWriter const& ) = delete;
61 XmlWriter& operator=( XmlWriter const& ) = delete;
62
63 XmlWriter& startElement( std::string const& name );
64
65 ScopedElement scopedElement( std::string const& name );
66
68
69 XmlWriter& writeAttribute( std::string const& name, std::string const& attribute );
70
71 XmlWriter& writeAttribute( std::string const& name, bool attribute );
72
73 template<typename T>
74 XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
76 rss << attribute;
77 return writeAttribute( name, rss.str() );
78 }
79
80 XmlWriter& writeText( std::string const& text, bool indent = true );
81
82 XmlWriter& writeComment( std::string const& text );
83
84 void writeStylesheetRef( std::string const& url );
85
87
88 void ensureTagClosed();
89
90 private:
91
92 void writeDeclaration();
93
94 void newlineIfNecessary();
95
96 bool m_tagIsOpen = false;
97 bool m_needsNewline = false;
98 std::vector<std::string> m_tags;
99 std::string m_indent;
100 std::ostream& m_os;
101 };
102
103}
104
105#endif // TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
std::string name
auto str() const -> std::string
void encodeTo(std::ostream &os) const
XmlEncode(std::string const &str, ForWhat forWhat=ForTextNodes)
friend std::ostream & operator<<(std::ostream &os, XmlEncode const &xmlEncode)
ScopedElement & writeText(std::string const &text, bool indent=true)
ScopedElement & writeAttribute(std::string const &name, T const &attribute)
ScopedElement & operator=(ScopedElement &&other) noexcept
XmlWriter & operator=(XmlWriter const &)=delete
XmlWriter(std::ostream &os=Catch::cout())
XmlWriter & writeAttribute(std::string const &name, T const &attribute)
ScopedElement scopedElement(std::string const &name)
XmlWriter & writeText(std::string const &text, bool indent=true)
XmlWriter & startElement(std::string const &name)
XmlWriter(XmlWriter const &)=delete
void writeStylesheetRef(std::string const &url)
XmlWriter & endElement()
XmlWriter & writeComment(std::string const &text)
XmlWriter & writeBlankLine()
XmlWriter & writeAttribute(std::string const &name, std::string const &attribute)
os_t os
std::ostream & cout()
#define T(meth, val, expected)
string url
Definition main.cpp:166