$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
pseudo_site.hh
1 // Copyright (C) 2008, 2009, 2011, 2012, 2013 EPITA Research and
2 // Development Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_CORE_CONCEPT_PSEUDO_SITE_HH
28 # define MLN_CORE_CONCEPT_PSEUDO_SITE_HH
29 
37 
38 # include <mln/core/concept/site_proxy.hh>
39 # include <mln/metal/is_a.hh>
40 
41 
42 
43 namespace mln
44 {
45 
46  // Fwd decl.
47  template <typename E> struct Pseudo_Site;
48 
49 
52  template <>
53  struct Pseudo_Site<void>
54  {
56  };
58 
59 
66  template <typename E>
67  struct Pseudo_Site : public Site_Proxy<E>
68  {
70 
71  // typedef target;
72 
73  // void change_target(const target& new_target);
74  // const target* target_() const; // Hook to the target.
75 
76  bool has_target() const;
77 
78  protected:
79  Pseudo_Site();
80  };
81 
82 
83  namespace if_possible
84  {
85  // Nota: This procedure is used in
86  // internal::site_set_iterator_base and
87  // site_relative_iterator_base.
88 
89  template <typename O, typename T>
90  void change_target(Object<O>&, const T&);
91 
92  } // end of namespace mln::if_possible
93 
94 
95 # ifndef MLN_INCLUDE_ONLY
96 
97  template <typename E>
98  inline
100  {
101  typedef mln_target(E) target;
102 
103  void (E::*m1)(const target&) = & E::change_target;
104  (void) m1;
105  const target* (E::*m2)() const = & E::target_;
106  (void) m2;
107  }
108 
109  template <typename E>
110  inline
111  bool
112  Pseudo_Site<E>::has_target() const
113  {
114  return exact(this)->target_() != 0;
115  }
116 
117 
118 
119  namespace if_possible
120  {
121 
122  namespace internal
123  {
124 
125  template <bool b> struct helper;
126 
127  template <>
128  struct helper< /* is an Object */ true >
129  {
130 
131  template <typename P>
132  void change_target(Pseudo_Site<P>& p,
133  const mln_target(P)& new_target) const
134  {
135  exact(p).change_target(new_target);
136  }
137 
138  template <typename O, typename D>
139  void change_target(Object<O>&, const D&) const
140  {
141  // No-op.
142  }
143 
144  };
145 
146  template <>
147  struct helper< /* NOT an Object */ false >
148  {
149  template <typename O, typename D>
150  void change_target(O&, const D&) const
151  {
152  // No-op.
153  }
154  };
155 
156  } // namespace mln::if_possible::internal
157 
158 
159  template <typename O, typename D>
160  void change_target(O& o, const D& d)
161  {
162  enum { is_object = mlc_is_a(O, Object)::value };
163  mln::if_possible::internal::helper< is_object >().change_target(exact(o),
164  d);
165  }
166 
167  } // end of namespace mln::if_possible
168 
169 # endif // ! MLN_INCLUDE_ONLY
170 
171 } // end of namespace mln
172 
173 
174 #endif // ! MLN_CORE_CONCEPT_PSEUDO_SITE_HH