Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
piter_adaptor.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_INTERNAL_PITER_ADAPTOR_HH
27 # define MLN_CORE_INTERNAL_PITER_ADAPTOR_HH
28 
37 
38 # include <mln/core/internal/site_iterator_base.hh>
39 
40 
41 namespace mln
42 {
43 
44  namespace internal
45  {
46 
52  template <typename Pi, typename S, typename E>
53  class piter_adaptor_ : public internal::site_iterator_base< S, E >
54  {
55  public:
56 
58  piter_adaptor_();
59 
61  piter_adaptor_(const Pi& piter);
62 
64  bool is_valid_() const;
65 
67  void invalidate_();
68 
70  void start_();
71 
73  void next_();
74 
76  const mln_psite(S)& p_hook_() const;
77 
79  void change_target(const S& s);
80 
83  void pi_change_target_(const S& s);
84 
85  protected:
86 
88  Pi pi_;
89  };
90 
91 
92 # ifndef MLN_INCLUDE_ONLY
93 
94  template <typename Pi, typename S, typename E>
95  inline
96  piter_adaptor_<Pi,S,E>::piter_adaptor_()
97  {
98  }
99 
100  template <typename Pi, typename S, typename E>
101  inline
102  piter_adaptor_<Pi,S,E>::piter_adaptor_(const Pi& pi)
103  : pi_(pi)
104  {
105  invalidate_();
106  }
107 
108  template <typename Pi, typename S, typename E>
109  inline
110  bool
111  piter_adaptor_<Pi,S,E>::is_valid_() const
112  {
113  return pi_.is_valid();
114  }
115 
116  template <typename Pi, typename S, typename E>
117  inline
118  void
119  piter_adaptor_<Pi,S,E>::invalidate_()
120  {
121  pi_.invalidate();
122  }
123 
124  template <typename Pi, typename S, typename E>
125  inline
126  void
127  piter_adaptor_<Pi,S,E>::start_()
128  {
129  pi_.start();
130  }
131 
132  template <typename Pi, typename S, typename E>
133  inline
134  void
135  piter_adaptor_<Pi,S,E>::next_()
136  {
137  pi_.next();
138  }
139 
140  template <typename Pi, typename S, typename E>
141  inline
142  const mln_psite(S)&
143  piter_adaptor_<Pi,S,E>::p_hook_() const
144  {
145  return pi_.p_hook_();
146  }
147 
148  template <typename Pi, typename S, typename E>
149  inline
150  void
151  piter_adaptor_<Pi,S,E>::change_target(const S& s)
152  {
153  this->s_ = & s;
154  // p might be also updated since it can hold a pointer towards
155  // the set it designates, so:
156  exact(this)->pi_change_target_(s);
157  // Last:
158  this->invalidate();
159  }
160 
161  template <typename Pi, typename S, typename E>
162  inline
163  void
164  piter_adaptor_<Pi,S,E>::pi_change_target_(const S& s)
165  {
166  this->pi_.change_target(s);
167  }
168 
169 # endif // ! MLN_INCLUDE_ONLY
170 
171  } // end of namespace mln::internal
172 
173 } // end of namespace mln
174 
175 
176 #endif // ! MLN_CORE_INTERNAL_PITER_ADAPTOR_HH