|
/************************************************************************
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_item.h"
#include <vector>
#include <iterator>
namespace Xport
{
template<typename T, typename U, typename V> class stylesheet_iterator;
}
template<typename CT, typename pointer_type, typename reference_type>
class Xport::stylesheet_iterator
#if defined(_MSC_VER) && _MSC_VER < 1300
: public std::iterator<std::random_access_iterator_tag, Xport::xhtml_stylesheet_item<CT> >
#else
: public std::iterator<std::random_access_iterator_tag, Xport::xhtml_stylesheet_item<CT>, ptrdiff_t, pointer_type, reference_type>
#endif
{
public:
stylesheet_iterator() {}
// conversion constructor for const_iterator, copy constructor for iterator
stylesheet_iterator(const stylesheet_iterator<CT, xhtml_stylesheet_item<CT>*, xhtml_stylesheet_item<CT>& >& src) : it(src.it) {}
virtual ~stylesheet_iterator() {}
protected:
explicit stylesheet_iterator(typename std::vector<xhtml_stylesheet_item<CT>*>::const_iterator _it) : it(_it) {}
public:
// typedefs
#if defined(_MSC_VER) && _MSC_VER < 1300
typedef ptrdiff_t difference_type;
#else
typedef typename std::iterator_traits<stylesheet_iterator>::difference_type difference_type;
#endif
// overloaded operators
reference_type operator*() const { return *(*it); }
pointer_type operator->() const { return *it; }
bool operator ==(const stylesheet_iterator<CT, const xhtml_stylesheet_item<CT>*, const xhtml_stylesheet_item<CT>&>& rhs) const { return it == rhs.it; }
bool operator !=(const stylesheet_iterator<CT, const xhtml_stylesheet_item<CT>*, const xhtml_stylesheet_item<CT>&>& rhs) const { return !(*this == rhs); }
#if !defined(_MSC_VER) || _MSC_VER >= 1300
bool operator ==(const stylesheet_iterator<CT, xhtml_stylesheet_item<CT>*, xhtml_stylesheet_item<CT>&>& rhs) const { return it == rhs.it; }
bool operator !=(const stylesheet_iterator<CT, xhtml_stylesheet_item<CT>*, xhtml_stylesheet_item<CT>&>& rhs) const { return !(*this == rhs); }
#endif
difference_type operator - (const stylesheet_iterator& rhs) const { return it - rhs.it; }
stylesheet_iterator& operator ++() { ++it; return *this; }
stylesheet_iterator operator ++(int) { stylesheet_iterator old(*this); ++*this; return old; }
stylesheet_iterator& operator --() { --it; return *this; }
stylesheet_iterator operator --(int) { stylesheet_iterator old(*this); --*this; return old; }
private:
// data
typename std::vector<xhtml_stylesheet_item<CT>*>::const_iterator it;
// friends
#if defined(_MSC_VER) && _MSC_VER < 1300
friend class xhtml_stylesheet<CT>;
#else
template<typename T> friend class xhtml_stylesheet;
#endif
friend class stylesheet_iterator<CT, const xhtml_stylesheet_item<CT>*, const xhtml_stylesheet_item<CT>&>; // needed for conversion constructor & equality operator
friend class stylesheet_iterator<CT, xhtml_stylesheet_item<CT>*, xhtml_stylesheet_item<CT>&>; // needed for equality operator
};
|
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.