679: Add oln abstract functions + move slice vtype definitions.

2006-10-25 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Add oln abstract functions + move slice vtype definitions. * oln/level/assign.hh: New. * oln/level/apply.hh: New. * oln/level/clone.hh: New. * oln/core/abstract/functions.hh: New. * oln/debug/track.hh (dummy): Add code to remove warning. * oln/debug/print.hh (OLN_ENV_2D): Guard specific code. * oln/level/fill.hh (fill): New couple of versions. * oln/basics1d.hh (OLN_ENV_1D): New. * oln/core/typedefs.hh (oln_plain_value, oln_plain_value_): New. * oln/core/iterator_vtypes.hh (slice): Move type definitions to... * oln/morpher/slice.hh: ...here. * oln/basics2d.hh (OLN_ENV_2D): New. * oln/basics3d.hh (OLN_ENV_3D): New. * oln/Makefile.am: Update. Index: oln/debug/track.hh =================================================================== --- oln/debug/track.hh (revision 678) +++ oln/debug/track.hh (working copy) @@ -38,6 +38,16 @@ static unsigned n_images = 0; static unsigned n_arrays = 0; + +# ifndef OLN_INCLUDE_ONLY + namespace dummy { + // FIXME: Quick hack to suppress the warning + // "'oln::debug::n_arrays' defined but not used" + void foo() { n_arrays = n_arrays; } + } +# endif + + } // end of namespace oln::debug } // end of namespace oln Index: oln/debug/print.hh =================================================================== --- oln/debug/print.hh (revision 678) +++ oln/debug/print.hh (working copy) @@ -34,9 +34,12 @@ # include <oln/core/abstract/iterator.hh> # include <oln/core/spe/row.hh> # include <oln/core/spe/col.hh> -# include <oln/core/2d/point2d.hh> +# ifdef OLN_ENV_2D +# include <oln/core/2d/point2d.hh> +# endif + namespace oln { @@ -76,6 +79,8 @@ } +# ifdef OLN_ENV_2D + /// Version for classical 2D images. template <typename I> void print(const abstract::classical_2d_image<I>& input, @@ -96,10 +101,12 @@ } } +# endif + + } // end of namespace oln::debug::impl - /// Facade. template <typename I> void print(const abstract::image<I>& input, std::ostream& ostr) Index: oln/level/assign.hh =================================================================== --- oln/level/assign.hh (revision 0) +++ oln/level/assign.hh (revision 0) @@ -0,0 +1,85 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and +// Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_LEVEL_ASSIGN_HH +# define OLN_LEVEL_ASSIGN_HH + +# include <iostream> + +# include <mlc/assert.hh> +# include <mlc/is_a.hh> + +# include <oln/core/abstract/image.hh> +# include <oln/core/abstract/iterator.hh> +# include <oln/core/automatic/image/mutable_image.hh> + + +namespace oln +{ + + namespace level + { + + /// Fwd decls. + + template <typename Idest, typename Isrc> + void assign(abstract::mutable_image<Idest>& dest, const abstract::image<Isrc>& src); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + /// Generic version. + template <typename Idest, typename Isrc> + void assign(abstract::mutable_image<Idest>& dest, const abstract::image<Isrc>& src) + { + oln_piter(Isrc) p(src.topo()); + for_all(p) + dest(p) = src(p); + } + + } // end of namespace oln::level::impl + + + /// Facade. + template <typename Idest, typename Isrc> + void assign(abstract::mutable_image<Idest>& dest, const abstract::image<Isrc>& src) + { + impl::assign(dest.exact(), src.exact()); + } + +# endif + + } // end of namespace oln::level + +} // end of namespace oln + + +#endif // ! OLN_LEVEL_ASSIGN_HH Index: oln/level/apply.hh =================================================================== --- oln/level/apply.hh (revision 0) +++ oln/level/apply.hh (revision 0) @@ -0,0 +1,109 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and +// Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_LEVEL_APPLY_HH +# define OLN_LEVEL_APPLY_HH + +# include <oln/core/abstract/image.hh> +# include <oln/core/abstract/iterator.hh> +# include <oln/core/abstract/functions.hh> + + +namespace oln +{ + + namespace level + { + + /// Fwd decl. + template <typename I, typename V> + oln_plain_value(I, V) + apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&)); + + /// Fwd decl. + template <typename I, typename F> + oln_plain_value(I, typename F::result_value) + apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + /// Generic version. + template <typename I, typename V> + oln_plain_value(I, V) + apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&)) + { + oln_plain_value(I, V) output(input.topo()); + oln_piter(I) p(input.topo()); + for_all(p) + output(p) = fun(input(p)); + return output; + } + + /// Generic version. + template <typename I, typename F> + oln_plain_value(I, typename F::result_value) + apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun) + { + oln_plain_value(I, typename F::result_value) output(input.topo()); + oln_piter(I) p(input.topo()); + for_all(p) + output(p) = fun.exact()(input(p)); + return output; + } + + } // end of namespace oln::level::impl + + + /// Facade. + template <typename I, typename V> + oln_plain_value(I, V) + apply(const abstract::image<I>& input, V (*fun)(const oln_value(I)&)) + { + return impl::apply(input, fun); + } + + /// Facade. + template <typename I, typename F> + oln_plain_value(I, typename F::result_value) + apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun) + { + return impl::apply(input, fun); + } + +# endif + + } // end of namespace oln::level + +} // end of namespace oln + + +#endif // ! OLN_LEVEL_APPLY_HH Index: oln/level/fill.hh =================================================================== --- oln/level/fill.hh (revision 678) +++ oln/level/fill.hh (working copy) @@ -36,6 +36,7 @@ # include <oln/core/abstract/image.hh> # include <oln/core/abstract/iterator.hh> +# include <oln/core/abstract/functions.hh> # include <oln/core/automatic/image/mutable_image.hh> @@ -68,7 +69,16 @@ template <typename I, typename V> void fill(abstract::mutable_image<I>& input, const V values[]); + /// Fwd decl. + template <typename I, typename V, typename P> + void fill(abstract::mutable_image<I>& input, V (*fun)(const P&)); + /// Fwd decl. + template <typename I, typename F> + void fill(abstract::mutable_image<I>& input, + const abstract::fun_p2v<F>& fun); + + # ifndef OLN_INCLUDE_ONLY namespace impl @@ -93,9 +103,30 @@ input(p) = values[i++]; } - } // end of namespace oln::level::fill + /// Generic version. + template <typename I, typename V, typename P> + void fill(abstract::mutable_image<I>& input, V (*fun)(const P&)) + { + oln_piter(I) p(input.topo()); + unsigned i = 0; + for_all(p) + input(p) = fun(p); + } + /// Generic version. + template <typename I, typename F> + void fill(abstract::mutable_image<I>& input, + const abstract::fun_p2v<F>& fun) + { + oln_piter(I) p(input.topo()); + unsigned i = 0; + for_all(p) + input(p) = fun.exact()(p); + } + } // end of namespace oln::level::impl + + /// Facade. template <typename I> void fill(abstract::mutable_image<I>& input, const oln_value(I)& value) @@ -110,7 +141,21 @@ return impl::fill(input.exact(), values); } + /// Facade. + template <typename I, typename V, typename P> + void fill(abstract::mutable_image<I>& input, V (*fun)(const P&)) + { + return impl::fill(input.exact(), fun); + } + /// Facade. + template <typename I, typename F> + void fill(abstract::mutable_image<I>& input, + const abstract::fun_p2v<F>& fun) + { + return impl::fill(input.exact(), fun); + } + # endif } // end of namespace oln::level Index: oln/level/clone.hh =================================================================== --- oln/level/clone.hh (revision 0) +++ oln/level/clone.hh (revision 0) @@ -0,0 +1,80 @@ +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and +// Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_LEVEL_CLONE_HH +# define OLN_LEVEL_CLONE_HH + +# include <oln/core/abstract/image.hh> +# include <oln/core/abstract/iterator.hh> + + +namespace oln +{ + + namespace level + { + + /// Fwd decl. + template <typename I> + oln_plain(I) clone(const abstract::image<I>& input); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + /// Generic version. + template <typename I> + oln_plain(I) clone(const abstract::image<I>& input) + { + oln_plain(I) output(input.topo()); + oln_piter(I) p(input.topo()); + for_all(p) + output(p) = input(p); + return output; + } + + } // end of namespace oln::level::impl + + + /// Facade. + template <typename I> + oln_plain(I) clone(const abstract::image<I>& input) + { + return impl::clone(input); + } + +# endif + + } // end of namespace oln::level + +} // end of namespace oln + + +#endif // ! OLN_LEVEL_CLONE_HH Index: oln/basics1d.hh =================================================================== --- oln/basics1d.hh (revision 678) +++ oln/basics1d.hh (working copy) @@ -30,6 +30,9 @@ # define OLN_BASICS1D_HH +# define OLN_ENV_1D + + # include <oln/core/1d/aliases.hh> # include <oln/core/gen/grid.hh> Index: oln/core/typedefs.hh =================================================================== --- oln/core/typedefs.hh (revision 678) +++ oln/core/typedefs.hh (working copy) @@ -279,6 +279,9 @@ # define oln_plain(T) typename oln::type_fun::plain<T>::ret # define oln_plain_(T) oln::type_fun::plain<T>::ret +# define oln_plain_value(I, V) typename oln::type_fun::ch_value< oln_plain(I), V >::ret +# define oln_plain_value_(I, V) oln::type_fun::ch_value< oln_plain(I), V >::ret + /// \} Index: oln/core/iterator_vtypes.hh =================================================================== --- oln/core/iterator_vtypes.hh (revision 678) +++ oln/core/iterator_vtypes.hh (working copy) @@ -33,7 +33,7 @@ # include <oln/core/1d/aliases.hh> # include <oln/core/2d/aliases.hh> # include <oln/core/3d/aliases.hh> -# include <oln/core/type_fun/slice.hh> +// # include <oln/core/type_fun/slice.hh> namespace oln @@ -272,67 +272,7 @@ }; - /*-----------------------------. - | oln::morpher::slice<Image>. | - `-----------------------------*/ - // Forward declarations. - namespace morpher - { - template <typename Image> struct slice; - } - template <typename Piter, typename Topo> class piter_slice_; - - - // piters. - - /// fwd_piter vtype of morpher::slice. - template <typename Image> - struct single_vtype< morpher::slice<Image>, typedef_::fwd_piter_type > - { - private: - typedef oln_type_of(Image, fwd_piter) orig_fwd_piter; - public: - typedef typename type_fun::slice_iterator<orig_fwd_piter>::ret ret; - }; - - /// bkd_piter vtype of morpher::slice. - template <typename Image> - struct single_vtype< morpher::slice<Image>, typedef_::bkd_piter_type > - { - private: - typedef oln_type_of(Image, bkd_piter) orig_bkd_piter; - public: - typedef typename type_fun::slice_iterator<orig_bkd_piter>::ret ret; - }; - - - // qiters. - - /// fwd_qiter vtype of morpher::slice. - template <typename Image> - struct single_vtype< morpher::slice<Image>, typedef_::fwd_qiter_type > - { - private: - typedef oln_type_of(Image, fwd_qiter) orig_fwd_qiter; - public: - typedef typename type_fun::slice_iterator<orig_fwd_qiter>::ret ret; - }; - - /// bkd_qiter vtype of morpher::slice. - template <typename Image> - struct single_vtype< morpher::slice<Image>, typedef_::bkd_qiter_type > - { - private: - typedef oln_type_of(Image, bkd_qiter) orig_bkd_qiter; - public: - typedef typename type_fun::slice_iterator<orig_bkd_qiter>::ret ret; - }; - - - // FIXME: What about niters? - - } // end of namespace oln Index: oln/core/abstract/functions.hh =================================================================== --- oln/core/abstract/functions.hh (revision 0) +++ oln/core/abstract/functions.hh (revision 0) @@ -0,0 +1,98 @@ +// Copyright (C) 2006 EPITA Research and Development Laboratory +// +// This file is part of the Olena Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License version 2 as published by the +// Free Software Foundation. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING. If not, write to +// the Free Software Foundation, 51 Franklin Street, Fifth Floor, +// Boston, MA 02111-1307, USA. +// +// As a special exception, you may use this file as part of a free +// software library without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to +// produce an executable, this file does not by itself cause the +// resulting executable to be covered by the GNU General Public +// License. This exception does not however invalidate any other +// reasons why the executable file might be covered by the GNU General +// Public License. + +#ifndef OLN_CORE_ABSTRACT_FUNCTIONS_HH +# define OLN_CORE_ABSTRACT_FUNCTIONS_HH + +# include <stc/any.hh> +# include <oln/core/type.hh> + + +namespace oln +{ + + namespace abstract + { + + // Point -> Value. + + template <typename E> + struct fun_p2v : public virtual stc::any__simple<E>, + public oln::type + { + protected: + fun_p2v(); + }; + + + // Value -> Value. + + template <typename E> + struct fun_v2v : public virtual stc::any__simple<E>, + public oln::type + { + protected: + fun_v2v(); + }; + + + // Point -> Point. + + template <typename E> + struct fun_p2p : public virtual stc::any__simple<E>, + public oln::type + { + protected: + fun_p2p(); + }; + + +# ifndef OLN_INCLUDE_ONLY + + template <typename E> + fun_p2v<E>::fun_p2v() + { + } + + template <typename E> + fun_v2v<E>::fun_v2v() + { + } + + template <typename E> + fun_p2p<E>::fun_p2p() + { + } + +# endif + + } // end of namespace oln::abstract + +} // end of namespace oln + + +#endif // ! OLN_CORE_ABSTRACT_FUNCTIONS_HH Index: oln/basics2d.hh =================================================================== --- oln/basics2d.hh (revision 678) +++ oln/basics2d.hh (working copy) @@ -30,6 +30,9 @@ # define OLN_BASICS2D_HH +# define OLN_ENV_2D + + # include <oln/core/2d/aliases.hh> # include <oln/core/gen/grid.hh> Index: oln/Makefile.am =================================================================== --- oln/Makefile.am (revision 678) +++ oln/Makefile.am (working copy) @@ -80,6 +80,7 @@ core/abstract/bbox.hh \ core/abstract/dpoint.hh \ core/abstract/entry.hh \ + core/abstract/functions.hh \ core/abstract/fwd_decls.hh \ core/abstract/grid.hh \ core/abstract/image.hh \ @@ -165,6 +166,9 @@ \ io/pnm.hh \ \ + level/apply.hh \ + level/assign.hh \ + level/clone.hh \ level/fill.hh \ \ morpher/internal/image_extension.hh \ Index: oln/basics3d.hh =================================================================== --- oln/basics3d.hh (revision 678) +++ oln/basics3d.hh (working copy) @@ -30,6 +30,9 @@ # define OLN_BASICS3D_HH +# define OLN_ENV_3D + + # include <oln/core/3d/aliases.hh> # include <oln/core/gen/grid.hh> Index: oln/morpher/slice.hh =================================================================== --- oln/morpher/slice.hh (revision 678) +++ oln/morpher/slice.hh (working copy) @@ -140,6 +140,58 @@ /// \} + + + + // piters. + + /// fwd_piter vtype of morpher::slice. + template <typename Image> + struct single_vtype< morpher::slice<Image>, typedef_::fwd_piter_type > + { + private: + typedef oln_type_of(Image, fwd_piter) orig_fwd_piter; + public: + typedef typename type_fun::slice_iterator<orig_fwd_piter>::ret ret; + }; + + /// bkd_piter vtype of morpher::slice. + template <typename Image> + struct single_vtype< morpher::slice<Image>, typedef_::bkd_piter_type > + { + private: + typedef oln_type_of(Image, bkd_piter) orig_bkd_piter; + public: + typedef typename type_fun::slice_iterator<orig_bkd_piter>::ret ret; + }; + + + // qiters. + + /// fwd_qiter vtype of morpher::slice. + template <typename Image> + struct single_vtype< morpher::slice<Image>, typedef_::fwd_qiter_type > + { + private: + typedef oln_type_of(Image, fwd_qiter) orig_fwd_qiter; + public: + typedef typename type_fun::slice_iterator<orig_fwd_qiter>::ret ret; + }; + + /// bkd_qiter vtype of morpher::slice. + template <typename Image> + struct single_vtype< morpher::slice<Image>, typedef_::bkd_qiter_type > + { + private: + typedef oln_type_of(Image, bkd_qiter) orig_bkd_qiter; + public: + typedef typename type_fun::slice_iterator<orig_bkd_qiter>::ret ret; + }; + + + + + namespace morpher { @@ -203,4 +255,5 @@ } // end of namespace oln + #endif // ! OLN_MORPHER_SLICE_HH
participants (1)
-
Thierry GERAUD