func_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 
00029 
00030 #ifndef OLENA_MORPHER_FUNC_MORPHER_HH
00031 # define OLENA_MORPHER_FUNC_MORPHER_HH
00032 
00033 # include <oln/morpher/generic_morpher.hh>
00034 
00035 
00036 namespace oln {
00037 
00038   namespace morpher {
00039 
00040     template <class SrcType, class Ftor, class Exact = mlc::final>
00041     struct func_morpher;
00042 
00043 
00044   } // end of namespace morpher
00045 
00046   template <class SrcType, class Ftor, class Exact>
00047   struct image_id<oln::morpher::func_morpher<SrcType, Ftor, Exact> >
00048   {
00049     enum {dim = SrcType::dim};
00051     typedef oln_impl_type(SrcType) impl_type;
00053     typedef oln_value_type(SrcType) value_type;
00055     typedef typename mlc::exact_vt<oln::morpher::func_morpher<SrcType, Ftor, Exact>,
00056                                     Exact>::ret exact_type;
00057 
00058     typedef oln_point_type(SrcType) point_type;
00059   };
00060 
00069   template <class SrcType, class Ftor, class Exact>
00070   struct image_traits <oln::morpher::func_morpher<SrcType, Ftor, Exact> > :
00071     public image_traits<oln::morpher::abstract::generic_morpher<SrcType,
00072                                                                 typename image_id<oln::morpher::func_morpher<SrcType, Ftor, Exact> >::exact_type> >
00073   {
00074   };
00075 
00076   namespace morpher {
00077 
00078 
00079 
00080     template <class SrcType, class Ftor, class Exact>
00081     struct func_morpher:
00082       public abstract::generic_morpher<SrcType,
00083                                        typename oln::image_id<func_morpher<SrcType, Ftor, Exact> >::exact_type>
00084     {
00085 
00086       Ftor f;
00087 
00089       typedef typename oln::image_id<func_morpher<SrcType, Ftor, Exact> >::exact_type exact_type;
00090 
00092       typedef abstract::generic_morpher<SrcType,
00093                                         exact_type> super_type;
00094 
00096       typedef typename image_id<exact_type>::value_type value_type;
00097       typedef typename image_id<exact_type>::point_type point_type;
00098       typedef typename image_id<exact_type>::impl_type impl_type;
00099 
00101       func_morpher(const SrcType &ima, const Ftor f_)
00102         : super_type(ima)
00103       { f = f_;}
00104 
00106       func_morpher(const func_morpher<SrcType, Ftor>& r)
00107         : super_type(r.get_ima())
00108       { f = r.f; }
00109 
00114       func_morpher() {}
00115 
00117       const value_type
00118       at(const point_type& p) const
00119       {
00120         return f(this->ima_, p);
00121       }
00122 
00124       const impl_type*
00125       impl() const
00126       {
00127         return this->ima_.impl();
00128       }
00129 
00130       static std::string
00131       name()
00132       {
00133         return "subq_morpher<" + SrcType::name() + ">";
00134       }
00135 
00136     };
00137   }
00138 }
00139 
00140 
00141 
00142 #endif // !OLENA_MORPHER_FUNC_MORPHER_HH

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