Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
p_if_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_IF_PITER_HH
27 # define MLN_CORE_SITE_SET_P_IF_PITER_HH
28 
34 # include <mln/core/internal/piter_adaptor.hh>
35 # include <mln/core/site_set/p_if.hh>
36 
37 
38 namespace mln
39 {
40 
41 
49  template <typename Pi, typename S, typename F>
50  struct p_if_piter_
51  : public internal::piter_adaptor_< Pi, // Adaptee.
52  p_if<S,F>, // Site_Set.
53  p_if_piter_<Pi,S,F> > // Exact.
54  {
56  p_if_piter_();
57 
59  p_if_piter_(const p_if<S,F>& s);
60 
62  void start_();
63 
65  void next_();
66 
68  void pi_change_target_(const p_if<S,F>& s);
69 
70  private:
71  typedef p_if_piter_<Pi,S,F> self_;
72  typedef internal::piter_adaptor_<Pi, p_if<S,F>, self_> super_;
73 
74  protected:
75  using super_::s_;
76  using super_::pi_;
77  };
78 
79 
80 
81 # ifndef MLN_INCLUDE_ONLY
82 
83  template <typename Pi, typename S, typename F>
84  inline
85  p_if_piter_<Pi,S,F>::p_if_piter_()
86  {
87  }
88 
89  template <typename Pi, typename S, typename F>
90  inline
91  p_if_piter_<Pi,S,F>::p_if_piter_(const p_if<S,F>& s)
92  {
93  this->change_target(s);
94  }
95 
96  template <typename Pi, typename S, typename F>
97  inline
98  void
99  p_if_piter_<Pi,S,F>::start_()
100  {
101  pi_.start();
102  while (pi_.is_valid() && ! s_->pred(pi_))
103  pi_.next();
104  }
105 
106  template <typename Pi, typename S, typename F>
107  inline
108  void
109  p_if_piter_<Pi,S,F>::next_()
110  {
111  do
112  pi_.next();
113  while (pi_.is_valid() && ! s_->pred(pi_));
114  }
115 
116  template <typename Pi, typename S, typename F>
117  inline
118  void
119  p_if_piter_<Pi,S,F>::pi_change_target_(const p_if<S,F>& s)
120  {
121  pi_.change_target(s.overset());
122  }
123 
124 # endif // ! MLN_INCLUDE_ONLY
125 
126 } // end of namespace mln
127 
128 
129 #endif // ! MLN_CORE_SITE_SET_P_IF_PITER_HH