Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
plain.hh
1 // Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
2 // 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_IMAGE_IMORPH_PLAIN_HH
28 # define MLN_CORE_IMAGE_IMORPH_PLAIN_HH
29 
34 
35 # include <mln/core/internal/image_identity.hh>
36 # include <mln/core/routine/duplicate.hh>
37 # include <mln/metal/is_not_const.hh>
38 
39 
40 namespace mln
41 {
42 
43  // Forward declaration.
44  template <typename I> class plain;
45 
46 
47  namespace internal
48  {
49 
51  template <typename I>
52  struct data< plain<I> >
53  {
54  data(const I& ima);
55  I ima_;
56  };
57 
58  } // end of namespace mln::internal
59 
60 
61  namespace trait
62  {
63 
64  template <typename I>
65  struct image_< plain<I> > : image_< I > // Same as I except...
66  {
67  // ...these changes:
68  typedef trait::image::category::identity_morpher category;
69  typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest.
70  };
71 
72  } // end of namespace mln::trait
73 
74 
75 
81  //
82  template <typename I>
83  class plain
84 
85  : public mln::internal::image_identity< I, mln_domain(I), plain<I> >,
86  private mlc_is_not_const(I)::check_t
87  {
88  typedef plain<I> self_;
89  typedef mln::internal::image_identity<I, mln_domain(I), self_> super_;
90 
91  public:
92 
95 
97  plain();
98 
100  plain(const plain<I>& rhs);
101 
103  plain(const I& ima);
104 
106  void init_(const I& ima);
107 
109  plain<I>& operator=(const plain<I>& rhs);
110 
112  plain<I>& operator=(const I& ima);
113 
115  operator I () const;
116  };
117 
118 
119 
120 # ifndef MLN_INCLUDE_ONLY
121 
122 
123  // internal::data< plain<I> >
124 
125  namespace internal
126  {
127 
128  template <typename I>
129  inline
130  data< plain<I> >::data(const I& ima)
131  : ima_(duplicate(ima))
132  {
133  }
134 
135  } // end of namespace mln::internal
136 
137 
138  // plain<I>
139 
140  template <typename I>
141  inline
143  {
144  }
145 
146  template <typename I>
147  inline
149  : super_()
150  {
151  mln_precondition(rhs.is_valid());
152  init_(rhs.data_->ima_);
153  }
154 
155  template <typename I>
156  inline
157  plain<I>::plain(const I& ima)
158  {
159  mln_precondition(ima.is_valid());
160  init_(ima);
161  }
162 
163  template <typename I>
164  inline
165  void
166  plain<I>::init_(const I& ima)
167  {
168  mln_precondition(ima.is_valid());
169  this->data_ = new internal::data< plain<I> >(ima);
170  }
171 
172  template <typename I>
173  inline
174  plain<I>&
176  {
177  mln_precondition(rhs.is_valid());
178  if (&rhs == this)
179  return *this;
180  this->destroy();
181  init_(rhs.data_->ima_);
182  return *this;
183  }
184 
185  template <typename I>
186  inline
187  plain<I>&
188  plain<I>::operator=(const I& ima)
189  {
190  mln_precondition(ima.is_valid());
191  this->destroy();
192  init_(ima);
193  return *this;
194  }
195 
196  template <typename I>
197  inline
199  {
200  mln_precondition(this->is_valid());
201  return duplicate(this->data_->ima_);
202  }
203 
204 # endif // ! MLN_INCLUDE_ONLY
205 
206 } // end of namespace mln
207 
208 
209 #endif // ! MLN_CORE_IMAGE_IMORPH_PLAIN_HH