https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Clean-up morpho, accumulators, and vtypes in base classes.
* oln/morpho/erosion.hh: Rename as...
* oln/morpho/elementary_erosion.hh: ...this.
(erosion): Rename as...
(elementary_erosion): ...this and update.
* oln/core/concept/function.hh (Accumulator): Move to...
* oln/core/concept/accumulator.hh: ...this new file.
* oln/accumulator/: New.
* oln/function/min.hh: Rename as...
* oln/accumulator/min.hh: ...this.
Split decls and defs.
* oln/core/internal/dpoint_nd.hh: Remove; obsolete.
* oln/level/apply.hh (apply_local): Uncomment and move to...
* oln/level/apply_local.hh: ...this new file.
* oln/level/apply.hh (apply_inplace): Uncomment and move to...
* oln/level/apply_inplace.hh: ...this new file.
* oln/level/local.hh: Fix sigs.
* oln/core/init.hh (init): Strengthen sigs with Any.
* oln/core/equipment.hh (argument, oln_argument): New.
(oln_dim, oln_dpoint, oln_grid): New.
(include): Reject init.hh to end of file.
* oln/core/gen/fun.hh (fun_v2v_, functorize_v2v): New.
* oln/core/internal/point_base.hh,
* oln/core/internal/dpoint_base.hh,
* oln/core/internal/point_set_base.hh,
* oln/core/internal/window_base.hh,
* oln/core/internal/neighborhood_base.hh,
* oln/core/internal/image_base.hh: Simplify type deductions.
accumulator/min.hh | 58 ++++++++++---
core/concept/accumulator.hh | 60 +++++++++++++
core/concept/function.hh | 12 --
core/equipment.hh | 18 +++-
core/gen/fun.hh | 51 +++++++++++
core/init.hh | 26 ++---
core/internal/dpoint_base.hh | 2
core/internal/image_base.hh | 9 --
core/internal/neighborhood_base.hh | 2
core/internal/point_base.hh | 2
core/internal/point_set_base.hh | 5 -
core/internal/window_base.hh | 2
level/apply.hh | 143 ++++----------------------------
level/apply_inplace.hh | 162 +++++--------------------------------
level/apply_local.hh | 153 ++++------------------------------
level/local.hh | 38 +++-----
morpho/elementary_erosion.hh | 42 +++++----
17 files changed, 300 insertions(+), 485 deletions(-)
Index: oln/accumulator/min.hh
--- oln/accumulator/min.hh (revision 0)
+++ oln/accumulator/min.hh (working copy)
@@ -25,43 +25,73 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef _FUNCTION_MIN_HH
-# define _FUNCTION_MIN_HH
+#ifndef OLN_ACCUMULATOR_MIN_HH
+# define OLN_ACCUMULATOR_MIN_HH
-#include <oln/core/concept/functions.hh>
+# include <oln/core/concept/accumulator.hh>
#include <oln/core/internal/max_value.hh>
namespace oln
{
- namespace function
+ namespace accumulator
{
template <typename T>
- struct min_ : public oln::Accumulator< min_<T> >
+ struct min_ : public Accumulator< min_<T> >
{
typedef T argument;
typedef T result;
- min_() { this->init(); }
+ min_();
- void init() const { val_ = oln_max(T); }
- result value() const { return val_; }
+ void init() const;
+ result value() const;
template <typename U>
- void operator()(U i) const
- {
- if (i < val_)
- val_ = static_cast<T>(i);
- }
+ void operator()(U i) const;
private:
mutable T val_;
};
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ min_<T>::min_()
+ {
+ this->init();
+ }
+
+ template <typename T>
+ void
+ min_<T>::init() const
+ {
+ this->val_ = oln_max(T);
+ }
+
+ template <typename T>
+ typename min_<T>::result
+ min_<T>::value() const
+ {
+ return this->val_;
}
+ template <typename T>
+ template <typename U>
+ void
+ min_<T>::operator()(U i) const
+ {
+ if (i < this->val_)
+ this->val_ = static_cast<T>(i);
}
-#endif // ! OLN_FUNCTION_MIN_HH
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::accumulator
+
+} // end of namespace oln
+
+#endif // ! OLN_ACCUMULATOR_MIN_HH
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 886)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2007 EPITA Research and
-// Development Laboratory
+// Copyright (C) 2007 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
@@ -26,11 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_EROSION_HH
-# define OLN_MORPHO_EROSION_HH
+#ifndef OLN_MORPHO_ELEMENTARY_EROSION_HH
+# define OLN_MORPHO_ELEMENTARY_EROSION_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/accumulator/min.hh>
-#include <oln/level/local.hh>
-#include <oln/function/min.hh>
namespace oln
{
@@ -38,8 +38,12 @@
namespace morpho
{
+ // Fwd decl.
+
template <typename I>
- I erosion(const Image_with_Nbh<I>& input);
+ oln_plain(I)
+ elementary_erosion(const Image_with_Nbh<I>& input);
+
# ifndef OLN_INCLUDE_ONLY
@@ -49,24 +53,30 @@
/// Generic version
template <typename I>
- I erosion(const Image_with_Nbh<I>& input)
+ oln_plain(I)
+ elementary_erosion_(const Image_with_Nbh<I>& input)
{
- function::min_<oln_value(I)> min;
- return ::oln::level::apply_local(min, input);
- }
+ accumulator::min_<oln_value(I)> min;
+ return level::apply_local(min, input);
}
+ } // end of namespace oln::morpho::impl
+
+
// Facade.
template <typename I>
- I erosion(const Image_with_Nbh<I>& input)
+ oln_plain(I)
+ elementary_erosion(const Image_with_Nbh<I>& input)
{
- return impl::erosion(exact(input));
+ return impl::elementary_erosion_(exact(input));
}
#endif // ! OLN_INCLUDE_ONLY
- } // end of namespace
-}
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
-#endif // ! OLN_MORPHO_EROSION_HH
+#endif // ! OLN_MORPHO_ELEMENTARY_EROSION_HH
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 887)
+++ oln/level/apply.hh (working copy)
@@ -30,9 +30,9 @@
# define OLN_LEVEL_APPLY_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/concept/iterator.hh>
+# include <oln/core/gen/fun.hh>
# include <oln/core/internal/f_ch_value.hh>
-# include <oln/level/local.hh>
+
namespace oln
{
@@ -40,24 +40,15 @@
namespace level
{
- /// Fwd decl.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input);
-
-
-// /// 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);
+ /// Fwd decls.
-// /// Fwd decl.
-// template <typename I, typename V>
-// void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&));
+ template <typename F, typename I>
+ oln_plain_value(I, typename F::result)
+ apply(const Function_v2v<F>& f, const Image<I>& input);
-// /// Fwd decl.
-// template <typename I, typename F>
-// void apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun);
+ template <typename R, typename A, typename I>
+ oln_plain_value(I, R)
+ apply(R (*f)(A), const Image<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -65,138 +56,42 @@
namespace impl
{
- /// apply
+ // Generic version.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply( F& f, const Image<I>& input)
+ apply_(const F& f, const Image<I>& input)
{
- typedef typename F::result result;
typedef typename F::argument argument;
-
- oln_ch_value(I, result) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = f( static_cast< argument >(input(p)) );
- return output;
- }
-
-
- /// apply_local
-
- template <typename F, typename I>
- I apply_local(const Accumulator<F>& f,
- const Image_with_Nbh<I>& input)
- {
typedef typename F::result result;
- typedef typename F::argument argument;
- typename I::delegatee out(input.points());
- I output(out, input.nbhood());
- // I output(exact(input).image(), input.nbhood());
- // FIXME: init(output, with, input);
+ oln_plain_value(I, result) output;
+ init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
- output(p) = level::local(f, input, p);
+ output(p) = f(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;
-// }
-
-
-// /// Generic version.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&))
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun(input(p));
-// }
-
-// /// Generic version.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun)
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun.exact()(input(p));
-// }
-
} // end of namespace oln::level::impl
- /// Facades.
- //----------------------------
-
- /// Apply.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply(fun, exact(input));
- }
+ /// Facades.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply(F& f, const Image<I>& input)
+ apply(const Function_v2v<F>& f, const Image<I>& input)
{
- return impl::apply(f, exact(input));
+ return impl::apply_(exact(f), exact(input));
}
- /// Apply local
-
template <typename R, typename A, typename I>
oln_plain_value(I, R)
- apply_local(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply_local(fun, exact(input));
- }
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
- const Image_with_Nbh<I>& input)
+ apply(R (*f)(A), const Image<I>& input)
{
- return impl::apply_local(fun, input);
+ return impl::apply_(functorize_v2v(f), exact(input));
}
-// /// 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);
-// }
-
-
-// /// Facade.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&))
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
-// /// Facade.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply_inplace(input, fun);
-// }
# endif
Index: oln/level/local.hh
--- oln/level/local.hh (revision 887)
+++ oln/level/local.hh (working copy)
@@ -29,11 +29,9 @@
# define OLN_LEVEL_LOCAL_HH
#include <oln/core/concept/image.hh>
-#include <oln/core/concept/point.hh>
-#include <oln/core/concept/functions.hh>
#include <oln/core/concept/window.hh>
-#include <oln/core/concept/iterator.hh> // bizarre
-#include <oln/core/equipment.hh>
+# include <oln/core/concept/accumulator.hh>
+
namespace oln
{
@@ -42,7 +40,7 @@
{
template <typename A, typename I>
- int //typename A::result
+ typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p);
@@ -54,37 +52,32 @@
const oln_point(I)& p,
const Window<W>& win);
+
# ifndef OLN_INCLUDE_ONLY
namespace impl
{
- /// Local Apply on neighborhood (nbh included in image).
+ // Generic version with neighborhood.
template <typename A, typename I>
- int//typename A::result
+ typename A::result
local_(const A& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
f.init();
- oln_niter(I) n(p, input.points());
+ oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be 'input'!
for_all(n)
f(input(n));
return f.value();
}
- /// Local Apply on neighborhood (nhb given as argument).
-
- // ...FIXME
+ // FIXME: Generic version with nbh given as argument?
- /// Local Apply on window (window included in image).
-
- // ...FIXME
-
- /// Local Apply on window (window is given).
+ // Generic version with window.
template <typename F, typename I, typename W>
typename F::result
@@ -97,16 +90,16 @@
oln_qiter(W) q(p, win);
for_all(q)
f(input(q));
-
return f.value();
}
- }
+ } // end of namespace oln::level::impl
+
- /// Facades.
+ // Facades.
template <typename A, typename I>
- int//typename A::result
+ typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
@@ -126,7 +119,8 @@
#endif // ! OLN_INCLUDE_ONLY
- }
-}
+ } // end of namespace oln::level
+
+} // end of namespace oln
#endif // ! OLN_LEVEL_LOCAL_HH
Index: oln/level/apply_local.hh
--- oln/level/apply_local.hh (revision 886)
+++ oln/level/apply_local.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
-// Research and Development Laboratory
+// Copyright (C) 2007 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
@@ -26,14 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_LEVEL_APPLY_HH
-# define OLN_LEVEL_APPLY_HH
+#ifndef OLN_LEVEL_APPLY_LOCAL_HH
+# define OLN_LEVEL_APPLY_LOCAL_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/concept/iterator.hh>
+# include <oln/core/concept/accumulator.hh>
# include <oln/core/internal/f_ch_value.hh>
# include <oln/level/local.hh>
+
namespace oln
{
@@ -41,23 +41,11 @@
{
/// Fwd decl.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input);
-
-
-// /// 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);
-
-// /// Fwd decl.
-// template <typename I, typename V>
-// void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&));
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// void apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun);
+
+ template <typename F, typename I>
+ oln_plain_value(I, typename F::result)
+ apply_local(const Accumulator<F>& f,
+ const Image_with_Nbh<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -65,139 +53,34 @@
namespace impl
{
- /// apply
+ // Generic version.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply( F& f, const Image<I>& input)
- {
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- oln_ch_value(I, result) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = f( static_cast< argument >(input(p)) );
- return output;
- }
-
-
- /// apply_local
-
- template <typename F, typename I>
- I apply_local(const Accumulator<F>& f,
+ apply_local_(const Accumulator<F>& f,
const Image_with_Nbh<I>& input)
{
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- typename I::delegatee out(input.points());
- I output(out, input.nbhood());
- // I output(exact(input).image(), input.nbhood());
- // FIXME: init(output, with, input);
+ oln_plain_value(I, typename F::result) output;
+ init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
output(p) = level::local(f, 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;
-// }
-
-
-// /// Generic version.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&))
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun(input(p));
-// }
-
-// /// Generic version.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun)
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun.exact()(input(p));
-// }
-
} // end of namespace oln::level::impl
- /// Facades.
- //----------------------------
- /// Apply.
-
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply(fun, exact(input));
- }
+ // Facade.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply(F& f, const Image<I>& input)
- {
- return impl::apply(f, exact(input));
- }
-
- /// Apply local
-
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply_local(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply_local(fun, exact(input));
- }
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
+ apply_local(const Accumulator<F>& f,
const Image_with_Nbh<I>& input)
{
- return impl::apply_local(fun, input);
+ return impl::apply_local_(exact(f), exact(input));
}
-// /// 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);
-// }
-
-
-// /// Facade.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&))
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
-// /// Facade.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
# endif
} // end of namespace oln::level
@@ -205,4 +88,4 @@
} // end of namespace oln
-#endif // ! OLN_LEVEL_APPLY_HH
+#endif // ! OLN_LEVEL_APPLY_LOCAL_HH
Index: oln/level/apply_inplace.hh
--- oln/level/apply_inplace.hh (revision 886)
+++ oln/level/apply_inplace.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
-// Research and Development Laboratory
+// Copyright (C) 2007 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
@@ -26,13 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_LEVEL_APPLY_HH
-# define OLN_LEVEL_APPLY_HH
+#ifndef OLN_LEVEL_APPLY_INPLACE_HH
+# define OLN_LEVEL_APPLY_INPLACE_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/concept/iterator.hh>
-# include <oln/core/internal/f_ch_value.hh>
-# include <oln/level/local.hh>
+# include <oln/core/gen/fun.hh>
+
namespace oln
{
@@ -40,24 +38,15 @@
namespace level
{
- /// Fwd decl.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input);
+ /// Fwd decls.
+ template <typename F, typename I>
+ void
+ apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input)
-// /// 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);
-
-// /// Fwd decl.
-// template <typename I, typename V>
-// void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&));
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// void apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun);
+ template <typename R, typename A, typename I>
+ void
+ apply_inplace(R (*f)(A), Mutable_Image<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -65,139 +54,38 @@
namespace impl
{
- /// apply
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply( F& f, const Image<I>& input)
- {
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- oln_ch_value(I, result) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = f( static_cast< argument >(input(p)) );
- return output;
- }
-
-
- /// apply_local
+ // Generic version.
template <typename F, typename I>
- I apply_local(const Accumulator<F>& f,
- const Image_with_Nbh<I>& input)
+ void
+ apply_inplace_(const F& f, Mutable_Image<I>& input)
{
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- typename I::delegatee out(input.points());
- I output(out, input.nbhood());
- // I output(exact(input).image(), input.nbhood());
- // FIXME: init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
- output(p) = level::local(f, input, p);
- return output;
+ input(p) = f(input(p));
+ // FIXME: input(p) = static_cast<oln_value(I)>( f_(
static_cast<oln_argument(F)>(input(p)) ) );
}
-// /// 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;
-// }
-
-
-// /// Generic version.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&))
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun(input(p));
-// }
-
-// /// Generic version.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun)
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun.exact()(input(p));
-// }
-
} // end of namespace oln::level::impl
- /// Facades.
- //----------------------------
-
- /// Apply.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply(fun, exact(input));
- }
+ /// Facades.
template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply(F& f, const Image<I>& input)
+ void
+ apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input)
{
- return impl::apply(f, exact(input));
+ impl::apply_inplace_(exact(f), exact(input));
}
- /// Apply local
-
template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply_local(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply_local(fun, exact(input));
- }
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
- const Image_with_Nbh<I>& input)
+ void
+ apply_inplace(R (*f)(A), Mutable_Image<I>& input)
{
- return impl::apply_local(fun, input);
+ impl::apply_inplace_(functorize_v2v(fun), exact(input));
}
-// /// 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);
-// }
-
-
-// /// Facade.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const
oln_value(I)&))
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
-// /// Facade.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const
abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
# endif
} // end of namespace oln::level
@@ -205,4 +93,4 @@
} // end of namespace oln
-#endif // ! OLN_LEVEL_APPLY_HH
+#endif // ! OLN_LEVEL_APPLY_INPLACE_HH
Index: oln/core/concept/function.hh
--- oln/core/concept/function.hh (revision 887)
+++ oln/core/concept/function.hh (working copy)
@@ -90,16 +90,6 @@
};
- // Values -> Value.
-
- template <typename Exact>
- struct Accumulator : public Function<Exact>
- {
- protected:
- Accumulator();
- };
-
-
/*
// Value1 -> Value2 *and* Value2 -> Value1.
@@ -187,7 +177,7 @@
{
}
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/accumulator.hh
--- oln/core/concept/accumulator.hh (revision 0)
+++ oln/core/concept/accumulator.hh (revision 0)
@@ -0,0 +1,60 @@
+// Copyright (C) 2007 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_CONCEPT_ACCUMULATOR_HH
+# define OLN_CORE_CONCEPT_ACCUMULATOR_HH
+
+# include <oln/core/concept/function.hh>
+
+
+namespace oln
+{
+
+ // Values -> Value.
+
+ template <typename Exact>
+ struct Accumulator : public Function<Exact>
+ {
+ protected:
+ Accumulator();
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Accumulator<Exact>::Accumulator()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_CONCEPT_ACCUMULATOR_HH
Index: oln/core/init.hh
--- oln/core/init.hh (revision 887)
+++ oln/core/init.hh (working copy)
@@ -84,19 +84,19 @@
// Regular version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, const Data& data);
+ bool init(Any<Target>& target, with_t, const Any<Data>& data);
// Assignment.
template <typename T>
- bool init(T& target, with_t, const T& data);
+ bool init(Any<T>& target, with_t, const Any<T>& data);
- // Unconst data version.
+ // Unconst->const data version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, Data& data);
+ bool init(Any<Target>& target, with_t, Any<Data>& data);
// Guard: we cannot have "const Target".
template <typename Target, typename Data>
- bool init(const Target& target, with_t, const Data& data);
+ bool init(const Any<Target>& target, with_t, const Any<Data>&
data);
@@ -145,24 +145,24 @@
// Regular version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, const Data& data)
+ bool init(Any<Target>& target, with_t, const Any<Data>& data)
{
- return init_(&target, data);
+ return init_(exact(&target), exact(data));
}
// Assignment.
template <typename T>
- bool init(T& target, with_t, const T& data)
+ bool init(Any<T>& target, with_t, const Any<T>& data)
{
- target = data;
+ exact(target) = exact(data);
return true;
}
- // Unconst data version.
+ // Unconst->const data version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, Data& data)
+ bool init(Any<Target>& target, with_t, Any<Data>& data)
{
- return init_(&target, const_cast<const Data&>(data));
+ return init(target, const_cast<const Data&>(data));
}
@@ -174,7 +174,7 @@
// Guard: we cannot have "const Target".
template <typename Target, typename Data>
- bool init(const Target&, with_t, const Data&)
+ bool init(const Any<Target>&, with_t, const Any<Data>&)
{
mlc::abort_< Target,
ERROR::initialization_of_temporary_or_const_object_<Target> >::check();
return false;
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 887)
+++ oln/core/equipment.hh (working copy)
@@ -34,7 +34,6 @@
# else
# include <stc/scoop-alt.hh>
# endif
-# include <oln/core/init.hh>
# define oln_typename_shortcut__(Type, Alias) typename Type::Alias
@@ -52,6 +51,9 @@
// a
stc_decl_associated_type( adapted );
+ stc_decl_associated_type( argument );
+
+# define oln_argument(T) oln_typename_shortcut__(T, argument)
// b
stc_decl_associated_type( bkd_niter );
@@ -74,6 +76,9 @@
stc_decl_associated_type( dim );
stc_decl_associated_type( dpoint );
+# define oln_dim(T) oln_typename_shortcut__(T, dim)
+# define oln_dpoint(T) oln_typename_shortcut__(T, dpoint)
+
// f
stc_decl_associated_type( fwd_niter );
stc_decl_associated_type( fwd_piter );
@@ -86,6 +91,8 @@
// g
stc_decl_associated_type( grid );
+# define oln_grid(T) oln_typename_shortcut__(T, grid)
+
// i
stc_decl_associated_type( index );
@@ -144,5 +151,14 @@
+/// \{
+/// FIXME: Bad!
+
+# include <oln/core/init.hh>
+
+/// \}
+
+
+
#endif // ! OLN_CORE_EQUIPMENT_HH
Index: oln/core/gen/fun.hh
--- oln/core/gen/fun.hh (revision 887)
+++ oln/core/gen/fun.hh (working copy)
@@ -82,6 +82,9 @@
+ // ----------------------------- fun_p2b_<F>
+
+
// Fwd decl.
template <typename F> struct fun_p2b_;
@@ -114,6 +117,54 @@
};
+
+
+ // ----------------------------- fun_v2v_<F>
+
+
+ // Fwd decl.
+ template <typename F> struct fun_v2v_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename F>
+ struct set_category_of_< fun_v2v_<F> >
+ {
+ typedef stc::is< Function_v2v > ret;
+ };
+ }
+
+ // Class.
+ template <typename F>
+ struct fun_v2v_ : public Function_v2v< fun_v2v_<F> >
+ {
+ typedef oln_arg_of_(F) argument;
+ typedef oln_res_of_(F) result;
+
+ fun_v2v_(F f) : f_(f) {}
+
+ result operator()(argument arg) const
+ {
+ return this->f_(arg);
+ }
+
+ private:
+ F f_;
+ };
+
+
+ // functorize_v2v
+ template <typename R, typename A>
+ fun_v2v_<R (*)(A)>
+ functorize_v2v(R (*f)(A))
+ {
+ fun_v2v_<R (*)(A)> tmp(f);
+ return tmp;
+ }
+
+
+
} // end of namespace oln
Index: oln/core/internal/point_base.hh
--- oln/core/internal/point_base.hh (revision 887)
+++ oln/core/internal/point_base.hh (working copy)
@@ -57,7 +57,7 @@
typedef stc_deferred(grid) grid__;
// Final:
- typedef stc::final<typename grid__::dim> dim; // FIXME: Propagate this kind of
changes.
+ typedef stc::final< oln_dim(grid__) > dim;
typedef stc::final< stc::is<Point> > category;
};
Index: oln/core/internal/dpoint_base.hh
--- oln/core/internal/dpoint_base.hh (revision 887)
+++ oln/core/internal/dpoint_base.hh (working copy)
@@ -54,7 +54,7 @@
typedef stc::abstract grid;
typedef stc_deferred(grid) grid__;
- typedef stc::final<stc_type(grid__, dim)> dim;
+ typedef stc::final< oln_dim(grid__) > dim;
typedef stc::abstract coord;
typedef stc::abstract point; // FIXME: Just like in point_base.hh
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 887)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -59,9 +59,8 @@
typedef stc_deferred(fwd_piter) fwd_piter__;
typedef stc::final< stc::is<Point_Set> > category;
-
typedef stc::final< box_<point__> > box;
- typedef stc::final<stc_type(point__, grid)> grid;
+ typedef stc::final< oln_grid(point__) > grid;
typedef stc::final<fwd_piter__> piter;
};
@@ -117,7 +116,7 @@
{
typedef oln_strip_(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
- mlc::assert_equal_< P_, typename S::point >::check();
+ mlc::assert_equal_< P_, oln_point(S) >::check();
op_<const S, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(lhs), f);
return tmp;
}
Index: oln/core/internal/window_base.hh
--- oln/core/internal/window_base.hh (revision 887)
+++ oln/core/internal/window_base.hh (working copy)
@@ -58,7 +58,7 @@
typedef stc_deferred(point) point__;
typedef stc_deferred(fwd_qiter) fwd_qiter__;
- typedef stc::final< stc_type(point__, grid) > grid;
+ typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< fwd_qiter__ > qiter;
};
Index: oln/core/internal/neighborhood_base.hh
--- oln/core/internal/neighborhood_base.hh (revision 887)
+++ oln/core/internal/neighborhood_base.hh (working copy)
@@ -55,7 +55,7 @@
typedef stc::abstract point;
typedef stc_deferred(point) point__;
- typedef stc::final< stc_type(point__, grid) > grid;
+ typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< stc::is<Neighborhood> > category;
};
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 887)
+++ oln/core/internal/image_base.hh (working copy)
@@ -149,10 +149,10 @@
typedef stc::final< stc::is<Image> > category;
typedef stc::final< box_<point__> > box;
- typedef stc::final< stc_type(point__, grid) > grid;
- typedef stc::final< stc_type(point__, dpoint) > dpoint;
- typedef stc::final< typename pset__::fwd_piter > fwd_piter;
- typedef stc::final< typename pset__::bkd_piter > bkd_piter;
+ typedef stc::final< oln_grid(point__) > grid;
+ typedef stc::final< oln_dpoint(point__) > dpoint;
+ typedef stc::final< oln_fwd_piter(pset__) > fwd_piter;
+ typedef stc::final< oln_bkd_piter(pset__) > bkd_piter;
typedef fwd_piter piter;
};
@@ -432,7 +432,6 @@
// init
-
template <typename P, typename I>
bool init_(box_<P>* this_, const internal::image_base_<I>& data);