iter_morpher.hh

00001 // Copyright (C) 2004  EPITA Research and Development Laboratory
00002 //
00003 // This file is part of the Olena Library.  This library is free
00004 // software; you can redistribute it and/or modify it under the terms
00005 // of the GNU General Public License version 2 as published by the
00006 // Free Software Foundation.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this library; see the file COPYING.  If not, write to
00015 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
00016 // MA 02111-1307, USA.
00017 //
00018 // As a special exception, you may use this file as part of a free
00019 // software library 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
00022 // produce an executable, this file does not by itself cause the
00023 // resulting executable to be covered by the GNU General Public
00024 // License.  This exception does not however invalidate any other
00025 // reasons why the executable file might be covered by the GNU General
00026 // Public License.
00027 
00028 #ifndef OLN_MORPHER_ITER_MORPHER_HH
00029 # define OLN_MORPHER_ITER_MORPHER_HH
00030 
00031 # include <oln/morpher/generic_morpher.hh>
00032 
00033 namespace oln {
00034 
00035   namespace morpher {
00036 
00037     template <class SrcType, class IterType, class Exact = mlc::final>
00038     struct iter_morpher;
00039 
00040   } // end of namespace morpher
00041 
00043   template <class SrcType, class IterType, class Exact>
00044   struct image_id< morpher::iter_morpher<SrcType, IterType, Exact> >
00045   {
00046     enum {dim = SrcType::dim}; 
00047     typedef oln_impl_type(SrcType) impl_type;
00049     typedef oln_value_type(SrcType) value_type;
00051     typedef typename mlc::exact_vt<
00052         morpher::iter_morpher<SrcType, IterType, Exact>,
00053         Exact
00054       >::ret exact_type;
00056     typedef oln_point_type(SrcType) point_type;
00057     typedef oln_dpoint_type(SrcType) dpoint_type;
00058     typedef oln_size_type(SrcType) size_type;
00059     typedef IterType iter_type;
00060   };
00061 
00063   template <class SrcType, class IterType, class Exact>
00064   struct image_traits < morpher::iter_morpher<SrcType, IterType, Exact> >
00065     : public
00066   image_traits<
00067     morpher::abstract::generic_morpher<
00068       SrcType,
00069       typename image_id<morpher::iter_morpher<SrcType,
00070                                               IterType,
00071                                               Exact> >::exact_type
00072     >
00073   >
00074   {
00075     typedef IterType iter_type;
00076   };
00077 
00078   namespace morpher {
00079 
00080     template <class SrcType, class IterType, class Exact>
00081     struct iter_morpher
00082       : public abstract::generic_morpher<
00083           SrcType,
00084           typename image_id<iter_morpher<SrcType,
00085                                          IterType,
00086                                          Exact> >::exact_type
00087         >
00088     {
00089       typedef iter_morpher<SrcType, IterType, Exact> self_type;
00090       typedef typename image_id<self_type>::exact_type exact_type;
00091       typedef abstract::generic_morpher<SrcType, exact_type> super_type;
00092 
00093       typedef typename image_id<exact_type>::iter_type iter_type;
00094       typedef typename image_id<exact_type>::value_type value_type;
00095       typedef typename image_id<exact_type>::point_type point_type;
00096 
00098       iter_morpher(const SrcType &ima)
00099         : super_type(ima)
00100       {}
00101 
00103       iter_morpher(const self_type& r)
00104         : super_type(r.get_ima())
00105       {}
00106 
00112       iter_morpher() {}
00113 
00118       self_type&
00119       assign(self_type& rhs)
00120       {
00121         oln_iter_type(SrcType)  it(rhs);
00122 
00123         for_all(it)
00124           this->at(it) = rhs[it];
00125         return this->exact();
00126       }
00127 
00133       value_type&
00134       at(const point_type& p)
00135       {
00136         return const_cast<value_type &>
00137           ( const_cast<SrcType &>(this->ima_)[p] );
00138       }
00139 
00145       const value_type
00146       at(const point_type& p) const
00147       {
00148         return this->ima_[p];
00149       }
00150 
00152       static std::string
00153       name()
00154       {
00155         return "iter_morpher<" + super_type::name() + ">";
00156       }
00157 
00158     };
00159 
00161     template <class SrcType, class IterType, class Exact>
00162     struct iter_morpher<const SrcType, IterType, Exact>
00163       : public
00164     abstract::generic_morpher<
00165       const SrcType,
00166       typename image_id<iter_morpher<const SrcType,
00167                                      IterType,
00168                                      Exact> >::exact_type
00169     >
00170     {
00171       typedef iter_morpher<const SrcType, IterType, Exact> self_type;
00172       typedef typename image_id<self_type>::exact_type exact_type;
00173       typedef abstract::generic_morpher<const SrcType, exact_type>
00174       super_type;
00175 
00176       typedef typename image_id<exact_type>::iter_type iter_type;
00177       typedef typename image_id<exact_type>::value_type value_type;
00178       typedef typename image_id<exact_type>::point_type point_type;
00179 
00181       iter_morpher(const SrcType &ima)
00182         : super_type(ima)
00183       {}
00184 
00186       iter_morpher(const self_type& r)
00187         : super_type(r.get_ima())
00188       {}
00189 
00195       iter_morpher() {}
00196 
00201       self_type&
00202       assign(self_type& rhs)
00203       {
00204         oln_iter_type(SrcType)  it(rhs);
00205 
00206         for_all(it)
00207           this->at(it) = rhs[it];
00208         return this->exact();
00209       }
00210 
00216       const value_type
00217       at(const point_type& p) const
00218       {
00219         return this->ima_[p];
00220       }
00221 
00223       static std::string
00224       name()
00225       {
00226         return "iter_morpher<" + super_type::name() + ">";
00227       }
00228 
00229     };
00230 
00271     template <class IterType, class I>
00272     const iter_morpher<I, IterType>
00273     iter_morph(I &ima)
00274     {
00275       return iter_morpher<I, IterType>(ima);
00276     }
00277 
00278   } // End of namespace morpher.
00279 
00280 } // End of namespace oln.
00281 
00282 #endif // !ITER_MORPHER

Generated on Thu Apr 15 20:13:13 2004 for Olena by doxygen 1.3.6-20040222