cleanup-2008 2474: Make tutorial examples compile.

https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Make tutorial examples compile. * doc/tutorial/examples/image_safe.cc: Fix missing update. * mln/core/site_set/p_priority.hh (q_type_): New. Use it instead of explicit type name, so fix bugs. * mln/core/image/safe.hh (init_): Remove extra overload, so fix bug in this method presence checking. * mln/convert/from_to.hh: Move overload vec->Gpoint... * mln/core/concept/gpoint.hh: ...here. (from_to): New overload for Gpoint->vec. * mln/convert/from_to.hxx: Update. * mln/core/window.hh (delta_): New. (delta): Fix the case where D is a delta-index. * mln/border/fill.hh: Fix warning. * mln/util/dindex.hh (literal::zero): Handle constructor and assignment. (literal::one): Likewise. doc/tutorial/examples/image_safe.cc | 2 - mln/border/fill.hh | 3 +- mln/convert/from_to.hh | 16 +------------- mln/convert/from_to.hxx | 5 ++++ mln/core/concept/gpoint.hh | 33 ++++++++++++++++++++++++++++++ mln/core/image/safe.hh | 10 --------- mln/core/site_set/p_priority.hh | 10 +++++---- mln/core/window.hh | 27 +++++++++++++++++++++--- mln/util/dindex.hh | 39 +++++++++++++++++++++++++++++++++--- 9 files changed, 108 insertions(+), 37 deletions(-) Index: doc/tutorial/examples/image_safe.cc --- doc/tutorial/examples/image_safe.cc (revision 2473) +++ doc/tutorial/examples/image_safe.cc (working copy) @@ -1,5 +1,5 @@ # include <mln/core/image/image2d.hh> -# include <mln/core/site_set/line2d.hh> +# include <mln/core/site_set/p_line2d.hh> # include <mln/core/image/safe.hh> # include <mln/debug/println.hh> # include <mln/level/fill.hh> Index: mln/core/site_set/p_priority.hh --- mln/core/site_set/p_priority.hh (revision 2473) +++ mln/core/site_set/p_priority.hh (working copy) @@ -177,8 +177,10 @@ protected: + typedef std::map<P, Q, util::ord<P> > q_type_; + util::set<P> p_; - std::map<P, Q, util::ord<P> > q_; + q_type_ q_; unsigned n_; // Run invariance tests and return the result. @@ -308,7 +310,7 @@ { mln_invariant(run_()); std::size_t mem_q = 0; - typename std::map<P, Q>::const_iterator i; + typename q_type_::const_iterator i; for (i = q_.begin(); i != q_.end(); ++i) mem_q += i->second.memory_size(); return p_.memory_size() + sizeof(q_) + sizeof(n_); @@ -322,7 +324,7 @@ static const Q nil_ = Q(); if (exists_priority(priority)) // Also test invariants. { - std::map<P,Q>& mq = const_cast<std::map<P,Q>&>(q_); + q_type_& mq = const_cast<q_type_&>(q_); mln_assertion(mq[priority].nsites() > 0); return mq[priority]; } @@ -380,7 +382,7 @@ p_priority<P,Q>::set_2_(const P& priority) const { mln_precondition(p_.has(priority)); - std::map<P,Q>& mq = const_cast<std::map<P,Q>&>(q_); + q_type_& mq = const_cast<q_type_&>(q_); mln_precondition(mq[priority].nsites() > 0); return mq[priority]; } Index: mln/core/image/safe.hh --- mln/core/image/safe.hh (revision 2473) +++ mln/core/image/safe.hh (working copy) @@ -94,7 +94,6 @@ safe_image(I& ima, const mln_value(I)& default_value); // Initialize an empty image. - void init_(I& ima); void init_(I& ima, const mln_value(I)& default_value); mln_rvalue(I) operator()(const mln_psite(I)& p) const; @@ -161,15 +160,6 @@ template <typename I> inline void - safe_image<I>::init_(I& ima) - { - mln_precondition(ima.has_data()); - this->data_ = new internal::data< safe_image<I> >(ima, mln_value(I)()); - } - - template <typename I> - inline - void safe_image<I>::init_(I& ima, const mln_value(I)& default_value) { mln_precondition(ima.has_data()); Index: mln/core/concept/gpoint.hh --- mln/core/concept/gpoint.hh (revision 2473) +++ mln/core/concept/gpoint.hh (working copy) @@ -36,6 +36,7 @@ # include <mln/core/concept/site.hh> # include <mln/core/concept/gdpoint.hh> # include <mln/value/concept/scalar.hh> +# include <mln/algebra/vec.hh> # include <mln/util/ord.hh> @@ -120,6 +121,14 @@ void from_to(const Gpoint<P>& from, mln_delta(P)& to); + template <typename P, unsigned n, typename T> + void + from_to(const Gpoint<P>& from, algebra::vec<n,T>& to); + + template <unsigned n, typename T, typename P> + void + from_to(const algebra::vec<n,T>& from, Gpoint<P>& to); + } // end of namespace::convert @@ -282,6 +291,7 @@ namespace convert { + // Gpoint -> delta template <typename P> inline void @@ -296,6 +306,29 @@ dp[i] = p[i]; } + // Gpoint -> algebra::vec. + template <typename P, unsigned n, typename T> + void + from_to(const Gpoint<P>& from_, algebra::vec<n,T>& to) + { + mlc_bool(n == P::dim)::check(); + const P& from = exact(from_); + for (unsigned i = 0; i < n; ++i) + to[i] = static_cast< T >(from[i]); // FIXME: cast -> best effort... + } + + // algebra::vec -> Gpoint. + template <unsigned n, typename T, typename P> + inline + void + from_to(const algebra::vec<n,T>& from, Gpoint<P>& to_) + { + mlc_bool(P::dim == n)::check(); + P& to = exact(to_); + for (unsigned i = 0; i < n; ++i) + to[i] = static_cast< typename P::coord >(from[i]); // FIXME: cast -> best effort... + } + } // end of namespace::convert Index: mln/core/window.hh --- mln/core/window.hh (revision 2473) +++ mln/core/window.hh (working copy) @@ -43,11 +43,13 @@ */ # include <mln/core/internal/window_base.hh> +# include <mln/core/concept/gdpoint.hh> # include <mln/metal/is_a.hh> # include <mln/util/set.hh> # include <mln/fun/i2v/all_to.hh> # include <mln/norm/linfty.hh> +# include <mln/literal/zero.hh> namespace mln @@ -181,6 +183,9 @@ private: util::set<D> dps_; + + unsigned delta_(int i) const; // For indices. + unsigned delta_(const Gdpoint<D>& dp) const; // For grids delta-points. }; @@ -221,8 +226,7 @@ bool window<D>::is_centered() const { - static const D origin = all_to(0); - return this->dps_.has(origin); // FIXME: Use literal::origin. + return this->dps_.has(literal::zero); } template <typename D> @@ -258,12 +262,11 @@ unsigned window<D>::delta() const { - // FIXME: Is-it correct? unsigned d = 0; const unsigned n = size(); for (unsigned i = 0; i < n; ++i) { - unsigned dd = norm::linfty(dp(i).to_vec()); + unsigned dd = delta_(dp(i)); if (dd > d) d = dd; } @@ -273,6 +276,22 @@ template <typename D> inline unsigned + window<D>::delta_(int i) const + { + return i; + } + + template <typename D> + inline + unsigned + window<D>::delta_(const Gdpoint<D>& dp) const + { + return norm::linfty(exact(dp).to_vec()); + } + + template <typename D> + inline + unsigned window<D>::size() const { return dps_.nelements(); Index: mln/border/fill.hh --- mln/border/fill.hh (revision 2473) +++ mln/border/fill.hh (working copy) @@ -67,9 +67,10 @@ template <typename I> inline - void fill_tests(const Image<I>& ima, const mln_value(I)& v) + void fill_tests(const Image<I>& ima, const mln_value(I)&) { mln_precondition(exact(ima).has_data()); + (void) ima; } } // end of namespace mln::border::internal Index: mln/convert/from_to.hh --- mln/convert/from_to.hh (revision 2473) +++ mln/convert/from_to.hh (working copy) @@ -32,8 +32,6 @@ * * \brief General conversion procedure between two objects. * - * \todo Use 'round' instead of static_cast in vec->Gpoint. - * * \todo Test the effectiveness of guards. * \todo Add fwd decls. * \todo Dispatch code in appropriate files. @@ -74,6 +72,7 @@ from_to(const int& from, Object<T>& to); + # ifndef MLN_INCLUDE_ONLY @@ -102,18 +101,6 @@ mln::convert::impl::from_image_to_site_set(from, to); } - // algebra::vec -> Gpoint. - template <unsigned n, typename T, typename P> - inline - void - from_to(const algebra::vec<n,T>& from, Gpoint<P>& to_) - { - mlc_bool(P::dim == n)::check(); - P& to = exact(to_); - for (unsigned i = 0; i < n; ++i) - to[i] = static_cast< typename P::coord >(from[i]); - } - // Value -> Value template <typename F, typename T> inline @@ -123,6 +110,7 @@ mln::convert::impl::from_value_to_value(from, to); } + // float -> Object template <typename T> inline Index: mln/convert/from_to.hxx --- mln/convert/from_to.hxx (revision 2473) +++ mln/convert/from_to.hxx (working copy) @@ -93,6 +93,11 @@ void from_to(const Image<I>& from, Site_Set<S>& to); + // Gpoint -> algebra::vec. + template <typename P, unsigned n, typename T> + void + from_to(const Gpoint<P>& from, algebra::vec<n,T>& to); + // algebra::vec -> Gpoint. template <unsigned n, typename T, typename P> void Index: mln/util/dindex.hh --- mln/util/dindex.hh (revision 2473) +++ mln/util/dindex.hh (working copy) @@ -38,6 +38,8 @@ */ # include <mln/util/index.hh> +# include <mln/literal/zero.hh> +# include <mln/literal/one.hh> namespace mln @@ -66,15 +68,46 @@ int i_; - dindex_() {} - dindex_(int i) : i_(i) {} + dindex_() + { + } + + dindex_(int i) + : i_(i) + { + } + + /// \{ Constructors/assignments with literals. + dindex_(const literal::zero_t&) + : i_(0) + { + } + dindex_<Tag>& operator=(const literal::zero_t&) + { + i_ = 0; + return *this; + } + + dindex_(const literal::one_t&) + : i_(1) + { + } + dindex_<Tag>& operator=(const literal::one_t&) + { + i_ = 1; + return *this; + } + /// \} bool operator<(const dindex_& rhs) const { return i_ < rhs.i_; } - operator int() const { return i_; } + operator int() const + { + return i_; + } }; typedef dindex_<void> dindex;
participants (1)
-
Thierry Geraud