Commit 90e0d7ac authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Make the trait solver rely on category inheritance.

	Fix image_if related-classes.
	
	* mln/core/image_if.hh,
	* mln/core/internal/image_if_base.hh,
	* mln/core/image_if_value.hh: Fix.
	* mln/labeling/estimate.hh: Update.
	* tests/image_if_value.cc: New.

	Make float01[_] work on float!
	
	* mln/value/float01_.hh,
	* mln/value/float01.hh: Fix.

	
	Enhance the trait solver mechanism; now it can rely
	on category inheritance :-)
	
	* mln/core/concept/image.hh,
	* mln/core/concept/function.hh,
	* mln/core/concept/meta_accumulator.hh,
	* mln/core/concept/value_set.hh,
	* mln/core/concept/weighted_window.hh,
	* mln/core/concept/browsing.hh,
	* mln/core/concept/dpoint.hh,
	* mln/core/concept/object.hh,
	* mln/core/concept/neighborhood.hh,
	* mln/core/concept/window.hh,
	* mln/core/concept/value.hh,
	* mln/core/concept/point_site.hh,
	* mln/core/concept/accumulator.hh: Specialize the category flag.
	(super): New in those specializations.

	
	Update.
	
	* tests/trait_op_uminus.cc: New.
	* tests/core_category.cc: New.
	* tests/trait_op_plus.cc: Augment.
	* mln/trait/op_plus.hh (set_binary_): Set category.
	* mln/trait/promote.hh: Likewise.
	* mln/trait/op_uminus.hh: Likewise.
	* mln/trait/solve.hh: Augment.
	* mln/trait/all.hh: Typo.
	* mln/core/category.hh (Unknown<void>): New.
	(Built_In): Move into...
	* mln/value/builtin.hh: ...this new file.
	* mln/core/ops.hh: Include builtin.hh.


	Misc.

	* mln/core/internal/exact.hh: Remove useless param.
	* mln/value/graylevel.hh: Fix.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1222 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent c7d6efbc
2007-10-02 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Make the trait solver rely on category inheritance.
Fix image_if related-classes.
* mln/core/image_if.hh,
* mln/core/internal/image_if_base.hh,
* mln/core/image_if_value.hh: Fix.
* mln/labeling/estimate.hh: Update.
* tests/image_if_value.cc: New.
Make float01[_] work on float!
* mln/value/float01_.hh,
* mln/value/float01.hh: Fix.
Enhance the trait solver mechanism; now it can rely
on category inheritance :-)
* mln/core/concept/image.hh,
* mln/core/concept/function.hh,
* mln/core/concept/meta_accumulator.hh,
* mln/core/concept/value_set.hh,
* mln/core/concept/weighted_window.hh,
* mln/core/concept/browsing.hh,
* mln/core/concept/dpoint.hh,
* mln/core/concept/object.hh,
* mln/core/concept/neighborhood.hh,
* mln/core/concept/window.hh,
* mln/core/concept/value.hh,
* mln/core/concept/point_site.hh,
* mln/core/concept/accumulator.hh: Specialize the category flag.
(super): New in those specializations.
Update.
* tests/trait_op_uminus.cc: New.
* tests/core_category.cc: New.
* tests/trait_op_plus.cc: Augment.
* mln/trait/op_plus.hh (set_binary_): Set category.
* mln/trait/promote.hh: Likewise.
* mln/trait/op_uminus.hh: Likewise.
* mln/trait/solve.hh: Augment.
* mln/trait/all.hh: Typo.
* mln/core/category.hh (Unknown<void>): New.
(Built_In): Move into...
* mln/value/builtin.hh: ...this new file.
* mln/core/ops.hh: Include builtin.hh.
Misc.
* mln/core/internal/exact.hh: Remove useless param.
* mln/value/graylevel.hh: Fix.
2007-10-02 Matthieu Garrigues <garrigues@lrde.epita.fr>
Better tests on float01.
......
......@@ -43,6 +43,20 @@ namespace mln
struct Unknown;
template <>
struct Unknown<void>
{
typedef Unknown<void> super;
// Unknown is used to terminate the meta-program that solves a
// call to a trait. This meta-program can browse several branches
// at the same time---if the trait takes 2 types as arguments, the
// program runs over the trellis formed by the "couples of
// categories"--- and when the end of one branch is reached, we do
// not want the program to end; so it continues on that branch
// with the no-op "jump to the super type of Unknown"!
};
template <typename T>
struct category
{
......@@ -50,17 +64,6 @@ namespace mln
};
// The case of built-in types.
template <typename E>
struct Built_In;
template <> struct category< int > { typedef Built_In<void> ret; };
template <> struct category< float > { typedef Built_In<void> ret; };
template <> struct category< double > { typedef Built_In<void> ret; };
// FIXME: ...
} // end of namespace mln
......
......@@ -41,6 +41,16 @@
namespace mln
{
// Fwd decl.
template <typename E> struct Accumulator;
// Accumulator category flag type.
template <>
struct Accumulator<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation of accumulators.
*
......
......@@ -38,6 +38,17 @@
namespace mln
{
// Fwd decl.
template <typename E> struct Browsing;
// Browsing category flag type.
template <>
struct Browsing<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation classes that are browsings.
*
* \see mln::doc::Browsing for a complete documentation of this
......
......@@ -39,6 +39,16 @@
namespace mln
{
// Fwd decl.
template <typename E> struct Dpoint;
// Dpoint category flag type.
template <>
struct Dpoint<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation of delta-point classes.
*
......
......@@ -39,6 +39,16 @@
namespace mln
{
// Fwd decl.
template <typename E> struct Function;
// Function category flag type.
template <>
struct Function<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation of function-objects.
*
......
......@@ -48,6 +48,16 @@ namespace mln
{
// Fwd decl.
template <typename E> struct Image;
// Image category flag type.
template <>
struct Image<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation of image classes.
*
......
......@@ -49,6 +49,16 @@ typename A::template with< T >::ret::result
namespace mln
{
// Fwd decl.
template <typename E> struct Meta_Accumulator;
// Meta_Accumulator category flag type.
template <>
struct Meta_Accumulator<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation of meta accumulators.
*
......
......@@ -38,6 +38,17 @@
namespace mln
{
// Fwd decl.
template <typename E> struct Neighborhood;
// Neighborhood category flag type.
template <>
struct Neighborhood<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation classes that are neighborhoods.
*
* \see mln::doc::Neighborhood for a complete documentation of this
......
......@@ -37,6 +37,7 @@
# include <iostream>
# include <mln/core/macros.hh>
# include <mln/core/category.hh>
# include <mln/core/contract.hh>
# include <mln/core/internal/fixme.hh>
# include <mln/trace/all.hh>
......@@ -59,6 +60,17 @@
namespace mln
{
// Fwd decl.
template <typename E> struct Object;
// Object category flag type.
template <>
struct Object<void>
{
typedef Unknown<void> super;
};
/*! \brief Base class for almost every class defined in milena.
*
* The parameter \a E is the exact type.
......
......@@ -38,10 +38,19 @@
namespace mln
{
// Fwd decl (used in the "category" definition).
template <typename P> struct Point;
// FIXME: Hack is "Point" instead of "Points_Site"; change it!
// Fwd decl.
template <typename E> struct Point;
// Point_Site category flag type.
template <>
struct Point<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation classes of the notion of
* "point site".
......
......@@ -38,6 +38,17 @@
namespace mln
{
// Fwd decl.
template <typename E> struct Value;
// Value category flag type.
template <>
struct Value<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation classes of values.
*
* \see mln::doc::Value for a complete documentation of this class
......@@ -96,6 +107,7 @@ namespace mln
# include <mln/value/cast.hh>
# include <mln/value/builtin.hh>
#endif // ! MLN_CORE_CONCEPT_VALUE_HH
......@@ -32,12 +32,23 @@
* \brief Definition of the concept of mln::Value_Set.
*/
# include <mln/core/concept/value_iterator.hh>
# include <mln/core/concept/value_iterator.hh> // FIXME: Why not object.hh?
namespace mln
{
// Fwd decl.
template <typename E> struct Value_Set;
// Value_Set category flag type.
template <>
struct Value_Set<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation classes of sets of values.
*
* \see mln::doc::Value_Set for a complete documentation of this
......
......@@ -40,6 +40,17 @@
namespace mln
{
// Fwd decl.
template <typename E> struct Weighted_Window;
// Weighted_Window category flag type.
template <>
struct Weighted_Window<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation classes that are
* weighted_windows.
*
......
......@@ -39,6 +39,16 @@
namespace mln
{
// Fwd decl.
template <typename E> struct Window;
// Window category flag type.
template <>
struct Window<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation classes that are windows.
*
......
......@@ -35,17 +35,51 @@
# include <mln/core/internal/image_if_base.hh>
# define Super mln::internal::image_if_base_< I, F, image_if<I,F> >
namespace mln
{
// Fwd decl.
template <typename I, typename F> struct image_if;
// internal::data_.
namespace internal
{
template <typename I, typename F>
struct data_< image_if<I,F> > : data_< Super >
{
data_(I& ima, const F& f);
};
} // end of namespace mln::internal
namespace trait
{
template <typename I, typename F>
struct image_< image_if<I,F> > : trait::image_< Super >
{
};
} // end of namespace mln::trait
/*! \brief An image class FIXME.
*
*/
template <typename I, typename F>
struct image_if : public internal::image_if_base< I, F >
struct image_if : public Super
{
/// Skeleton.
typedef image_if< tag::image_<I>, F > skeleton;
typedef image_if< tag::image_<I>, tag::function_<F> > skeleton;
/// Constructor from an image \p ima and a predicate \p f.
image_if(I& ima, const F& f);
......@@ -58,6 +92,25 @@ namespace mln
};
// init_.
template <typename I, typename F>
void init_(tag::function_t, F& f, const image_if<I,F>& model)
{
f = model.domain().predicate();
}
template <typename I, typename F, typename J>
void init_(tag::image_t, image_if<I,F>& target, const J& model)
{
I ima;
init_(tag::image, ima, exact(model));
F f;
init_(tag::function, f, exact(model));
target.init_(ima, f);
}
// Operators.
// Image | Function_p2b.
......@@ -73,6 +126,19 @@ namespace mln
# ifndef MLN_INCLUDE_ONLY
// internal::data_
namespace internal
{
template <typename I, typename F>
data_< image_if<I,F> >::data_(I& ima, const F& f)
: data_< Super >(ima, f)
{
}
}
// image_if<I,F>
template <typename I, typename F>
......@@ -89,7 +155,9 @@ namespace mln
template <typename I, typename F>
image_if<I,F>::operator image_if<const I,F>() const
{
image_if<const I,F> tmp(this->data_->ima_, this->data_->pset_);
mln_precondition(this->has_data());
image_if<const I,F> tmp(this->data_->ima_,
this->data_->pset_.predicate());
return tmp;
}
......@@ -116,4 +184,7 @@ namespace mln
} // end of namespace mln
# undef Super
#endif // ! MLN_CORE_IMAGE_IF_HH
......@@ -34,85 +34,164 @@
*/
# include <mln/core/internal/image_if_base.hh>
# include <mln/metal/unconst.hh>
# define F fun::eq_p2b_expr_< pw::value_<mlc_unconst(I)>, pw::cst_<mln_value(I)> >
# define Super mln::internal::image_if_base_< I, F, image_if_value<I> >
namespace mln
{
// Fwd decl.
template <typename I> struct image_if_value;
// internal::data_.
namespace internal
{
template <typename I>
struct data_< image_if_value<I> > : data_< Super >
{
data_(I& ima, const F& f);
};
} // end of namespace mln::internal
namespace trait
{
template <typename I>
struct image_< image_if_value<I> > : trait::image_< Super >
{
};
} // end of namespace mln::trait
/*! \brief An image class FIXME.
*
*/
template <typename I, typename F>
struct image_if_value : public internal::image_if_base< I, F >
template <typename I>
struct image_if_value : public Super
{
/// Skeleton.
typedef image_if_value< tag::image_<I>, tag::function_<F> > skeleton;
typedef image_if_value< tag::image_<I> > skeleton;
/// Natural constructor from an image \p ima and a value \p v.
image_if_value(I& ima, const mln_value(I)& v);
/// Constructor from an image \p ima and a predicate \p f.
/// Ancestral constructor from an image \p ima and a function \p f.
image_if_value(I& ima, const F& f);
/// Constructor without argument.
image_if_value();
/// Const promotion via convertion.
operator image_if_value<const I, F>() const;
// FIXME: Conversion below does *not* work automatically.
/// Const promotion via conversion.
operator image_if_value<const I> () const;
};
// init_.
template <typename I>
void init_(tag::function_t, F& f, const image_if_value<I>& model)
{
f = model.domain().predicate();
}
template <typename I, typename J>
void init_(tag::image_t, image_if_value<I>& target, const J& model)
{
I ima;
init_(tag::image, ima, exact(model));
F f;
init_(tag::function, f, exact(model));
target.init_(ima, f);
}
// Operators.
// Image | value.
template <typename I>
image_if_value< I,
fun::eq_p2b_expr_< pw::value_<I>,
pw::cst_<mln_value(I)> > >
image_if_value<I>
operator | (Image<I>& ima, const mln_value(I)& v);
template <typename I>
image_if_value< const I,
fun::eq_p2b_expr_< pw::value_<I>,
pw::cst_<mln_value(I)> > >
image_if_value<const I>
operator | (const Image<I>& ima, const mln_value(I)& v);
# ifndef MLN_INCLUDE_ONLY
// image_if_value<I,F>
// image_if_value<I>
template <typename I, typename F>
image_if_value<I,F>::image_if_value()
template <typename I>
image_if_value<I>::image_if_value()
{
}
template <typename I, typename F>
image_if_value<I,F>::image_if_value(I& ima, const F& f)
template <typename I>
image_if_value<I>::image_if_value(I& ima, const F& f)
{
this->init_(ima, f);
}
template <typename I, typename F>
image_if_value<I,F>::operator image_if_value<const I, F>() const
template <typename I>
image_if_value<I>::image_if_value(I& ima, const mln_value(I)& v)
{
image_if_value<const I, F> tmp(this->data_->ima_, this->data_->pset_);
this->init_(ima, pw::value(ima) == pw::cst(v));
}