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,
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 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(const oln::abstract::image<I> &im,
00051                              coord border_size) const
00052       {
00053         im.border_adapt_mirror(border_size);
00054       }
00055   };
00056 
00057   // set the border to a specific value
00058 
00065   template <class T, class Exact = mlc::final>
00066   class value_behavior:
00067     public abstract::behavior<mlc_2_exact_vt_type(value_behavior, T, Exact)>
00068   {
00069   public:
00070     typedef value_behavior<T, Exact>            self_type;
00071     typedef mlc_exact_vt_type(self_type, Exact) exact_type;
00072     typedef T                                   value_type;
00073 
00074     explicit value_behavior(value_type value): value_(value)
00075       {
00076       };
00077 
00078       template <class I>
00079       void adapt_border_impl(const abstract::image<I> &im,
00080                              coord border_size) const
00081       {
00082         im.border_adapt_assign(border_size,
00083                                ntg::cast::force<oln_value_type(I)>(value_));
00084       }
00085 
00087       value_behavior() {}
00088 
00089   protected:
00090     value_type  value_;
00091   };
00092 
00093   // replicate the border
00094 
00101   template <class Exact = mlc::final>
00102   class replicate_behavior:
00103     public abstract::behavior<mlc_exact_vt_type(replicate_behavior<Exact>, Exact)>
00104   {
00105   public:
00106     typedef replicate_behavior<Exact>           self_type;
00107     typedef mlc_exact_vt_type(self_type, Exact) exact_type;
00108 
00109     template <class I>
00110       void adapt_border_impl(const abstract::image<I> &im,
00111                              coord border_size) const
00112       {
00113         im.border_adapt_copy(border_size);
00114       }
00115 
00116   };
00117 
00118   // tools to call ctors with type inference
00120   inline mirror_behavior<> mirror_bhv()
00121   {
00122     return mirror_behavior<>();
00123   }
00124 
00126   template <class T>
00127   inline value_behavior<T> value_bhv(const T &value)
00128   {
00129     return value_behavior<T>(value);
00130   }
00131 
00133   inline replicate_behavior<> replicate_bhv()
00134   {
00135     return replicate_behavior<>();
00136   }
00137 } // !oln
00138 
00139 #endif // !OLN_CORE_BEHAVIOR_HH

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