Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_transformed_piter.hh
1 // Copyright (C) 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_TRANSFORMED_PITER_HH
27 # define MLN_CORE_SITE_SET_P_TRANSFORMED_PITER_HH
28 
32 
33 # include <mln/core/internal/site_set_iterator_base.hh>
34 # include <mln/core/site_set/p_transformed.hh>
35 # include <mln/convert/to.hh>
36 
37 
38 namespace mln
39 {
40 
41 
48  //
49  template <typename Pi, typename S, typename F>
51  : public internal::site_set_iterator_base< p_transformed<S,F>, // Site_Set.
52  p_transformed_piter<Pi,S,F> > // Exact.
53  {
56 
59 
61  bool is_valid_() const;
62 
64  void invalidate_();
65 
67  void start_();
68 
70  void next_();
71 
73  void change_target(const p_transformed<S,F>& s);
74 
75  private:
77  typedef internal::site_set_iterator_base<p_transformed<S,F>, self_> super_;
78 
79  protected:
80  using super_::s_;
81  using super_::p_;
82 
83  // The underlying site iterator.
84  Pi pi_;
85  };
86 
87 
88 
89 # ifndef MLN_INCLUDE_ONLY
90 
91  template <typename Pi, typename S, typename F>
92  inline
94  {
95  }
96 
97  template <typename Pi, typename S, typename F>
98  inline
100  {
101  this->change_target(s);
102  }
103 
104  template <typename Pi, typename S, typename F>
105  inline
106  bool
108  {
109  return pi_.is_valid();
110  }
111 
112  template <typename Pi, typename S, typename F>
113  inline
114  void
115  p_transformed_piter<Pi,S,F>::invalidate_()
116  {
117  pi_.invalidate();
118  }
119 
120  template <typename Pi, typename S, typename F>
121  inline
122  void
123  p_transformed_piter<Pi,S,F>::start_()
124  {
125  pi_.start();
126  if (pi_.is_valid())
127  p_ = s_->function()(convert::to<mln_argument(F)>(pi_));
128  }
129 
130  template <typename Pi, typename S, typename F>
131  inline
132  void
133  p_transformed_piter<Pi,S,F>::next_()
134  {
135  pi_.next();
136  if (pi_.is_valid())
137  p_ = s_->function()(convert::to<mln_argument(F)>(pi_));
138  }
139 
140  template <typename Pi, typename S, typename F>
141  inline
142  void
144  {
145  s_ = & s;
146  // p might be also updated since it can hold a pointer towards
147  // the set it designates, so:
148  pi_.change_target(s.primary_set());
149  // Last:
150  this->invalidate();
151  }
152 
153 # endif // ! MLN_INCLUDE_ONLY
154 
155 } // end of namespace mln
156 
157 
158 #endif // ! MLN_CORE_SITE_SET_P_TRANSFORMED_PITER_HH