|
/************************************************************************
Xport: XHTML Parsing & Objective Reporting Toolkit
Copyright (C) 2007 Mitchel Haas
This file is part of Xport.
Xport is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Xport is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Xport. If not, see <http://www.gnu.org/licenses/>.
For complete documentation on this library and alternative
licensing options, visit http://www.xportpro.com
Email questions, comments or suggestions to mitchel.haas@xportpro.com
************************************************************************/
#pragma once
#include <string>
#include <vector>
#include <iosfwd>
#include <fstream>
namespace Xport
{
template<typename T, typename U> class xhtml_stylesheet_formatter;
template<typename T, typename U> class xhtml_stylesheet;
template<typename T> class xhtml_stylesheet_item;
template<typename T> class stylesheet_declaration;
template<typename T, typename U> class xhtml_stylesheet_comment;
template<typename T, typename U> class xhtml_stylesheet_import;
template<typename T, typename U> class xhtml_stylesheet_rule;
enum ss_formatter_integer_option { selector_indent, declaration_indent };
enum ss_formatter_boolean_option { newline_after_selector };
enum ss_formatter_string_option { rule_heading };
}
template<typename CT, typename SBT>
class Xport::xhtml_stylesheet_formatter
{
public:
explicit inline xhtml_stylesheet_formatter(const std::basic_string<CT>& filename);
explicit inline xhtml_stylesheet_formatter(std::basic_ostream<CT>& out);
~xhtml_stylesheet_formatter();
private:
xhtml_stylesheet_formatter();
public:
// public interface
bool operator !() const { return output->fail(); }
// query options
bool option(ss_formatter_boolean_option bool_opt) const;
int option(ss_formatter_integer_option int_opt) const;
std::basic_string<CT> option(ss_formatter_string_option string_opt) const;
encoding option(formatter_encoding_option opt) const;
// mutate options
bool option(ss_formatter_boolean_option bool_opt, bool bool_value);
bool option(ss_formatter_integer_option int_opt, int int_value);
bool option(ss_formatter_string_option string_opt, const std::basic_string<CT>& string_value);
bool option(formatter_encoding_option opt, encoding enc);
xhtml_stylesheet_formatter& operator << (const xhtml_stylesheet<CT, SBT>& ss) { ss.write(*this); return *this; }
xhtml_stylesheet_formatter& operator << (const SBT& si) { si.write(*this); return *this; }
private:
// private interface
xhtml_stylesheet_formatter(const xhtml_stylesheet_formatter& src); // prevent copying
xhtml_stylesheet_formatter& operator =(const xhtml_stylesheet_formatter& src); // prevent assignment
void insert_comment(const std::basic_string<CT>& data) const;
void insert_import(const std::basic_string<CT>& path) const;
void insert_rule(const std::basic_string<CT>& selector, const std::vector<stylesheet_declaration<CT> >& decls) const;
// data
std::basic_string<CT> rheader;
bool created_output;
bool rule_sep;
bool newline_after_sel;
short selector_ind;
short declaration_ind;
mutable std::basic_ostream<CT>* output;
encoding file_encoding;
// friends
friend class xhtml_stylesheet<CT, SBT>;
friend class xhtml_stylesheet_import<CT, SBT>;
friend class xhtml_stylesheet_rule<CT, SBT>;
friend class xhtml_stylesheet_comment<CT, SBT>;
};
#include "stylesheet_formatter.inl"
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.