Commit 0b71ec5a authored by Thierry Geraud's avatar Thierry Geraud
Browse files

2006-09-01 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>

	* oln/core/abstract/piter.hh (to_point): New.
	* oln/core/abstract/bbox.hh (pmin, pmax): New overloaded methods.
	(is_valid, print, operator<<): New.
	* oln/core/abstract/iter.hh (iter): Change inheritance from
	any__simple to any__best_memory to fix trouble with multiple
	inheritance.
	(ctor): Remove dangerous call to invalidate.
	* oln/core/abstract/point_nd.hh (operator<<): New.
	(impl_less): Update.
	* oln/core/abstract/pset.hh (coord_type): New.
	* oln/core/2d/point2d.hh (coord_t): Move to public so that this
	associated type is directly accessible from...
	* oln/core/gen/bbox.hh (vtypes): ...this set of types.
	* oln/core/gen/fwd_piter.hh (psup_): Remove.
	(bbox): New accessor.
	(impl_next): Rewrite.
	(print, operator<<): New.
	(invariant): Strengthen.
	* oln/core/gen/bkd_piter.hh: Likewise.



git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@516 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent f460aa55
2006-09-01 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
* oln/core/abstract/piter.hh (to_point): New.
* oln/core/abstract/bbox.hh (pmin, pmax): New overloaded methods.
(is_valid, print, operator<<): New.
* oln/core/abstract/iter.hh (iter): Change inheritance from
any__simple to any__best_memory to fix trouble with multiple
inheritance.
(ctor): Remove dangerous call to invalidate.
* oln/core/abstract/point_nd.hh (operator<<): New.
(impl_less): Update.
* oln/core/abstract/pset.hh (coord_type): New.
* oln/core/2d/point2d.hh (coord_t): Move to public so that this
associated type is directly accessible from...
* oln/core/gen/bbox.hh (vtypes): ...this set of types.
* oln/core/gen/fwd_piter.hh (psup_): Remove.
(bbox): New accessor.
(impl_next): Rewrite.
(print, operator<<): New.
(invariant): Strengthen.
* oln/core/gen/bkd_piter.hh: Likewise.
2006-09-01 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> 2006-09-01 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Add bboxes and iterators. Add bboxes and iterators.
......
...@@ -60,13 +60,13 @@ namespace oln ...@@ -60,13 +60,13 @@ namespace oln
{ {
typedef point2d_<C> self_t; typedef point2d_<C> self_t;
typedef abstract::point_nd<self_t> super_t; typedef abstract::point_nd<self_t> super_t;
typedef oln_type_of(self_t, coord) coord_t;
using super_t::v_; using super_t::v_;
public: public:
// Cf. BUG! typedef oln_type_of(self_t, grid) grid_t; // Cf. BUG! typedef oln_type_of(self_t, grid) grid_t;
typedef oln_type_of(self_t, coord) coord_t;
/// Ctor. /// Ctor.
point2d_() point2d_()
......
...@@ -59,6 +59,7 @@ namespace oln ...@@ -59,6 +59,7 @@ namespace oln
{ {
typedef E exact_t; typedef E exact_t;
typedef oln_type_of(E, point) point_t; typedef oln_type_of(E, point) point_t;
typedef oln_type_of(E, coord) coord_t;
typedef oln_type_of(point_t, dim) dim; typedef oln_type_of(point_t, dim) dim;
enum { n = mlc_value(dim) }; enum { n = mlc_value(dim) };
...@@ -79,12 +80,24 @@ namespace oln ...@@ -79,12 +80,24 @@ namespace oln
return pmin_; return pmin_;
} }
coord_t pmin(unsigned i) const
{
precondition(is_valid_ and i < n);
return pmin_[i];
}
const point_t& pmax() const const point_t& pmax() const
{ {
precondition(is_valid_); precondition(is_valid_);
return pmax_; return pmax_;
} }
coord_t pmax(unsigned i) const
{
precondition(is_valid_ and i < n);
return pmax_[i];
}
unsigned size(unsigned i) const unsigned size(unsigned i) const
{ {
precondition(is_valid_ and i < n); precondition(is_valid_ and i < n);
...@@ -148,6 +161,26 @@ namespace oln ...@@ -148,6 +161,26 @@ namespace oln
return true; return true;
} }
bool is_valid() const
{
return is_valid_;
}
void print(std::ostream& ostr) const
{
ostr << "{ pmin=" << pmin_
<< ", pmax=" << pmax_
<< ", valid=" << is_valid_
<< " }";
}
friend
std::ostream& operator<<(std::ostream& ostr, const abstract::bbox<E>& bb)
{
bb.print(ostr);
return ostr;
}
// FIXME: Add the scool code below. // FIXME: Add the scool code below.
// invariant { // invariant {
......
...@@ -41,7 +41,7 @@ namespace oln ...@@ -41,7 +41,7 @@ namespace oln
/// Abstract iterator class. /// Abstract iterator class.
template <typename E> template <typename E>
class iter : public stc::any__simple<E>, class iter : public stc::any__best_memory<E>,
public oln::type public oln::type
{ {
public: public:
...@@ -71,7 +71,6 @@ namespace oln ...@@ -71,7 +71,6 @@ namespace oln
iter() iter()
{ {
this->invalidate();
} }
}; // end of class oln::abstract::iter<E> }; // end of class oln::abstract::iter<E>
......
...@@ -74,6 +74,12 @@ namespace oln ...@@ -74,6 +74,12 @@ namespace oln
return p_; return p_;
} }
point_t to_point() const
{
precondition(this->is_valid());
return p_;
}
protected: protected:
point_t p_; point_t p_;
......
...@@ -97,7 +97,7 @@ namespace oln ...@@ -97,7 +97,7 @@ namespace oln
bool impl_less(const self_t& rhs) const bool impl_less(const self_t& rhs) const
{ {
return xtd::lexi(v_, rhs.vec()); return xtd::lexi_less(v_, rhs.vec());
} }
E& impl_plus_equal(const dpoint_t& rhs) E& impl_plus_equal(const dpoint_t& rhs)
...@@ -153,6 +153,14 @@ namespace oln ...@@ -153,6 +153,14 @@ namespace oln
} // end of namespace oln::abstract } // end of namespace oln::abstract
template <typename E>
std::ostream& operator<<(std::ostream& ostr, const abstract::point_nd<E>& p)
{
ostr << p.vec();
return ostr;
}
/// abstract::point_nd + abstract::dpoint_nd /// abstract::point_nd + abstract::dpoint_nd
template <typename P, typename D> template <typename P, typename D>
......
...@@ -49,6 +49,7 @@ namespace oln ...@@ -49,6 +49,7 @@ namespace oln
typedef mlc::undefined point_type; typedef mlc::undefined point_type;
typedef mlc::undefined fwd_piter_type; typedef mlc::undefined fwd_piter_type;
typedef mlc::undefined bkd_piter_type; typedef mlc::undefined bkd_piter_type;
typedef mlc::undefined coord_type;
// FIXME: Add grid. // FIXME: Add grid.
}; };
......
...@@ -58,6 +58,7 @@ namespace oln ...@@ -58,6 +58,7 @@ namespace oln
typedef point point_type; typedef point point_type;
typedef fwd_piter_<point> fwd_piter_type; typedef fwd_piter_<point> fwd_piter_type;
typedef bkd_piter_<point> bkd_piter_type; typedef bkd_piter_<point> bkd_piter_type;
typedef typename point::coord_t coord_type;
// BUG! typedef oln_type_of(point, grid) grid_type; // BUG! typedef oln_type_of(point, grid) grid_type;
// BUG! typedef typename point::grid_t grid_type; // BUG! typedef typename point::grid_t grid_type;
}; };
......
...@@ -75,65 +75,54 @@ namespace oln ...@@ -75,65 +75,54 @@ namespace oln
bkd_piter_(const bbox_<point>& bb) bkd_piter_(const bbox_<point>& bb)
: bb_(bb) : bb_(bb)
{ {
nop_ = bb_.pmax(); nop_ = bb_.pmin();
++nop_[0]; --nop_[0];
}
psup_ = bb_.pmax().vec(); const bbox_<point>& bbox() const
for (unsigned i = 0; i < point::n; ++i) {
++psup_[i]; return bb_;
} }
void impl_start() void impl_start()
{ {
p_ = bb_.pmin(); p_ = bb_.pmax();
} invariant(implies(p_ != nop_, bb_.has(p_)));
}
void impl_next() void impl_next()
{ {
assert(this->is_valid()); invariant(implies(p_ != nop_, bb_.has(p_)));
++p_[0]; for (int i = point::n - 1; i >= 0; --i)
unsigned i = 0; if (p_[i] == bb_.pmin(i))
while (i + 1 < point::n) p_[i] = bb_.pmax(i);
{ else
if (p_[i] == psup_[i]) {
{ --p_[i];
p_[i] = bb_.pmin_[i]; break;
++p_[i+1]; }
} if (p_ == bb_.pmax())
++i; p_ = nop_;
} }
}
// def next =
// {
// precondition { is_valid }
// }
void impl_invalidate() void impl_invalidate()
{ {
assert(this->is_valid()); invariant(implies(p_ != nop_, bb_.has(p_)));
p_ = nop_; p_ = nop_;
} }
bool impl_is_valid() const bool impl_is_valid() const
{ {
return p_ != nop_; invariant(implies(p_ != nop_, bb_.has(p_)));
} return p_ != nop_;
}
protected: protected:
bbox_<point> bb_; bbox_<point> bb_;
point nop_; point nop_;
point psup_;
// invariant
// {
// p <= nop
// }
// make : [D : type] (data : D) = { @bb = data.bbox }
}; // end of class oln::bkd_piter_<point> }; // end of class oln::bkd_piter_<point>
......
...@@ -78,52 +78,65 @@ namespace oln ...@@ -78,52 +78,65 @@ namespace oln
{ {
nop_ = bb_.pmax(); nop_ = bb_.pmax();
++nop_[0]; ++nop_[0];
psup_ = bb_.pmax().vec();
for (unsigned i = 0; i < point::n; ++i)
++psup_[i];
} }
const bbox_<point>& bbox() const
{
return bb_;
}
void impl_start() void impl_start()
{ {
p_ = bb_.pmin(); p_ = bb_.pmin();
invariant(p_ <= nop_); invariant(implies(p_ != nop_, bb_.has(p_)));
} }
void impl_next() void impl_next()
{ {
invariant(p_ <= nop_); invariant(implies(p_ != nop_, bb_.has(p_)));
++p_[0]; for (int i = point::n - 1; i >= 0; --i)
unsigned i = 0; if (p_[i] == bb_.pmax(i))
while (i + 1 < point::n) p_[i] = bb_.pmin(i);
else
{ {
if (p_[i] == psup_[i]) ++p_[i];
{ break;
p_[i] = bb_.pmin_[i];
++p_[i+1];
}
++i;
} }
invariant(p_ <= nop_); if (p_ == bb_.pmin())
p_ = nop_;
} }
void impl_invalidate() void impl_invalidate()
{ {
invariant(p_ <= nop_); invariant(implies(p_ != nop_, bb_.has(p_)));
p_ = nop_; p_ = nop_;
} }
bool impl_is_valid() const bool impl_is_valid() const
{ {
invariant(p_ <= nop_); invariant(implies(p_ != nop_, bb_.has(p_)));
return p_ != nop_; return p_ != nop_;
} }
void print(std::ostream& ostr) const
{
ostr << "{ bb=" << bb_
<< ", p=" << p_
<< ", nop=" << nop_
<< " }";
}
friend
std::ostream& operator<<(std::ostream& ostr, const fwd_piter_<point>& i)
{
i.print(ostr);
return ostr;
}
protected: protected:
bbox_<point> bb_; bbox_<point> bb_;
point nop_; point nop_;
point psup_;
}; // end of class oln::fwd_piter_<point> }; // end of class oln::fwd_piter_<point>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment