behavior.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, but
00009 // 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 OLENA_CORE_BEHAVIOR_HH
00029 # define OLENA_CORE_BEHAVIOR_HH
00030 # include <oln/core/abstract/behavior.hh>
00031 # include <mlc/type.hh>
00032 
00033 namespace oln {
00040   // mirror the image content into the border
00041   template <class Exact = mlc::final>
00042   class mirror_behavior:
00043     public abstract::behavior<mlc_exact_vt_type(mirror_behavior<Exact>, Exact)>
00044   {
00045   public:
00046     typedef mirror_behavior<Exact>                      self_type;
00047     typedef mlc_exact_vt_type(self_type, Exact) exact_type;
00048 
00049     template <class I>
00050       void adapt_border_impl(oln::abstract::image<I> &im, coord border_size) const
00051       {
00052         im.border_adapt_mirror(border_size);
00053       };
00054   };
00055 
00056   // set the border to a specific value
00057   
00064   template <class T, class Exact = mlc::final>
00065   class value_behavior:
00066     public abstract::behavior<mlc_2_exact_vt_type(value_behavior, T, Exact)>
00067   {
00068   public:
00069     typedef value_behavior<T, Exact>            self_type;
00070     typedef mlc_exact_vt_type(self_type, Exact) exact_type;
00071     typedef T                                   value_type;
00072 
00073     explicit value_behavior(value_type value): value_(value)
00074       {
00075       };
00076 
00077       template <class I>
00078       void adapt_border_impl(abstract::image<I> &im, coord border_size) const
00079       {
00080         im.border_adapt_assign(border_size, ntg::cast::force<oln_value_type(I)>(value_));
00081       };
00082 
00083   protected:
00084     value_type  value_;
00085   };
00086 
00087   // replicate the border
00088 
00095   template <class Exact = mlc::final>
00096   class replicate_behavior:
00097     public abstract::behavior<mlc_exact_vt_type(replicate_behavior<Exact>, Exact)>
00098   {
00099   public:
00100     typedef replicate_behavior<Exact>           self_type;
00101     typedef mlc_exact_vt_type(self_type, Exact) exact_type;
00102 
00103     template <class I>
00104       void adapt_border_impl(abstract::image<I> &im, coord border_size) const
00105       {
00106         im.border_adapt_copy(border_size);
00107       };
00108   };
00109 
00110   // tools to call ctors with type inference
00112   inline mirror_behavior<> mirror_bhv()
00113   {
00114     return mirror_behavior<>();
00115   }
00116 
00118   template <class T>
00119   inline value_behavior<T> value_bhv(const T &value)
00120   {
00121     return value_behavior<T>(value);
00122   }
00123 
00125   inline replicate_behavior<> replicate_bhv()
00126   {
00127     return replicate_behavior<>();
00128   }
00129 } // !oln
00130 
00131 #endif // !OLN_CORE_BEHAVIOR_HH

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