|
rpm-build |
a7f80b |
/*
|
|
rpm-build |
a7f80b |
* Created by Phil on 09/12/2010.
|
|
rpm-build |
a7f80b |
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
|
rpm-build |
a7f80b |
*
|
|
rpm-build |
a7f80b |
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
rpm-build |
a7f80b |
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
rpm-build |
a7f80b |
*/
|
|
rpm-build |
a7f80b |
#ifndef TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
|
|
rpm-build |
a7f80b |
#define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
#include "catch_stream.h"
|
|
rpm-build |
a7f80b |
#include "catch_compiler_capabilities.h"
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
#include <vector>
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
namespace Catch {
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
class XmlEncode {
|
|
rpm-build |
a7f80b |
public:
|
|
rpm-build |
a7f80b |
enum ForWhat { ForTextNodes, ForAttributes };
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
void encodeTo( std::ostream& os ) const;
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
private:
|
|
rpm-build |
a7f80b |
std::string m_str;
|
|
rpm-build |
a7f80b |
ForWhat m_forWhat;
|
|
rpm-build |
a7f80b |
};
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
class XmlWriter {
|
|
rpm-build |
a7f80b |
public:
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
class ScopedElement {
|
|
rpm-build |
a7f80b |
public:
|
|
rpm-build |
a7f80b |
ScopedElement( XmlWriter* writer );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
ScopedElement( ScopedElement&& other ) noexcept;
|
|
rpm-build |
a7f80b |
ScopedElement& operator=( ScopedElement&& other ) noexcept;
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
~ScopedElement();
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
ScopedElement& writeText( std::string const& text, bool indent = true );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
template<typename T>
|
|
rpm-build |
a7f80b |
ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
|
|
rpm-build |
a7f80b |
m_writer->writeAttribute( name, attribute );
|
|
rpm-build |
a7f80b |
return *this;
|
|
rpm-build |
a7f80b |
}
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
private:
|
|
rpm-build |
a7f80b |
mutable XmlWriter* m_writer = nullptr;
|
|
rpm-build |
a7f80b |
};
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlWriter( std::ostream& os = Catch::cout() );
|
|
rpm-build |
a7f80b |
~XmlWriter();
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlWriter( XmlWriter const& ) = delete;
|
|
rpm-build |
a7f80b |
XmlWriter& operator=( XmlWriter const& ) = delete;
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlWriter& startElement( std::string const& name );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
ScopedElement scopedElement( std::string const& name );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlWriter& endElement();
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlWriter& writeAttribute( std::string const& name, std::string const& attribute );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlWriter& writeAttribute( std::string const& name, bool attribute );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
template<typename T>
|
|
rpm-build |
a7f80b |
XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
|
|
rpm-build |
a7f80b |
ReusableStringStream rss;
|
|
rpm-build |
a7f80b |
rss << attribute;
|
|
rpm-build |
a7f80b |
return writeAttribute( name, rss.str() );
|
|
rpm-build |
a7f80b |
}
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlWriter& writeText( std::string const& text, bool indent = true );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlWriter& writeComment( std::string const& text );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
void writeStylesheetRef( std::string const& url );
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
XmlWriter& writeBlankLine();
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
void ensureTagClosed();
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
private:
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
void writeDeclaration();
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
void newlineIfNecessary();
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
bool m_tagIsOpen = false;
|
|
rpm-build |
a7f80b |
bool m_needsNewline = false;
|
|
rpm-build |
a7f80b |
std::vector<std::string> m_tags;
|
|
rpm-build |
a7f80b |
std::string m_indent;
|
|
rpm-build |
a7f80b |
std::ostream& m_os;
|
|
rpm-build |
a7f80b |
};
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
}
|
|
rpm-build |
a7f80b |
|
|
rpm-build |
a7f80b |
#endif // TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
|