Commit b962d902 authored by Roland Levillain's avatar Roland Levillain
Browse files

Have mln:p_set be able to erase its elements.

	* mln/core/p_set.hh (mln::p_set<P>::remove): Enable this method.
	* mln/core/internal/set_of.hh (mln::internal::set_of_<E>::s_):
	Make it protected.
	(mln::internal::set_of_<E>::remove): Use std::set::erase instead
	of std::remove.
	* tests/core/p_set.cc: Exercise mln::p_set<P>::remove.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@1999 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent aea80741
2008-06-06 Roland Levillain <roland@lrde.epita.fr>
Have mln:p_set be able to erase its elements.
* mln/core/p_set.hh (mln::p_set<P>::remove): Enable this method.
* mln/core/internal/set_of.hh (mln::internal::set_of_<E>::s_):
Make it protected.
(mln::internal::set_of_<E>::remove): Use std::set::erase instead
of std::remove.
* tests/core/p_set.cc: Exercise mln::p_set<P>::remove.
2008-06-04 Graud Bguin <geraud.beguin@lrde.epita.fr>
* mln/util/graph.hh: Typo.
......
......@@ -147,13 +147,14 @@ namespace mln
*/
mutable std::vector<E> v_;
protected:
/*! \brief Set of elements.
*
* This structure is always up-to-date w.r.t. the set contents.
*/
std::set<E> s_;
private:
/*! \brief Update \a v_ from \a s_.
*
* FIXME: explain.
......@@ -206,8 +207,7 @@ namespace mln
set_of_<E>&
set_of_<E>::remove(const E& elt)
{
// FIXME : doesn't compile
std::remove(s_.begin(), s_.end(), elt);
s_.erase(elt);
if (needs_update_ == false)
needs_update_ = true;
return internal::force_exact< set_of_<E> >(*this);
......
......@@ -78,9 +78,8 @@ namespace mln
/// Insert a point \p p.
p_set<P>& insert(const P& p);
// FIXME : doesn't compile
// /// Remove a point \p p.
// p_set<P>& remove(P& p);
/// Remove a point \p p.
p_set<P>& remove(const P& p);
/// Return the \p i-th point.
const P& operator[](unsigned i) const;
......@@ -132,17 +131,19 @@ namespace mln
return *this;
}
// FIXME : finish it.
// template <typename P>
// p_set<P>&
// p_set<P>::remove(P& p)
// {
// this->super_::remove(p);
// // FIXME: need to rebuild bb_ ?
// //bb_.untake(p);
// return *this;
// }
template <typename P>
inline
p_set<P>&
p_set<P>::remove(const P& p)
{
this->super_::remove(p);
// Rebuild the bounding box.
bb_.init();
for (typename std::set<P>::const_iterator i = this->s_.begin();
i != this->s_.end(); ++i)
bb_.take(*i);
return *this;
}
template <typename P>
inline
......
......@@ -50,7 +50,14 @@ int main()
mln_assertion(ps.npoints() == 3);
std::cout << ps.bbox() << std::endl;
std::copy(ps.vect().begin(), ps.vect().end(),
std::ostream_iterator<point2d>(std::cout, " "));
std::cout << std::endl;
ps.remove(make::point2d(4, 2));
mln_assertion(ps.npoints() == 2);
std::cout << ps.bbox() << std::endl;
std::copy(ps.vect().begin(), ps.vect().end(),
std::ostream_iterator<point2d>(std::cout, " "));
std::cout << std::endl;
......
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