https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
sandbox: psite/site refactorization: add the rle image type.
* sandbox/ballas/refactorization/test/rle.cc: New tests.
* sandbox/ballas/refactorization/p_run.hh,
* sandbox/ballas/refactorization/rle_pset.hh,
* sandbox/ballas/refactorization/rle_psite.hh,
* sandbox/ballas/refactorization/rle_image.hh: New, rle image type.
* sandbox/ballas/refactorization/internal/pset_base.hh,
* sandbox/ballas/refactorization/internal/image_base.hh,
* sandbox/ballas/refactorization/internal/piter_base.hh,
* sandbox/ballas/refactorization/internal/psite_base.hh,
* sandbox/ballas/refactorization/box2d.hh,
* sandbox/ballas/refactorization/point2d.hh: update
box2d.hh | 4
internal/image_base.hh | 9 +
internal/piter_base.hh | 27 ++--
internal/pset_base.hh | 25 +++
internal/psite_base.hh | 20 +--
p_run.hh | 286 +++++++++++++++++++++++++++++++++++++++++++++
point2d.hh | 13 ++
rle_image.hh | 118 ++++++++++++++++++
rle_pset.hh | 308 +++++++++++++++++++++++++++++++++++++++++++++++++
rle_psite.hh | 137 +++++++++++++++++++++
test/rle.cc | 41 ++++++
11 files changed, 962 insertions(+), 26 deletions(-)
Index: sandbox/ballas/refactorization/test/rle.cc
--- sandbox/ballas/refactorization/test/rle.cc (revision 0)
+++ sandbox/ballas/refactorization/test/rle.cc (revision 0)
@@ -0,0 +1,41 @@
+// # include <rle_pset.hh>
+# include <iostream>
+
+# include <point2d.hh>
+//# include <p_run.hh>
+//# include <rle_psite.hh>
+# include <rle_image.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef point2d<int> point;
+
+ point p1(5, 5), p2(12, 2), p3(7, 6);
+ p_run<point> prun1(p1, 5);
+ p_run<point> prun2(p2, 12);
+ p_run<point> prun3(p3, 4);
+
+ rle_pset<point> pset;
+// pset.insert(prun1);
+// pset.insert(prun2);
+// pset.insert(prun3);
+
+// rle_pset<point>::piter p(pset);
+// for (p.start(); p.is_valid(); p.next())
+// std::cout << (point) p << std::endl;
+
+ rle_image<point, int> ima;
+
+ ima.insert(prun1, 1);
+ ima.insert(prun2, 2);
+ ima.insert(prun3, 3);
+
+ rle_image<point, int>::piter p(ima.domain());
+ for (p.start(); p.is_valid(); p.next())
+ std::cout << ima(p) << std::endl;
+
+}
+
Index: sandbox/ballas/refactorization/p_run.hh
--- sandbox/ballas/refactorization/p_run.hh (revision 0)
+++ sandbox/ballas/refactorization/p_run.hh (revision 0)
@@ -0,0 +1,286 @@
+#ifndef P_RUN_HH_
+# define P_RUN_HH_
+
+# include <cstddef>
+# include <iostream>
+# include <internal/pset_base.hh>
+# include <internal/piter_base.hh>
+
+namespace mln
+{
+ // Fwd decls.
+ template <typename P> struct p_run_fwd_piter_;
+
+ template <typename P>
+ class p_run :
+ public internal::pset_base_< P, p_run<P> >
+ {
+ public:
+ typedef P site;
+ typedef P psite;
+
+ typedef p_run_fwd_piter_<P> fwd_piter;
+ typedef p_run_fwd_piter_<P> bkd_piter;
+ typedef fwd_piter piter;
+
+ p_run();
+ p_run(const P& start, std::size_t len);
+ void set_run(const P& start, std::size_t len);
+
+ bool owns_(const P& p) const;
+ std::size_t nsites() const;
+ std::size_t length() const;
+
+ P operator[](unsigned i) const;
+
+ const P& first() const;
+
+ protected:
+ P p_;
+ std::size_t len_;
+ bool is_valid_;
+ };
+
+ template <typename P>
+ std::ostream& operator<<(std::ostream& out, const p_run<P>&
pr);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ p_run<P>::p_run()
+ {
+ is_valid_ = false;
+ }
+
+ template <typename P>
+ inline
+ p_run<P>::p_run(const P& start, std::size_t len)
+ : p_(start),
+ len_(len)
+ {
+ assert(len != 0);
+ P p = start;
+// bb_.init();
+// bb_.take(p);
+// p[P::dim - 1] += len - 1;
+// bb_.take(p);
+ is_valid_ = true;
+ }
+
+ template <typename P>
+ inline
+ void
+ p_run<P>::set_run(const P& start, std::size_t len)
+ {
+ assert(len != 0);
+ p_ = start;
+ len_ = len;
+ P p = start;
+// bb_.init();
+// bb_.take(p);
+// p[P::dim - 1] += len - 1;
+// bb_.take(p);
+ is_valid_ = true;
+ }
+
+ template <typename P>
+ inline
+ bool
+ p_run<P>::owns_(const P& p) const
+ {
+ assert(is_valid_);
+ bool res = true;
+ for (int i = P::dim - 2; i >= 0; --i)
+ if (!(res = (res && p[i] == p_[i])))
+ return false;
+ return (p[P::dim - 1] >= p_[P::dim - 1]
+ && p[P::dim - 1] < p_[P::dim - 1] + (signed)len_);
+ }
+
+ template <typename P>
+ inline
+ std::size_t
+ p_run<P>::nsites() const
+ {
+ assert(is_valid_);
+ return len_;
+ }
+
+ template <typename P>
+ inline
+ std::size_t
+ p_run<P>::length() const
+ {
+ assert(is_valid_);
+ return len_;
+ }
+
+ template <typename P>
+ inline
+ P
+ p_run<P>::operator[](unsigned i) const
+ {
+ assert(is_valid_);
+ assert(i < nsites());
+ P p = p_;
+ p[P::dim - 1] += i;
+ return p;
+ }
+
+ template <typename P>
+ inline
+ const P&
+ p_run<P>::first() const
+ {
+ return p_;
+ }
+
+
+ template <typename P>
+ std::ostream&
+ operator<<(std::ostream& out, const p_run<P>& pr)
+ {
+ out << "Run: (" << pr.first() << ", " <<
pr.length() << ")";
+ return out;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ /// Iterators
+
+ template <typename P>
+ struct p_run_fwd_piter_ :
+ public internal::piter_base_< p_run_fwd_piter_<P>, P, p_run<P> >
+ {
+ typedef p_run_fwd_piter_<P> self_;
+ typedef internal::piter_base_< p_run_fwd_piter_<P>, P, p_run<P> >
super_;
+ public:
+
+ typedef P site;
+ typedef p_run<P> psite;
+
+ enum { dim = P::dim };
+
+ p_run_fwd_piter_();
+ p_run_fwd_piter_(const p_run<P>& pr);
+ void assign_run(const p_run<P>& pr);
+
+ const site& to_site() const;
+ const psite& to_psite() const;
+
+ /// operator[] ?
+
+ bool is_valid() const;
+ void invalidate();
+ void start();
+ void next_();
+
+ /// Get the index of the point in the run.
+ unsigned ind() const;
+
+
+ protected:
+ const p_run<P>* run_;
+ bool is_valid_;
+ unsigned i_;
+ P p_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ p_run_fwd_piter_<P>::p_run_fwd_piter_()
+ : run_ (0),
+ is_valid_(false)
+ {
+ }
+
+ template <typename P>
+ inline
+ p_run_fwd_piter_<P>::p_run_fwd_piter_(const p_run<P>& pr)
+ : run_(&pr),
+ is_valid_(false)
+ {
+ }
+
+ template <typename P>
+ inline
+ void
+ p_run_fwd_piter_<P>::assign_run(const p_run<P>& pr)
+ {
+ run_ = ≺
+ is_valid_ = false;
+ }
+
+ template <typename P>
+ inline
+ const typename p_run_fwd_piter_<P>::site&
+ p_run_fwd_piter_<P>::to_site() const
+ {
+ assert(is_valid());
+ return p_;
+ }
+
+ template <typename P>
+ inline
+ const typename p_run_fwd_piter_<P>::psite&
+ p_run_fwd_piter_<P>::to_psite() const
+ {
+ assert(is_valid());
+ return *run_;
+ }
+
+ template <typename P>
+ inline
+ bool
+ p_run_fwd_piter_<P>::is_valid() const
+ {
+ return is_valid_;
+ }
+
+ template <typename P>
+ inline
+ void
+ p_run_fwd_piter_<P>::invalidate()
+ {
+ is_valid_ = false;
+ }
+
+ template <typename P>
+ inline
+ void
+ p_run_fwd_piter_<P>::start()
+ {
+ p_ = run_->first();
+ i_ = 0;
+ is_valid_ = true;
+ }
+
+ template <typename P>
+ inline
+ void
+ p_run_fwd_piter_<P>::next_()
+ {
+ p_[dim - 1]++;
+ ++i_;
+ is_valid_ = p_[dim - 1] - run_->first()[dim - 1] < (signed)run_->length();
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ p_run_fwd_piter_<P>::ind() const
+ {
+ return i_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // !P_RUN_HH_
Index: sandbox/ballas/refactorization/rle_image.hh
--- sandbox/ballas/refactorization/rle_image.hh (revision 0)
+++ sandbox/ballas/refactorization/rle_image.hh (revision 0)
@@ -0,0 +1,118 @@
+#ifndef RLE_IMAGE_CC_
+# define RLE_IMAGE_CC_
+
+
+# include <rle_pset.hh>
+# include <internal/image_base.hh>
+
+namespace mln
+{
+
+ // note P must be a point
+ template <typename P, typename T>
+ class rle_image :
+ public internal::image_base_<rle_pset<P>, rle_image<P, T> >
+ {
+ public:
+
+ typedef T value;
+ typedef T& lvalue;
+ typedef const T rvalue;
+
+ typedef P site;
+ typedef rle_psite<P> psite;
+
+ typedef rle_pset<P> pset;
+ typedef typename pset::fwd_piter fwd_piter;
+ typedef typename pset::bkd_piter bkd_piter;
+ typedef typename pset::fwd_piter piter;
+
+
+ rle_image();
+
+ void insert(const p_run<P>& pr, T value);
+ rvalue operator() (const rle_psite<P>& psite) const;
+ lvalue operator() (const rle_psite<P>& psite);
+ bool has_data() const;
+
+ bool owns_(const rle_psite<P>& ps) const;
+ const pset& domain() const;
+
+ protected:
+ std::vector<T> values_;
+ rle_pset<P> domain_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename T>
+ inline
+ rle_image<P, T>::rle_image()
+ {
+ }
+
+ template <typename P, typename T>
+ inline
+ bool
+ rle_image<P, T>::has_data() const
+ {
+ return this->values_.size() != 0;
+ }
+
+ template <typename P, typename T>
+ inline
+ void
+ rle_image<P, T>::insert(const p_run<P>& pr, T value)
+ {
+ this->domain_.insert(pr);
+ this->values_.push_back(value);
+ }
+
+ template <typename P, typename T>
+ inline
+ typename rle_image<P, T>::rvalue
+ rle_image<P, T>::operator() (const rle_psite<P>& psite)
+ const
+ {
+ assert(this->owns_(psite));
+ return this->values_[psite.p_of_run()];
+ }
+
+ template <typename P, typename T>
+ inline
+ typename rle_image<P, T>::lvalue
+ rle_image<P, T>::operator() (const rle_psite<P>& psite)
+ {
+ assert(this->owns_(psite));
+ return this->values_[psite.p_of_run()];
+ }
+
+ template <typename P, typename T>
+ inline
+ const typename rle_image<P, T>::pset&
+ rle_image<P, T>::domain() const
+ {
+ return this->domain_;
+ }
+
+ template <typename P, typename T>
+ inline
+ bool
+ rle_image<P, T>::owns_(const rle_psite<P>& ps) const
+ {
+ if (!this->has_data())
+ return false;
+ else
+ return (ps.p_of_run() < this->domain_.nruns() &&
+ ps.p_in_run() < this->domain_[ps.p_of_run()].length() &&
+ this->domain_[ps.p_of_run()][ps.p_in_run()] == ps.to_site());
+ /// FIXME -> to_site....
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // !RLE_IMAGE_CC_
Index: sandbox/ballas/refactorization/rle_psite.hh
--- sandbox/ballas/refactorization/rle_psite.hh (revision 0)
+++ sandbox/ballas/refactorization/rle_psite.hh (revision 0)
@@ -0,0 +1,137 @@
+#ifndef RLE_PSITE_HH_
+# define RLE_PSITE_HH_
+
+
+# include <internal/psite_base.hh>
+
+namespace mln
+{
+
+ template <typename P> class rle_pset;
+
+ template <typename P>
+ class rle_psite : public internal::psite_base_< rle_psite<P>, P>
+ {
+ public:
+
+ enum { dim = 2 };
+
+ typedef P site;
+ typedef rle_psite<P> psite;
+ // FIXME dpsite??
+
+ rle_psite(const rle_pset<P>& pr, unsigned in_run, unsigned of_run);
+
+ P& range_start_();
+ const P& range_start_() const;
+ unsigned p_of_run() const;
+ unsigned& p_of_run();
+ unsigned p_in_run() const;
+ unsigned& p_in_run();
+ const P& to_site() const;
+ void update_();
+
+ protected:
+ const rle_pset<P>& pr_;
+
+ unsigned p_in_run_;
+ unsigned p_of_run_;
+
+ P p_;
+ };
+
+ template <typename P>
+ inline
+ bool operator==(const rle_psite<P>& lhs_, const rle_psite<P>&
rhs_);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ void
+ rle_psite<P>::update_()
+ {
+ this->p_.operator= (pr_[p_of_run_][p_in_run_]);
+ }
+
+ template <typename P>
+ inline
+ rle_psite<P>::rle_psite(const rle_pset<P>& pr,
+ unsigned in_run,
+ unsigned of_run)
+ : pr_(pr),
+ p_in_run_(in_run),
+ p_of_run_(of_run),
+ p_(pr[p_of_run_][p_in_run_])
+ {
+ }
+
+ template <typename P>
+ inline
+ const P&
+ rle_psite<P>::range_start_() const
+ {
+ return pr_[p_of_run_].first();
+ }
+
+ template <typename P>
+ inline
+ P&
+ rle_psite<P>::range_start_()
+ {
+ return pr_[p_of_run_].first();
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ rle_psite<P>::p_of_run() const
+ {
+ return p_of_run_;
+ }
+
+ template <typename P>
+ inline
+ unsigned&
+ rle_psite<P>::p_of_run()
+ {
+ return p_of_run_;
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ rle_psite<P>::p_in_run() const
+ {
+ return p_in_run_;
+ }
+
+ template <typename P>
+ inline
+ unsigned&
+ rle_psite<P>::p_in_run()
+ {
+ return p_in_run_;
+ }
+
+ template <typename P>
+ inline
+ const P&
+ rle_psite<P>::to_site() const
+ {
+ return p_;
+ }
+
+ template <typename P>
+ inline
+ bool operator==(const rle_psite<P>& lhs_, const rle_psite<P>&
rhs_)
+ {
+ return lhs_.p_of_run_ == lhs_.p_of_run && lhs_.p_in_run_ == rhs_.p_in_run_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+# include <rle_psite.hh>
+
+#endif // !RLE_PSITE_HH_
Index: sandbox/ballas/refactorization/rle_pset.hh
--- sandbox/ballas/refactorization/rle_pset.hh (revision 0)
+++ sandbox/ballas/refactorization/rle_pset.hh (revision 0)
@@ -0,0 +1,308 @@
+// 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 RLE_PSET_HH_
+# define RLE_PSET_HH_
+
+
+
+# include <internal/pset_base.hh>
+# include <internal/psite_base.hh>
+
+# include <rle_psite.hh>
+# include <p_run.hh>
+
+# include <vector>
+# include <utility>
+
+
+
+namespace mln
+{
+
+ // Forward declaration
+ template <typename P> struct rle_pset_fwd_piter_;
+
+ template <typename P>
+ class rle_pset :
+ public internal::pset_base_< rle_psite<P>, rle_pset<P> >
+ {
+ typedef std::vector< p_run<P> >container;
+ public:
+ typedef rle_pset_fwd_piter_<P> fwd_piter;
+ typedef fwd_piter bkd_piter;
+ typedef fwd_piter piter;
+
+ rle_pset();
+
+ /// Test is \p p belongs to this point set.
+ bool owns_(const rle_psite<P>& ps) const;
+
+ typename std::size_t nsites() const;
+ void insert(const p_run<P>& pr);
+
+
+ unsigned nruns() const;
+ unsigned range_len_(const P& p) const;
+
+ const p_run<P>& operator[](unsigned i) const;
+
+ const container& con() const;
+
+ protected:
+
+ typename std::size_t nsites_;
+ container con_;
+
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ rle_pset<P>::rle_pset() :
+ nsites_(0)
+ {
+ }
+
+ template <typename P>
+ inline
+ bool
+ rle_pset<P>::owns_(const rle_psite<P>& ps) const
+ {
+ if (ps.p_of_run() < nruns()
+ && ps.p_in_run() < con_[ps.p_of_run()].length())
+ return (ps == con_[ps.p_of_run()][ps.p_in_run()]);
+ else
+ return false;
+ }
+
+ template <typename P>
+ inline
+ typename std::size_t
+ rle_pset<P>::nsites() const
+ {
+ return nsites_;
+ }
+
+ template <typename P>
+ inline
+ void
+ rle_pset<P>::insert(const p_run<P>& pr)
+ {
+ /// This doesn't deal with recovering pset.
+ con_.push_back(pr);
+ nsites_ += pr.nsites();
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ rle_pset<P>::nruns() const
+ {
+ return con_.size();
+ }
+
+ template <typename P>
+ inline
+ unsigned
+ rle_pset<P>::range_len_(const P& p) const
+ {
+ unsigned i;
+ for (i = 0; i < con_.size(); ++i)
+ {
+ if (con_[i].first == p)
+ return con_[i].nsites();
+ }
+
+ assert(i < con_.size());
+ return (con_.size());
+ }
+
+ template <typename P>
+ inline
+ const p_run<P>&
+ rle_pset<P>::operator[](unsigned i) const
+ {
+ return con_[i];
+ }
+
+ template <typename P>
+ const typename rle_pset<P>::container&
+ rle_pset<P>::con() const
+ {
+ return con_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ template <typename P, typename E>
+ class rle_pset_piter_ : public internal::piter_base_<E, P, rle_psite<P> >
+ {
+ public:
+ typedef P site;
+ typedef rle_psite<P> psite;
+
+ const P& to_site() const;
+
+ protected:
+ P p_;
+ const rle_pset<P>& con_;
+ rle_pset_piter_(const rle_pset<P>& pset);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename E>
+ inline
+ rle_pset_piter_<P, E>::rle_pset_piter_(const rle_pset<P>& pset) :
+ con_(pset)
+ {
+ }
+
+ template <typename P, typename E>
+ inline
+ const P&
+ rle_pset_piter_<P, E>::to_site() const
+ {
+ assert(exact(this)->is_valid());
+ return p_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+ template <typename P>
+ class rle_pset_fwd_piter_ :
+ public rle_pset_piter_<P, rle_pset_fwd_piter_<P> >
+ {
+ typedef rle_pset_piter_<P, rle_pset_fwd_piter_<P> > super;
+ public:
+
+ rle_pset_fwd_piter_(const rle_pset<P>& pset);
+
+ bool is_valid() const;
+ void invalidate();
+ void start();
+ void next_();
+
+ const rle_psite<P>& to_psite() const;
+
+ protected:
+ void update_();
+
+ unsigned i_;
+ p_run_fwd_piter_<P> it_;
+ rle_psite<P> ps_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ inline
+ rle_pset_fwd_piter_<P>::rle_pset_fwd_piter_(const rle_pset<P>& pset) :
+ super(pset),
+ ps_(pset, 0, 0)
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ inline
+ bool
+ rle_pset_fwd_piter_<P>::is_valid() const
+ {
+ return i_ < this->con_.nruns();
+ }
+
+ template <typename P>
+ inline
+ void
+ rle_pset_fwd_piter_<P>::invalidate()
+ {
+ i_ = this->con_.nruns();
+ }
+
+ template <typename P>
+ inline
+ void
+ rle_pset_fwd_piter_<P>::start()
+ {
+ i_ = 0;
+ it_.assign_run(this->con_[i_]);
+ it_.start();
+ this->p_ = it_;
+ this->update_();
+ }
+
+ template <typename P>
+ inline
+ void
+ rle_pset_fwd_piter_<P>::next_()
+ {
+ assert(this->is_valid());
+ it_.next();
+ if (!it_.is_valid())
+ {
+ ++i_;
+ if (is_valid())
+ {
+ it_.assign_run(this->con_[i_]);
+ it_.start();
+ }
+ else
+ return;
+ }
+ this->update_();
+ }
+
+ template <typename P>
+ void
+ rle_pset_fwd_piter_<P>::update_()
+ {
+ this->p_ = it_;
+ ps_.p_in_run() = it_.ind();
+ ps_.p_of_run() = i_;
+ this->ps_.update_();
+ }
+
+ template <typename P>
+ const rle_psite<P>&
+ rle_pset_fwd_piter_<P>::to_psite() const
+ {
+ return ps_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace mln
+
+
+#endif // !RLE_PSET_HH_
Index: sandbox/ballas/refactorization/internal/pset_base.hh
--- sandbox/ballas/refactorization/internal/pset_base.hh (revision 1782)
+++ sandbox/ballas/refactorization/internal/pset_base.hh (working copy)
@@ -3,6 +3,7 @@
# include <concept.hh>
+# include <exact.hh>
namespace mln
{
@@ -15,9 +16,33 @@
template <typename P, typename E>
struct pset_base_ : public Pset<E>
{
+ /// !!!
typedef typename P::site site;
typedef P psite;
+
+
+ bool has(const P& ps) const;
+ protected:
+ pset_base_();
};
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P, typename E>
+ pset_base_<P, E>::pset_base_()
+ {
+ }
+
+ template <typename P, typename E>
+ bool
+ pset_base_<P, E>::has(const P& ps) const
+ {
+ return exact(this)->owns_(ps);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
}
}
Index: sandbox/ballas/refactorization/internal/image_base.hh
--- sandbox/ballas/refactorization/internal/image_base.hh (revision 1782)
+++ sandbox/ballas/refactorization/internal/image_base.hh (working copy)
@@ -19,7 +19,7 @@
typedef typename S::fwd_piter fwd_piter;
typedef typename S::bkd_piter bkd_piter;
- bool has(const psite&) const;
+ bool has(const psite& ps) const;
protected:
image_base_();
@@ -34,6 +34,13 @@
{
}
+ template <typename S, typename E>
+ bool
+ image_base_<S, E>::has(const psite& ps) const
+ {
+ return exact(this)->owns_(ps);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
}
Index: sandbox/ballas/refactorization/internal/piter_base.hh
--- sandbox/ballas/refactorization/internal/piter_base.hh (revision 1782)
+++ sandbox/ballas/refactorization/internal/piter_base.hh (working copy)
@@ -2,6 +2,8 @@
# define INTERNAL_PITER_BASE_HH_
# include <concept.hh>
+# include <point2d_impl.hh>
+
# include <exact.hh>
# include <metal/bool.hh>
# include <metal/equal.hh>
@@ -13,40 +15,39 @@
{
/// fwd declaration
- template <typename E, typename B>
+ template <typename E, typename Site, typename B>
struct piter_base_site_cast;
/// Psite = Site
- template <typename E>
- struct piter_base_site_cast<E, metal::true_> : public Piter<E>
+ template <typename E, typename Site>
+ struct piter_base_site_cast<E, Site, metal::true_> : public Piter<E>
{
};
/// Psite != site
- template <typename E>
- struct piter_base_site_cast<E, metal::false_> : public Piter<E>
+ template <typename E, typename Site>
+ struct piter_base_site_cast<E, Site, metal::false_> : public Piter<E>
{
- operator typename E::site() const;
+ operator Site() const;
};
/// Piter base
template <typename E, typename Site, typename Psite>
struct piter_base_ :
- public piter_base_site_cast<E,
- typename mlc_equal(Site,
- Psite)::eval>
+ public impl<Site>,
+ public piter_base_site_cast<E, Site,
+ typename mlc_equal(Site, Psite)::eval>
{
operator Psite () const;
protected:
piter_base_();
-
};
# ifndef MLN_INCLUDE_ONLY
- template <typename E>
- piter_base_site_cast<E, metal::false_>::operator typename E::site () const
+ template <typename E, typename Site>
+ piter_base_site_cast<E, Site, metal::false_>::operator Site () const
{
return exact(this)->to_site();
}
@@ -55,7 +56,7 @@
template <typename E, typename Site, typename Psite>
piter_base_<E, Site, Psite>::operator Psite () const
{
- return exact(this)->to_site();
+ return exact(this)->to_psite();
}
Index: sandbox/ballas/refactorization/internal/psite_base.hh
--- sandbox/ballas/refactorization/internal/psite_base.hh (revision 1782)
+++ sandbox/ballas/refactorization/internal/psite_base.hh (working copy)
@@ -9,26 +9,26 @@
namespace internal
{
- template <typename E>
- struct psite_base : public Psite<E>,
- public impl<typename E::site>
+ template <typename E, typename P>
+ struct psite_base_ : public Psite<E>,
+ public impl<P>
{
- operator typename E::psite () const;
+ operator E() const;
protected:
- psite_base();
+ psite_base_();
};
# ifndef MLN_INCLUDE_ONLY
- template <typename E>
- psite_base<E>::operator typename E::psite () const
+ template <typename E, typename P>
+ psite_base_<E, P>::operator E() const
{
- return exact(this)->to_site();
+ return exact(this)->to_psite();
}
- template <typename E>
- psite_base<E>::psite_base()
+ template <typename E, typename P>
+ psite_base_<E, P>::psite_base_()
{
}
Index: sandbox/ballas/refactorization/box2d.hh
--- sandbox/ballas/refactorization/box2d.hh (revision 1782)
+++ sandbox/ballas/refactorization/box2d.hh (working copy)
@@ -36,7 +36,7 @@
box2d();
box2d(const site& pmin, const site& pmax);
- bool has(const site& p) const;
+ bool owns_(const site& p) const;
protected:
point2d<C> pmin_, pmax_;
@@ -98,7 +98,7 @@
template <typename C>
inline
bool
- box2d<C>::has(const site& p) const
+ box2d<C>::owns_(const site& p) const
{
for (unsigned i = 0; i < C::dim; ++i)
if (p[i] < pmin_[i] || p[i] > pmax_[i])
Index: sandbox/ballas/refactorization/point2d.hh
--- sandbox/ballas/refactorization/point2d.hh (revision 1782)
+++ sandbox/ballas/refactorization/point2d.hh (working copy)
@@ -38,6 +38,7 @@
enum { dim = 2 };
typedef dpoint2d<C> dpoint;
+ typedef point2d<C> site;
typedef C coord;
@@ -51,6 +52,7 @@
point2d<C>& operator+=(const dpoint& dp);
point2d<C>& operator-=(const dpoint& dp);
+ point2d<C>& operator=(const point2d<C>& p);
protected:
std::vector<C> coord_;
@@ -189,6 +191,17 @@
}
template <typename C>
+ inline
+ point2d<C>&
+ point2d<C>::operator=(const point2d<C>& p)
+ {
+ if (&p != this)
+ for (unsigned i = 0; i < dim; ++i)
+ this->coord_[i] = p.coord_[i];
+ return *this;
+ }
+
+ template <typename C>
std::ostream& operator<<(std::ostream& ostr, const point2d<C>&
p)
{
return ostr << "(" << p[0] << "," << p[1]
<< ")";