mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-16 10:05:39 +02:00
Changed all .hpp extensions to .h where there is now a corresponding .cpp
This commit is contained in:
108
include/internal/catch_xmlwriter.h
Normal file
108
include/internal/catch_xmlwriter.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Created by Phil on 09/12/2010.
|
||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
|
||||
|
||||
#include "catch_stream.h"
|
||||
#include "catch_compiler_capabilities.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class XmlEncode {
|
||||
public:
|
||||
enum ForWhat { ForTextNodes, ForAttributes };
|
||||
|
||||
XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes );
|
||||
|
||||
void encodeTo( std::ostream& os ) const;
|
||||
|
||||
friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode );
|
||||
|
||||
private:
|
||||
std::string m_str;
|
||||
ForWhat m_forWhat;
|
||||
};
|
||||
|
||||
class XmlWriter {
|
||||
public:
|
||||
|
||||
class ScopedElement {
|
||||
public:
|
||||
ScopedElement( XmlWriter* writer );
|
||||
|
||||
ScopedElement( ScopedElement&& other ) noexcept;
|
||||
ScopedElement& operator=( ScopedElement&& other ) noexcept;
|
||||
|
||||
~ScopedElement();
|
||||
|
||||
ScopedElement& writeText( std::string const& text, bool indent = true );
|
||||
|
||||
template<typename T>
|
||||
ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
|
||||
m_writer->writeAttribute( name, attribute );
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable XmlWriter* m_writer = nullptr;
|
||||
};
|
||||
|
||||
XmlWriter( std::ostream& os = Catch::cout() );
|
||||
~XmlWriter();
|
||||
|
||||
XmlWriter( XmlWriter const& ) = delete;
|
||||
XmlWriter& operator=( XmlWriter const& ) = delete;
|
||||
|
||||
XmlWriter& startElement( std::string const& name );
|
||||
|
||||
ScopedElement scopedElement( std::string const& name );
|
||||
|
||||
XmlWriter& endElement();
|
||||
|
||||
XmlWriter& writeAttribute( std::string const& name, std::string const& attribute );
|
||||
|
||||
XmlWriter& writeAttribute( std::string const& name, bool attribute );
|
||||
|
||||
template<typename T>
|
||||
XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
|
||||
m_oss.clear();
|
||||
m_oss.str(std::string());
|
||||
m_oss << attribute;
|
||||
return writeAttribute( name, m_oss.str() );
|
||||
}
|
||||
|
||||
XmlWriter& writeText( std::string const& text, bool indent = true );
|
||||
|
||||
XmlWriter& writeComment( std::string const& text );
|
||||
|
||||
void writeStylesheetRef( std::string const& url );
|
||||
|
||||
XmlWriter& writeBlankLine();
|
||||
|
||||
void ensureTagClosed();
|
||||
|
||||
private:
|
||||
|
||||
void writeDeclaration();
|
||||
|
||||
void newlineIfNecessary();
|
||||
|
||||
bool m_tagIsOpen = false;
|
||||
bool m_needsNewline = false;
|
||||
std::vector<std::string> m_tags;
|
||||
std::string m_indent;
|
||||
std::ostream& m_os;
|
||||
std::ostringstream m_oss;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
|
Reference in New Issue
Block a user