Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Change on rle_class.
* static/doc/tiny/more_scoop_2/main.cc: .
* olena/ChangeLog: .
* olena/oln/core/rle/rle_image.hh: .
* olena/oln/core/rle/rle_psite.hh: .
* olena/oln/core/rle/rle_pset.hh: .
* metalic/mlc/bool.hh: .
olena/ChangeLog | 9 +++
olena/oln/core/rle/rle_image.hh | 51 +++++++----------
olena/oln/core/rle/rle_pset.hh | 114 ++++++++++++++++++++++++++--------------
olena/oln/core/rle/rle_psite.hh | 72 ++++++++++++++-----------
4 files changed, 145 insertions(+), 101 deletions(-)
Index: olena/ChangeLog
--- olena/ChangeLog (revision 870)
+++ olena/ChangeLog (working copy)
@@ -1,3 +1,12 @@
+2007-03-13 Nicolas Ballas <ballas(a)lrde.epita.fr>
+
+ Change rle_image/rle_pset storage structure(map<point, value>/
map<point/unsigned>).
+ Note that rle_image know bugs (memory problem).
+
+ * oln/core/rle/rle_image.hh Update
+ * oln/core/rle/rle_pset.hh Update
+ * oln/core/rle/rle_psite.hh Adapte rle_psite class to rle_image and rle_pset changement
+
2007-03-13 Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add oln_plain_value, update level::apply, and provide a sample test code.
Index: olena/oln/core/rle/rle_image.hh
--- olena/oln/core/rle/rle_image.hh (revision 870)
+++ olena/oln/core/rle/rle_image.hh (working copy)
@@ -64,12 +64,14 @@
typedef P point;
typedef typename P::coord coord;
- typedef rle_psite<P, T> psite;
+ typedef rle_psite<P> psite;
typedef rle_pset<point> pset;
// typedef typename pset::box box;
- typedef std::map<std::pair<point, unsigned>, value> data;
+ typedef mlc::none plain;
+
+ typedef std::pair< pset, std::map<point, value> > data;
};
@@ -99,11 +101,6 @@
rvalue impl_read(const psite& p) const;
lvalue impl_read_write(const psite& p);
- //Internal
- const data& get_data_() const;
-
- protected:
- pset pset_;
};
# ifndef OLN_INCLUDE_ONLY
@@ -111,72 +108,66 @@
template <typename P, typename T>
rle_image<P, T>::rle_image()
{
- this->data_ = new typename rle_image<P, T>::data;
+ this->data_ = new data;
}
template <typename P, typename T>
typename rle_image<P, T>::pset
rle_image<P, T>::impl_points() const
{
- return pset_;
+ return this->data_->first;
}
-
template <typename P, typename T>
typename rle_image<P, T>::box
rle_image<P, T>::impl_bbox() const
{
- return pset_.bbox();
+ return this->data_->first.bbox();
}
template <typename P, typename T>
bool
rle_image<P, T>::impl_has(const typename rle_image<P, T>::point& p)
const
{
- return this->pset_.has(p.point_());
+ return this->data_->first.has(p);
}
template <typename P, typename T>
bool
rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p)
const
{
- //FIXME
- return this->pset_.has(p.point_());
+ return this->data_->first.has(p);
}
template <typename P, typename T>
void
rle_image<P, T>::insert(const typename rle_image<P, T>::point& p,
unsigned len, rle_image<P, T>::value val)
{
- pset_.insert(p, len);
- ((this->data_))->operator[](std::make_pair(p, len)) = val;
+ this->data_->first.insert(p, len);
+ this->data_->second[p] = val;
}
template <typename P, typename T>
typename rle_image<P, T>::rvalue
- rle_image<P, T>::impl_read(const rle_image<P, T>::psite& p) const
+ rle_image<P, T>::impl_read(const rle_image<P, T>::psite& ps) const
{
- precondition(p.iterator_() != this->data_->end());
- return p.iterator_()->second;
+ // precondition(p.iterator_() != this->data_->second.end());
+ return this->data_->second[ps];
}
+ int a = 5;
template <typename P, typename T>
typename rle_image<P, T>::lvalue
- rle_image<P, T>::impl_read_write(const rle_image<P, T>::psite& p)
+ rle_image<P, T>::impl_read_write(const rle_image<P, T>::psite& ps)
{
- precondition(p.iterator_() != this->data_->end());
- return p.iterator_()->second;
- }
+ std::cout << "read_write: " << std::endl;
+ std::cout << (point)ps << std::endl;
- template <typename P, typename T>
- const typename rle_image<P, T>::data&
- rle_image<P, T>::get_data_() const
- {
- //FIXME: another way to do that?
- return *(this->data_.ptr_);
+ // precondition(p.iterator_() != this->data_->second.end());
+ //return this->data_->second[ps];
+ return a;
}
-
# endif // !OLN_INCLUDE_ONLY
} // end of namespace oln
Index: olena/oln/core/rle/rle_psite.hh
--- olena/oln/core/rle/rle_psite.hh (revision 870)
+++ olena/oln/core/rle/rle_psite.hh (working copy)
@@ -46,55 +46,63 @@
**
**
*/
- template <typename P, typename T>
+ template <typename P>
class rle_psite
{
public:
- rle_psite(const rle_image<P, T>& ima, const P& p);
- const typename std::map<std::pair<P, unsigned>, T>::iterator&
iterator_() const;
- typename std::map<std::pair<P, unsigned>, T>::iterator& iterator_();
- const P& point_() const;
- protected:
- P p_; /*!< point
corresponding to the psite */
- typename std::map<std::pair<P, unsigned>, T>::iterator it_;
/*!< it_ on image map corresponding to p_*/
+ rle_psite();
+ // template <typename T>
+// rle_psite(const rle_image<P, T>& ima, const P& p);
+
+ P to_point() const;
+ operator P () const;
+
+ P start_; /*!< start of the range which contains the psite */
+ unsigned index_; /*!< index of the point in the range */
};
# ifndef OLN_INCLUDE_ONLY
- template <typename P, typename T>
- rle_psite<P, T>::rle_psite(const rle_image<P, T>& ima, const P& p)
: p_(p)//, it_(ima.points().con())
+ template <typename P>
+ rle_psite<P>::rle_psite()
{
- P pend;
+ }
-// for (this->it_ = ima.get_data_().begin(); this->it_ !=
ima.get_data_().end(); ++(this->it_))
+// template <typename P>
+// template <typename T>
+// rle_psite<P>::rle_psite(const rle_image<P, T>& ima, const P& p)
: start_(p)
+// {
+// P pend;
+
+// typename rle_image<P, T>::piter it (ima.points());
+
+// for (it.start(); it.is_valid(); it.next())
+// {
+// pend = it;
+// pend[0] += it->second - 1;
+// if (*it >= p && p <= pend)
// {
-// pend = this->it_->first.first;
-// pend[0] += this->it_->first.second - 1;
-// if (this->it_->first.first >= p && p <= pend)
-// return;
+// this->start_ = it->first;
+// this->index_ = it->second - this->start[0];
+// }
+// }
// }
- it_ = ima.get_data_().end();
- }
- template <typename P, typename T>
- const typename std::map<std::pair<P, unsigned>, T>::iterator&
- rle_psite<P, T>::iterator_() const
- {
- return this->it_;
- }
- template <typename P, typename T>
- typename std::map<std::pair<P, unsigned>, T>::iterator&
- rle_psite<P, T>::iterator_()
+ template <typename P>
+ P
+ rle_psite<P>::to_point() const
{
- return this->it_;
+ P p = this->start_;
+
+ p[0] += this->index_;
+ return p;
}
- template <typename P, typename T>
- const P&
- rle_psite<P, T>::point_() const
+ template <typename P>
+ rle_psite<P>::operator P() const
{
- return p_;
+ return this->to_point();
}
# endif /* !OLN_INCLUDE_ONLY */
Index: olena/oln/core/rle/rle_pset.hh
--- olena/oln/core/rle/rle_pset.hh (revision 870)
+++ olena/oln/core/rle/rle_pset.hh (working copy)
@@ -54,7 +54,7 @@
typedef P point;
typedef typename P::grid grid;
- typedef fbbox_<point> box;
+ typedef box_<point> box;
typedef rle_pset_fwd_piter_<P> fwd_piter;
typedef rle_pset_bkd_piter_<P> bkd_piter;
@@ -62,7 +62,6 @@
};
// rle_pset class
-
template <typename P>
class rle_pset : public internal::point_set_base_<rle_pset <P> >
{
@@ -72,7 +71,7 @@
stc_using(point);
stc_using(box);
- typedef std::set< std::pair<point, unsigned> > std_container;
+ typedef std::map<point, unsigned> std_container;
rle_pset();
@@ -82,6 +81,7 @@
bool impl_has(const P& p) const;
const std_container& con() const;
+ unsigned range_len_(const P& range_start);
protected:
unsigned npts;
std_container con_;
@@ -108,8 +108,9 @@
void
rle_pset<P>::insert(const P& p, unsigned len)
{
- con_.insert(std::make_pair(p, len));
- P pend;
+ point pend;
+
+ this->con_[p] = len;
//update bbox
fb_.take(p);
@@ -132,7 +133,8 @@
bool
rle_pset<P>::impl_has(const P& p) const
{
- point pend;
+ P pend;
+
typename std_container::const_iterator iter;
for (iter = con_.begin(); iter != con_.end(); ++iter )
@@ -145,8 +147,6 @@
return 0;
}
- // end of rle_pset class
-
template <typename P>
const typename rle_pset<P>::std_container&
rle_pset<P>::con() const
@@ -154,9 +154,16 @@
return this->con_;
}
+ template <typename P>
+ unsigned
+ rle_pset<P>::range_len_(const P& range_start)
+ {
+ return this->con_[range_start];
+ }
# endif // !OLN_INCLUDE_ONLY
+ // end of rle_pset class
// -------------------- iterators on classes deriving from
internal::rle_pset<P>
@@ -186,13 +193,17 @@
void impl_next();
void impl_invalidate();
bool impl_is_valid() const;
+
+ const rle_psite<P>& impl_to_psite() const;
point impl_to_point() const;
- const point* impl_point_adr() const;
+ const point* impl_psite_adr() const;
+
+ operator rle_psite<P> () const;
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_iterator it_;
- point p_;
+ rle_psite<P> ps_;
};
# ifndef OLN_INCLUDE_ONLY
@@ -208,26 +219,26 @@
rle_pset_fwd_piter_<P>::impl_start()
{
this->it_ = this->con_.begin();
- this->p_ = this->it_->first;
+ this->ps_.start_ = this->it_->first;
+ this->ps_.index_ = 0;
}
template <typename P>
void
rle_pset_fwd_piter_<P>::impl_next()
{
- point pend;
-
- if (!this->is_valid())
- return;
+ precondition(this->is_valid());
- pend = this->it_->first;
- pend[0] += this->it_->second - 1;
+ std::cout << "next: " << std::endl;
+ std::cout << "point start: " << ps_.start_ << "
index: " << ps_.index_ << std::endl;
+ std::cout << "point start: " << it_->first << "
index: " << it_->second << " ref" << std::endl;
- ++p_[0];
- if (p_ > pend)
+ ++this->ps_.index_;
+ if (this->ps_.index_ >= this->it_->second)
{
++it_;
- p_ = this->it_->first;
+ this->ps_.start_ = this->it_->first;
+ this->ps_.index_ = 0;
}
}
@@ -249,14 +260,27 @@
typename rle_pset_fwd_piter_<P>::point
rle_pset_fwd_piter_<P>::impl_to_point() const
{
- return p_;
+ return ps_.to_point();
+ }
+
+ template <typename P>
+ const rle_psite<P>&
+ rle_pset_fwd_piter_<P>::impl_to_psite() const
+ {
+ return ps_;
+ }
+
+ template <typename P>
+ rle_pset_fwd_piter_<P>::operator rle_psite<P> () const
+ {
+ return this->impl_to_psite();
}
template <typename P>
const typename rle_pset_fwd_piter_<P>::point*
- rle_pset_fwd_piter_<P>::impl_point_adr() const
+ rle_pset_fwd_piter_<P>::impl_psite_adr() const
{
- return &p_;
+ return &ps_;
}
# endif // !OLN_INCLUDE_ONLY
@@ -290,13 +314,15 @@
void impl_next();
void impl_invalidate();
bool impl_is_valid() const;
+ const rle_psite<P>& impl_to_psite() const;
point impl_to_point() const;
- const point* impl_point_adr() const;
+ const point* impl_psite_adr() const;
+ operator rle_psite<P> () const;
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_reverse_iterator it_;
- point p_;
+ rle_psite<P> ps_;
};
# ifndef OLN_INCLUDE_ONLY
@@ -312,27 +338,24 @@
rle_pset_bkd_piter_<P>::impl_start()
{
this->it_ = this->con_.rbegin();
- this->p_ = this->it_->first;
- this->p_[0] += this->it_->second - 1;
+ this->ps_.start_ = this->it_->first;
+ this->ps_.index_ = this->it_->second - 1;
}
template <typename P>
void
rle_pset_bkd_piter_<P>::impl_next()
{
- point pend;
+ precondition(this->is_valid());
- if (!this->is_valid())
- return;
+ --ps_.index_;
- pend = this->it_->first;
-
- --p_[0];
- if (p_ < pend)
+ // ps.index_ is unsigned
+ if (ps_.index_ + 1 == 0)
{
++it_;
- p_ = this->it_->first;
- this->p_[0] += this->it_->second - 1;
+ this->ps_.start_ = this->it_->first;
+ this->ps_.index_ = this->it_->second - 1;
}
}
@@ -351,17 +374,30 @@
}
template <typename P>
+ const rle_psite<P>&
+ rle_pset_bkd_piter_<P>::impl_to_psite() const
+ {
+ return ps_;
+ }
+
+ template <typename P>
typename rle_pset_bkd_piter_<P>::point
rle_pset_bkd_piter_<P>::impl_to_point() const
{
- return p_;
+ return ps_;
+ }
+
+ template <typename P>
+ rle_pset_bkd_piter_<P>::operator rle_psite<P> () const
+ {
+ return this->impl_to_psite();
}
template <typename P>
const typename rle_pset_bkd_piter_<P>::point*
- rle_pset_bkd_piter_<P>::impl_point_adr() const
+ rle_pset_bkd_piter_<P>::impl_psite_adr() const
{
- return &p_;
+ return &ps_;
}
# endif // !OLN_INCLUDE_ONLY
Index: metalic/mlc/bool.hh