|
/************************************************************************
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 "stylesheet_rule_iterator.h"
#include <string>
#include <ostream>
namespace Xport
{
template<typename T, typename U> class xhtml_stylesheet;
template<typename T> class xhtml_stylesheet_item;
template<typename T, typename U> class xhtml_stylesheet_rule;
template<typename T, typename U> class xhtml_stylesheet_import;
template<typename T, typename U> class xhtml_stylesheet_comment;
template<typename T, typename U> class xhtml_stylesheet_formatter;
template<typename T> struct deref_comp;
enum ss_item_type { sit_unknown, sit_rule, sit_comment, sit_import };
template<typename T> bool operator == (const xhtml_stylesheet_item<T>& lhs, const xhtml_stylesheet_item<T>& rhs) { return lhs.stylesheet_item_type() == rhs.stylesheet_item_type() && lhs.identifier() == rhs.identifier() && lhs.declarations == rhs.declarations; }
template<typename T> bool operator != (const xhtml_stylesheet_item<T>& lhs, const xhtml_stylesheet_item<T>& rhs) { return !(lhs == rhs); }
}
/************************************************************************/
/* xhtml_stylesheet_item */
/************************************************************************/
template<typename CT = char>
class Xport::xhtml_stylesheet_item
{
protected:
xhtml_stylesheet_item() {}
virtual ~xhtml_stylesheet_item() {}
public:
// typedefs
typedef stylesheet_declaration<CT> value_type;
typedef stylesheet_declaration<CT>& reference_type;
typedef const stylesheet_declaration<CT>& const_reference_type;
typedef stylesheet_declaration<CT>* pointer_type;
typedef const stylesheet_declaration<CT>* const_pointer_type;
typedef ptrdiff_t difference_type;
typedef size_t size_type;
// iterators
typedef stylesheet_rule_iterator<CT, stylesheet_declaration<CT>*, stylesheet_declaration<CT>&> iterator;
typedef stylesheet_rule_iterator<CT, const stylesheet_declaration<CT>*, const stylesheet_declaration<CT>&> const_iterator;
// iterator operations
iterator begin() { return iterator(declarations.begin()); }
const_iterator begin() const { return const_iterator(declarations.begin()); }
iterator end() { return iterator(declarations.end()); }
const_iterator end() const { return const_iterator(declarations.end()); }
// public interface
virtual iterator insert(const stylesheet_declaration<CT>& decl) { return iterator(declarations.end()); }
virtual iterator insert(const_iterator pos, const stylesheet_declaration<CT>& decl) { return iterator(declarations.end()); }
virtual void push_back(const stylesheet_declaration<CT>& decl) { }
xhtml_stylesheet_item& operator << (const stylesheet_declaration<CT>& decl) { this->insert(decl); return *this; }
stylesheet_declaration<CT>& operator[](size_type n) { return declarations[n]; }
const stylesheet_declaration<CT>& operator[](size_type n) const { return declarations[n]; }
stylesheet_declaration<CT>& at(size_type n) { return declarations.at(n); }
const stylesheet_declaration<CT>& at(size_type n) const { return declarations.at(n); }
bool empty() const { return declarations.empty(); }
void clear() { declarations.clear(); }
size_type size() const { return declarations.size(); }
virtual void erase(const css::css_property property) { }
virtual iterator erase(const const_iterator& pos) { return iterator(declarations.end()); }
virtual iterator erase(const const_iterator& pos1, const iterator& pos2) { return iterator(declarations.end()); }
virtual void write(const xhtml_stylesheet_formatter<CT, xhtml_stylesheet_item<CT> >& fmtr) const { }
virtual std::basic_string<CT> selector() const { return typed_string<CT>(""); }
virtual ss_item_type stylesheet_item_type() const { return sit_unknown; }
private:
// implementation
virtual std::basic_string<CT> identifier() const { return typed_string<CT>(""); }
virtual xhtml_stylesheet_item<CT>* clone() const { return NULL; }
protected:
// data
std::vector<stylesheet_declaration<CT> > declarations;
// friends
#if defined(_MSC_VER) && _MSC_VER < 1300
friend class xhtml_stylesheet<CT, xhtml_stylesheet_item<CT> >;
friend bool operator == (const xhtml_stylesheet_item& lhs, const xhtml_stylesheet_item& rhs);
#else
template<typename T, typename U> friend class xhtml_stylesheet;
friend bool operator ==<> (const xhtml_stylesheet_item& lhs, const xhtml_stylesheet_item& rhs);
#endif
};
/************************************************************************/
/* xhtml_stylesheet_import */
/************************************************************************/
template<typename CT, typename SBT>
class Xport::xhtml_stylesheet_import : public SBT
{
public:
explicit xhtml_stylesheet_import(const std::basic_string<CT>& path) : import_path(path) {}
virtual ~xhtml_stylesheet_import() {}
virtual ss_item_type stylesheet_item_type() const { return sit_import; }
virtual void write(const xhtml_stylesheet_formatter<CT, SBT>& fmtr) const { fmtr.insert_import(import_path); }
private:
// implementation
virtual std::basic_string<CT> identifier() const {return import_path;}
virtual SBT* clone() const { return new xhtml_stylesheet_import<CT, SBT>(*this); }
// data
std::basic_string<CT> import_path;
// friends
friend class xhtml_stylesheet<CT, SBT>;
};
/************************************************************************/
/* xhtml_stylesheet_comment */
/************************************************************************/
template<typename CT, typename SBT>
class Xport::xhtml_stylesheet_comment : public SBT
{
public:
explicit xhtml_stylesheet_comment(const std::basic_string<CT>& commnt) : data(commnt) {}
virtual ~xhtml_stylesheet_comment() {}
virtual ss_item_type stylesheet_item_type() const { return sit_comment; }
virtual void write(const xhtml_stylesheet_formatter<CT, SBT>& fmtr) const { fmtr.insert_comment(data); }
private:
// implementation
virtual std::basic_string<CT> identifier() const { return data; }
virtual SBT* clone() const { return new xhtml_stylesheet_comment<CT, SBT>(*this); }
// data
std::basic_string<CT> data;
// friends
friend class xhtml_stylesheet<CT, SBT>;
};
|
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.