$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
p.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_ACCU_P_HH
27 # define MLN_ACCU_P_HH
28 
32 
33 # include <mln/core/concept/meta_accumulator.hh>
34 
35 # include <mln/accu/internal/base.hh>
36 # include <mln/metal/is_a.hh>
37 
38 
39 namespace mln
40 {
41 
42  namespace accu
43  {
44 
45 
49  template <typename A>
50  struct p : public mln::accu::internal::base< const mln_result(A)& , p<A> >
51  {
52  typedef mln_argument(A) argument;
53 
54  p();
55  p(const A& a);
56 
59  void init();
60  void take_as_init_(const argument& t);
61  void take(const argument& t);
62  void take(const p<A>& other);
64 
66  const mln_result(A)& to_result() const;
67 
70  bool is_valid() const;
71 
72  protected:
73  A a_;
74  };
75 
76 
77  namespace meta
78  {
79 
81 
82  template <typename mA>
83  struct p : public Meta_Accumulator< p<mA> >
84  {
85  template <typename V>
86  struct with
87  {
88  typedef p<V> ret;
89  };
90  };
91 
92  } // end of namespace mln::accu::meta
93 
94 
95 # ifndef MLN_INCLUDE_ONLY
96 
97  template <typename A>
98  inline
99  p<A>::p()
100  {
101  init();
102  }
103 
104  template <typename A>
105  inline
106  p<A>::p(const A& a)
107  : a_(a)
108  {
109  init();
110  }
111 
112  template <typename A>
113  inline
114  void
115  p<A>::init()
116  {
117  a_.init();
118  }
119 
120  template <typename A>
121  inline
122  void
123  p<A>::take_as_init_(const argument& t)
124  {
125  a_.take_as_init_(t.p()); // FIXME: Generalize with "psite(t)".
126  }
127 
128  template <typename A>
129  inline
130  void
131  p<A>::take(const argument& t)
132  {
133  a_.take(t.p());
134  }
135 
136  template <typename A>
137  inline
138  void
139  p<A>::take(const p<A>& other)
140  {
141  a_.take(other.a_);
142  }
143 
144  template <typename A>
145  inline
146  const mln_result(A)&
147  p<A>::to_result() const
148  {
149  return a_.to_result();
150  }
151 
152  template <typename A>
153  inline
154  bool
155  p<A>::is_valid() const
156  {
157  return a_.is_valid();
158  }
159 
160 # endif // ! MLN_INCLUDE_ONLY
161 
162  } // end of namespace mln::accu
163 
164 } // end of namespace mln
165 
166 
167 #endif // ! MLN_ACCU_P_HH