piece_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, Inc., 51 Franklin Street, Fifth Floor,
00016 // Boston, MA 02110-1301, 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 PIECE_MORPHER_HH
00029 # define PIECE_MORPHER_HH
00030 
00031 # include <oln/morpher/generic_morpher.hh>
00032 
00033 namespace oln {
00034 
00035   namespace morpher {
00036 
00037     template <class I, class Exact = mlc::final>
00038     struct piece_morpher;
00039     template <class I, class Exact = mlc::final>
00040     struct super_piece_morpher;
00041 
00042   } // end of namespace morpher
00043 
00045   template <class SrcType, class Exact>
00046   struct image_id< morpher::super_piece_morpher<SrcType, Exact> >
00047   {
00048     typedef typename mlc::exact_vt<
00049       morpher::super_piece_morpher<SrcType, Exact>,
00050       Exact>::ret
00051     exact_type;
00053   };
00054 
00056   template <class SrcType, class Exact>
00057   struct image_id< morpher::piece_morpher<SrcType, Exact> >
00058   {
00059     enum {dim = SrcType::dim}; 
00060     typedef oln_impl_type(SrcType) impl_type;
00062     typedef oln_value_type(SrcType) value_type;
00064     typedef typename mlc::exact_vt<morpher::piece_morpher<SrcType, Exact>,
00065                                    Exact>::ret exact_type;
00067     typedef oln_point_type(SrcType) point_type;
00068     typedef oln_dpoint_type(SrcType) dpoint_type;
00069     typedef oln_size_type(SrcType) size_type;
00070     typedef oln_iter_type(SrcType) iter_type;
00071   };
00072 
00074   template <class SrcType, class Exact>
00075   struct image_traits < morpher::piece_morpher<SrcType, Exact> >
00076     : public
00077   image_traits<
00078     morpher::abstract::generic_morpher<
00079       SrcType,
00080       typename image_id<morpher::piece_morpher<SrcType,
00081                                                Exact> >::exact_type
00082     >
00083   >
00084   {};
00085 
00086 
00087   namespace morpher {
00088 
00090     template <class SrcType, class Exact>
00091     class super_piece_morpher
00092       : public abstract::generic_morpher<SrcType, Exact>
00093     {
00094 
00095     public:
00096 
00097       typedef super_piece_morpher<SrcType, Exact> self_type;
00098       typedef typename image_id<self_type>::exact_type exact_type;
00099       typedef abstract::generic_morpher<SrcType, Exact> super_type;
00100 
00101       typedef typename image_id<exact_type>::dpoint_type dpoint_type;
00102       typedef typename image_id<exact_type>::size_type size_type;
00103 
00104     protected:
00105 
00115       super_piece_morpher(const SrcType &ima, const dpoint_type& p,
00116                           const size_type& s)
00117         : super_type(ima), size_(s), p_(p)
00118       {}
00119 
00120       const size_type size_; 
00121       const dpoint_type p_;
00123 
00129       super_piece_morpher()
00130         : super_type(), size_(), p_()
00131       {}
00132 
00133     public:
00134 
00136       const size_type
00137       size() const
00138       {
00139         return size_;
00140       }
00141 
00143       const dpoint_type
00144       ref_point() const
00145       {
00146         return p_;
00147       }
00148 
00150       static std::string
00151       name()
00152       {
00153         return "super_piece_morpher<" + super_type::name() + ">";
00154       }
00155 
00156     };
00157 
00166     template <class SrcType, class Exact>
00167     struct piece_morpher
00168       : public super_piece_morpher<
00169           SrcType,
00170           typename image_id<piece_morpher<SrcType, Exact> >::exact_type
00171         >
00172     {
00173       typedef piece_morpher<SrcType, Exact> self_type;
00174       typedef typename image_id<self_type>::exact_type exact_type;
00175       typedef super_piece_morpher<SrcType, exact_type> super_type;
00176 
00177       typedef typename image_id<exact_type>::point_type point_type;
00178       typedef typename image_id<exact_type>::dpoint_type dpoint_type;
00179       typedef typename image_id<exact_type>::size_type size_type;
00180       typedef typename image_id<exact_type>::value_type value_type;
00181 
00183       piece_morpher(const SrcType &ima, const dpoint_type p,
00184                     const size_type s)
00185         : super_type(ima, p, s)
00186       {}
00187 
00189       piece_morpher(const self_type& r)
00190         : super_type(r.get_ima(), r.ref_point(), r.size())
00191       {}
00192 
00198       piece_morpher()
00199         : super_type()
00200       {}
00201 
00207       value_type&
00208       at(const point_type& p)
00209       {
00210         return const_cast<value_type &>
00211           ( const_cast<SrcType &>(this->ima_)[p + this->p_] );
00212       }
00213 
00219       const value_type
00220       at(const point_type& p) const
00221       {
00222         return this->ima_[p + this->p_];
00223       }
00224 
00229       self_type&
00230       assign(self_type& rhs)
00231       {
00232         oln_iter_type(SrcType)  it(rhs);
00233 
00234         for_all(it)
00235           this->at(it) = rhs[it];
00236         return this->exact();
00237       }
00238 
00242       self_type&
00243       operator=(SrcType& rhs)
00244       {
00245         return this->exact().assign(rhs);
00246       }
00247 
00249       static std::string
00250       name()
00251       {
00252         return "piece_morpher<" + super_type::name() + ">";
00253       }
00254 
00255     };
00256 
00258     template <class SrcType, class Exact>
00259     struct piece_morpher<const SrcType, Exact>
00260       : public super_piece_morpher<
00261           const SrcType,
00262           typename image_id<piece_morpher<const SrcType,
00263                                           Exact> >::exact_type
00264         >
00265     {
00266       typedef piece_morpher<const SrcType, Exact> self_type;
00267       typedef typename image_id<self_type>::exact_type exact_type;
00268       typedef super_piece_morpher<const SrcType, exact_type> super_type;
00269 
00270       typedef typename image_id<exact_type>::point_type point_type;
00271       typedef typename image_id<exact_type>::dpoint_type dpoint_type;
00272       typedef typename image_id<exact_type>::size_type size_type;
00273       typedef typename image_id<exact_type>::value_type value_type;
00274 
00281       piece_morpher(const SrcType &ima, const dpoint_type p,
00282                     const size_type s)
00283         : super_type(ima, p, s)
00284       {}
00285 
00287       piece_morpher(const self_type& r)
00288         : super_type(r.get_ima(), r.ref_point(), r.size())
00289       {}
00290 
00296       piece_morpher() {}
00297 
00303       const value_type
00304       at(const point_type &p) const
00305       {
00306         return this->ima_[p + this->p_];
00307       }
00308 
00310       static std::string
00311       name()
00312       {
00313         return "piece_morpher<" + super_type::name() + ">";
00314       }
00315 
00316     };
00317 
00318 
00347     template <class I, class PointType, class SizeType>
00348     const piece_morpher<I>
00349     piece_morph(I &ima, const PointType p, const SizeType s)
00350     {
00351       return piece_morpher<I>(ima, p, s);
00352     }
00353 
00354 
00355   } // end namespace morpher
00356 
00357 } // end namespace oln
00358 
00359 #endif // !PIECE_MORPHER

Generated on Tue Feb 20 20:20:16 2007 for Olena by  doxygen 1.5.1