Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_run_piter.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_CORE_SITE_SET_P_RUN_PITER_HH
27 # define MLN_CORE_SITE_SET_P_RUN_PITER_HH
28 
34 # include <mln/core/site_set/p_run.hh>
35 # include <mln/core/internal/site_set_iterator_base.hh>
36 
37 
38 namespace mln
39 {
40 
44  template <typename P>
45  class p_run_fwd_piter_
46  :
47  public internal::site_set_iterator_base< p_run<P>,
48  p_run_fwd_piter_<P> >
49  {
50  typedef p_run_fwd_piter_<P> self_;
51  typedef internal::site_set_iterator_base< p_run<P>, self_ > super_;
52  public:
53 
55  p_run_fwd_piter_();
56 
58  p_run_fwd_piter_(const p_run<P>& r);
59 
61  bool is_valid_() const;
62 
64  void invalidate_();
65 
67  void start_();
68 
70  void next_();
71 
72  protected:
73  using super_::p_;
74  using super_::s_;
75  };
76 
77 
78 
82  template <typename P>
83  class p_run_bkd_piter_
84  :
85  public internal::site_set_iterator_base< p_run<P>,
86  p_run_bkd_piter_<P> >
87  {
88  typedef p_run_bkd_piter_<P> self_;
89  typedef internal::site_set_iterator_base< p_run<P>, self_ > super_;
90  public:
91 
93  p_run_bkd_piter_();
94 
96  p_run_bkd_piter_(const p_run<P>& r);
97 
99  bool is_valid_() const;
100 
102  void invalidate_();
103 
105  void start_();
106 
108  void next_();
109 
110  protected:
111  using super_::p_;
112  using super_::s_;
113  };
114 
115 
116 
117 # ifndef MLN_INCLUDE_ONLY
118 
119  // p_run_fwd_piter_<P>
120 
121  template <typename P>
122  inline
123  p_run_fwd_piter_<P>::p_run_fwd_piter_()
124  {
125  }
126 
127  template <typename P>
128  inline
129  p_run_fwd_piter_<P>::p_run_fwd_piter_(const p_run<P>& r)
130  {
131  this->change_target(r);
132  }
133 
134  template <typename P>
135  inline
136  bool
137  p_run_fwd_piter_<P>::is_valid_() const
138  {
139  mln_invariant(p_.index() >= 0);
140  return p_.index() < int(s_->length());
141  }
142 
143  template <typename P>
144  inline
145  void
146  p_run_fwd_piter_<P>::invalidate_()
147  {
148  p_.change_index(s_->length());
149  }
150 
151  template <typename P>
152  inline
153  void
154  p_run_fwd_piter_<P>::start_()
155  {
156  p_.change_index(0);
157  }
158 
159  template <typename P>
160  inline
161  void
162  p_run_fwd_piter_<P>::next_()
163  {
164  p_.inc_index();
165  }
166 
167 
168  // p_run_bkd_piter_<P>
169 
170  template <typename P>
171  inline
172  p_run_bkd_piter_<P>::p_run_bkd_piter_()
173  {
174  }
175 
176  template <typename P>
177  inline
178  p_run_bkd_piter_<P>::p_run_bkd_piter_(const p_run<P>& r)
179  {
180  this->change_target(r);
181  }
182 
183  template <typename P>
184  inline
185  bool
186  p_run_bkd_piter_<P>::is_valid_() const
187  {
188  mln_invariant(p_.index() < int(s_->length()));
189  return p_.index() >= 0;
190  }
191 
192  template <typename P>
193  inline
194  void
195  p_run_bkd_piter_<P>::invalidate_()
196  {
197  p_.change_index(-1);
198  }
199 
200  template <typename P>
201  inline
202  void
203  p_run_bkd_piter_<P>::start_()
204  {
205  p_.change_index(s_->length() - 1);
206  }
207 
208  template <typename P>
209  inline
210  void
211  p_run_bkd_piter_<P>::next_()
212  {
213  p_.dec_index();
214  }
215 
216 
217 # endif // ! MLN_INCLUDE_ONLY
218 
219 } // end of namespace mln
220 
221 
222 #endif // ! MLN_CORE_SITE_SET_P_RUN_PITER_HH