// iterator.hpp // Copyright (c) 2015-2018 Ben Hanson (http://www.benhanson.net/) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef LEXERTL_ITERATOR_HPP #define LEXERTL_ITERATOR_HPP #include #include "lookup.hpp" #include "state_machine.hpp" namespace lexertl { template class iterator { public: using value_type = results; using difference_type = ptrdiff_t; using pointer = const value_type *; using reference = const value_type &; using iterator_category = std::forward_iterator_tag; iterator() : _results(iter(), iter()), _sm(nullptr) { } iterator(const iter &start_, const iter &end_, const sm_type &sm) : _results(start_, end_), _sm(&sm) { lookup(); } // Only need this because of warnings with gcc with -Weffc++ iterator(const iterator &rhs_) { _results = rhs_._results; _sm = rhs_._sm; } // Only need this because of warnings with gcc with -Weffc++ iterator &operator =(const iterator &rhs_) { if (&rhs_ != this) { _results = rhs_._results; _sm = rhs_._sm; } return *this; } iterator &operator ++() { lookup(); return *this; } iterator operator ++(int) { iterator iter_ = *this; lookup(); return iter_; } const value_type &operator *() const { return _results; } const value_type *operator ->() const { return &_results; } bool operator ==(const iterator &rhs_) const { return _sm == rhs_._sm && (_sm == nullptr ? true : _results == rhs_._results); } bool operator !=(const iterator &rhs_) const { return !(*this == rhs_); } const sm_type &sm() const { return *_sm; } private: value_type _results; const sm_type *_sm; void lookup() { lexertl::lookup(*_sm, _results); if (_results.first == _results.eoi) { _sm = nullptr; } } }; using siterator = iterator; using citerator = iterator; using wsiterator = iterator; using wciterator = iterator; using u32siterator = iterator; using u32citerator = iterator; using sriterator = iterator; using criterator = iterator; using wsriterator = iterator; using wcriterator = iterator; using u32sriterator = iterator; using u32criterator = iterator; } #endif