921: Enforce impl check in concepts.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Enforce impl check in concepts. * oln/core/rle/rle_pset.hh (box, impl_bbox): Fix. * oln/core/concept/iterator_on_points.hh, * oln/core/concept/generator.hh, * oln/core/concept/point.hh, * oln/core/concept/iterator.hh, * oln/core/concept/dpoint.hh, * oln/core/concept/point_set.hh (check__): New. * oln/core/gen/literal.hh (operator()): Use typedefs. * oln/core/internal/f_pset_plain.hh (box2d) : Fix. * oln/draw/bresenham.hh (fill): Move overload with values to... * oln/level/fill.hh: ...this new file. * oln/debug/fill.hh: New; extracted from oln/level/fill.hh. * oln/level/paste.hh; New. core/concept/dpoint.hh | 23 +++++++++- core/concept/generator.hh | 10 ++++ core/concept/iterator.hh | 19 ++++++++ core/concept/iterator_on_points.hh | 18 +++++++- core/concept/point.hh | 20 ++++++++ core/concept/point_set.hh | 15 ++++-- core/gen/literal.hh | 6 +- core/internal/f_pset_plain.hh | 9 ++-- core/rle/rle_pset.hh | 8 +-- debug/fill.hh | 61 +++++++++++++++++++++++++++ draw/bresenham.hh | 5 ++ level/fill.hh | 72 ++++++++++++-------------------- level/paste.hh | 83 +++++++++++++++++++++++++++++++++++++ 13 files changed, 284 insertions(+), 65 deletions(-) Index: oln/debug/fill.hh --- oln/debug/fill.hh (revision 0) +++ oln/debug/fill.hh (revision 0) @@ -0,0 +1,61 @@ +// 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_DEBUG_FILL_HH +# define OLN_DEBUG_FILL_HH + +# include <oln/core/concept/image.hh> + + +namespace oln +{ + + namespace debug + { + + template <typename I, typename V> + void fill(Mutable_Image<I>& input, const V values[]); + + +# ifndef OLN_INCLUDE_ONLY + + template <typename I> + void fill(Mutable_Image<I>& input, const oln_value(I)& value) + { + oln_piter(I) p(input.points()); + for_all(p) + input(p) = value; + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::debug + +} // end of namespace oln + + +#endif // ! OLN_DEBUG_FILL_HH Index: oln/core/rle/rle_pset.hh --- oln/core/rle/rle_pset.hh (revision 920) +++ oln/core/rle/rle_pset.hh (working copy) @@ -32,13 +32,11 @@ # include <utility> # include <oln/core/rle/rle_psite.hh> - # include <oln/core/internal/point_set_base.hh> - # include <oln/core/internal/iterator_on_points_base.hh> - # include <oln/core/gen/fbbox.hh> + namespace oln { @@ -61,7 +59,7 @@ { typedef P point; - typedef gen_box<P> box; + typedef typename f_box_from_point_<P>::ret box; typedef rle_pset_fwd_piter_<P> fwd_piter; typedef rle_pset_bkd_piter_<P> bkd_piter; }; @@ -145,7 +143,7 @@ const typename rle_pset<P>::box& rle_pset<P>::impl_bbox() const { - return fb_; + return fb_.box(); } template <typename P> Index: oln/core/concept/iterator_on_points.hh --- oln/core/concept/iterator_on_points.hh (revision 920) +++ oln/core/concept/iterator_on_points.hh (working copy) @@ -50,12 +50,15 @@ point to_point() const; const point* point_adr() const; - // Default. + // Final. operator point() const; protected: Iterator_on_Points(); + private: + void check__() const; + }; // end of class oln::Iterator_on_Points<Exact> @@ -91,6 +94,17 @@ Iterator_on_Points<Exact>::Iterator_on_Points() { mlc::assert_< mlc_is_a(typename Iterator_on_Points<Exact>::point, Point) >::check(); + this->check__(); + } + + template <typename Exact> + void Iterator_on_Points<Exact>::check__() const + { + point (Exact::*impl_to_point_adr)() const = & Exact::impl_to_point; + impl_to_point_adr = 0; + const point* (Exact::*impl_point_adr_adr)() const = & Exact::impl_point_adr; + impl_point_adr_adr = 0; + // FIXME: & Exact::operator point... } template <typename Exact> @@ -99,7 +113,7 @@ return ostr << pit.to_point(); } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/generator.hh --- oln/core/concept/generator.hh (revision 920) +++ oln/core/concept/generator.hh (working copy) @@ -41,6 +41,9 @@ { protected: Generator(); + + private: + void check__() const; }; @@ -50,6 +53,13 @@ template <typename Exact> Generator<Exact>::Generator() { + this->check__(); + } + + template <typename Exact> + void Generator<Exact>::check__() const + { + // FIXME: Is it possible to check Exact's body? } # endif // ! OLN_INCLUDE_ONLY Index: oln/core/concept/iterator.hh --- oln/core/concept/iterator.hh (revision 920) +++ oln/core/concept/iterator.hh (working copy) @@ -54,6 +54,9 @@ protected: Iterator(); + private: + void check__() const; + }; // end of class oln::Iterator<Exact> @@ -88,9 +91,23 @@ template <typename Exact> Iterator<Exact>::Iterator() { + this->check__(); + } + + template <typename Exact> + void Iterator<Exact>::check__() const + { + void (Exact::*impl_start_adr)() = & Exact::impl_start; + impl_start_adr = 0; + void (Exact::*impl_next_adr)() = & Exact::impl_next; + impl_next_adr = 0; + void (Exact::*impl_invalidate_adr)() = & Exact::impl_invalidate; + impl_invalidate_adr = 0; + bool (Exact::*impl_is_valid_adr)() const = & Exact::impl_is_valid; + impl_is_valid_adr = 0; } -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/point.hh --- oln/core/concept/point.hh (revision 920) +++ oln/core/concept/point.hh (working copy) @@ -69,6 +69,9 @@ protected: Point(); + private: + void check__() const; + }; // end of oln::Point<Exact> @@ -158,12 +161,29 @@ template <typename Exact> Point<Exact>::Point() { + this->check__(); + // FIXME: Uncomment! // mlc::assert_defined_< oln_vtype(Exact, grid) >::check(); // mlc::assert_defined_< oln_vtype(Exact, dPoint) >::check(); // mlc::assert_defined_< oln_vtype(Exact, coord) >::check(); // mlc::assert_defined_< oln_vtype(Exact, dim) >::check(); } + template <typename Exact> + void Point<Exact>::check__() const + { + bool (Exact::*impl_op_equal_adr)(const Exact& rhs) const = & Exact::impl_op_equal_; + impl_op_equal_adr = 0; + bool (Exact::*impl_op_less_adr)(const Exact& rhs) const = & Exact::impl_op_less_; + impl_op_less_adr = 0; + Exact& (Exact::*impl_op_plus_equal_adr)(const dpoint& rhs) = & Exact::impl_op_plus_equal_; + impl_op_plus_equal_adr = 0; + Exact& (Exact::*impl_op_minus_equal_adr)(const dpoint& rhs) = & Exact::impl_op_minus_equal_; + impl_op_minus_equal_adr = 0; + dpoint (Exact::*impl_op_minus_adr)(const Exact& rhs) const = & Exact::impl_op_minus_; + impl_op_minus_adr = 0; + } + template <typename P> typename P::dpoint operator-(const Point<P>& lhs, const Point<P>& rhs) Index: oln/core/concept/dpoint.hh --- oln/core/concept/dpoint.hh (revision 920) +++ oln/core/concept/dpoint.hh (working copy) @@ -77,6 +77,9 @@ protected: Dpoint(); + private: + void check__() const; + }; // end of oln::Dpoint<Exact> @@ -158,6 +161,8 @@ template <typename Exact> Dpoint<Exact>::Dpoint() { + this->check__(); + // FIXME: Uncomment! // mlc::assert_defined_< oln_vtype(Exact, grid) >::check(); // mlc::assert_defined_< oln_vtype(Exact, point) >::check(); // mlc::assert_defined_< oln_vtype(Exact, coord) >::check(); @@ -165,6 +170,22 @@ } + template <typename Exact> + void Dpoint<Exact>::check__() const + { + bool (Exact::*impl_op_equal_adr)(const Exact& rhs) const = & Exact::impl_op_equal_; + impl_op_equal_adr = 0; + bool (Exact::*impl_op_less_adr)(const Exact& rhs) const = & Exact::impl_op_less_; + impl_op_less_adr = 0; + Exact& (Exact::*impl_op_plus_equal_adr)(const Exact& rhs) = & Exact::impl_op_plus_equal_; + impl_op_plus_equal_adr = 0; + Exact& (Exact::*impl_op_minus_equal_adr)(const Exact& rhs) = & Exact::impl_op_minus_equal_; + impl_op_minus_equal_adr = 0; + Exact (Exact::*impl_op_unary_minus_adr)() const = & Exact::impl_op_unary_minus_; + impl_op_unary_minus_adr = 0; + } + + /// \{ /// Operators. @@ -184,7 +205,7 @@ /// \} -# endif +# endif // ! OLN_INCLUDE_ONLY } // end of namespace oln Index: oln/core/concept/point_set.hh --- oln/core/concept/point_set.hh (revision 920) +++ oln/core/concept/point_set.hh (working copy) @@ -59,7 +59,9 @@ protected: Point_Set(); - ~Point_Set(); + + private: + void check__() const; }; // end of oln::Point_Set<Exact> @@ -115,13 +117,18 @@ template <typename Exact> Point_Set<Exact>::Point_Set() { + this->check__(); } template <typename Exact> - Point_Set<Exact>::~Point_Set() + void Point_Set<Exact>::check__() const { - // FIXME: check method impls. - // unsigned (Exact::*m)() const = & Exact::impl_npoints; + unsigned (Exact::*impl_npoints_adr)() const = & Exact::impl_npoints; + impl_npoints_adr = 0; + bool (Exact::*impl_has_adr)(const point& p) const = & Exact::impl_has; + impl_has_adr = 0; + const box& (Exact::*impl_bbox_adr)() const = & Exact::impl_bbox; + impl_bbox_adr = 0; } template <typename Exact> Index: oln/core/gen/literal.hh --- oln/core/gen/literal.hh (revision 920) +++ oln/core/gen/literal.hh (working copy) @@ -47,16 +47,16 @@ template <typename T> struct literal_ : public Generator< literal_<T> > { - typedef T result; + typedef const T& result; literal_(const T& val) : val_(val) {} - const result& operator()() const + result operator()() const { return this->val_; } - const result& value() const + result value() const { return this->val_; } Index: oln/core/internal/f_pset_plain.hh --- oln/core/internal/f_pset_plain.hh (revision 920) +++ oln/core/internal/f_pset_plain.hh (working copy) @@ -38,9 +38,10 @@ { // Fwd decls. - struct grid2d_rec; + struct grid2d; template <typename P> class box_; - typedef box_<point2d> box2d; + class box2d; + template <typename T> class image2d; template <typename T> class image2d_b; @@ -51,9 +52,9 @@ struct f_pset_plain__; template <typename T> - struct f_pset_plain__< grid2d_rec, box2d, T > + struct f_pset_plain__< grid2d, box2d, T > { - typedef image2d_b<T> ret; + typedef image2d/*_b*/<T> ret; // FIXME: this type is not always known! }; template <typename Ps, typename T> Index: oln/draw/bresenham.hh --- oln/draw/bresenham.hh (revision 920) +++ oln/draw/bresenham.hh (working copy) @@ -31,6 +31,8 @@ # include <oln/core/concept/image.hh> # include <oln/core/gen/safe_image.hh> # include <oln/core/2d/line2d.hh> +# include <oln/core/gen/single_value_image.hh> +// # include <oln/level/paste.hh> @@ -60,6 +62,9 @@ { line2d l(begin, end); safe_image<I> input_(input); +// // FIXME: rec pb. +// single_value_image<typename I::pset, oln_value(I)> tmp(input.points(), value); +// level::paste((tmp | l), input); typename line2d::piter p(l); // FIXME: Generalize with an 'assign' routine... for_all(p) input_(p) = value; Index: oln/level/fill.hh --- oln/level/fill.hh (revision 920) +++ oln/level/fill.hh (working copy) @@ -49,27 +49,24 @@ namespace level { - /// Fwd decls. + // Fwd decls. template <typename I> - void fill(Mutable_Image<I>& input, const oln_value(I)& value); - - template <typename I, typename V> - void fill(Mutable_Image<I>& input, const V values[]); + void fill(Mutable_Image<I>& target, /* with */ const oln_value(I)& value); template <typename I, typename J> - void fill(Mutable_Image<I>& input, const Image<J>& ima); + void fill(Mutable_Image<I>& target, /* with */ const Image<J>& data); template <typename I, typename F> - void fill(Mutable_Image<I>& input, const Function_p2v<F>& fun); + void fill(Mutable_Image<I>& target, /* with */ const Function_p2v<F>& fun); template <typename I, typename V, typename P> - void fill(Mutable_Image<I>& input, V (*fun)(P)); + void fill(Mutable_Image<I>& target, /* with */ V (*fun)(P)); // FIXME: Inactivated. // template <typename I> -// void fill(Value_Wise_Mutable_Image<I>& input, const oln_value(I)& value); +// void fill(Value_Wise_Mutable_Image<I>& target, const oln_value(I)& value); # ifndef OLN_INCLUDE_ONLY @@ -79,45 +76,36 @@ { template <typename I> - void fill_from_value_(Mutable_Image<I>& input, const oln_value(I)& value) - { - oln_piter(I) p(input.points()); - for_all(p) - input(p) = value; - } - - template <typename I, typename V> - void fill_from_values_(Mutable_Image<I>& input, const V values[]) + void fill_from_value_(Mutable_Image<I>& target, const oln_value(I)& value) { - oln_piter(I) p(input.points()); - unsigned i = 0; + oln_piter(I) p(target.points()); for_all(p) - input(p) = values[i++]; + target(p) = value; } template <typename I, typename J> - void fill_from_image_(Mutable_Image<I>& input, const Image<J>& ima) + void fill_from_image_(Mutable_Image<I>& target, const Image<J>& data) { - oln_piter(I) p(input.points()); + oln_piter(I) p(target.points()); for_all(p) - input(p) = ima(p); + target(p) = data(p); } template <typename I, typename F> - void fill_from_function_(Mutable_Image<I>& input, const F& f) + void fill_from_function_(Mutable_Image<I>& target, const F& f) { - oln_piter(I) p(input.points()); + oln_piter(I) p(target.points()); for_all(p) - input(p) = f(p); + target(p) = f(p); } // template <typename I> -// void fill_(Value_Wise_Mutable_Image<I>& input, +// void fill_(Value_Wise_Mutable_Image<I>& target, // const oln_value(I)& value) // { -// oln_viter(I) v(input); +// oln_viter(I) v(target); // for_all(v) -// input.value_(v) = value; +// target.value_(v) = value; // } } // end of namespace oln::level::impl @@ -127,36 +115,30 @@ /// Facades. template <typename I> - void fill(Mutable_Image<I>& input, const oln_value(I)& value) - { - impl::fill_from_value_(exact(input), value); - } - - template <typename I, typename V> - void fill(Mutable_Image<I>& input, const V values[]) + void fill(Mutable_Image<I>& target, const oln_value(I)& value) { - impl::fill_from_values_(exact(input), values); + impl::fill_from_value_(exact(target), value); } template <typename I, typename J> - void fill(Mutable_Image<I>& input, const Image<J>& ima) + void fill(Mutable_Image<I>& target, const Image<J>& data) { assert_same_grid_<I, J>::check(); - precondition(input.points() <= ima.points()); - impl::fill_from_image_(exact(input), exact(ima)); + precondition(target.points() <= data.points()); + impl::fill_from_image_(exact(target), exact(data)); } template <typename I, typename F> - void fill(Mutable_Image<I>& input, const Function_p2v<F>& fun) + void fill(Mutable_Image<I>& target, const Function_p2v<F>& fun) { - impl::fill_from_function_(exact(input), exact(fun)); + impl::fill_from_function_(exact(target), exact(fun)); } template <typename I, typename V, typename P> - void fill(Mutable_Image<I>& input, V (*f)(P)) + void fill(Mutable_Image<I>& target, V (*f)(P)) { mlc::assert_< mlc_is_a(P, Point) >::check(); // FIXME: Add err msg. - impl::fill_from_function_(exact(input), functorize_p2v(f)); + impl::fill_from_function_(exact(target), functorize_p2v(f)); } # endif // ! OLN_INCLUDE_ONLY Index: oln/level/paste.hh --- oln/level/paste.hh (revision 0) +++ oln/level/paste.hh (revision 0) @@ -0,0 +1,83 @@ +// 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_LEVEL_PASTE_HH +# define OLN_LEVEL_PASTE_HH + +# include <oln/core/concept/image.hh> + + +namespace oln +{ + + namespace level + { + + // Fwd decl. + + template <typename I, typename J> + void paste(const Image<I>& data, /* in */ Mutable_Image<J>& destination); + + +# ifndef OLN_INCLUDE_ONLY + + namespace impl + { + + // Generic version. + + template <typename I, typename J> + void paste_(const Image<I>& data, Mutable_Image<J>& destination) + { + oln_piter(I) p(data.points()); + for_all(p) + destination(p) = data(p); + } + + // FIXME: Fast version... + + } // end of namespace oln::level::impl + + + // Facade. + + template <typename I, typename J> + void paste(const Image<I>& data, Mutable_Image<J>& destination) + { + assert_same_grid_<I, J>::check(); + precondition(data.points() <= destination.points()); + impl::paste_(exact(data), exact(destination)); + } + +# endif // ! OLN_INCLUDE_ONLY + + } // end of namespace oln::level + +} // end of namespace oln + + +#endif // ! OLN_LEVEL_PASTE_HH
participants (1)
-
Thierry Geraud