|
/************************************************************************
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 "common.h"
#include "stylesheet_formatter.h"
#include "stylesheet_iterator.h"
#include <vector>
#include <iostream>
#include <string>
namespace Xport
{
template<typename T> class xhtml_stylesheet;
typedef xhtml_stylesheet<char> stylesheet;
typedef xhtml_stylesheet<wchar_t> wstylesheet;
typedef xhtml_stylesheet_item<char> stylesheet_item;
typedef xhtml_stylesheet_item<wchar_t> wstylesheet_item;
typedef xhtml_stylesheet_rule<char> stylesheet_rule;
typedef xhtml_stylesheet_rule<wchar_t> wstylesheet_rule;
typedef xhtml_stylesheet_import<char> stylesheet_import;
typedef xhtml_stylesheet_import<wchar_t> wstylesheet_import;
typedef xhtml_stylesheet_comment<char> stylesheet_comment;
typedef xhtml_stylesheet_comment<wchar_t> wstylesheet_comment;
typedef stylesheet_declaration<char> declaration;
typedef stylesheet_declaration<wchar_t> wdeclaration;
typedef xhtml_stylesheet_formatter<char> stylesheet_formatter;
typedef xhtml_stylesheet_formatter<wchar_t> wstylesheet_formatter;
template<typename T> bool operator == (const xhtml_stylesheet<T>& lhs, const xhtml_stylesheet<T>& rhs)
{ typename xhtml_stylesheet<T>::const_iterator it1 = lhs.begin(), it2 = rhs.begin();
while (it1 != lhs.end() && it2 != rhs.end())
if (*it1++ != *it2++)
return false;
return true;
}
template<typename T> bool operator != (const xhtml_stylesheet<T>& lhs, const xhtml_stylesheet<T>& rhs) { return !(lhs == rhs); }
}
template<typename CT = char>
class Xport::xhtml_stylesheet
{
public:
xhtml_stylesheet() {}
xhtml_stylesheet(const xhtml_stylesheet& src) { const_iterator it = src.begin(); while (it != src.end()) push_back(*(it++)->clone()); }
~xhtml_stylesheet() { clear(); }
// typedefs
typedef xhtml_stylesheet_item<CT> value_type;
typedef xhtml_stylesheet_item<CT>& reference_type;
typedef const xhtml_stylesheet_item<CT>& const_reference_type;
typedef xhtml_stylesheet_item<CT>* pointer_type;
typedef const xhtml_stylesheet_item<CT>* const_pointer_type;
typedef ptrdiff_t difference_type;
typedef size_t size_type;
// iterators
typedef stylesheet_iterator<CT, xhtml_stylesheet_item<CT>*, xhtml_stylesheet_item<CT>&> iterator;
typedef stylesheet_iterator<CT, const xhtml_stylesheet_item<CT>*, const xhtml_stylesheet_item<CT>&> const_iterator;
public:
// public interface
iterator insert(const xhtml_stylesheet_item<CT>& item) { return iterator(items.insert(items.end(), item.clone())); }
iterator insert(const const_iterator& pos, const xhtml_stylesheet_item<CT>& item);
void push_back(const xhtml_stylesheet_item<CT>& item) { items.push_back(item.clone()); }
xhtml_stylesheet& operator << (const xhtml_stylesheet_item<CT>& item) { items.push_back(item.clone()); return *this; }
xhtml_stylesheet& operator = (const xhtml_stylesheet& src) { if (&src == this) return *this; const_iterator it = src.begin(); while (it != src.end()) push_back(*(it++)->clone()); return *this; }
iterator erase(const const_iterator& pos);
iterator erase(const const_iterator& beg_pos, const const_iterator& end_pos);
bool erase(const std::basic_string<CT>& selector);
xhtml_stylesheet_item<CT>& operator[] (size_type n) { return *items[n]; }
const xhtml_stylesheet_item<CT>& operator[](size_type n) const { return *items[n]; }
xhtml_stylesheet_item<CT>& at(size_type n) { return *items.at(n); }
const xhtml_stylesheet_item<CT>& at(size_type n) const { return *items.at(n); }
bool empty() const { return items.empty(); }
void clear();
bool write(const xhtml_stylesheet_formatter<CT>& fmtr) const;
bool write(const std::basic_string<CT>& path) const;
bool parse(std::basic_istream<CT>& strm);
bool parse(const std::basic_string<CT>& filename);
size_type size() const { return items.size(); }
// iterator operations
iterator begin() { return iterator(items.begin()); }
const_iterator begin() const { return const_iterator(items.begin()); }
iterator end() { return iterator(items.end()); }
const_iterator end() const { return const_iterator(items.end()); }
private:
// implementation
bool parse_input(std::basic_istream<CT>** ppInput);
void parse_import(std::basic_istream<CT>& strm);
void parse_rule(std::basic_istream<CT>& strm);
void parse_comment(std::basic_istream<CT>& strm);
std::basic_string<CT> parse_selector(std::basic_istream<CT>& strm);
void parse_declarations(std::basic_istream<CT>& strm, xhtml_stylesheet_rule<CT>* pRule);
css::css_property parse_css_property(std::basic_istream<CT>& strm);
std::basic_string<CT> parse_decl_value(std::basic_istream<CT>& strm);
// data
std::vector<xhtml_stylesheet_item<CT>*> items;
// friends
#if defined(_MSC_VER) && _MSC_VER < 1300
friend bool operator == (const xhtml_stylesheet& lhs, const xhtml_stylesheet& rhs);
#else
friend bool operator ==<> (const xhtml_stylesheet& lhs, const xhtml_stylesheet& rhs);
#endif
};
#include "stylesheet.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.