The Battle for Wesnoth  1.13.11+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ucs4_iterator_base.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017-2018 by the Battle for Wesnoth Project http://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
16 #include <iterator> //input_iterator_tag
17 #include <utility> //pair
18 #include <cstddef> //ptrdiff_t
19 #include <cassert> //assert
20 
21 #include "unicode_types.hpp"
22 
23 namespace ucs4
24 {
25  template<typename string_type, typename update_implementation>
27  {
28  public:
29  typedef std::input_iterator_tag iterator_category;
31  typedef ptrdiff_t difference_type;
34 
35  iterator_base(const string_type& str)
36  : current_char(0)
37  , string_end(str.end())
38  , current_substr(std::make_pair(str.begin(), str.begin()))
39  {
40  update();
41  }
42 
43  iterator_base(typename string_type::const_iterator const& begin, typename string_type::const_iterator const& end)
44  : current_char(0)
45  , string_end(end)
46  , current_substr(std::make_pair(begin, begin))
47  {
48  update();
49  }
50 
51  static iterator_base begin(const string_type& str)
52  {
53  return iterator_base(str.begin(), str.end());
54  }
55 
56  static iterator_base end(const string_type& str)
57  {
58  return iterator_base(str.end(), str.end());
59  }
60 
61  bool operator==(const iterator_base& a) const
62  {
63  return current_substr.first == a.current_substr.first;
64  }
65 
66  bool operator!=(const iterator_base& a) const
67  {
68  return ! (*this == a);
69  }
70 
72  {
73  current_substr.first = current_substr.second;
74  update();
75  return *this;
76  }
77 
79  {
80  return current_char;
81  }
82 
83  bool next_is_end() const
84  {
85  if(current_substr.second == string_end)
86  return true;
87  return false;
88  }
89 
90  const std::pair<typename string_type::const_iterator, typename string_type::const_iterator>& substr() const
91  {
92  return current_substr;
93  }
94  private:
95  void update()
96  {
97  assert(current_substr.first == current_substr.second);
98  if(current_substr.first == string_end)
99  return;
101  }
102 
104  typename string_type::const_iterator string_end;
105  std::pair<typename string_type::const_iterator, typename string_type::const_iterator> current_substr;
106  };
107 
108 }
bool operator==(const iterator_base &a) const
static iterator_base begin(const string_type &str)
iterator_base(typename string_type::const_iterator const &begin, typename string_type::const_iterator const &end)
ucs4::char_t operator*() const
#define a
STL namespace.
iterator_base & operator++()
uint32_t char_t
std::input_iterator_tag iterator_category
iterator_base(const string_type &str)
bool operator!=(const iterator_base &a) const
void read(config &cfg, std::istream &in, abstract_validator *validator)
Definition: parser.cpp:612
static iterator_base end(const string_type &str)
const std::pair< typename string_type::const_iterator, typename string_type::const_iterator > & substr() const
std::pair< typename string_type::const_iterator, typename string_type::const_iterator > current_substr
string_type::const_iterator string_end