Milena (Olena)  User documentation 2.0a Id
plain.hh
00001 // Copyright (C) 2007, 2008, 2009, 2011 EPITA Research and Development
00002 // Laboratory (LRDE)
00003 //
00004 // This file is part of Olena.
00005 //
00006 // Olena is free software: you can redistribute it and/or modify it under
00007 // the terms of the GNU General Public License as published by the Free
00008 // Software Foundation, version 2 of the License.
00009 //
00010 // Olena is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software project without restriction.  Specifically, if other files
00020 // instantiate templates or use macros or inline functions from this
00021 // file, or you compile this file and link it with other files to produce
00022 // an executable, this file does not by itself cause the resulting
00023 // executable to be covered by the GNU General Public License.  This
00024 // exception does not however invalidate any other reasons why the
00025 // executable file might be covered by the GNU General Public License.
00026 
00027 #ifndef MLN_CORE_IMAGE_IMORPH_PLAIN_HH
00028 # define MLN_CORE_IMAGE_IMORPH_PLAIN_HH
00029 
00034 
00035 # include <mln/core/internal/image_identity.hh>
00036 # include <mln/core/routine/duplicate.hh>
00037 # include <mln/metal/is_not_const.hh>
00038 
00039 
00040 namespace mln
00041 {
00042 
00043   // Forward declaration.
00044   template <typename I> class plain;
00045 
00046 
00047   namespace internal
00048   {
00049 
00051     template <typename I>
00052     struct data< plain<I> >
00053     {
00054       data(const I& ima);
00055       I ima_;
00056     };
00057 
00058   } // end of namespace mln::internal
00059 
00060 
00061   namespace trait
00062   {
00063 
00064     template <typename I>
00065     struct image_< plain<I> > : image_< I > // Same as I except...
00066     {
00067       // ...these changes:
00068       typedef trait::image::category::identity_morpher category;
00069       typedef mln_internal_trait_image_speed_from(I) speed; // Un-fastest.
00070     };
00071 
00072   } // end of namespace mln::trait
00073 
00074 
00075 
00081   //
00082   template <typename I>
00083   class plain
00084 
00085     : public mln::internal::image_identity< I, mln_domain(I), plain<I> >,
00086       private mlc_is_not_const(I)::check_t
00087   {
00088     typedef plain<I> self_;
00089     typedef mln::internal::image_identity<I, mln_domain(I), self_> super_;
00090 
00091   public:
00092 
00094     typedef plain< tag::image_<I> > skeleton;
00095 
00097     plain();
00098 
00100     plain(const plain<I>& rhs);
00101 
00103     plain(const I& ima);
00104 
00106     void init_(const I& ima);
00107 
00109     plain<I>& operator=(const plain<I>& rhs);
00110 
00112     plain<I>& operator=(const I& ima);
00113 
00115     operator I () const;
00116   };
00117 
00118 
00119 
00120 # ifndef MLN_INCLUDE_ONLY
00121 
00122 
00123   // internal::data< plain<I> >
00124 
00125   namespace internal
00126   {
00127 
00128     template <typename I>
00129     inline
00130     data< plain<I> >::data(const I& ima)
00131       : ima_(duplicate(ima))
00132     {
00133     }
00134 
00135   } // end of namespace mln::internal
00136 
00137 
00138   // plain<I>
00139 
00140   template <typename I>
00141   inline
00142   plain<I>::plain()
00143   {
00144   }
00145 
00146   template <typename I>
00147   inline
00148   plain<I>::plain(const plain<I>& rhs)
00149     : super_()
00150   {
00151     mln_precondition(rhs.is_valid());
00152     init_(rhs.data_->ima_);
00153   }
00154 
00155   template <typename I>
00156   inline
00157   plain<I>::plain(const I& ima)
00158   {
00159     mln_precondition(ima.is_valid());
00160     init_(ima);
00161   }
00162 
00163   template <typename I>
00164   inline
00165   void
00166   plain<I>::init_(const I& ima)
00167   {
00168     mln_precondition(ima.is_valid());
00169     this->data_ = new internal::data< plain<I> >(ima);
00170   }
00171 
00172   template <typename I>
00173   inline
00174   plain<I>&
00175   plain<I>::operator=(const plain<I>& rhs)
00176   {
00177     mln_precondition(rhs.is_valid());
00178     if (&rhs == this)
00179       return *this;
00180     this->destroy();
00181     init_(rhs.data_->ima_);
00182     return *this;
00183   }
00184 
00185   template <typename I>
00186   inline
00187   plain<I>&
00188   plain<I>::operator=(const I& ima)
00189   {
00190     mln_precondition(ima.is_valid());
00191     this->destroy();
00192     init_(ima);
00193     return *this;
00194   }
00195 
00196   template <typename I>
00197   inline
00198   plain<I>::operator I () const
00199   {
00200     mln_precondition(this->is_valid());
00201     return duplicate(this->data_->ima_);
00202   }
00203 
00204 # endif // ! MLN_INCLUDE_ONLY
00205 
00206 } // end of namespace mln
00207 
00208 
00209 #endif // ! MLN_CORE_IMAGE_IMORPH_PLAIN_HH
 All Classes Namespaces Functions Variables Typedefs Enumerator