Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add rle_class, not finish yet.
* oln/core/rle: New.
* oln/core/rle/rle_image.hh: New.
* oln/core/rle/rle_psite.hh: New.
* oln/core/rle/rle_pset.hh: New.
rle_image.hh | 184 ++++++++++++++++++++++++++++
rle_pset.hh | 375 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rle_psite.hh | 104 ++++++++++++++++
3 files changed, 663 insertions(+)
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 0)
+++ oln/core/rle/rle_image.hh (revision 0)
@@ -0,0 +1,184 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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 OLN_CORE_RLE_RLE_IMAGE_HH_
+# define OLN_CORE_RLE_RLE_IMAGE_HH_
+
+# include <map>
+# include <utility>
+
+
+# include <oln/core/internal/image_base.hh>
+# include <oln/core/rle/rle_psite.hh>
+# include <oln/core/rle/rle_pset.hh>
+
+
+
+namespace oln
+{
+ // Fwd decl.
+ template <typename P, typename T>
+ struct rle_image;
+
+ // Super type.
+ template <typename P, typename T>
+ struct super_trait_< rle_image<P, T> >
+ {
+ typedef rle_image<P, T> current;
+ typedef internal::primitive_image_<current> ret;
+ };
+
+ // Virtual types
+ template <typename P, typename T>
+ struct vtypes< rle_image<P, T> >
+ {
+ typedef T value;
+ typedef const T& rvalue;
+ typedef T& lvalue;
+
+ typedef P point;
+ typedef typename P::coord coord;
+
+ typedef rle_psite<P, T> psite;
+
+ typedef rle_pset<point> pset;
+// typedef typename pset::box box;
+
+ typedef std::map<std::pair<point, unsigned>, value> data;
+ };
+
+
+ // Rle image class
+ template < typename P, typename T>
+ class rle_image : public internal::primitive_image_< rle_image<P, T> >
+ {
+ typedef rle_image<P, T> current;
+ typedef internal::primitive_image_< rle_image<P, T> > super;
+ public:
+ stc_using(pset);
+ stc_using(box);
+ stc_using(point);
+ stc_using(value);
+ stc_using(rvalue);
+ stc_using(lvalue);
+ stc_using(psite);
+ stc_using(data);
+
+ rle_image();
+
+ pset impl_points() const;
+ box impl_bbox() const;
+ bool impl_has(const point& p) const;
+ bool impl_owns_(const psite& p) const;
+ void insert(const point& p, unsigned len, value val);
+ 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
+
+ template <typename P, typename T>
+ rle_image<P, T>::rle_image()
+ {
+ this->data_ = new typename rle_image<P, T>::data;
+ }
+
+ template <typename P, typename T>
+ typename rle_image<P, T>::pset
+ rle_image<P, T>::impl_points() const
+ {
+ return pset_;
+ }
+
+
+ template <typename P, typename T>
+ typename rle_image<P, T>::box
+ rle_image<P, T>::impl_bbox() const
+ {
+ return pset_.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_());
+ }
+
+ 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_());
+ }
+
+ 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;
+ }
+
+ 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
+ {
+ precondition(p.iterator_() != this->data_->end());
+ return p.iterator_()->second;
+ }
+
+ 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)
+ {
+ precondition(p.iterator_() != this->data_->end());
+ return p.iterator_()->second;
+ }
+
+ 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_);
+ }
+
+
+# endif // !OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+#endif /* !OLN_CORE_RLE_RLE_IMAGE_HH_ */
Index: oln/core/rle/rle_psite.hh
--- oln/core/rle/rle_psite.hh (revision 0)
+++ oln/core/rle/rle_psite.hh (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2006, 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 OLN_CORE_RLE_RLE_PSITE_HH_
+# define OLN_CORE_RLE_RLE_PSITE_HH_
+
+
+# include <map>
+# include <utility>
+
+namespace oln
+{
+
+
+ // Forward declaration
+ template <typename P, typename T> struct rle_image;
+
+ /*
+ ** \class rle_piste
+ ** \brief psite for rle image
+ **
+ **
+ **
+ */
+ template <typename P, typename T>
+ 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_*/
+ };
+
+# 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())
+ {
+ P pend;
+
+// for (this->it_ = ima.get_data_().begin(); this->it_ != ima.get_data_().end(); ++(this->it_))
+// {
+// pend = this->it_->first.first;
+// pend[0] += this->it_->first.second - 1;
+// if (this->it_->first.first >= p && p <= pend)
+// return;
+// }
+ 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_()
+ {
+ return this->it_;
+ }
+
+ template <typename P, typename T>
+ const P&
+ rle_psite<P, T>::point_() const
+ {
+ return p_;
+ }
+
+# endif /* !OLN_INCLUDE_ONLY */
+
+ //end of class rle_psite
+}
+#endif /* !OLN_CORE_RLE_RLE_PSITE_HH_ */
Index: oln/core/rle/rle_pset.hh
--- oln/core/rle/rle_pset.hh (revision 0)
+++ oln/core/rle/rle_pset.hh (revision 0)
@@ -0,0 +1,375 @@
+// Copyright (C) 2006, 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 OLN_CORE_RLE_RLE_PSET_HH_
+# define OLN_CORE_RLE_RLE_PSET_HH_
+
+# include <set>
+# include <utility>
+
+# include <oln/core/rle/rle_psite.hh>
+
+# include <oln/core/internal/point_set_base.hh>
+
+# include <oln/core/concept/iterator_on_points.hh>
+
+# include <oln/core/gen/fbbox.hh>
+
+namespace oln
+{
+
+ // Forwards declaration
+ template <typename P> struct rle_pset;
+ template <typename P> struct rle_pset_fwd_piter_;
+ template <typename P> struct rle_pset_bkd_piter_;
+
+ // Vtypes associated to rle_pset class
+ template <typename P>
+ struct vtypes< rle_pset<P> >
+ {
+ typedef P point;
+ typedef typename P::grid grid;
+
+ typedef fbbox_<point> box;
+
+ typedef rle_pset_fwd_piter_<P> fwd_piter;
+ typedef rle_pset_bkd_piter_<P> bkd_piter;
+ typedef fwd_piter piter;
+ };
+
+ // rle_pset class
+
+ template <typename P>
+ class rle_pset : public internal::point_set_base_<rle_pset <P> >
+ {
+ typedef rle_pset<P> current;
+ typedef internal::point_set_base_<rle_pset<P> > super;
+ public:
+ stc_using(point);
+ stc_using(box);
+
+ typedef std::set< std::pair<point, unsigned> > std_container;
+
+ rle_pset();
+
+ unsigned impl_npoints() const;
+ const box& impl_bbox() const;
+ void insert(const P& p, unsigned len);
+ bool impl_has(const P& p) const;
+ const std_container& con() const;
+
+ protected:
+ unsigned npts;
+ std_container con_;
+ fbbox_<point> fb_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename P>
+ rle_pset<P>::rle_pset() : npts(0)
+ {
+ }
+
+
+ template <typename P>
+ unsigned
+ rle_pset<P>::impl_npoints() const
+ {
+ return npts;
+ }
+
+ template <typename P>
+ void
+ rle_pset<P>::insert(const P& p, unsigned len)
+ {
+ con_.insert(std::make_pair(p, len));
+ P pend;
+
+ //update bbox
+ fb_.take(p);
+ pend = p;
+ pend[0] += len - 1;
+ fb_.take(pend);
+
+ // update size
+ npts += len;
+ }
+
+ template <typename P>
+ const typename rle_pset<P>::box&
+ rle_pset<P>::impl_bbox() const
+ {
+ return fb_;
+ }
+
+ template <typename P>
+ bool
+ rle_pset<P>::impl_has(const P& p) const
+ {
+ point pend;
+ typename std_container::const_iterator iter;
+
+ for (iter = con_.begin(); iter != con_.end(); ++iter )
+ {
+ pend = iter->first;
+ pend[0] += iter->second - 1;
+ if (iter->first >= p && p <= pend)
+ return 1;
+ }
+ return 0;
+ }
+
+ // end of rle_pset class
+
+ template <typename P>
+ const typename rle_pset<P>::std_container&
+ rle_pset<P>::con() const
+ {
+ return this->con_;
+ }
+
+
+# endif // !OLN_INCLUDE_ONLY
+
+
+ // -------------------- iterators on classes deriving from internal::rle_pset<P>
+
+ // Forward declaration
+ template <typename P>
+ class rle_pset_fwd_piter_;
+
+ // Virtual types
+ template <typename P>
+ struct vtypes< rle_pset_fwd_piter_<P> >
+ {
+ typedef P point;
+ };
+
+ // class rle_pset_fwd_iterator_
+ template <typename P>
+ class rle_pset_fwd_piter_ : public Iterator_on_Points< rle_pset_fwd_piter_<P> >
+ {
+ typedef Iterator_on_Points< rle_pset_fwd_piter_<P> > super;
+ typedef rle_pset_fwd_piter_<P> current;
+ public:
+ stc_using(point);
+
+ rle_pset_fwd_piter_(const rle_pset<P>& con);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
+
+ protected:
+ const typename rle_pset<P>::std_container& con_;
+ typename rle_pset<P>::std_container::const_iterator it_;
+ point p_;
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename P>
+ rle_pset_fwd_piter_<P>::rle_pset_fwd_piter_(const rle_pset<P>& cont) : con_(cont.con())
+ {
+ this->it_ = this->con_.end();
+ }
+
+ template <typename P>
+ void
+ rle_pset_fwd_piter_<P>::impl_start()
+ {
+ this->it_ = this->con_.begin();
+ this->p_ = this->it_->first;
+ }
+
+ template <typename P>
+ void
+ rle_pset_fwd_piter_<P>::impl_next()
+ {
+ point pend;
+
+ if (!this->is_valid())
+ return;
+
+ pend = this->it_->first;
+ pend[0] += this->it_->second - 1;
+
+ ++p_[0];
+ if (p_ > pend)
+ {
+ ++it_;
+ p_ = this->it_->first;
+ }
+ }
+
+ template <typename P>
+ void
+ rle_pset_fwd_piter_<P>::impl_invalidate()
+ {
+ this->it_ = this->con_.end();
+ }
+
+ template <typename P>
+ bool
+ rle_pset_fwd_piter_<P>::impl_is_valid() const
+ {
+ return this->it_ != this->con_.end();
+ }
+
+ template <typename P>
+ typename rle_pset_fwd_piter_<P>::point
+ rle_pset_fwd_piter_<P>::impl_to_point() const
+ {
+ return p_;
+ }
+
+ template <typename P>
+ const typename rle_pset_fwd_piter_<P>::point*
+ rle_pset_fwd_piter_<P>::impl_point_adr() const
+ {
+ return &p_;
+ }
+
+# endif // !OLN_INCLUDE_ONLY
+
+ //end of class rle_pset_fwd_iterator_
+
+ // Forward declaration
+ template <typename P>
+ class rle_pset_bkd_piter_;
+
+ // Virtual type
+ template <typename P>
+ struct vtypes< rle_pset_bkd_piter_<P> >
+ {
+ typedef P point;
+ };
+
+ // class rle_pset_bkd_piter_
+
+ template <typename P>
+ class rle_pset_bkd_piter_ : public Iterator_on_Points< rle_pset_bkd_piter_<P> >
+ {
+ typedef Iterator_on_Points< rle_pset_bkd_piter_<P> > super;
+ typedef rle_pset_bkd_piter_<P> current;
+ public:
+ stc_using(point);
+
+ rle_pset_bkd_piter_(const rle_pset<P>& con);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
+
+ protected:
+ const typename rle_pset<P>::std_container& con_;
+ typename rle_pset<P>::std_container::const_reverse_iterator it_;
+ point p_;
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename P>
+ rle_pset_bkd_piter_<P>::rle_pset_bkd_piter_(const rle_pset<P>& cont) : con_(cont.con())
+ {
+ this->it_ = this->con_.rend();
+ }
+
+ template <typename P>
+ void
+ rle_pset_bkd_piter_<P>::impl_start()
+ {
+ this->it_ = this->con_.rbegin();
+ this->p_ = this->it_->first;
+ this->p_[0] += this->it_->second - 1;
+ }
+
+ template <typename P>
+ void
+ rle_pset_bkd_piter_<P>::impl_next()
+ {
+ point pend;
+
+ if (!this->is_valid())
+ return;
+
+ pend = this->it_->first;
+
+ --p_[0];
+ if (p_ < pend)
+ {
+ ++it_;
+ p_ = this->it_->first;
+ this->p_[0] += this->it_->second - 1;
+ }
+ }
+
+ template <typename P>
+ void
+ rle_pset_bkd_piter_<P>::impl_invalidate()
+ {
+ this->it_ = this->con_.rend();
+ }
+
+ template <typename P>
+ bool
+ rle_pset_bkd_piter_<P>::impl_is_valid() const
+ {
+ return this->it_ != this->con_.rend();
+ }
+
+ template <typename P>
+ typename rle_pset_bkd_piter_<P>::point
+ rle_pset_bkd_piter_<P>::impl_to_point() const
+ {
+ return p_;
+ }
+
+ template <typename P>
+ const typename rle_pset_bkd_piter_<P>::point*
+ rle_pset_bkd_piter_<P>::impl_point_adr() const
+ {
+ return &p_;
+ }
+
+# endif // !OLN_INCLUDE_ONLY
+
+ // end of class rle_pset_bkd_piter_
+
+
+} // end of namespace oln
+
+
+#endif /* !OLN_CORE_RLE_RLE_PSET_HH_ */
2
1
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
2
1
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
sparse_encode working.
* oln/core/encode/sparse_encode.hh: Update
sparse_encode.hh | 39 ++++++++++++++++++++++++++++++++++++---
1 file changed, 36 insertions(+), 3 deletions(-)
Index: oln/core/encode/sparse_encode.hh
--- oln/core/encode/sparse_encode.hh (revision 879)
+++ oln/core/encode/sparse_encode.hh (working copy)
@@ -33,6 +33,8 @@
# include <oln/core/sparse/sparse_image.hh>
+# include <vector>
+
namespace oln
{
@@ -45,13 +47,44 @@
*/
template <typename I>
sparse_image<typename I::point, typename I::value>
- sparse_encode(const Image<I> input)
+ sparse_encode(const Image<I>& input)
{
sparse_image<typename I::point, typename I::value> output;
typename I::piter p (input.points());
- // typename I::coord len = 1;
+ unsigned len = 1;
+ typename I::coord old = 1; /*!< old point first dim coordinate */
typename I::point rstart; /*!< range pointstart */
- typename I::value rvalue; /*!< range value */
+ std::vector<typename I::value> values; /*!< range value */
+
+ p.start();
+ if (!p.is_valid())
+ return output;
+
+ rstart = p;
+ //FIXME: is it generall ?
+ old = (p.to_point())[0];
+ values.push_back(input(p.to_point()));
+ p.next();
+ while (p.is_valid())
+ {
+ if ((p.to_point())[0] - 1 == old)
+ {
+ ++len;
+ values.push_back(input(p.to_point()));
+ }
+ else
+ {
+ output.insert(rstart, len, values);
+ rstart = p;
+ len = 1;
+ values.clear();
+ values.push_back(input(p.to_point()));
+ }
+ old = (p.to_point())[0];
+ p.next();
+ }
+ output.insert(rstart, len, values);
+ return output;
}
}
2
1
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Fix bug on sparse image.
* oln/core/encode/sparse_encode.hh: New.
* oln/core/sparse/sparse_image.hh: sparse_image class working now
encode/sparse_encode.hh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++
sparse/sparse_image.hh | 8 +++---
2 files changed, 62 insertions(+), 4 deletions(-)
Index: oln/core/encode/sparse_encode.hh
--- oln/core/encode/sparse_encode.hh (revision 0)
+++ oln/core/encode/sparse_encode.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 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 SPARSE_ENCODE_HH_
+# define SPARSE_ENCODE_HH_
+
+# include <oln/core/concept/image.hh>
+
+# include <oln/core/sparse/sparse_image.hh>
+
+namespace oln
+{
+
+ /*!
+ ** encode a generic image to a sparse image format
+ **
+ ** @param input an Image
+ **
+ ** @return a sparse image
+ */
+ template <typename I>
+ sparse_image<typename I::point, typename I::value>
+ sparse_encode(const Image<I> input)
+ {
+ sparse_image<typename I::point, typename I::value> output;
+ typename I::piter p (input.points());
+ // typename I::coord len = 1;
+ typename I::point rstart; /*!< range pointstart */
+ typename I::value rvalue; /*!< range value */
+ }
+}
+
+#endif /* !SPARSE_ENCODE_HH_ */
Index: oln/core/sparse/sparse_image.hh
--- oln/core/sparse/sparse_image.hh (revision 878)
+++ oln/core/sparse/sparse_image.hh (working copy)
@@ -133,9 +133,9 @@
typename sparse_image<P, T>::rvalue
sparse_image<P, T>::impl_read(const sparse_image<P, T>::psite& ps) const
{
- typename std::map<point, value>::const_iterator irun;
+ typename std::map<point, std::vector<value> >::const_iterator irun;
- irun = this->data_->second.find(ps.start_);
+ irun.operator= (this->data_->second.find(ps.start_));
assert(irun != this->data_->second.end() && ps.index_ < this->data_->first.range_len_(ps.start_));
return irun->second[ps.index_];
}
@@ -144,9 +144,9 @@
typename sparse_image<P, T>::lvalue
sparse_image<P, T>::impl_read_write(const sparse_image<P, T>::psite& ps)
{
- typename std::map<point, value>::const_iterator irun;
+ typename std::map<point, std::vector<value> >::iterator irun;
- irun = this->data_->second.find(ps.start_);
+ irun.operator= (this->data_->second.find(ps.start_));
assert(irun != this->data_->second.end() && ps.index_ < this->data_->first.range_len_(ps.start_));
return irun->second[ps.index_];
}
2
1
max and min value for any type can be obtain with std lib yet.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Update and add : apply, local canvas.
* tests/core/Makefile.am: .
* oln/function: New.
* oln/function/min.hh: New.
* oln/level/apply.hh: .
* oln/level/local.hh: New.
* oln/core/concept/image.hh: .
* oln/core/concept/functions.hh: .
* oln/core/internal/max_value.hh: New.
* oln/morphomath: New.
* oln/morphomath/dilatation.hh: New.
* oln/morphomath/erosion.hh: New.
oln/core/concept/functions.hh | 10 ++++
oln/core/internal/max_value.hh | 42 +++++++++++++++++
oln/function/min.hh | 68 +++++++++++++++++++++++++++++
oln/level/apply.hh | 87 ++++++++++++++++++++++++++++++++++---
oln/level/local.hh | 96 +++++++++++++++++++++++++++++++++++++++++
oln/morphomath/dilatation.hh | 29 ++++++++++++
oln/morphomath/erosion.hh | 59 +++++++++++++++++++++++++
tests/core/Makefile.am | 1
8 files changed, 384 insertions(+), 8 deletions(-)
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 874)
+++ tests/core/Makefile.am (working copy)
@@ -37,7 +37,6 @@
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
window2d_SOURCES = window2d.cc
-neighb2d_SOURCES = neighb2d.cc
# Methods.
at_SOURCES = at.cc
Index: oln/function/min.hh
--- oln/function/min.hh (revision 0)
+++ oln/function/min.hh (revision 0)
@@ -0,0 +1,68 @@
+// 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 OLN_FUNCTION_MIN_HH_
+# define OLN_FUNCTION_MIN_HH_
+
+namespace oln
+{
+
+ template <typename T>
+ struct min_ : oln::Function< min_<T> >
+ {
+ typedef T argument;
+ typedef void result;
+
+ min_()
+ {
+ init();
+ }
+
+ void init()
+ {
+ val_ = oln_max_value(T);
+ }
+
+ T value() const
+ {
+ return val_;
+ }
+
+ template <typename U>
+ void operator()(U i) const
+ {
+ if (i < val_)
+ val_ = static_cast<T>(i);
+ }
+ private:
+ mutable T val_;
+ };
+
+}
+
+#endif /* !OLN_FUNCTION_MIN_HH_ */
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 874)
+++ oln/level/apply.hh (working copy)
@@ -63,16 +63,63 @@
namespace impl
{
- /// Generic version.
+ template < typename F >
+ struct result
+ {
+ typedef typename F::result ret;
+ };
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
+ template < typename R (*fun)(A) >
+ struct result
+ {
+ typedef typename R ret;
+ };
+
+ template < typename F >
+ struct argument
+ {
+ typedef typename F::argument ret;
+ };
+
+ template < typename R (*fun)(A) >
+ struct argument
+ {
+ typedef typename A ret;
+ };
+
+
+ // APPLY //
+ //---------
+
+ template <typename F, typename I>
+ oln_plain_value(I, result<typename F>::ret)
+ apply(const F& fun, const Image<I>& input)
+ {
+ typedef argument<typename F>::ret A;
+ typedef result<typename F>::ret R;
+
+ oln_ch_value(I, R) output(input.points());
+ oln_piter(I) p(input.points());
+ for_all(p)
+ output(p) = fun( static_cast<A>(input(p)) );
+ return output;
+ }
+
+
+ // APPLY_LOCAL //
+ //---------------
+
+ template <typename F, typename I>
+ oln_plain_value(I, result<typename F>::ret)
+ apply_local(const F& fun, const Image<I>& input)
{
- oln_plain_value(I, R) output(input.points());
+ typedef argument<typename F>::ret A;
+ typedef result<typename F>::ret R;
+
+ oln_ch_value(I, R) output(input.points());
oln_piter(I) p(input.points());
for_all(p)
- output(p) = fun(input(p));
+ output(p) = local_apply(fun, input, p);
return output;
}
@@ -112,8 +159,11 @@
} // end of namespace oln::level::impl
+ /// Facades.
+ //----------------------------
+
+ /// Apply.
- /// Facade.
template <typename R, typename A, typename I>
oln_plain_value(I, R)
apply(R (*fun)(A), const Image<I>& input)
@@ -121,6 +171,29 @@
return impl::apply(fun, exact(input));
}
+ template <typename F, typename I>
+ oln_plain_value(I, typename F::result)
+ apply(const F& fun, const Image<I>& input)
+ {
+ return impl::apply(fun, exact(input));
+ }
+
+ /// Apply local
+
+ template <typename R, typename A, typename I>
+ oln_plain_value(I, R)
+ apply_local(R (*fun)(A), const Image<I>& input)
+ {
+ return impl::apply_local(fun, exact(input));
+ }
+
+ template <typename F, typename I>
+ oln_plain_value(I, typename F::result)
+ apply_local(const F& fun, const Image<I>& input)
+ {
+ return impl::apply_local(fun, exact(input));
+ }
+
// /// Facade.
// template <typename I, typename F>
// oln_plain_value(I, typename F::result_value)
Index: oln/level/local.hh
--- oln/level/local.hh (revision 0)
+++ oln/level/local.hh (revision 0)
@@ -0,0 +1,96 @@
+// 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 OLN_LEVEL_LOCAL_HH_
+# define OLN_LEVEL_LOCAL_HH_
+
+namespace oln
+{
+
+ namespace impl
+ {
+
+ // LOCAL APPLICATION ON NBH //
+ //----------------------------
+
+ /// Local Apply on neighborhood ( nbh included in image ).
+
+ template <typename R, typename A, typename I>
+ typename A::result
+ local_apply(const Accumulator< A >& fun,
+ const Image_with_Nbh< I >& input,
+ const oln_point( I )& p)
+ {
+ fun.init();
+ oln_niter(I) n(p, input.points());
+ for_all(n)
+ fun(input(n));
+ return fun.value();
+ }
+
+
+ /// Local Apply on neighborhood ( nhb has to be given ).
+
+ // ...FIXME
+
+
+ // LOCAL APPLICATION ON WINDOW //
+ //-------------------------------
+
+ /// Local Apply on window ( window included in image).
+
+ // ...FIXME
+
+
+ /// Local Apply on window ( window is given ).
+
+ template <typename F, typename I, typename W>
+ typename F::result
+ local_apply(const Accumulator<F>& fun,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ fun.init();
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ fun(input(q));
+ return fun.value();
+ }
+
+ }
+
+ /// Facades.
+
+ local_apply( )
+ {
+
+ }
+
+}
+#endif /* !OLN_LEVEL_LOCAL_HH_ */
Index: oln/core/concept/image.hh
Index: oln/core/concept/functions.hh
--- oln/core/concept/functions.hh (revision 874)
+++ oln/core/concept/functions.hh (working copy)
@@ -73,6 +73,16 @@
};
+ // Neighborhood -> Value.
+
+ template <typename Exact>
+ struct Accumulator : public Function<Exact>
+ {
+ protected:
+ Accumulator();
+ };
+
+
/*
// Value1 -> Value2 *and* Value2 -> Value1.
Index: oln/core/internal/max_value.hh
--- oln/core/internal/max_value.hh (revision 0)
+++ oln/core/internal/max_value.hh (revision 0)
@@ -0,0 +1,42 @@
+// 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 OLN_CORE_INTERNAL_MAX_VALUE_HH_
+# define OLN_CORE_INTERNAL_MAX_VALUE_HH_
+
+#include <cassert>
+#include <limits>
+#include <iostream>
+
+namespace oln
+{
+
+#define oln_max(T) std::numeric_limits< T >::max()
+
+}
+
+#endif /* !OLN_CORE_INTERNAL_MAX_VALUE_HH_ */
Index: oln/morphomath/dilatation.hh
--- oln/morphomath/dilatation.hh (revision 0)
+++ oln/morphomath/dilatation.hh (revision 0)
@@ -0,0 +1,29 @@
+#ifndef OLN_MORPHOMATH_DILATATION_HH_
+# define OLN_MORPHOMATH_DILATATION_HH_
+
+// Facade.
+
+namespace impl
+{
+
+ /// Generic version
+
+ template <typename I, typename W>
+ I dilatation(const Image<I>& input)
+ {
+ max_<oln_value(I)> max;
+ return apply(max, input);
+ }
+
+}
+
+
+/// Facade.
+
+template <typename I, typename W>
+I erosion(const Image<I>& input)
+{
+ return impl::dilatation(exact(input));
+}
+
+#endif /* !OLN_MORPHOMATH_DILATATION_HH_ */
Index: oln/morphomath/erosion.hh
--- oln/morphomath/erosion.hh (revision 0)
+++ oln/morphomath/erosion.hh (revision 0)
@@ -0,0 +1,59 @@
+// 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 OLN_MORPHOMATH_EROSION_HH_
+# define OLN_MORPHOMATH_EROSION_HH_
+
+#include <oln/fonction/min.hh>
+#include <oln/level/local.hh>
+
+namespace oln
+{
+ namespace impl
+ {
+
+ /// Generic version
+
+ template <typename I, typename W>
+ I erosion(const Image<I>& input)
+ {
+ min_<oln_value(I)> min;
+ return apply(min, input);
+ }
+ }
+
+ // Facade.
+
+ template <typename I, typename W>
+ I erosion(const Point_Wise_Accessible_Image<I>& input)
+ {
+ return impl::erosion(exact(input));
+ }
+}
+
+#endif /* !OLN_MORPHOMATH_EROSION_HH_ */
2
1
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
New test for rle_class and sparse_image class.
* tests/core/sparse_image.cc: New.
* tests/core/rle_image.cc: New.
* tests/core/Makefile.am: Update
Makefile.am | 5 +++
rle_image.cc | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
sparse_image.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 148 insertions(+)
Index: tests/core/sparse_image.cc
--- tests/core/sparse_image.cc (revision 0)
+++ tests/core/sparse_image.cc (revision 0)
@@ -0,0 +1,69 @@
+#include <iostream>
+#include <oln/core/rle/rle_psite.hh>
+#include <oln/core/2d/image2d.hh>
+#include <oln/debug/print.hh>
+#include <oln/core/rle/rle_pset.hh>
+#include <oln/core/sparse/sparse_image.hh>
+#include <oln/core/encode/sparse_encode.hh>
+
+template <typename Ps>
+void test(const Ps& pset)
+{
+ typename Ps::fwd_piter it (pset);
+
+ for (it.start(); it.is_valid(); it.next())
+ std::cout << it.to_point() << std::endl;
+}
+
+template <typename Ps>
+void rtest(const Ps& pset)
+{
+ typename Ps::bkd_piter it (pset);
+
+ for (it.start(); it.is_valid(); it.next())
+ std::cout << it.to_point() << std::endl;
+}
+
+
+ template <typename I>
+ void print(I& ima)
+{
+ typename I::piter it (ima.points());
+
+ for (it.start(); it.is_valid(); it.next())
+ {
+ std::cout << (oln::point2d) it << std::endl;
+ std::cout << ima(it) << std::endl;
+ }
+}
+
+
+int main()
+{
+ oln::point2d p(0,1), q(2,2), r(3, 0);
+ oln::image2d<int> ima2d (1, 5);
+ oln::sparse_image<oln::point2d, int> sparse;
+ oln::sparse_image<oln::point2d, int> sparse2;
+
+ ima2d(oln::point2d(0, 4)) = 5;
+ oln::debug::print(ima2d);
+
+ std::vector<int> values;
+ int a =5;
+ values.push_back(a);
+ a = 6;
+ values.push_back(a);
+ a = 42;
+ values.push_back(a);
+
+ sparse.insert(q, 3, values);
+
+ oln::debug::print(sparse);
+
+ std::cout << "encode sparse" << std::endl;
+ sparse2 = sparse_encode(ima2d);
+
+ oln::debug::print(sparse2);
+
+ return 0;
+}
Index: tests/core/rle_image.cc
--- tests/core/rle_image.cc (revision 0)
+++ tests/core/rle_image.cc (revision 0)
@@ -0,0 +1,74 @@
+#include <iostream>
+#include <oln/core/rle/rle_psite.hh>
+#include <oln/core/rle/rle_image.hh>
+#include <oln/core/2d/image2d.hh>
+#include <oln/debug/print.hh>
+#include <oln/core/rle/rle_pset.hh>
+#include <oln/core/encode/rle_encode.hh>
+
+
+template <typename Ps>
+void test(const Ps& pset)
+{
+ typename Ps::fwd_piter it (pset);
+
+ for (it.start(); it.is_valid(); it.next())
+ std::cout << it.to_point() << std::endl;
+}
+
+template <typename Ps>
+void rtest(const Ps& pset)
+{
+ typename Ps::bkd_piter it (pset);
+
+ for (it.start(); it.is_valid(); it.next())
+ std::cout << it.to_point() << std::endl;
+}
+
+
+ template <typename I>
+ void print(I& ima)
+{
+ typename I::piter it (ima.points());
+
+ for (it.start(); it.is_valid(); it.next())
+ {
+ std::cout << (oln::point2d) it << std::endl;
+ std::cout << ima(it) << std::endl;
+ }
+}
+
+
+int main()
+{
+ oln::point2d p(0,1), q(2,2), r(3, 0);
+ oln::rle_pset<oln::point2d> my_set;
+ oln::rle_image<oln::point2d, int> rle;
+ oln::rle_image<oln::point2d, int> rle2;
+
+ my_set.insert(p, 5);
+ my_set.insert(q, 8);
+
+ rle.insert(p, 5, 4);
+ rle.insert(q, 8, 9);
+ std::cout << my_set.has(q) << std::endl;
+ test(my_set);
+ std::cout << "reverse" << std::endl;
+ rtest(my_set);
+ std::cout << "ima" << std::endl;
+ print(rle);
+
+ oln::debug::print(rle);
+ std::cout << rle.points().npoints() << std::endl;
+
+ std::cout << "encode rle" << std::endl;
+ oln::image2d<int> ima2d (1, 5);
+ ima2d(oln::point2d(0, 4)) = 5;
+
+ oln::debug::print(ima2d);
+
+ rle2 = rle_encode(ima2d);
+
+ oln::debug::print(rle2);
+ return 0;
+}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 880)
+++ tests/core/Makefile.am (working copy)
@@ -19,6 +19,8 @@
check_PROGRAMS = \
+ rle_image \
+ sparse_image \
apply \
dpoint2d \
point2d \
@@ -30,6 +32,7 @@
window2d \
at
+
# Images and auxiliary structures.
dpoint2d_SOURCES = dpoint2d.cc
point2d_SOURCES = point2d.cc
@@ -39,6 +42,8 @@
npoints_SOURCES = npoints.cc
subset_SOURCES = subset.cc
window2d_SOURCES = window2d.cc
+rle_image_SOURCES = rle_image.cc
+sparse_image_SOURCES = sparse_image.cc
# Methods.
at_SOURCES = at.cc
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Add test for neighborhood.
* tests/core/neighb2d.cc: New.
* tests/core/Makefile.am: .
* oln/core/automatic/impl.hh: .
* oln/core/abstract/internal/image_impl.hh: .
oln/core/abstract/internal/image_impl.hh | 2
oln/core/automatic/impl.hh | 2
tests/core/Makefile.am | 2
tests/core/neighb2d.cc | 65 +++++++++++++++++++++++++++++++
4 files changed, 69 insertions(+), 2 deletions(-)
Index: tests/core/neighb2d.cc
--- tests/core/neighb2d.cc (revision 0)
+++ tests/core/neighb2d.cc (revision 0)
@@ -0,0 +1,65 @@
+// 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.
+
+/// Test oln::neighb2d.
+
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/neighb2d.hh>
+
+
+namespace test
+{
+
+ template <typename I>
+ unsigned run(const oln::Image_with_Nbh<I>& input)
+ {
+ oln_piter(I) p(input.points());
+ oln_niter(I) n(p, input.nbhood());
+ unsigned count = 0;
+
+ for_all(p)
+ {
+ for_all(n)
+ if (input.owns_(n))
+ ++count;
+ }
+ return count;
+ }
+}
+
+
+int main()
+{
+ using namespace oln;
+
+ image2d<bool> ima(3, 3);
+ // 2 + 3 + 2 +
+ // 3 + 4 + 3 +
+ // 2 + 3 + 2 = 24
+ std::cout << test::run(ima + c4) << std::endl;
+ assert(test::run(ima + c4) == 24);
+}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 860)
+++ tests/core/Makefile.am (working copy)
@@ -24,6 +24,7 @@
grid \
image2d \
npoints \
+ neighb2d \
window2d \
at
@@ -34,6 +35,7 @@
image2d_SOURCES = image2d.cc
npoints_SOURCES = npoints.cc
window2d_SOURCES = window2d.cc
+neighb2d_SOURCES = neighb2d.cc
# Methods.
at_SOURCES = at.cc
Index: oln/core/automatic/impl.hh
--- oln/core/automatic/impl.hh (revision 860)
+++ oln/core/automatic/impl.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef OLN_CORE_AUTOMATIC_IMPL_HH
# define OLN_CORE_AUTOMATIC_IMPL_HH
-# include <oln/core/typedefs.hh>
+// # include <oln/core/typedefs.hh>
namespace oln
Index: oln/core/abstract/internal/image_impl.hh
--- oln/core/abstract/internal/image_impl.hh (revision 860)
+++ oln/core/abstract/internal/image_impl.hh (working copy)
@@ -29,7 +29,7 @@
# define OLN_CORE_ABSTRACT_INTERNAL_IMAGE_IMPL_HH
# include <mlc/flags.hh>
-# include <oln/core/typedefs.hh>
+// # include <oln/core/typedefs.hh>
# include <oln/core/abstract/any.hh>
# include <oln/core/macros.hh>
2
1
https://svn.lrde.epita.fr/svn/oln/trunk/static
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Update SCOOP 2 alternative implementation.
* stc/scoop-alt.hh: Split this file into...
* stc/scoop-alt.hh, stc/scoop-alt.inc: ...these.
Catch up with the interface of oln/stc/scoop.hh and
oln/stc/scoop.hxx.
* stc/Makefile.am (nobase_stc_HEADERS): Add scoop-alt.inc.
* tests/scoop-alt.cc: Adjust existing tests.
(ex8, ex9): New tests.
(main): Run them.
stc/Makefile.am | 1
stc/scoop-alt.hh | 720 ++++---------------------
stc/scoop-alt.inc | 1471 +++++++++++++++++++++++++++++------------------------
tests/scoop-alt.cc | 393 +++++++++++---
4 files changed, 1255 insertions(+), 1330 deletions(-)
Index: tests/scoop-alt.cc
--- tests/scoop-alt.cc (revision 877)
+++ tests/scoop-alt.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 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
@@ -31,31 +31,42 @@
/// These examples comes from doc/algorithm.ml.
+#include <cassert>
-#include <mlc/cmp.hh>
#include <mlc/assert.hh>
+#include <mlc/cmp.hh>
#include <stc/scoop-alt.hh>
-// Namespace equipment.
-stc_scoop_equipment_for_namespace(my);
+#include <mlc/int.hh>
// FIXME: Check single_vtype, too.
namespace my
{
+
+ // ------------------------------------------------- Namespace equipment.
+
+# include <stc/scoop-alt.inc>
+
+
// ------------------------------------------------------------ Typedefs.
mlc_decl_typedef(my_type);
- mlc_decl_typedef(foo_type);
- mlc_decl_typedef(bar_type);
- mlc_decl_typedef(baz_type);
- mlc_decl_typedef(quux_type);
- mlc_decl_typedef(hop_type);
+ mlc_decl_typedef(foo);
+ mlc_decl_typedef(bar);
+ mlc_decl_typedef(baz);
+ mlc_decl_typedef(quux);
+ mlc_decl_typedef(hop);
+
+ mlc_decl_typedef(value);
- mlc_decl_typedef(value_type);
+ mlc_decl_typedef(dim);
+ mlc_decl_typedef(mydim);
+
+ mlc_decl_typedef(grid);
@@ -78,7 +89,7 @@
}
// Set super type.
- template <> struct set_super_type<ex1::A> { typedef stc::none ret; };
+ template <> struct super_trait_<ex1::A> { typedef stc::none ret; };
/// Virtual types associated to A.
template <>
@@ -95,7 +106,7 @@
check()
{
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex1::A, my), int)
+ mlc_eq(stc_find_type_(my::ex1::A, my_type), int)
>::check();
}
}
@@ -131,9 +142,9 @@
}
// Set super types.
- template <> struct set_super_type<ex2::A> { typedef stc::none ret; };
- template <> struct set_super_type<ex2::B> { typedef ex2::A ret; };
- template <> struct set_super_type<ex2::C> { typedef ex2::B ret; };
+ template <> struct super_trait_<ex2::A> { typedef stc::none ret; };
+ template <> struct super_trait_<ex2::B> { typedef ex2::A ret; };
+ template <> struct super_trait_<ex2::C> { typedef ex2::B ret; };
/// Virtual types associated to A.
template <>
@@ -166,15 +177,15 @@
check()
{
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex2::A, my), int)
+ mlc_eq(stc_find_type_(my::ex2::A, my_type), int)
>::check();
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex2::B, my), float)
+ mlc_eq(stc_find_type_(my::ex2::B, my_type), float)
>::check();
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex2::C, my), int)
+ mlc_eq(stc_find_type_(my::ex2::C, my_type), int)
>::check();
}
}
@@ -205,8 +216,8 @@
}
// Set super types.
- template <> struct set_super_type<ex3::A> { typedef stc::none ret; };
- template <> struct set_super_type<ex3::B> { typedef ex3::A ret; };
+ template <> struct super_trait_<ex3::A> { typedef stc::none ret; };
+ template <> struct super_trait_<ex3::B> { typedef ex3::A ret; };
/// Virtual types associated to A.
template <>
@@ -231,7 +242,7 @@
check()
{
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex3::B, my), int)
+ mlc_eq(stc_find_type_(my::ex3::B, my_type), int)
>::check();
}
}
@@ -258,7 +269,7 @@
}
// Set super type.
- template <> struct set_super_type<ex4::A> { typedef stc::none ret; };
+ template <> struct super_trait_<ex4::A> { typedef stc::none ret; };
/// Virtual types associated to A.
template <>
@@ -275,7 +286,7 @@
check()
{
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex4::A, my), int)
+ mlc_eq(stc_find_type_(my::ex4::A, my_type), int)
>::check();
}
}
@@ -303,7 +314,7 @@
// C<>--D
class C < stc::none
{
- vtype delegatee_type = D;
+ vtype delegatee = D;
}
type t = C#my_type;
@@ -318,9 +329,9 @@
}
// Set super types.
- template <> struct set_super_type<ex5::A> { typedef stc::none ret; };
- template <> struct set_super_type<ex5::D> { typedef stc::none ret; };
- template <> struct set_super_type<ex5::C> { typedef ex5::A ret; };
+ template <> struct super_trait_<ex5::A> { typedef stc::none ret; };
+ template <> struct super_trait_<ex5::D> { typedef stc::none ret; };
+ template <> struct super_trait_<ex5::C> { typedef ex5::A ret; };
/// Virtual types associated to A.
template <>
@@ -339,7 +350,7 @@
template <>
struct vtypes<ex5::C>
{
- typedef ex5::D delegatee_type;
+ typedef ex5::D delegatee;
};
namespace ex5
@@ -352,7 +363,7 @@
check()
{
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex5::C, my), stc::not_found)
+ mlc_eq(stc_find_type_(my::ex5::C, my_type), stc::not_found)
>::check();
}
}
@@ -381,7 +392,7 @@
class A < stc::none | class C < B
{ | {
- } | vtype delegatee_type = Y;
+ } | vtype delegatee = Y;
class B < A | vtype foo = int;
{ | vtype baz = not_delegated;
vtype foo = 0; | vtype hop = not_delegated;
@@ -414,15 +425,15 @@
}
// Set super types.
- template <> struct set_super_type<ex6::A> { typedef stc::none ret; };
- template <> struct set_super_type<ex6::B> { typedef ex6::A ret; };
+ template <> struct super_trait_<ex6::A> { typedef stc::none ret; };
+ template <> struct super_trait_<ex6::B> { typedef ex6::A ret; };
- template <> struct set_super_type<ex6::X> { typedef stc::none ret; };
- template <> struct set_super_type<ex6::Y> { typedef ex6::X ret; };
+ template <> struct super_trait_<ex6::X> { typedef stc::none ret; };
+ template <> struct super_trait_<ex6::Y> { typedef ex6::X ret; };
- template <> struct set_super_type<ex6::C> { typedef ex6::B ret; };
- template <> struct set_super_type<ex6::D> { typedef ex6::C ret; };
- template <> struct set_super_type<ex6::E> { typedef ex6::D ret; };
+ template <> struct super_trait_<ex6::C> { typedef ex6::B ret; };
+ template <> struct super_trait_<ex6::D> { typedef ex6::C ret; };
+ template <> struct super_trait_<ex6::E> { typedef ex6::D ret; };
/// Virtual types associated to A.
template <>
@@ -434,47 +445,47 @@
template <>
struct vtypes<ex6::B>
{
- typedef stc::abstract foo_type;
+ typedef stc::abstract foo;
};
/// Virtual types associated to X.
template <>
struct vtypes<ex6::X>
{
- typedef stc::abstract bar_type;
- typedef int hop_type;
+ typedef stc::abstract bar;
+ typedef int hop;
};
/// Virtual types associated to Y.
template <>
struct vtypes<ex6::Y>
{
- typedef short baz_type;
- typedef char bar_type;
+ typedef short baz;
+ typedef char bar;
};
/// Virtual types associated to C.
template <>
struct vtypes<ex6::C>
{
- typedef ex6::Y delegatee_type;
- typedef int foo_type;
- typedef stc::not_delegated baz_type;
- typedef stc::not_delegated hop_type;
+ typedef ex6::Y delegatee;
+ typedef int foo;
+ typedef stc::not_delegated baz;
+ typedef stc::not_delegated hop;
};
/// Virtual types associated to D.
template <>
struct vtypes<ex6::D>
{
- typedef unsigned quux_type;
+ typedef unsigned quux;
};
/// Virtual types associated to E.
template <>
struct vtypes<ex6::E>
{
- typedef float baz_type;
+ typedef float baz;
};
namespace ex6
@@ -493,23 +504,23 @@
check()
{
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex6::E, foo), int)
+ mlc_eq(stc_find_type_(my::ex6::E, foo), int)
>::check();
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex6::E, bar), char)
+ mlc_eq(stc_find_type_(my::ex6::E, bar), char)
>::check();
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex6::E, baz), float)
+ mlc_eq(stc_find_type_(my::ex6::E, baz), float)
>::check();
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex6::E, quux), unsigned)
+ mlc_eq(stc_find_type_(my::ex6::E, quux), unsigned)
>::check();
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex6::E, hop), stc::not_found)
+ mlc_eq(stc_find_type_(my::ex6::E, hop), stc::not_found)
>::check();
}
}
@@ -521,24 +532,24 @@
class /image_entry/ < stc::none
{
- vtype value_type = 0;
+ vtype value = 0;
}
class image2d<int> < image_entry
{
- vtypes value_type = int;
+ vtypes value = int;
}
class /value_morpher/ < image_entry
{
- vtype delegatee_type = 0;
- vtype value_type = stc::not_delegated;
+ vtype delegatee = 0;
+ vtype value = stc::not_delegated;
}
class value_cast<image2d<int>, float> < value_morpher
{
- vtype delegatee_type = image2d<int>;
- vtype value_type = float;
+ vtype delegatee = image2d<int>;
+ vtype value = float;
}
*/
@@ -557,22 +568,22 @@
// Set super types.
template <>
- struct set_super_type<ex7::abstract::image_entry>
+ struct super_trait_<ex7::abstract::image_entry>
{
typedef stc::none ret;
};
template <>
- struct set_super_type<ex7::abstract::value_morpher>
+ struct super_trait_<ex7::abstract::value_morpher>
{
typedef ex7::abstract::image_entry ret;
};
template <typename T>
- struct set_super_type< ex7::image2d<T> >
+ struct super_trait_< ex7::image2d<T> >
{
typedef ex7::abstract::image_entry ret;
};
template <typename I, typename T>
- struct set_super_type< ex7::value_cast<I, T> >
+ struct super_trait_< ex7::value_cast<I, T> >
{
typedef ex7::abstract::value_morpher ret;
};
@@ -582,30 +593,30 @@
template <>
struct vtypes<ex7::abstract::image_entry>
{
- typedef stc::abstract value_type;
+ typedef stc::abstract value;
};
/// Virtual types associated to abstract::value_morpher.
template <>
struct vtypes<ex7::abstract::value_morpher>
{
- typedef stc::abstract delegatee_type;
- typedef stc::not_delegated value_type;
+ typedef stc::abstract delegatee;
+ typedef stc::not_delegated value;
};
/// Virtual types associated to image2d<T>.
template <typename T>
struct vtypes< ex7::image2d<T> >
{
- typedef T value_type;
+ typedef T value;
};
/// Virtual types associated to value_cast<I, T>.
template <typename I, typename T>
struct vtypes< ex7::value_cast<I, T> >
{
- typedef I delegatee_type;
- typedef T value_type;
+ typedef I delegatee;
+ typedef T value;
};
@@ -628,16 +639,254 @@
check()
{
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, my::ex7::image2d<int>, value), int)
+ mlc_eq(stc_find_type_(my::ex7::image2d<int>, value), int)
>::check();
typedef value_cast< image2d<int>, float> morphed_type;
mlc::assert_<
- mlc_eq(stc_find_vtype_(my, morphed_type, value), float)
+ mlc_eq(stc_find_type_(morphed_type, value), float)
>::check();
}
}
+
+ /* ---------------------------------------------------------------- Ex 8.
+
+ Another Olena-like example with recursive definitions.
+
+ class internal_dpoint_nd < stc::none
+ {
+ vtype mydim = find dpoint2d "dim";
+ }
+
+ class dpoint2d < internal_dpoint_nd
+ {
+ // Dummy value (because our C++ types are limited in this prototype).
+ vtype dim = int
+ }
+
+ This example is translated to C++ using the Exact-type-passing
+ technique in order to perform a test closer to what can be found
+ in Olena. */
+
+ namespace ex8
+ {
+ // Forward declarations.
+ template <typename Exact> struct internal_dpoint_nd;
+ struct dpoint2d;
+ }
+
+ // Set super types.
+ template <typename Exact>
+ struct super_trait_< ex8::internal_dpoint_nd<Exact> >
+ {
+ typedef stc::none ret;
+ };
+ template <>
+ struct super_trait_<ex8::dpoint2d>
+ {
+ typedef ex8::internal_dpoint_nd< ex8::dpoint2d > ret;
+ };
+
+ /// Virtual types associated to internal_dpoint_nd<Exact>.
+ template <typename Exact>
+ struct vtypes< ex8::internal_dpoint_nd <Exact> >
+ {
+ typedef stc_find_type(Exact, dim) mydim;
+ };
+ /// Virtual types associated to dpoint2d.
+ template <>
+ struct vtypes< ex8::dpoint2d >
+ {
+ typedef int dim;
+ };
+
+ namespace ex8
+ {
+ template <typename Exact>
+ struct internal_dpoint_nd : public stc::none
+ {
+ };
+ struct dpoint2d : public internal_dpoint_nd< dpoint2d >
+ {
+ };
+
+ void
+ check()
+ {
+ mlc::assert_<
+ mlc_eq(stc_find_type_(my::ex8::dpoint2d, mydim), int)
+ >::check();
+ }
+
+ } // end of namespace my::ex8
+
+
+ /* ---------------------------------------------------------------- Ex 9.
+
+ Another Olena-inspired example.
+
+ ...
+
+ There are other virtual types in the Olena version of the
+ following classes, but we don't need them for this simple test. */
+
+ // FIXME: I (Roland) don't know why this test succeeds, while the
+ // equivalent SCOOP 2 hierarchy doesn't work in Olena.
+
+ /*------------------------.
+ | internal::point_base_. |
+ `------------------------*/
+
+ // Forward declaration.
+ namespace ex9
+ {
+ namespace internal
+ {
+ template <typename Exact> struct point_base_;
+ }
+ }
+
+ /// Set super type.
+ template <typename Exact>
+ struct super_trait_< ex9::internal::point_base_<Exact> >
+ {
+ typedef stc::none ret;
+ };
+
+ /// Virtual types associated to internal::point_base_<Exact>
+ template <typename Exact>
+ struct vtypes< ex9::internal::point_base_<Exact> >
+ {
+ typedef stc::abstract grid;
+
+ typedef stc_deferred(grid) grid__;
+ typedef stc::final<stc_type(grid__, dim)> dim;
+
+ };
+
+ // Actual definition.
+ namespace ex9
+ {
+ namespace internal
+ {
+ template <typename Exact>
+ struct point_base_ : public stc::none
+ {
+ stc_typename(dim);
+ static const unsigned dim_val = mlc_value(dim);
+ };
+ } // end of namespace my::ex9::internal
+ }
+
+
+ /*---------------------.
+ | internal::point2d_. |
+ `---------------------*/
+
+ // FIXME: Add internal::point2d_, as in Olena, and check whether
+ // this addition triggers the same behavior observed in Olena.
+
+// namespace ex9
+// {
+// // Forward declarations.
+// namespace internal
+// {
+// template <typename Exact> struct point2d_;
+// }
+// }
+
+ // ...
+
+
+ /*---------.
+ | grid2d. |
+ `---------*/
+
+ // Forward declaration.
+ namespace ex9
+ {
+ struct grid2d;
+ }
+
+ /// Set super type.
+ template <>
+ struct super_trait_< ex9::grid2d >
+ {
+ typedef stc::none ret;
+ };
+
+ /// Virtual types associated to grid2d.
+ template <>
+ struct vtypes< ex9::grid2d >
+ {
+ typedef mlc::uint_<2u> dim;
+ };
+
+ // Actual definition.
+ namespace ex9
+ {
+ struct grid2d : public stc::none
+ {
+ };
+ }
+
+
+ /*----------.
+ | point2d. |
+ `----------*/
+
+ // Forward declaration.
+ namespace ex9
+ {
+ struct point2d;
+ }
+
+ /// Set super type.
+ template <>
+ struct super_trait_< ex9::point2d >
+ {
+ typedef ex9::internal::point_base_<ex9::point2d> ret;
+ };
+
+
+ /// Virtual types associated to point2d.
+ template <>
+ struct vtypes< ex9::point2d >
+ {
+ typedef ex9::grid2d grid;
+ };
+
+ // Actual definition.
+ namespace ex9
+ {
+ struct point2d : public internal::point_base_< point2d >
+ {
+ };
+ }
+
+
+ /*---------------------.
+ | Client (test) code. |
+ `---------------------*/
+
+ namespace ex9
+ {
+ void
+ check()
+ {
+ mlc::assert_<
+ mlc_eq(stc_find_type_(my::ex9::point2d, dim), mlc::uint_<2u>)
+ >::check();
+
+ assert(ex9::point2d::dim_val == 2);
+
+ point2d p;
+ }
+
+ } // end of namespace my::ex9
+
+
} // end of namespace my
@@ -651,4 +900,6 @@
my::ex5::check();
my::ex6::check();
my::ex7::check();
+ my::ex8::check();
+ my::ex9::check();
}
Index: stc/scoop-alt.hh
--- stc/scoop-alt.hh (revision 877)
+++ stc/scoop-alt.hh (working copy)
@@ -35,9 +35,15 @@
#ifndef STC_SCOOP_ALT_HH
# define STC_SCOOP_ALT_HH
+/** Define a stick-macro so that we can check in
+ \file stc/scoop-alt.inc that \file stc/scoop-alt.hh has been
+ included (or not) when including the former from client code. */
+# define STATIC_SCOOP_ALT_HH_INCLUDED
+
# include <mlc/flags.hh>
# include <mlc/typedef.hh>
# include <mlc/abort.hh>
+# include <mlc/case.hh>
# include <stc/internal/match-with.hh>
@@ -53,31 +59,46 @@
#endif
using mlc::none;
+ // FIXME: Likewise, define a true stc::not_found type.
+#if 0
struct not_found;
+#endif
+ typedef mlc::not_found not_found;
struct abstract;
struct not_delegated;
struct not_delegated_abstract;
template <typename T> struct final;
+ template < template <class> class category >
+ struct is;
- /// \brief Shortcuts for comparison with stc::not_found.
- ///
- /// Duplicate with their Metalic's homonyms, but still useful, since
- /// they deal with std::not_found (not mlc::not_found).
+
+
+ /// Equality test between a couple of types.
/// \{
template <typename T>
- struct is_not_found_ : public mlc_is_a(T, stc::not_found)::bexpr
- {
- };
+ struct is_found : public mlc::bexpr_<true>
+ {};
+
+ template <>
+ struct is_found< mlc::not_found > : public mlc::bexpr_<false>
+ {};
template <typename T>
- struct is_found_ : public mlc_is_not_a(T, stc::not_found)::bexpr
- {
- };
+ struct is_not_found : public mlc::bexpr_<false>
+ {};
+
+ template <>
+ struct is_not_found< mlc::not_found > : public mlc::bexpr_<true>
+ {};
/// \}
+
namespace ERROR
{
+ template <typename class_name>
+ struct super_trait_not_defined_for_;
+
struct IN_find_VIRTUAL_TYPE_IS_ABSTRACT;
struct IN_find_local_VIRTUAL_TYPE_MULTIPLY_DEFINED;
@@ -98,613 +119,108 @@
} // end of namespace stc
-#define stc_super(T) typename set_super_type< T >::ret
+/*------------------.
+| Shortcuts macro. |
+`------------------*/
-// Based on doc/algorithm.ml.
+# define stc_decl_associated_type mlc_decl_typedef
+# define stc_super(T) typename super_trait_< T >::ret
-#define stc_scoop_equipment_for_namespace(SCOOPED_NAMESPACE) \
- \
-namespace SCOOPED_NAMESPACE \
-{ \
- \
- /* Declare delegatee_type. */ \
- mlc_decl_typedef(delegatee_type); \
- \
- \
- template <typename class_name> \
- struct set_super_type \
- { \
- }; \
- \
- template <typename class_name> \
- struct vtypes \
- { \
- }; \
- \
- template <typename class_name, typename type_name> \
- struct single_vtype \
- { \
- typedef mlc::not_found ret; \
- }; \
- \
- /* ----------------------------------------------------- find_local. */ \
- \
- /* Highly inspired from Th�o's get_stm! */ \
- \
- namespace find_local_ \
- { \
- /* Forward declaration. */ \
- template <typename T, typename U> struct match_with; \
- \
- template <typename T> \
- struct match_with <T, mlc::not_found> \
- { \
- typedef T ret; \
- }; \
- \
- template <typename U> \
- struct match_with <mlc::not_found, U> \
- { \
- typedef U ret; \
- }; \
- \
- template <> \
- struct match_with <mlc::not_found, mlc::not_found> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename T, typename U> \
- struct match_with : \
- mlc::abort_<T, \
- stc::ERROR::IN_find_local_VIRTUAL_TYPE_MULTIPLY_DEFINED> \
- { \
- }; \
- \
- } /* end of namespace find_local_ */ \
- \
- template <typename source, typename target> \
- struct find_local \
- { \
- typedef SCOOPED_NAMESPACE::vtypes<source> decl1; \
- typedef typename target::template from_<decl1>::ret res1; \
- \
- typedef SCOOPED_NAMESPACE::single_vtype<source, target> decl2; \
- typedef typename decl2::ret ret2; \
- \
- \
- /* Result. */ \
- typedef typename find_local_::match_with<res1, ret2>::ret ret; \
- }; \
- \
- \
- /* --------------------------------------------------------- merge2. */ \
- \
- \
- namespace merge2_ \
- { \
- /* Forward declaration. */ \
- template <typename T, typename U> struct match_with; \
- \
- \
- /* ----------------------------- */ \
- /* local_res == stc::not_found. */ \
- /* ----------------------------- */ \
- \
- stc_internal_match_pair_0p_with(stc::not_found, stc::not_found, \
- stc::not_found); \
- \
- stc_internal_match_pair_0p_with(stc::not_found, stc::abstract, \
- stc::not_found); \
- \
- stc_internal_match_pair_1p_with(U, \
- stc::not_found, stc::final<U>, \
- stc::final<U>); \
- \
- stc_internal_match_pair_1p_with(U, \
- stc::not_found, U, \
- U); \
- \
- \
- /* ---------------------------- */ \
- /* local_res == stc::abstract. */ \
- /* ---------------------------- */ \
- \
- stc_internal_match_pair_0p_with(stc::abstract, stc::not_found, \
- stc::abstract); \
- \
- stc_internal_match_pair_0p_with(stc::abstract, stc::abstract, \
- stc::abstract); \
- \
- stc_internal_match_pair_1p_with_error(U, \
- stc::abstract, stc::final<U>, \
- stc::ERROR::IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED_ABSTRACT); \
- \
- stc_internal_match_pair_1p_with_error(U, \
- stc::abstract, U, \
- stc::ERROR::IN_merge2_VIRTUAL_TYPE_REDEFINED_ABSTRACT); \
- \
- \
- /* ---------------------------- */ \
- /* local_res == stc::final<T>. */ \
- /* ---------------------------- */ \
- \
- stc_internal_match_pair_1p_with(T, \
- stc::final<T>, stc::not_found, \
- stc::final<T>); \
- \
- stc_internal_match_pair_1p_with(T, \
- stc::final<T>, stc::abstract, \
- stc::final<T>); \
- \
- stc_internal_match_pair_2p_with_error(T, U, \
- stc::final<T>, stc::final<U>, \
- stc::ERROR::IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED_FINAL); \
- \
- stc_internal_match_pair_2p_with(T, U, \
- stc::final<T>, U, \
- stc::final<T>); \
- \
- \
- /* ---------------- */ \
- /* local_res == T. */ \
- /* ---------------- */ \
- \
- stc_internal_match_pair_1p_with(T, \
- T, stc::not_found, \
- T); \
- \
- stc_internal_match_pair_1p_with(T, \
- T, stc::abstract, \
- T); \
- \
- stc_internal_match_pair_2p_with_error(T, U, \
- T, stc::final<U>, \
- stc::ERROR::IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED); \
- \
- template <typename T, typename U> \
- struct match_with \
- { \
- typedef T ret; \
- }; \
- \
- } /* end of namespace merge2_ */ \
- \
- template <typename local_res, typename super_res> \
- struct merge2 \
- { \
- /* Result. */ \
- typedef typename merge2_::match_with<local_res, super_res>::ret ret; \
- }; \
- \
- \
- /* --------------------------------------------------------- merge3. */ \
- \
- \
- namespace merge3_ \
- { \
- /* Forward declaration. */ \
- template <typename T, typename U, typename V> struct match_with; \
- \
- \
- /* ----------------------------- */ \
- /* local_res == stc::not_found. */ \
- /* ----------------------------- */ \
- \
- /* super_res == stc::not_found. */ \
- stc_internal_match_triple_0p_with( \
- stc::not_found, stc::not_found, stc::not_found, \
- stc::not_found); \
- \
- stc_internal_match_triple_0p_with( \
- stc::not_found, stc::not_found, stc::abstract, \
- stc::not_found); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_found, stc::not_found, stc::final<V>, \
- stc::final<V>); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_found, stc::not_found, V, \
- V); \
- \
- /* super_res == stc::abstract. */ \
- stc_internal_match_triple_0p_with( \
- stc::not_found, stc::abstract, stc::not_found, \
- stc::not_found); \
- \
- stc_internal_match_triple_0p_with( \
- stc::not_found, stc::abstract, stc::abstract, \
- stc::abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_found, stc::abstract, stc::final<V>, \
- stc::final<V>); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_found, stc::abstract, V, \
- V); \
- \
- /* super_res is a concrete type. */ \
- stc_internal_match_triple_2p_with(U, V, \
- stc::not_found, stc::final<U>, V, \
- stc::final<U>); \
- \
- stc_internal_match_triple_2p_with(U, V, \
- stc::not_found, U, V, \
- U); \
- \
- \
- /* ---------------------------- */ \
- /* local_res == stc::abstract. */ \
- /* ---------------------------- */ \
- \
- /* super_res == stc::not_found. */ \
- stc_internal_match_triple_0p_with( \
- stc::abstract, stc::not_found, stc::not_found, \
- stc::abstract); \
- \
- stc_internal_match_triple_0p_with( \
- stc::abstract, stc::not_found, stc::abstract, \
- stc::abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::not_found, stc::final<V>, \
- stc::final<V>); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::not_found, V, \
- V); \
- \
- \
- /* super_res == stc::abstract. */ \
- stc_internal_match_triple_0p_with( \
- stc::abstract, stc::abstract, stc::not_found, \
- stc::abstract); \
- \
- stc_internal_match_triple_0p_with( \
- stc::abstract, stc::abstract, stc::abstract, \
- stc::abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::abstract, stc::final<V>, \
- stc::final<V>); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::abstract, V, \
- V); \
- \
- \
- /* super_res == stc::not_delegated_abstract. */ \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::not_delegated_abstract, V, \
- stc::not_delegated_abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::not_delegated, V, \
- stc::not_delegated_abstract); \
- \
- \
- /* super_res is a concrete type. */ \
- stc_internal_match_triple_2p_with_error(U, V, \
- stc::abstract, stc::final<U>, V, \
- stc::ERROR::IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED_ABSTRACT); \
- \
- stc_internal_match_triple_2p_with_error(U, V, \
- stc::abstract, U, V, \
- stc::ERROR::IN_merge3_VIRTUAL_TYPE_REDEFINED_ABSTRACT); \
- \
- \
- /* --------------------------------- */ \
- /* local_res == stc::not_delegated. */ \
- /* --------------------------------- */ \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_delegated, stc::not_found, V, \
- stc::not_delegated); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_delegated, stc::abstract, V, \
- stc::not_delegated_abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_delegated, stc::not_delegated_abstract, V, \
- stc::not_delegated_abstract); \
- \
- \
- /* ------------------------------------------ */ \
- /* local_res == stc::not_delegated_abstract. */ \
- /* ------------------------------------------ */ \
- \
- /* FIXME: Shouldn't we introduce a means to tag a vtype both as */ \
- /* abstract *and* not delegated? (Currently, the rule below */ \
- /* prevents this). */ \
- stc_internal_match_triple_2p_with_error(U, V, \
- stc::not_delegated_abstract, U, V, \
- stc::ERROR::IN_merge3_LOCAL_DECLARATION_OF_NOT_DELEGATED_AND_ABSTRACT); \
- \
- \
- /* ---------------------------- */ \
- /* local_res == stc::final<T>. */ \
- /* ---------------------------- */ \
- \
- stc_internal_match_triple_3p_with_error(T, U, V, \
- stc::final<T>, stc::final<U>, V, \
- stc::ERROR::IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED_FINAL); \
- \
- stc_internal_match_triple_3p_with(T, U, V, \
- stc::final<T>, U, V, \
- stc::final<T>); \
- \
- \
- /* ---------------- */ \
- /* local_res == T. */ \
- /* ---------------- */ \
- \
- stc_internal_match_triple_3p_with_error(T, U, V, \
- T, stc::final<U>, V, \
- stc::ERROR::IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED); \
- \
- template <typename T, typename U, typename V> \
- struct match_with \
- { \
- typedef T ret; \
- }; \
- \
- } /* end of namespace merge3_ */ \
- \
- \
- template <typename local_res, typename super_res, typename delegatee_res> \
- struct merge3 \
- { \
- /* Result. */ \
- typedef typename \
- merge3_::match_with<local_res, super_res, delegatee_res>::ret ret; \
- }; \
- \
- \
- /* ------------------------------------------------------ find_rec. */ \
- \
- /* Forward declarations. */ \
- template <typename source, typename target> struct find_rec; \
- template <typename source, typename target> struct find_rec_in_supers; \
- \
- \
- namespace find_rec_ \
- { \
- \
- namespace find_delegatee_res_ \
- { \
- /* Forward declaration. */ \
- template <typename delegatee, typename target> struct match_with; \
- \
- template <typename target> \
- struct match_with<stc::not_found, target> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename target> \
- struct match_with<stc::abstract, target> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename delegatee, typename target> \
- struct match_with \
- { \
- typedef typename find_rec<delegatee, target>::ret ret; \
- }; \
- \
- } /* end of namespace find_delegatee_res_ */ \
- \
- \
- /* Forward declaration. */ \
- template <typename source, typename target> struct match_with; \
- \
- template <typename target> \
- struct match_with<stc::none, target> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename source, typename target> \
- struct match_with \
- { \
- typedef typename find_local<source, target>::ret local_res; \
- typedef typename find_rec<stc_super(source), target>::ret super_res; \
- /* delegatee_type is the name of the (optional) virtual type */ \
- /* containing the (type of the) delgatee. */ \
- typedef typename \
- find_rec_in_supers<source, typedef_::delegatee_type>::ret delegatee; \
- \
- typedef typename \
- find_delegatee_res_::match_with<delegatee, target>::ret delegatee_res; \
- typedef typename \
- merge3<local_res, super_res, delegatee_res>::ret ret; \
- }; \
- \
- } /* end of namespace find_rec_ */ \
- \
- template <typename source, typename target> \
- struct find_rec \
- { \
- /* Result. */ \
- typedef typename find_rec_::match_with<source, target>::ret ret; \
- }; \
- \
- \
- /* --------------------------------------------- find_rec_in_supers. */ \
- \
- namespace find_rec_in_supers_ \
- { \
- /* Forward declaration. */ \
- template <typename source, typename target> struct match_with; \
- \
- template <typename target> \
- struct match_with<stc::none, target> \
- { \
- typedef stc::none ret; \
- }; \
- \
- template <typename source, typename target> \
- struct match_with \
- { \
- typedef typename find_local<source, target>::ret local_res; \
- typedef typename find_rec<stc_super(source), target>::ret super_res; \
- typedef typename merge2<local_res, super_res>::ret ret; \
- }; \
- \
- } /* end of namespace find_rec_in_supers_ */ \
- \
- template <typename source, typename target> \
- struct find_rec_in_supers \
- { \
- /* Result. */ \
- typedef typename \
- find_rec_in_supers_::match_with<source, target>::ret ret; \
- }; \
- \
- \
- /* ----------------------------------------------------------- find. */ \
- \
- namespace find_ \
- { \
- /* Forward declaration. */ \
- template <typename T> struct match_with; \
- \
- /* FIXME: We'd like to add a static abort here, but we can't, */ \
- /* since stc::abstract is not a free parameter (enabling this */ \
- /* abort statement would prevent any compilation). */ \
- template <> \
- struct match_with<stc::abstract> \
- /* : mlc::abort_<stc::abstract, \
- stc::ERROR::IN_find_VIRTUAL_TYPE_IS_ABSTRACT> */ \
- { \
- }; \
- \
- /* FIXME: We'd like to add a static abort here, but we can't, */ \
- /* since stc::not_delegated_abstract is not a free parameter */ \
- /* (enabling this abort statement would prevent any */ \
- /* compilation). */ \
- template <> \
- struct match_with<stc::not_delegated_abstract> \
- /* : mlc::abort_<stc::not_delegated_abstract, */ \
- /* stc::ERROR::IN_find_VIRTUAL_TYPE_IS_ABSTRACT> */ \
- { \
- }; \
- \
- template <> \
- struct match_with<stc::not_delegated> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename T> \
- struct match_with< stc::final<T> > \
- { \
- typedef T ret; \
- }; \
- \
- template <typename T> \
- struct match_with \
- { \
- typedef T ret; \
- }; \
- \
- } /* end of namespace find_ */ \
- \
- \
- /** Find a virtual type. */ \
- template <typename source, typename target> \
- struct find_vtype \
- { \
- typedef typename find_rec<source, target>::ret res; \
- /* Result. */ \
- typedef typename find_::match_with<res>::ret ret; \
- }; \
- \
- \
- /** Find a virtual type, and ensure it is found. */ \
- template <typename from, typename target> \
- struct vtype \
- { \
- typedef typename find_vtype<from, target>::ret res; \
- struct check_ : mlc::assert_< mlc::is_found_<res> > \
- { \
- typedef res ret; \
- }; \
- typedef typename check_::ret ret; \
- }; \
- \
-} /* end of SCOOPED_NAMESPACE */ \
- \
-struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_o_n;
+// FIXME: Document all these macros.
-/*------------------.
-| Shortcuts macro. |
-`------------------*/
+/// Access to associated type.
+/// \{
+# define stc_type_(Source, Target) vtype<Source, typedef_::Target>::ret
+# define stc_type(Source, Target) typename stc_type_(Source, Target)
+
+# define stc_type_in_(Namespace, Source, Target) \
+ Namespace::vtype<Source, Namespace::typedef_::Target>::ret
+# define stc_type_in(Namespace, Source, Target) \
+ typename stc_type_in_(Namespace, Source, Target)
+
+/// Access from the interior of the class.
+/// \{
+# define stc_get_type_(Target) vtype<Exact, typedef_::Target>::ret
+# define stc_get_type(Target) typename stc_get_type_(Target)
+/// \}
+
+/// \}
+
+
+/// Likewise, but more tolerant.
+/// \{
+# define stc_find_type_(Source, Target) \
+ find_vtype<Source, typedef_::Target>::ret
+# define stc_find_type(Source, Target) \
+ typename stc_find_type_(Source, Target)
+/// \}
+
+/// Boolean expression counterpart of stc_find_type
+/// \{
+# define stc_type_is_found(Target) \
+ stc::is_found< stc_deferred(Target) >
+# define stc_type_is_not_found(Target) \
+ stc::is_not_found< stc_deferred(Target) >
+/// \}
-// FIXME: Document all these macros.
-# define stc_find_vtype_(Namespace, Source, Target) \
- Namespace::find_vtype<Source, Namespace::typedef_::Target##_type>::ret
+# define stc_is_a(T, U) \
+ mlc::wrap_< \
+ typename mlc::is_a_< sizeof(mlc::form::of< U >()) > \
+ ::template ret< typename mlc::basic_< stc_deferred(T) >::ret, U > \
+ >
-# define stc_find_vtype(Namespace, Source, Target) \
- typename stc_find_vtype_(Namespace, Source, Target)
+
+/// For concepts.
+/// \{
+# define stc_typename(Target) typedef stc_type(Exact, Target) Target
+# define stc_using(Target) typedef typename super::Target Target
+# define stc_using_from(Abstraction, Target) \
+ typedef typename Abstraction<Exact>::Target Target
+# define stc_deduce_typename(Src, Target) typedef stc_type(Src, Target) Target
+/// \}
+
+
+/// For implementation classes.
+/// \{
+/// Dummy
+# define stc_deferred(Target) \
+ stc_find_type(Exact, Target)
+// typename deferred_vtype<Exact, typedef_::Target >::ret
+# define stc_lookup(Target) \
+ typedef typename vtype< stc_type(current, exact_type), \
+ typedef_::Target>::ret Target
+/// \}
+
+
+/// For set_impl classes.
+/// \{
+# define stc_deferred_typename(Target) typedef stc_deferred(Target) Target
+/// \}
// Dummy alias, for compatibility purpose (deferred virtual types are
// not currently handled by this version of stc/scoop2.hh).
-# define stc_deferred_vtype(Namespace, From, Target) \
- stc_find_vtype(Namespace, From, Target)
+# define stc_deferred_type(Source, Target) \
+ stc_find_type(Source, Target)
-# define stc_vtype_(Namespace, From, Target) \
- Namespace::vtype<From, Namespace::typedef_::Target##_type>::ret
-# define stc_vtype(Namespace, From, Target) \
- typename stc_vtype_(Namespace, From, Target)
+// The macro below was called stc_prop which was ambiguous
+// (that lets us think that it is true_ or false_) but the
+// result is a mlc::bexpr_! So it has been renamed as stc_is.
+# define stc_is(Target) mlc::eq_< stc_find_type(E, Target), stc::true_ >
+
+// Likewise.
+# define stc_is_not(Target) \
+ mlc::or_< mlc::eq_< stc_find_type(E, Target), \
+ mlc::not_found >, \
+ mlc::eq_< stc_find_type(E, Target), \
+ stc::false_ > >
-# define stc_find_deduce_vtype_(Namespace, From, Target1, Target2) \
- Namespace::find_vtype< \
- Namespace::find_vtype< \
- From, \
- Namespace::typedef_::Target1##_type \
- >::ret, \
- Namespace::typedef_::Target2##_type \
- >::ret
-
-# define stc_find_deduce_vtype(Namespace, From, Target1, Target2) \
- typename Namespace::find_vtype< \
- typename Namespace::find_vtype< \
- From, \
- Namespace::typedef_::Target1##_type \
- >::ret, \
- Namespace::typedef_::Target2##_type \
- >::ret
-
-# define stc_deduce_deferred_vtype(Namespace, From, Target1, Target2) \
- stc_find_deduce_vtype(Namespace, From, Target1, Target2)
-
-# define stc_deduce_vtype_(Namespace, From, Target1, Target2) \
- Namespace::vtype< \
- Namespace::vtype< \
- From, \
- Namespace::typedef_::Target1##_type \
- >::ret, \
- Namespace::typedef_::Target2##_type \
- >::ret
-
-# define stc_deduce_vtype(Namespace, From, Target1, Target2) \
- typename Namespace::vtype< \
- typename Namespace::vtype< \
- From, \
- Namespace::typedef_::Target1##_type \
- >::ret, \
- Namespace::typedef_::Target2##_type \
- >::ret
+# define stc_prop(Source, Target) \
+ typename mlc::eq_< stc_find_type(Source, Target), stc::true_ >::eval
#endif // ! STC_SCOOP_ALT_HH
Index: stc/Makefile.am
--- stc/Makefile.am (revision 877)
+++ stc/Makefile.am (working copy)
@@ -8,6 +8,7 @@
find_exact.hh \
scoop.hh \
scoop-alt.hh \
+ scoop-alt.inc \
valist_aggregator.hh \
\
internal/extract_vtype_from_list.hh \
Index: stc/scoop-alt.inc
--- stc/scoop-alt.inc (revision 877)
+++ stc/scoop-alt.inc (working copy)
@@ -1,3 +1,5 @@
+ // -*- C++ -*-
+
// Copyright (C) 2005, 2006, 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
@@ -26,685 +28,840 @@
// Public License.
-/* \file stc/scoop-alt.hh
+#ifndef STATIC_SCOOP_ALT_HH_INCLUDED
+# error "alt/scoop.inc included but alt/scoop.hh hasn't been included"
+#endif
+
+
+/* \file stc/scoop-alt.inc
\brief Alternative equipment for SCOOP 2 (in particular, virtual
- types). */
+ types).
+
+ To be included inside the namespace to equip. \file
+ stc/scoop-alt.hh must have been previously included before this
+ file. */
-#ifndef STC_SCOOP_ALT_HH
-# define STC_SCOOP_ALT_HH
+/* Install core virtual types in the equipped namespace. */
+/* \{ */
+mlc_decl_typedef(exact_);
-# include <mlc/flags.hh>
-# include <mlc/typedef.hh>
-# include <mlc/abort.hh>
+mlc_decl_typedef(category);
+mlc_decl_typedef(behavior);
+mlc_decl_typedef(delegatee);
+/* \} */
-# include <stc/internal/match-with.hh>
+/*--------.
+| Super. |
+`--------*/
-namespace stc
+/// Default version.
+template <typename class_name>
+struct super_trait_ :
+ mlc::abort_< class_name,
+ stc::ERROR::super_trait_not_defined_for_< class_name > >
{
- /* FIXME: Define a real stc::none, instead of making it an alias of
- mlc::none. For compatibility purpose with the current
- implementation of the SCOOP 2 paradigm (see stc/scoop.hh), we
- need to have stc::none be equal to mlc::none. */
-#if 0
- struct none {};
-#endif
- using mlc::none;
+ typedef mlc::none ret;
+};
- struct not_found;
- struct abstract;
- struct not_delegated;
- struct not_delegated_abstract;
- template <typename T> struct final;
+/// Version for abstractions (security cap).
+template <template <class> class abstraction, typename Exact>
+struct super_trait_< abstraction<Exact> >
+{
+ typedef mlc::none ret;
+};
+/// Helper for const versions.
+template <typename class_name>
+struct super_trait_ <const class_name> : public super_trait_<class_name>
+{
+};
+
+
+/*---------.
+| Vtypes. |
+`---------*/
+
+template <typename class_name>
+struct vtypes
+{
+};
+
+/// Helper for const versions.
+template <typename class_name>
+struct vtypes <const class_name> : public vtypes <class_name>
+{
+};
+
+template <typename class_name, typename type_name>
+struct single_vtype
+{
+ typedef mlc::not_found ret;
+};
+
+
+
+/*------.
+| Any. |
+`------*/
+
+// FIXME: Get rid of stc/any.hh?
+
+template <typename Exact>
+struct Any;
+
+template <typename Exact>
+struct super_trait_< Any<Exact> >
+{
+ typedef mlc::none ret;
+};
+
+template <typename Exact>
+struct vtypes< Any<Exact> >
+{
+ typedef stc::final<Exact> exact_;
+};
+
+template <typename Exact>
+struct Any
+{
+ typedef Exact exact_;
+protected:
+ Any() {}
+};
+
+
+/*--------.
+| Exact. |
+`--------*/
+
+template <typename Exact>
+Exact& exact(Any<Exact>& ref)
+{
+ return *(Exact*)(void*)(&ref);
+}
+
+template <typename Exact>
+const Exact& exact(const Any<Exact>& cref)
+{
+ return *(const Exact*)(const void*)(&cref);
+}
+
+
+template <typename Exact>
+Exact* exact(Any<Exact>* ptr)
+{
+ return (Exact*)(void*)(ptr);
+}
+
+template <typename Exact>
+const Exact* exact(const Any<Exact>* cptr)
+{
+ return (const Exact*)(const void*)(cptr);
+}
+
+template <typename Exact>
+const Exact* my_exact(const Any<Exact>* cptr)
+{
+ return (const Exact*)(const void*)(cptr);
+}
+
+
+/*----------------------.
+| Virtual type lookup. |
+`----------------------*/
+
+/* ----------------------------------------------------- find_local. */
+
+/* Highly inspired from Th�o's get_stm! */
+
+namespace find_local_
+{
+ /* Forward declaration. */
+ template <typename T, typename U> struct match_with;
+
+ template <typename T>
+ struct match_with <T, mlc::not_found>
+ {
+ typedef T ret;
+ };
+
+ template <typename U>
+ struct match_with <mlc::not_found, U>
+ {
+ typedef U ret;
+ };
+
+ template <>
+ struct match_with <mlc::not_found, mlc::not_found>
+ {
+ typedef stc::not_found ret;
+ };
+
+ template <typename T, typename U>
+ struct match_with :
+ mlc::abort_<T,
+ stc::ERROR::IN_find_local_VIRTUAL_TYPE_MULTIPLY_DEFINED>
+ {
+ };
+
+} /* End of namespace find_local_. */
+
+template <typename source, typename target>
+struct find_local
+{
+ typedef vtypes<source> decl1;
+ typedef typename target::template from_<decl1>::ret res1;
+
+ typedef single_vtype<source, target> decl2;
+ typedef typename decl2::ret ret2;
+
+
+ /* Result. */
+ typedef typename find_local_::match_with<res1, ret2>::ret ret;
+};
+
+
+/* --------------------------------------------------------- merge2. */
+
+
+namespace merge2_
+{
+ /* Forward declaration. */
+ template <typename T, typename U> struct match_with;
+
+
+ /* ----------------------------- */
+ /* local_res == stc::not_found. */
+ /* ----------------------------- */
+
+ stc_internal_match_pair_0p_with(stc::not_found, stc::not_found,
+ stc::not_found);
+
+ stc_internal_match_pair_0p_with(stc::not_found, stc::abstract,
+ stc::not_found);
+
+ stc_internal_match_pair_1p_with(U,
+ stc::not_found, stc::final<U>,
+ stc::final<U>);
+
+ stc_internal_match_pair_1p_with(U,
+ stc::not_found, U,
+ U);
+
+
+ /* ---------------------------- */
+ /* local_res == stc::abstract. */
+ /* ---------------------------- */
+
+ stc_internal_match_pair_0p_with(stc::abstract, stc::not_found,
+ stc::abstract);
+
+ stc_internal_match_pair_0p_with(stc::abstract, stc::abstract,
+ stc::abstract);
+
+ stc_internal_match_pair_1p_with_error(U,
+ stc::abstract, stc::final<U>,
+ stc::ERROR::IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED_ABSTRACT);
+
+ stc_internal_match_pair_1p_with_error(U,
+ stc::abstract, U,
+ stc::ERROR::IN_merge2_VIRTUAL_TYPE_REDEFINED_ABSTRACT);
+
+
+ /* ---------------------------- */
+ /* local_res == stc::final<T>. */
+ /* ---------------------------- */
+
+ stc_internal_match_pair_1p_with(T,
+ stc::final<T>, stc::not_found,
+ stc::final<T>);
+
+ stc_internal_match_pair_1p_with(T,
+ stc::final<T>, stc::abstract,
+ stc::final<T>);
+
+ stc_internal_match_pair_2p_with_error(T, U,
+ stc::final<T>, stc::final<U>,
+ stc::ERROR::IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED_FINAL);
+
+ stc_internal_match_pair_2p_with(T, U,
+ stc::final<T>, U,
+ stc::final<T>);
+
+
+ /* ---------------- */
+ /* local_res == T. */
+ /* ---------------- */
+
+ stc_internal_match_pair_1p_with(T,
+ T, stc::not_found,
+ T);
+
+ stc_internal_match_pair_1p_with(T,
+ T, stc::abstract,
+ T);
+
+ stc_internal_match_pair_2p_with_error(T, U,
+ T, stc::final<U>,
+ stc::ERROR::IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED);
+
+ template <typename T, typename U>
+ struct match_with
+ {
+ typedef T ret;
+ };
+
+} /* End of namespace merge2_. */
+
+template <typename local_res, typename super_res>
+struct merge2
+{
+ /* Result. */
+ typedef typename merge2_::match_with<local_res, super_res>::ret ret;
+};
+
+
+/* --------------------------------------------------------- merge3. */
+
+
+namespace merge3_
+{
+ /* Forward declaration. */
+ template <typename T, typename U, typename V> struct match_with;
+
+
+ /* ----------------------------- */
+ /* local_res == stc::not_found. */
+ /* ----------------------------- */
+
+ /* super_res == stc::not_found. */
+ stc_internal_match_triple_0p_with(
+ stc::not_found, stc::not_found, stc::not_found,
+ stc::not_found);
+
+ stc_internal_match_triple_0p_with(
+ stc::not_found, stc::not_found, stc::abstract,
+ stc::not_found);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::not_found, stc::not_found, stc::final<V>,
+ stc::final<V>);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::not_found, stc::not_found, V,
+ V);
+
+ /* super_res == stc::abstract. */
+ stc_internal_match_triple_0p_with(
+ stc::not_found, stc::abstract, stc::not_found,
+ stc::not_found);
+
+ stc_internal_match_triple_0p_with(
+ stc::not_found, stc::abstract, stc::abstract,
+ stc::abstract);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::not_found, stc::abstract, stc::final<V>,
+ stc::final<V>);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::not_found, stc::abstract, V,
+ V);
+
+ /* super_res is a concrete type. */
+ stc_internal_match_triple_2p_with(U, V,
+ stc::not_found, stc::final<U>, V,
+ stc::final<U>);
+
+ stc_internal_match_triple_2p_with(U, V,
+ stc::not_found, U, V,
+ U);
+
+
+ /* ---------------------------- */
+ /* local_res == stc::abstract. */
+ /* ---------------------------- */
+
+ /* super_res == stc::not_found. */
+ stc_internal_match_triple_0p_with(
+ stc::abstract, stc::not_found, stc::not_found,
+ stc::abstract);
+
+ stc_internal_match_triple_0p_with(
+ stc::abstract, stc::not_found, stc::abstract,
+ stc::abstract);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::abstract, stc::not_found, stc::final<V>,
+ stc::final<V>);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::abstract, stc::not_found, V,
+ V);
+
+
+ /* super_res == stc::abstract. */
+ stc_internal_match_triple_0p_with(
+ stc::abstract, stc::abstract, stc::not_found,
+ stc::abstract);
+
+ stc_internal_match_triple_0p_with(
+ stc::abstract, stc::abstract, stc::abstract,
+ stc::abstract);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::abstract, stc::abstract, stc::final<V>,
+ stc::final<V>);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::abstract, stc::abstract, V,
+ V);
+
+
+ /* super_res == stc::not_delegated_abstract. */
+ stc_internal_match_triple_1p_with(V,
+ stc::abstract, stc::not_delegated_abstract, V,
+ stc::not_delegated_abstract);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::abstract, stc::not_delegated, V,
+ stc::not_delegated_abstract);
+
+
+ /* super_res is a concrete type. */
+ stc_internal_match_triple_2p_with_error(U, V,
+ stc::abstract, stc::final<U>, V,
+ stc::ERROR::IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED_ABSTRACT);
+
+ stc_internal_match_triple_2p_with_error(U, V,
+ stc::abstract, U, V,
+ stc::ERROR::IN_merge3_VIRTUAL_TYPE_REDEFINED_ABSTRACT);
+
+
+ /* --------------------------------- */
+ /* local_res == stc::not_delegated. */
+ /* --------------------------------- */
+
+ stc_internal_match_triple_1p_with(V,
+ stc::not_delegated, stc::not_found, V,
+ stc::not_delegated);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::not_delegated, stc::abstract, V,
+ stc::not_delegated_abstract);
+
+ stc_internal_match_triple_1p_with(V,
+ stc::not_delegated, stc::not_delegated_abstract, V,
+ stc::not_delegated_abstract);
+
+
+ /* ------------------------------------------ */
+ /* local_res == stc::not_delegated_abstract. */
+ /* ------------------------------------------ */
+
+ /* FIXME: Shouldn't we introduce a means to tag a vtype both as */
+ /* abstract *and* not delegated? (Currently, the rule below */
+ /* prevents this). */
+ stc_internal_match_triple_2p_with_error(U, V,
+ stc::not_delegated_abstract, U, V,
+ stc::ERROR::IN_merge3_LOCAL_DECLARATION_OF_NOT_DELEGATED_AND_ABSTRACT);
+
+
+ /* ---------------------------- */
+ /* local_res == stc::final<T>. */
+ /* ---------------------------- */
+
+ stc_internal_match_triple_3p_with_error(T, U, V,
+ stc::final<T>, stc::final<U>, V,
+ stc::ERROR::IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED_FINAL);
+
+ stc_internal_match_triple_3p_with(T, U, V,
+ stc::final<T>, U, V,
+ stc::final<T>);
+
+
+ /* ---------------- */
+ /* local_res == T. */
+ /* ---------------- */
+
+ stc_internal_match_triple_3p_with_error(T, U, V,
+ T, stc::final<U>, V,
+ stc::ERROR::IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED);
+
+ template <typename T, typename U, typename V>
+ struct match_with
+ {
+ typedef T ret;
+ };
+
+} /* End of namespace merge3_. */
+
+
+template <typename local_res, typename super_res, typename delegatee_res>
+struct merge3
+{
+ /* Result. */
+ typedef typename
+ merge3_::match_with<local_res, super_res, delegatee_res>::ret ret;
+};
+
+
+/* ------------------------------------------------------ find_rec. */
+
+/* Forward declarations. */
+template <typename source, typename target> struct find_rec;
+template <typename source, typename target> struct find_rec_in_supers;
+
+
+namespace find_rec_
+{
+
+ namespace find_delegatee_res_
+ {
+ /* Forward declaration. */
+ template <typename delegatee, typename target> struct match_with;
+
+ template <typename target>
+ struct match_with<stc::not_found, target>
+ {
+ typedef stc::not_found ret;
+ };
+
+ template <typename target>
+ struct match_with<stc::abstract, target>
+ {
+ typedef stc::not_found ret;
+ };
+
+ template <typename delegatee, typename target>
+ struct match_with
+ {
+ typedef typename find_rec<delegatee, target>::ret ret;
+ };
+
+ } /* End of namespace find_delegatee_res_. */
+
+
+ /* Forward declaration. */
+ template <typename source, typename target> struct match_with;
+
+ template <typename target>
+ struct match_with<stc::none, target>
+ {
+ typedef stc::not_found ret;
+ };
+
+ template <typename source, typename target>
+ struct match_with
+ {
+ typedef typename find_local<source, target>::ret local_res;
+ typedef typename find_rec<stc_super(source), target>::ret super_res;
+ /* delegatee is the name of the (optional) virtual type */
+ /* containing the (type of the) delgatee. */
+ typedef typename
+ find_rec_in_supers<source, typedef_::delegatee>::ret delegatee;
+
+ typedef typename
+ find_delegatee_res_::match_with<delegatee, target>::ret delegatee_res;
+ typedef typename
+ merge3<local_res, super_res, delegatee_res>::ret ret;
+ };
+
+} /* End of namespace find_rec_. */
+
+template <typename source, typename target>
+struct find_rec
+{
+ /* Result. */
+ typedef typename find_rec_::match_with<source, target>::ret ret;
+};
+
+
+/* --------------------------------------------- find_rec_in_supers. */
+
+namespace find_rec_in_supers_
+{
+ /* Forward declaration. */
+ template <typename source, typename target> struct match_with;
+
+ template <typename target>
+ struct match_with<stc::none, target>
+ {
+ typedef stc::none ret;
+ };
+
+ template <typename source, typename target>
+ struct match_with
+ {
+ typedef typename find_local<source, target>::ret local_res;
+ typedef typename find_rec<stc_super(source), target>::ret super_res;
+ typedef typename merge2<local_res, super_res>::ret ret;
+ };
+
+} /* End of namespace find_rec_in_supers_. */
+
+template <typename source, typename target>
+struct find_rec_in_supers
+{
+ /* Result. */
+ typedef typename
+ find_rec_in_supers_::match_with<source, target>::ret ret;
+};
+
+
+/* ----------------------------------------------------------- find. */
+
+namespace find_
+{
+ /* Forward declaration. */
+ template <typename T> struct match_with;
+
+ /* FIXME: We'd like to add a static abort here, but we can't, */
+ /* since stc::abstract is not a free parameter (enabling this */
+ /* abort statement would prevent any compilation). */
+ template <>
+ struct match_with<stc::abstract>
+ /* : mlc::abort_<stc::abstract, */
+ /* stc::ERROR::IN_find_VIRTUAL_TYPE_IS_ABSTRACT> */
+ {
+ };
+
+ /* FIXME: We'd like to add a static abort here, but we can't, */
+ /* since stc::not_delegated_abstract is not a free parameter */
+ /* (enabling this abort statement would prevent any */
+ /* compilation). */
+ template <>
+ struct match_with<stc::not_delegated_abstract>
+ /* : mlc::abort_<stc::not_delegated_abstract, */
+ /* stc::ERROR::IN_find_VIRTUAL_TYPE_IS_ABSTRACT> */
+ {
+ };
+
+ template <>
+ struct match_with<stc::not_delegated>
+ {
+ typedef stc::not_found ret;
+ };
- /// \brief Shortcuts for comparison with stc::not_found.
- ///
- /// Duplicate with their Metalic's homonyms, but still useful, since
- /// they deal with std::not_found (not mlc::not_found).
- /// \{
template <typename T>
- struct is_not_found_ : public mlc_is_a(T, stc::not_found)::bexpr
+ struct match_with< stc::final<T> >
{
+ typedef T ret;
};
template <typename T>
- struct is_found_ : public mlc_is_not_a(T, stc::not_found)::bexpr
+ struct match_with
{
+ typedef T ret;
};
- /// \}
- namespace ERROR
+} /* End of namespace find_. */
+
+
+/** Find a virtual type. */
+template <typename source, typename target>
+struct find_vtype
+{
+ typedef typename find_rec<source, target>::ret res;
+ /* Result. */
+ typedef typename find_::match_with<res>::ret ret;
+};
+
+
+/** Find a virtual type, and ensure it is found. */
+template <typename from, typename target>
+struct vtype
+{
+ typedef typename find_vtype<from, target>::ret res;
+ struct check_ : mlc::assert_< mlc::is_found_<res> >
+ {
+ typedef res ret;
+ };
+ typedef typename check_::ret ret;
+};
+
+
+/*------------.
+| Selectors. |
+`------------*/
+
+// FIXME: This part has been copied as-is from Th�o's version
+// (oln/stc/scoop.hxx).
+
+mlc_case_equipment_for_namespace(internal);
+
+
+namespace internal
+{
+
+
+ template < template <class> class abstraction,
+ unsigned num = 1 >
+ struct selector
{
- struct IN_find_VIRTUAL_TYPE_IS_ABSTRACT;
+ protected: selector() {}
+ };
+
+
+ /* fwd decl */
+ template < template <class> class abstraction, typename E, unsigned num >
+ struct plug_node;
+
+ template < template <class> class abstraction,
+ typename E,
+ unsigned num,
+ typename another_selector = mlc::false_ >
+ struct next_plug_node
+ {
+ /* here: no other selector */
+ protected: next_plug_node() {}
+ };
+
+ template < template <class> class abstraction,
+ typename E >
+ struct next_plug_node < abstraction, E, 1, mlc::false_ >
+ : public abstraction<E>
+ {
+ protected: next_plug_node() {}
+ };
+
+
+ template < template <class> class abstraction,
+ typename E,
+ unsigned num >
+ struct next_plug_node < abstraction,
+ E,
+ num,
+ mlc::true_>
+
+ : /* plug to client selectors */
+ public virtual switch_< selector<abstraction, num>, E >::ret,
+
+ /* here: another selector (number is 'num + 1') */
+ public plug_node<abstraction, E, num + 1>
+ {
+ protected: next_plug_node() {}
+ };
+
+
+ template < template <class> class abstraction,
+ typename E,
+ unsigned num >
+ struct plug_node
+ : public next_plug_node< abstraction,
+ E,
+ num,
+ typename mlc::is_defined_< case_< selector<abstraction, num>,
+ E, 1 > >::eval >
+ {
+ protected: plug_node() {}
+ };
+
- struct IN_find_local_VIRTUAL_TYPE_MULTIPLY_DEFINED;
+ template < template <class> class abstraction,
+ unsigned num,
+ typename E >
+ struct default_case_ < selector<abstraction, num>,
+ E >
+ {
+ typedef abstraction<E> ret;
+ };
+
+
+ template < template <class> class abstraction,
+ typename E >
+ struct plug : public plug_node<abstraction, E, 1>
+ {
+ protected: plug() {}
+ };
+
+ template <typename abstraction, typename E>
+ struct top__;
+
+ template <template<class> class abstraction, typename E>
+ struct top__ < stc::is<abstraction>, E > : public plug< abstraction, E >
+ {
+ protected: top__() {}
+ };
+
+ template <typename E>
+ struct top__ < mlc::none, E > : public Any<E>
+ {
+ protected: top__() {}
+ };
+
+ template <typename E>
+ struct top__ < mlc::not_found, E >; /* FIXME: Error msg here */
+
+
+} /* End of namespace internal. */
+
+
+/*--------------------------------------------.
+| Top class of the implementation hierarchy. |
+`--------------------------------------------*/
+
+// FIXME: This part has been copied as-is from Th�o's version
+// (oln/stc/scoop.hxx).
+
+template <typename E> struct top;
+
+template <typename E>
+struct vtypes< top<E> >
+{
+ typedef stc::final<E> exact;
+ /* default is "no category" */
+};
+
+template <typename E>
+struct top : public internal::top__< stc_find_type(E, category), E >
+{
+protected:
+ top() {}
+};
+
+
+/*----------------------------.
+| Automatic implementations. |
+`----------------------------*/
+
+// FIXME: This part has been copied (almost) as-is from Th�o's version
+// (oln/stc/scoop.hxx).
+
+namespace automatic
+{
+
+ /// set_impl
+ ///
+ /// To be defined by the client.
+ template < template <class> class abstraction, typename behavior,
+ typename E >
+ struct set_impl;
+
+
+ /// impl
+ /// \{
+ template < template <class> class abstraction, typename behavior,
+ typename E >
+ struct impl : public set_impl< abstraction, behavior, E >
+ { /* fetch */ };
+
+ template < template <class> class abstraction, typename E >
+ struct impl< abstraction, /* behavior is */ mlc::not_found, E >
+ { /* nothing */ };
+
+ template < template <class> class abstraction, typename E >
+ struct impl< abstraction, mlc::none /* behavior */, E >
+ { /* nothing */ };
+ /// \}
- struct IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED_ABSTRACT;
- struct IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED_FINAL;
- struct IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED;
- struct IN_merge2_VIRTUAL_TYPE_REDEFINED_ABSTRACT;
-
- struct IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED_ABSTRACT;
- struct IN_merge3_VIRTUAL_TYPE_REDEFINED_ABSTRACT;
- struct IN_merge3_LOCAL_DECLARATION_OF_NOT_DELEGATED_AND_ABSTRACT;
- struct IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED_FINAL;
- struct IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED;
-
- } // end of namespace ERROR
-
-} // end of namespace stc
-
-
-#define stc_super(T) typename set_super_type< T >::ret
-
-// Based on doc/algorithm.ml.
-
-
-
-#define stc_scoop_equipment_for_namespace(SCOOPED_NAMESPACE) \
- \
-namespace SCOOPED_NAMESPACE \
-{ \
- \
- /* Declare delegatee_type. */ \
- mlc_decl_typedef(delegatee_type); \
- \
- \
- template <typename class_name> \
- struct set_super_type \
- { \
- }; \
- \
- template <typename class_name> \
- struct vtypes \
- { \
- }; \
- \
- template <typename class_name, typename type_name> \
- struct single_vtype \
- { \
- typedef mlc::not_found ret; \
- }; \
- \
- /* ----------------------------------------------------- find_local. */ \
- \
- /* Highly inspired from Th�o's get_stm! */ \
- \
- namespace find_local_ \
- { \
- /* Forward declaration. */ \
- template <typename T, typename U> struct match_with; \
- \
- template <typename T> \
- struct match_with <T, mlc::not_found> \
- { \
- typedef T ret; \
- }; \
- \
- template <typename U> \
- struct match_with <mlc::not_found, U> \
- { \
- typedef U ret; \
- }; \
- \
- template <> \
- struct match_with <mlc::not_found, mlc::not_found> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename T, typename U> \
- struct match_with : \
- mlc::abort_<T, \
- stc::ERROR::IN_find_local_VIRTUAL_TYPE_MULTIPLY_DEFINED> \
- { \
- }; \
- \
- } /* end of namespace find_local_ */ \
- \
- template <typename source, typename target> \
- struct find_local \
- { \
- typedef SCOOPED_NAMESPACE::vtypes<source> decl1; \
- typedef typename target::template from_<decl1>::ret res1; \
- \
- typedef SCOOPED_NAMESPACE::single_vtype<source, target> decl2; \
- typedef typename decl2::ret ret2; \
- \
- \
- /* Result. */ \
- typedef typename find_local_::match_with<res1, ret2>::ret ret; \
- }; \
- \
- \
- /* --------------------------------------------------------- merge2. */ \
- \
- \
- namespace merge2_ \
- { \
- /* Forward declaration. */ \
- template <typename T, typename U> struct match_with; \
- \
- \
- /* ----------------------------- */ \
- /* local_res == stc::not_found. */ \
- /* ----------------------------- */ \
- \
- stc_internal_match_pair_0p_with(stc::not_found, stc::not_found, \
- stc::not_found); \
- \
- stc_internal_match_pair_0p_with(stc::not_found, stc::abstract, \
- stc::not_found); \
- \
- stc_internal_match_pair_1p_with(U, \
- stc::not_found, stc::final<U>, \
- stc::final<U>); \
- \
- stc_internal_match_pair_1p_with(U, \
- stc::not_found, U, \
- U); \
- \
- \
- /* ---------------------------- */ \
- /* local_res == stc::abstract. */ \
- /* ---------------------------- */ \
- \
- stc_internal_match_pair_0p_with(stc::abstract, stc::not_found, \
- stc::abstract); \
- \
- stc_internal_match_pair_0p_with(stc::abstract, stc::abstract, \
- stc::abstract); \
- \
- stc_internal_match_pair_1p_with_error(U, \
- stc::abstract, stc::final<U>, \
- stc::ERROR::IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED_ABSTRACT); \
- \
- stc_internal_match_pair_1p_with_error(U, \
- stc::abstract, U, \
- stc::ERROR::IN_merge2_VIRTUAL_TYPE_REDEFINED_ABSTRACT); \
- \
- \
- /* ---------------------------- */ \
- /* local_res == stc::final<T>. */ \
- /* ---------------------------- */ \
- \
- stc_internal_match_pair_1p_with(T, \
- stc::final<T>, stc::not_found, \
- stc::final<T>); \
- \
- stc_internal_match_pair_1p_with(T, \
- stc::final<T>, stc::abstract, \
- stc::final<T>); \
- \
- stc_internal_match_pair_2p_with_error(T, U, \
- stc::final<T>, stc::final<U>, \
- stc::ERROR::IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED_FINAL); \
- \
- stc_internal_match_pair_2p_with(T, U, \
- stc::final<T>, U, \
- stc::final<T>); \
- \
- \
- /* ---------------- */ \
- /* local_res == T. */ \
- /* ---------------- */ \
- \
- stc_internal_match_pair_1p_with(T, \
- T, stc::not_found, \
- T); \
- \
- stc_internal_match_pair_1p_with(T, \
- T, stc::abstract, \
- T); \
- \
- stc_internal_match_pair_2p_with_error(T, U, \
- T, stc::final<U>, \
- stc::ERROR::IN_merge2_FINAL_VIRTUAL_TYPE_REDEFINED); \
- \
- template <typename T, typename U> \
- struct match_with \
- { \
- typedef T ret; \
- }; \
- \
- } /* end of namespace merge2_ */ \
- \
- template <typename local_res, typename super_res> \
- struct merge2 \
- { \
- /* Result. */ \
- typedef typename merge2_::match_with<local_res, super_res>::ret ret; \
- }; \
- \
- \
- /* --------------------------------------------------------- merge3. */ \
- \
- \
- namespace merge3_ \
- { \
- /* Forward declaration. */ \
- template <typename T, typename U, typename V> struct match_with; \
- \
- \
- /* ----------------------------- */ \
- /* local_res == stc::not_found. */ \
- /* ----------------------------- */ \
- \
- /* super_res == stc::not_found. */ \
- stc_internal_match_triple_0p_with( \
- stc::not_found, stc::not_found, stc::not_found, \
- stc::not_found); \
- \
- stc_internal_match_triple_0p_with( \
- stc::not_found, stc::not_found, stc::abstract, \
- stc::not_found); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_found, stc::not_found, stc::final<V>, \
- stc::final<V>); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_found, stc::not_found, V, \
- V); \
- \
- /* super_res == stc::abstract. */ \
- stc_internal_match_triple_0p_with( \
- stc::not_found, stc::abstract, stc::not_found, \
- stc::not_found); \
- \
- stc_internal_match_triple_0p_with( \
- stc::not_found, stc::abstract, stc::abstract, \
- stc::abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_found, stc::abstract, stc::final<V>, \
- stc::final<V>); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_found, stc::abstract, V, \
- V); \
- \
- /* super_res is a concrete type. */ \
- stc_internal_match_triple_2p_with(U, V, \
- stc::not_found, stc::final<U>, V, \
- stc::final<U>); \
- \
- stc_internal_match_triple_2p_with(U, V, \
- stc::not_found, U, V, \
- U); \
- \
- \
- /* ---------------------------- */ \
- /* local_res == stc::abstract. */ \
- /* ---------------------------- */ \
- \
- /* super_res == stc::not_found. */ \
- stc_internal_match_triple_0p_with( \
- stc::abstract, stc::not_found, stc::not_found, \
- stc::abstract); \
- \
- stc_internal_match_triple_0p_with( \
- stc::abstract, stc::not_found, stc::abstract, \
- stc::abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::not_found, stc::final<V>, \
- stc::final<V>); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::not_found, V, \
- V); \
- \
- \
- /* super_res == stc::abstract. */ \
- stc_internal_match_triple_0p_with( \
- stc::abstract, stc::abstract, stc::not_found, \
- stc::abstract); \
- \
- stc_internal_match_triple_0p_with( \
- stc::abstract, stc::abstract, stc::abstract, \
- stc::abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::abstract, stc::final<V>, \
- stc::final<V>); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::abstract, V, \
- V); \
- \
- \
- /* super_res == stc::not_delegated_abstract. */ \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::not_delegated_abstract, V, \
- stc::not_delegated_abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::abstract, stc::not_delegated, V, \
- stc::not_delegated_abstract); \
- \
- \
- /* super_res is a concrete type. */ \
- stc_internal_match_triple_2p_with_error(U, V, \
- stc::abstract, stc::final<U>, V, \
- stc::ERROR::IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED_ABSTRACT); \
- \
- stc_internal_match_triple_2p_with_error(U, V, \
- stc::abstract, U, V, \
- stc::ERROR::IN_merge3_VIRTUAL_TYPE_REDEFINED_ABSTRACT); \
- \
- \
- /* --------------------------------- */ \
- /* local_res == stc::not_delegated. */ \
- /* --------------------------------- */ \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_delegated, stc::not_found, V, \
- stc::not_delegated); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_delegated, stc::abstract, V, \
- stc::not_delegated_abstract); \
- \
- stc_internal_match_triple_1p_with(V, \
- stc::not_delegated, stc::not_delegated_abstract, V, \
- stc::not_delegated_abstract); \
- \
- \
- /* ------------------------------------------ */ \
- /* local_res == stc::not_delegated_abstract. */ \
- /* ------------------------------------------ */ \
- \
- /* FIXME: Shouldn't we introduce a means to tag a vtype both as */ \
- /* abstract *and* not delegated? (Currently, the rule below */ \
- /* prevents this). */ \
- stc_internal_match_triple_2p_with_error(U, V, \
- stc::not_delegated_abstract, U, V, \
- stc::ERROR::IN_merge3_LOCAL_DECLARATION_OF_NOT_DELEGATED_AND_ABSTRACT); \
- \
- \
- /* ---------------------------- */ \
- /* local_res == stc::final<T>. */ \
- /* ---------------------------- */ \
- \
- stc_internal_match_triple_3p_with_error(T, U, V, \
- stc::final<T>, stc::final<U>, V, \
- stc::ERROR::IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED_FINAL); \
- \
- stc_internal_match_triple_3p_with(T, U, V, \
- stc::final<T>, U, V, \
- stc::final<T>); \
- \
- \
- /* ---------------- */ \
- /* local_res == T. */ \
- /* ---------------- */ \
- \
- stc_internal_match_triple_3p_with_error(T, U, V, \
- T, stc::final<U>, V, \
- stc::ERROR::IN_merge3_FINAL_VIRTUAL_TYPE_REDEFINED); \
- \
- template <typename T, typename U, typename V> \
- struct match_with \
- { \
- typedef T ret; \
- }; \
- \
- } /* end of namespace merge3_ */ \
- \
- \
- template <typename local_res, typename super_res, typename delegatee_res> \
- struct merge3 \
- { \
- /* Result. */ \
- typedef typename \
- merge3_::match_with<local_res, super_res, delegatee_res>::ret ret; \
- }; \
- \
- \
- /* ------------------------------------------------------ find_rec. */ \
- \
- /* Forward declarations. */ \
- template <typename source, typename target> struct find_rec; \
- template <typename source, typename target> struct find_rec_in_supers; \
- \
- \
- namespace find_rec_ \
- { \
- \
- namespace find_delegatee_res_ \
- { \
- /* Forward declaration. */ \
- template <typename delegatee, typename target> struct match_with; \
- \
- template <typename target> \
- struct match_with<stc::not_found, target> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename target> \
- struct match_with<stc::abstract, target> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename delegatee, typename target> \
- struct match_with \
- { \
- typedef typename find_rec<delegatee, target>::ret ret; \
- }; \
- \
- } /* end of namespace find_delegatee_res_ */ \
- \
- \
- /* Forward declaration. */ \
- template <typename source, typename target> struct match_with; \
- \
- template <typename target> \
- struct match_with<stc::none, target> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename source, typename target> \
- struct match_with \
- { \
- typedef typename find_local<source, target>::ret local_res; \
- typedef typename find_rec<stc_super(source), target>::ret super_res; \
- /* delegatee_type is the name of the (optional) virtual type */ \
- /* containing the (type of the) delgatee. */ \
- typedef typename \
- find_rec_in_supers<source, typedef_::delegatee_type>::ret delegatee; \
- \
- typedef typename \
- find_delegatee_res_::match_with<delegatee, target>::ret delegatee_res; \
- typedef typename \
- merge3<local_res, super_res, delegatee_res>::ret ret; \
- }; \
- \
- } /* end of namespace find_rec_ */ \
- \
- template <typename source, typename target> \
- struct find_rec \
- { \
- /* Result. */ \
- typedef typename find_rec_::match_with<source, target>::ret ret; \
- }; \
- \
- \
- /* --------------------------------------------- find_rec_in_supers. */ \
- \
- namespace find_rec_in_supers_ \
- { \
- /* Forward declaration. */ \
- template <typename source, typename target> struct match_with; \
- \
- template <typename target> \
- struct match_with<stc::none, target> \
- { \
- typedef stc::none ret; \
- }; \
- \
- template <typename source, typename target> \
- struct match_with \
- { \
- typedef typename find_local<source, target>::ret local_res; \
- typedef typename find_rec<stc_super(source), target>::ret super_res; \
- typedef typename merge2<local_res, super_res>::ret ret; \
- }; \
- \
- } /* end of namespace find_rec_in_supers_ */ \
- \
- template <typename source, typename target> \
- struct find_rec_in_supers \
- { \
- /* Result. */ \
- typedef typename \
- find_rec_in_supers_::match_with<source, target>::ret ret; \
- }; \
- \
- \
- /* ----------------------------------------------------------- find. */ \
- \
- namespace find_ \
- { \
- /* Forward declaration. */ \
- template <typename T> struct match_with; \
- \
- /* FIXME: We'd like to add a static abort here, but we can't, */ \
- /* since stc::abstract is not a free parameter (enabling this */ \
- /* abort statement would prevent any compilation). */ \
- template <> \
- struct match_with<stc::abstract> \
- /* : mlc::abort_<stc::abstract, \
- stc::ERROR::IN_find_VIRTUAL_TYPE_IS_ABSTRACT> */ \
- { \
- }; \
- \
- /* FIXME: We'd like to add a static abort here, but we can't, */ \
- /* since stc::not_delegated_abstract is not a free parameter */ \
- /* (enabling this abort statement would prevent any */ \
- /* compilation). */ \
- template <> \
- struct match_with<stc::not_delegated_abstract> \
- /* : mlc::abort_<stc::not_delegated_abstract, */ \
- /* stc::ERROR::IN_find_VIRTUAL_TYPE_IS_ABSTRACT> */ \
- { \
- }; \
- \
- template <> \
- struct match_with<stc::not_delegated> \
- { \
- typedef stc::not_found ret; \
- }; \
- \
- template <typename T> \
- struct match_with< stc::final<T> > \
- { \
- typedef T ret; \
- }; \
- \
- template <typename T> \
- struct match_with \
- { \
- typedef T ret; \
- }; \
- \
- } /* end of namespace find_ */ \
- \
- \
- /** Find a virtual type. */ \
- template <typename source, typename target> \
- struct find_vtype \
- { \
- typedef typename find_rec<source, target>::ret res; \
- /* Result. */ \
- typedef typename find_::match_with<res>::ret ret; \
- }; \
- \
- \
- /** Find a virtual type, and ensure it is found. */ \
- template <typename from, typename target> \
- struct vtype \
- { \
- typedef typename find_vtype<from, target>::ret res; \
- struct check_ : mlc::assert_< mlc::is_found_<res> > \
- { \
- typedef res ret; \
- }; \
- typedef typename check_::ret ret; \
- }; \
- \
-} /* end of SCOOPED_NAMESPACE */ \
- \
-struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_o_n;
-
-
-/*------------------.
-| Shortcuts macro. |
-`------------------*/
-
-// FIXME: Document all these macros.
-
-# define stc_find_vtype_(Namespace, Source, Target) \
- Namespace::find_vtype<Source, Namespace::typedef_::Target##_type>::ret
-
-# define stc_find_vtype(Namespace, Source, Target) \
- typename stc_find_vtype_(Namespace, Source, Target)
-
-// Dummy alias, for compatibility purpose (deferred virtual types are
-// not currently handled by this version of stc/scoop2.hh).
-# define stc_deferred_vtype(Namespace, From, Target) \
- stc_find_vtype(Namespace, From, Target)
-
-# define stc_vtype_(Namespace, From, Target) \
- Namespace::vtype<From, Namespace::typedef_::Target##_type>::ret
-
-# define stc_vtype(Namespace, From, Target) \
- typename stc_vtype_(Namespace, From, Target)
-
-# define stc_find_deduce_vtype_(Namespace, From, Target1, Target2) \
- Namespace::find_vtype< \
- Namespace::find_vtype< \
- From, \
- Namespace::typedef_::Target1##_type \
- >::ret, \
- Namespace::typedef_::Target2##_type \
- >::ret
-
-# define stc_find_deduce_vtype(Namespace, From, Target1, Target2) \
- typename Namespace::find_vtype< \
- typename Namespace::find_vtype< \
- From, \
- Namespace::typedef_::Target1##_type \
- >::ret, \
- Namespace::typedef_::Target2##_type \
- >::ret
-
-# define stc_deduce_deferred_vtype(Namespace, From, Target1, Target2) \
- stc_find_deduce_vtype(Namespace, From, Target1, Target2)
-
-# define stc_deduce_vtype_(Namespace, From, Target1, Target2) \
- Namespace::vtype< \
- Namespace::vtype< \
- From, \
- Namespace::typedef_::Target1##_type \
- >::ret, \
- Namespace::typedef_::Target2##_type \
- >::ret
-
-# define stc_deduce_vtype(Namespace, From, Target1, Target2) \
- typename Namespace::vtype< \
- typename Namespace::vtype< \
- From, \
- Namespace::typedef_::Target1##_type \
- >::ret, \
- Namespace::typedef_::Target2##_type \
- >::ret
+ /// get_impl
+ template < template <class> class abstraction, typename E >
+ struct get_impl : impl< abstraction, stc_find_type(E, behavior), E >
+ { /* depends upon behavior */ };
-#endif // ! STC_SCOOP_ALT_HH
+} // End of namespace automatic.
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add type of ''image restricted_to a subset''.
* tests/core/subset.cc: New.
* tests/core/Makefile.am: Update.
* oln/debug/println.hh: New.
* oln/core/internal/op_image_restricted_to_pset.hh: New.
* oln/debug/print.hh: Fix copyright.
* oln/core/concept/image.hh (bbox): Provide a final impl.
* oln/core/rle/rle_image.hh,
* oln/core/concept/image_identity.hh,
* oln/core/sparse/sparse_image.hh,
* oln/core/1d/image1d.hh
* oln/core/1d/image1d_b.hh
* oln/core/2d/image2d.hh
* oln/core/2d/image2d_b.hh: Update.
* oln/core/concept/neighborhood.hh (oln_decl_op_plus): Move to...
* oln/core/gen/neighb.hh: ...this file.
* oln/core/gen/op.hh (oln_decl_op_restricted_to, restricted_to):
New.
* oln/core/internal/point_set_base.hh (category): New.
* oln/core/internal/op_image_plus_nbh.hh: Add static assert.
* oln/core/internal/image_base.hh (include): Add
op_image_restricted_to_pset.hh.
oln/core/1d/image1d.hh | 9 -
oln/core/1d/image1d_b.hh | 8
oln/core/2d/image2d.hh | 9 -
oln/core/2d/image2d_b.hh | 8
oln/core/concept/image.hh | 9 -
oln/core/concept/image_identity.hh | 8
oln/core/concept/neighborhood.hh | 4
oln/core/gen/neighb.hh | 6
oln/core/gen/op.hh | 2
oln/core/internal/image_base.hh | 15 +
oln/core/internal/op_image_plus_nbh.hh | 5
oln/core/internal/op_image_restricted_to_pset.hh | 200 +++++++++++++++++++++++
oln/core/internal/point_set_base.hh | 2
oln/core/rle/rle_image.hh | 9 -
oln/core/sparse/sparse_image.hh | 8
oln/debug/print.hh | 2
oln/debug/println.hh | 61 +++++++
tests/core/Makefile.am | 2
tests/core/subset.cc | 43 ++++
19 files changed, 340 insertions(+), 70 deletions(-)
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 876)
+++ tests/core/Makefile.am (working copy)
@@ -26,6 +26,7 @@
image2d \
neighb2d \
npoints \
+ subset \
window2d \
at
@@ -36,6 +37,7 @@
image2d_SOURCES = image2d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
+subset_SOURCES = subset.cc
window2d_SOURCES = window2d.cc
# Methods.
Index: tests/core/subset.cc
--- tests/core/subset.cc (revision 0)
+++ tests/core/subset.cc (revision 0)
@@ -0,0 +1,43 @@
+// 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.
+
+#include <cassert>
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/neighb2d.hh>
+
+
+int main()
+{
+ using namespace oln;
+
+ image2d<int> ima(5, 5);
+
+ point2d p(1,1), q(3,3);
+ box2d b = init(from(p), to(q));
+
+ assert((ima | b).points().npoints() = 9); // FIXME: looks weird
+}
Index: oln/debug/println.hh
--- oln/debug/println.hh (revision 0)
+++ oln/debug/println.hh (revision 0)
@@ -0,0 +1,61 @@
+// 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 OLN_DEBUG_PRINTLN_HH
+# define OLN_DEBUG_PRINTLN_HH
+
+# include <oln/debug/print.hh>
+
+
+namespace oln
+{
+
+ namespace debug
+ {
+
+ template <typename I>
+ void println(const Image<I>& input, std::ostream& ostr = std::cout);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ void println(const Image<I>& input, std::ostream& ostr)
+ {
+ print(exact(input), ostr);
+ ostr << std::endl;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+
+ } // end of namespace oln::debug
+
+} // end of namespace oln
+
+
+#endif // ! OLN_DEBUG_PRINTLN_HH
Index: oln/debug/print.hh
--- oln/debug/print.hh (revision 876)
+++ oln/debug/print.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 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
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 876)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -80,7 +80,6 @@
**
** method:
** pset impl_points() const : return image pset
- ** box impl_bbox() const : return image bbox
** bool impl_has(const point& p) const : rle_image has p?
** bool impl_owns_(const psite& p) const : same has impl_has
** void insert(const point& p, unsigned len, value val) : insert a new range on the image
@@ -105,7 +104,6 @@
rle_image();
pset impl_points() const;
- box impl_bbox() const;
bool impl_has(const point& p) const;
bool impl_owns_(const psite& p) const;
void insert(const point& p, unsigned len, value val);
@@ -130,13 +128,6 @@
}
template <typename P, typename T>
- typename rle_image<P, T>::box
- rle_image<P, T>::impl_bbox() const
- {
- 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
{
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 876)
+++ oln/core/concept/image.hh (working copy)
@@ -134,9 +134,11 @@
bool owns_(const psite& p) const;
rvalue operator()(const psite& p) const;
- box bbox() const;
pset points() const;
+ // With final impl:
+ box bbox() const;
+
protected:
Image();
};
@@ -357,7 +359,7 @@
typename Image<Exact>::box
Image<Exact>::bbox() const
{
- return exact(this)->impl_bbox();
+ return this->points().bbox(); // Final impl.
}
template <typename Exact>
@@ -551,8 +553,7 @@
{
}
-# endif
-
+# endif // OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/neighborhood.hh
--- oln/core/concept/neighborhood.hh (revision 876)
+++ oln/core/concept/neighborhood.hh (working copy)
@@ -29,8 +29,6 @@
# define OLN_CORE_CONCEPT_NEIGHBORHOOD_HH
# include <oln/core/equipment.hh>
-# include <oln/core/internal/op_image_plus_nbh.hh>
-
@@ -52,8 +50,6 @@
}; // end of oln::Neighborhood<Exact>
- oln_decl_op_plus(Image, Neighborhood);
-
# ifndef OLN_INCLUDE_ONLY
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 876)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -54,7 +54,6 @@
bool impl_owns_(const psite& p) const;
rvalue impl_read(const psite& p) const;
- box impl_bbox() const;
pset impl_points() const;
};
@@ -193,13 +192,6 @@
}
template <typename Exact>
- typename set_impl< Image, behavior::identity, Exact >::box
- set_impl< Image, behavior::identity, Exact >::impl_bbox() const
- {
- return exact(this)->image().bbox();
- }
-
- template <typename Exact>
typename set_impl< Image, behavior::identity, Exact >::pset
set_impl< Image, behavior::identity, Exact >::impl_points() const
{
Index: oln/core/sparse/sparse_image.hh
--- oln/core/sparse/sparse_image.hh (revision 876)
+++ oln/core/sparse/sparse_image.hh (working copy)
@@ -83,7 +83,6 @@
sparse_image();
pset impl_points() const;
- box impl_bbox() const;
bool impl_has(const point& p) const;
bool impl_owns_(const psite& p) const;
void insert(const point& p, unsigned len, const std::vector<value>& val);
@@ -109,13 +108,6 @@
}
template <typename P, typename T>
- typename sparse_image<P, T>::box
- sparse_image<P, T>::impl_bbox() const
- {
- return this->data_->first.bbox();
- }
-
- template <typename P, typename T>
bool
sparse_image<P, T>::impl_has(const typename sparse_image<P, T>::point& p) const
{
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 876)
+++ oln/core/1d/image1d.hh (working copy)
@@ -97,7 +97,6 @@
std::size_t impl_npoints() const;
- box1d impl_bbox() const;
box1d impl_points() const;
};
@@ -176,19 +175,13 @@
}
template <typename T>
- box1d image1d<T>::impl_bbox() const
+ box1d image1d<T>::impl_points() const
{
assert(this->has_data());
box1d b(this->data_->imin(), this->data_->imax());
return b;
}
- template <typename T>
- box1d image1d<T>::impl_points() const
- {
- return this->bbox();
- }
-
# endif
Index: oln/core/1d/image1d_b.hh
--- oln/core/1d/image1d_b.hh (revision 876)
+++ oln/core/1d/image1d_b.hh (working copy)
@@ -105,7 +105,6 @@
std::size_t impl_npoints() const;
- box1d impl_bbox() const;
box1d impl_points() const;
unsigned border() const;
@@ -184,13 +183,6 @@
}
template <typename T>
- box1d image1d_b<T>::impl_bbox() const
- {
- assert(this->has_data());
- return this->data_->third;
- }
-
- template <typename T>
box1d image1d_b<T>::impl_points() const
{
assert(this->has_data());
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 876)
+++ oln/core/2d/image2d.hh (working copy)
@@ -100,7 +100,6 @@
std::size_t impl_npoints() const;
- box2d impl_bbox() const;
box2d impl_points() const;
};
@@ -203,7 +202,7 @@
}
template <typename T>
- box2d image2d<T>::impl_bbox() const
+ box2d image2d<T>::impl_points() const
{
assert(this->has_data());
point2d
@@ -213,12 +212,6 @@
return b;
}
- template <typename T>
- box2d image2d<T>::impl_points() const
- {
- return this->bbox();
- }
-
template <typename T, typename D>
bool init_(image2d<T>* this_, const D& dat)
{
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 876)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -146,7 +146,6 @@
std::size_t impl_npoints() const;
- box2d impl_bbox() const;
box2d impl_points() const;
unsigned border() const;
@@ -244,13 +243,6 @@
}
template <typename T>
- box2d image2d_b<T>::impl_bbox() const
- {
- assert(this->has_data());
- return this->data_->box;
- }
-
- template <typename T>
box2d image2d_b<T>::impl_points() const
{
assert(this->has_data());
Index: oln/core/gen/neighb.hh
--- oln/core/gen/neighb.hh (revision 876)
+++ oln/core/gen/neighb.hh (working copy)
@@ -31,12 +31,18 @@
# include <oln/core/internal/dpoints_impl.hh>
# include <oln/core/internal/neighborhood_base.hh>
+# include <oln/core/internal/op_image_plus_nbh.hh>
namespace oln
{
+ // Op.
+ oln_decl_op_plus(Image, Neighborhood);
+
+
+
// Fwd decl.
template <typename Dp> class neighb_;
Index: oln/core/gen/op.hh
--- oln/core/gen/op.hh (revision 876)
+++ oln/core/gen/op.hh (working copy)
@@ -73,6 +73,7 @@
# define oln_decl_op_plus(Lconcept, Rconcept) oln_decl_op_(plus, Lconcept, +, Rconcept)
# define oln_decl_op_such_as(Lconcept, Rconcept) oln_decl_op_(such_as, Lconcept, |, Rconcept)
+# define oln_decl_op_restricted_to(Lconcept, Rconcept) oln_decl_op_( restricted_to, Lconcept, |, Rconcept)
// ...
@@ -104,6 +105,7 @@
struct plus;
struct such_as;
+ struct restricted_to;
/// \}
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 876)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -58,6 +58,8 @@
typedef stc_deferred(point) point__;
typedef stc_deferred(fwd_piter) fwd_piter__;
+ typedef stc::final< stc::is<Point_Set> > category;
+
typedef stc::final< box_<point__> > box;
typedef stc::final<stc_type(point__, grid)> grid;
typedef stc::final<fwd_piter__> piter;
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 0)
+++ oln/core/internal/op_image_restricted_to_pset.hh (revision 0)
@@ -0,0 +1,200 @@
+// 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 OLN_CORE_INTERNAL_OP_IMAGE_RESTRICTED_TO_PSET_HH
+# define OLN_CORE_INTERNAL_OP_IMAGE_RESTRICTED_TO_PSET_HH
+
+# include <oln/core/internal/image_base.hh>
+# include <oln/core/concept/point_set.hh>
+# include <oln/core/gen/op.hh>
+
+
+namespace oln
+{
+
+# define current \
+ special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S >
+
+
+// /// Fwd decls.
+// template <typename Exact> struct Image;
+// template <typename Exact> struct Point_Set;
+
+
+ /// Super type.
+ template <typename I, typename S>
+ struct super_trait_< internal::current >
+ {
+ typedef internal::image_extension_< op_<I, restricted_to, S> > ret;
+ };
+
+
+ /// Virtual types.
+ template <typename I, typename S>
+ struct vtypes< internal::current >
+ {
+ typedef op_<I, restricted_to, S> Exact;
+ typedef stc_type(I, point) point__;
+
+ typedef I delegatee;
+ typedef internal::pair<I,S> data;
+
+ typedef S pset;
+
+ typedef op_<oln_plain(I), restricted_to, S> plain;
+ typedef op_<pl::rec<I>, restricted_to, S> skeleton;
+ };
+
+
+ namespace internal
+ {
+
+ /// Implementation class the result of "Image I | Point_Set S".
+
+ template <typename I, typename S>
+ class special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S >
+ :
+ public internal::image_extension_< op_<I, restricted_to, S> >
+ {
+ typedef internal::image_extension_< op_<I, restricted_to, S> > super;
+ public:
+ stc_using(pset);
+ stc_using(box);
+ stc_using(data);
+ stc_using(delegatee);
+
+ delegatee& impl_image();
+ const delegatee& impl_image() const;
+
+ pset impl_points() const;
+
+ protected:
+ special_op_();
+ special_op_(I& ima, S& subset);
+ };
+
+ } // end of namespace oln::internal
+
+
+ // init
+
+ template <typename I, typename S, typename D>
+ bool init_(internal::current* target, const D& dat);
+
+ template <typename S, typename I>
+ bool init(Point_Set<S>& target,
+ with_t,
+ const internal::current& dat);
+
+ template <typename I, typename S>
+ bool init(Image<I>& target,
+ with_t,
+ const internal::current& dat);
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename I, typename S>
+ current::special_op_()
+ {
+ }
+
+ template <typename I, typename S>
+ current::special_op_(I& ima, S& subset)
+ {
+ this->data_ = new data(ima, subset);
+ }
+
+ template <typename I, typename S>
+ typename current::delegatee&
+ current::impl_image()
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+ template <typename I, typename S>
+ const typename current::delegatee&
+ current::impl_image() const
+ {
+ assert(this->has_data());
+ return this->data_->first;
+ }
+
+ template <typename I, typename S>
+ typename current::pset
+ current::impl_points() const
+ {
+ assert(this->has_data());
+ return this->data_->second;
+ }
+
+ } // end of namespace oln::internal
+
+
+ // init
+
+ template <typename I, typename S, typename D>
+ bool init_(internal::current* this_, const D& dat)
+ {
+ precondition(not this_->has_data());
+ this_->data__() = new typename op_<I, restricted_to, S>::data;
+ bool image_ok = init(this_->data__()->first, with, dat);
+ bool subset_ok = init(this_->data__()->second, with, dat);
+ postcondition(image_ok);
+ postcondition(subset_ok);
+ return image_ok and subset_ok;
+ }
+
+ template <typename S, typename I>
+ bool init_(Point_Set<S>* this_,
+ const internal::current& data)
+ {
+ *this_ = data.points();
+ return true;
+ }
+
+ template <typename I, typename S>
+ bool init(Image<I>* this_,
+ const internal::current& data)
+ {
+ *this_ = data.image();
+ return true;
+ }
+
+# endif // OLN_INCLUDE_ONLY
+
+# undef current
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_OP_IMAGE_RESTRICTED_TO_PSET_HH
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 876)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -84,7 +84,8 @@
template <typename I, typename N>
class special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N >
:
- public internal::image_extension_< op_<I, plus, N> >
+ public internal::image_extension_< op_<I, plus, N> >,
+ private mlc::assert_< mlc_is_not_a(I, Image_with_Nbh) > // FIXME: Add err msg.
{
typedef internal::image_extension_< op_<I, plus, N> > super;
public:
@@ -167,8 +168,6 @@
// init
- // FIXME: N is nbh?
-
template <typename I, typename N, typename D>
bool init_(internal::current* this_, const D& dat)
{
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 876)
+++ oln/core/internal/image_base.hh (working copy)
@@ -461,8 +461,21 @@
} // end of namespace oln
-// FIXME: Bad!
+
+
+/// \{
+/// FIXME: Bad!
+
# include <oln/core/internal/f_ch_value.hh>
+# include <oln/core/internal/op_image_restricted_to_pset.hh>
+
+namespace oln
+{
+ oln_decl_op_restricted_to(Image, Point_Set);
+
+} // end of namespace oln
+
+/// \}
1
0
15 Mar '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add external initialization through ''init(target, with, data)''.
* oln/core/internal/utils.hh (value1, value2, value3, value4):
Rename as...
(first, second, third, fourth): ...these.
* oln/core/init.hh (init): New version.
(with_t, with, init_): New.
* oln/core/1d/image1d.hh (plain, skeleton): New.
* oln/core/1d/image1d_b.hh: Likewise and update.
* oln/core/2d/neighb2d.hh (OLN_ENABLE_DEFAULT): New.
(init_): New.
* oln/core/2d/array2d.hh: Add FIXMEs.
* oln/core/2d/image2d.hh (init_): New.
* oln/core/2d/image2d_b.hh: Likewise.
* oln/core/2d/box2d.hh (init__): Change sig.
* oln/core/2d/point2d.hh (init__): Replace by...
(point2d): ...this new ctor.
* oln/core/gen/box.hh: Likewise.
* oln/core/equipment.hh (include): Add init.hh.
* oln/core/gen/op.hh (op_): New ctor.
* oln/core/gen/single_value_image.hh: Update.
* oln/core/concept/point_set.hh (box): New instant value.
* oln/core/concept/grid.hh (include): Remove.
* oln/core/concept/point.hh (include): Add grid.hh.
(point): New instant value.
* oln/core/concept/value.hh: Fix.
* oln/core/internal/initializer.hh (operator*): Rename as...
(value): ...this.
(init__): Secure.
* oln/core/internal/op_image_plus_nbh.hh (current): Move.
(init_): New.
Update.
* oln/core/internal/instant_value.hh (oln_decl_instant_value):
Move type definitions into internal.
(operator M<W>): Add FIXME.
* oln/core/internal/image_base.hh (ima): New instant value.
(data__): New method.
(init_): New.
1d/image1d.hh | 3 +
1d/image1d_b.hh | 21 +++++-----
2d/array2d.hh | 2
2d/box2d.hh | 47 ++++++++++++-----------
2d/image2d.hh | 14 ++++++
2d/image2d_b.hh | 14 ++++++
2d/neighb2d.hh | 23 ++++++++++-
2d/point2d.hh | 37 ++++--------------
concept/grid.hh | 1
concept/point.hh | 3 +
concept/point_set.hh | 6 ++
concept/value.hh | 3 -
equipment.hh | 2
gen/box.hh | 44 +++++++--------------
gen/op.hh | 10 ++++
gen/single_value_image.hh | 10 ++--
init.hh | 85 ++++++++++++++++++++++++++++++++++++++++++
internal/image_base.hh | 47 ++++++++++++++++++++++-
internal/initializer.hh | 59 +++++++++++++++++++++--------
internal/instant_value.hh | 22 ++++++++--
internal/op_image_plus_nbh.hh | 78 ++++++++++++++++++++++++++++++++++----
internal/utils.hh | 46 +++++++++++-----------
22 files changed, 428 insertions(+), 149 deletions(-)
Index: oln/core/concept/point_set.hh
--- oln/core/concept/point_set.hh (revision 875)
+++ oln/core/concept/point_set.hh (working copy)
@@ -28,13 +28,17 @@
#ifndef OLN_CORE_CONCEPT_POINT_SET_HH
# define OLN_CORE_CONCEPT_POINT_SET_HH
-# include <ostream>
+# include <iostream>
# include <oln/core/concept/point.hh>
+# include <oln/core/concept/iterator.hh> // for "for_all"
namespace oln
{
+ /// Instant value.
+ oln_decl_instant_value(box);
+
/// Concept-class "Point_Set".
Index: oln/core/concept/grid.hh
--- oln/core/concept/grid.hh (revision 875)
+++ oln/core/concept/grid.hh (working copy)
@@ -30,7 +30,6 @@
# define OLN_CORE_CONCEPT_GRID_HH
# include <oln/core/equipment.hh>
-# include <oln/core/internal/instant_value.hh>
namespace oln
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 875)
+++ oln/core/concept/point.hh (working copy)
@@ -30,12 +30,15 @@
# define OLN_CORE_CONCEPT_POINT_HH
# include <mlc/value.hh>
+# include <oln/core/concept/grid.hh>
# include <oln/core/concept/operators.hh>
namespace oln
{
+ /// Instant value.
+ oln_decl_instant_value(point);
/// Concept-class "Point".
Index: oln/core/concept/value.hh
--- oln/core/concept/value.hh (revision 875)
+++ oln/core/concept/value.hh (working copy)
@@ -47,7 +47,8 @@
# ifndef OLN_INCLUDE_ONLY
- Value::Value()
+ template <typename Exact>
+ Value<Exact>::Value()
{
}
Index: oln/core/init.hh
--- oln/core/init.hh (revision 875)
+++ oln/core/init.hh (working copy)
@@ -38,6 +38,11 @@
{
+ template <typename D>
+ internal::initializer_<D>
+ init(const D& d);
+
+
template <template<class> class M, typename V>
internal::initializer_< internal::singleton< M<V> > >
init(const internal::instant_value_<M,V>& v);
@@ -61,9 +66,49 @@
// ...
+ const struct with_t {} with = with_t();
+
+
+ /*
+ *
+ * // To be specialized.
+ * template <typename This_, typename Data>
+ * bool init_(This_* this_, const Data& data); // FIXME: give code? err?
+ *
+ */
+
+
+ // The init versions below calls the above init_ routine.
+ // FIXME: Add oln::Any<*> to signature?
+
+
+ // Regular version.
+ template <typename Target, typename Data>
+ bool init(Target& target, with_t, const Data& data);
+
+ // Assignment.
+ template <typename T>
+ bool init(T& target, with_t, const T& data);
+
+ // Unconst data version.
+ template <typename Target, typename Data>
+ bool init(Target& target, with_t, Data& data);
+
+ // Guard: we cannot have "const Target".
+ template <typename Target, typename Data>
+ bool init(const Target& target, with_t, const Data& data);
+
+
# ifndef OLN_INCLUDE_ONLY
+ template <typename D>
+ internal::initializer_<D>
+ init(const D& d)
+ {
+ return d;
+ }
+
template <template<class> class M, typename V>
internal::initializer_< internal::singleton< M<V> > >
init(const internal::instant_value_<M,V>& v)
@@ -96,6 +141,46 @@
// ...
+
+
+ // Regular version.
+ template <typename Target, typename Data>
+ bool init(Target& target, with_t, const Data& data)
+ {
+ return init_(&target, data);
+ }
+
+ // Assignment.
+ template <typename T>
+ bool init(T& target, with_t, const T& data)
+ {
+ target = data;
+ return true;
+ }
+
+ // Unconst data version.
+ template <typename Target, typename Data>
+ bool init(Target& target, with_t, Data& data)
+ {
+ return init_(&target, const_cast<const Data&>(data));
+ }
+
+
+ namespace ERROR
+ {
+ template <typename T>
+ struct initialization_of_temporary_or_const_object_;
+ }
+
+ // Guard: we cannot have "const Target".
+ template <typename Target, typename Data>
+ bool init(const Target&, with_t, const Data&)
+ {
+ mlc::abort_< Target, ERROR::initialization_of_temporary_or_const_object_<Target> >::check();
+ return false;
+ }
+
+
# endif // OLN_INCLUDE_ONLY
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 875)
+++ oln/core/1d/image1d.hh (working copy)
@@ -56,6 +56,9 @@
typedef box1d pset;
typedef array1d_<value, coord> data;
+
+ typedef image1d<T> plain;
+ typedef image1d<pl::value> skeleton;
};
Index: oln/core/1d/image1d_b.hh
--- oln/core/1d/image1d_b.hh (revision 875)
+++ oln/core/1d/image1d_b.hh (working copy)
@@ -63,6 +63,9 @@
typedef internal::triplet< array1d_<T, int>,
unsigned,
box_<point1d> > data;
+
+ typedef image1d_b<T> plain;
+ typedef image1d_b<pl::value> skeleton;
};
@@ -140,21 +143,21 @@
bool image1d_b<T>::impl_owns_(const point1d& p) const
{
assert(this->has_data());
- return this->data_->value1.has(p.ind());
+ return this->data_->first.has(p.ind());
}
template <typename T>
bool image1d_b<T>::impl_has(const point1d& p) const
{
assert(this->has_data());
- return this->data_->value3.has(p);
+ return this->data_->third.has(p);
}
template <typename T>
const T& image1d_b<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
- return this->data_->value1(p.ind());
+ return this->data_->first(p.ind());
}
template <typename T>
@@ -162,14 +165,14 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->value1[i];
+ return this->data_->first[i];
}
template <typename T>
T& image1d_b<T>::impl_read_write(const point1d& p)
{
assert(this->has_data());
- return this->data_->value1(p.ind());
+ return this->data_->first(p.ind());
}
template <typename T>
@@ -177,28 +180,28 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->value1[i];
+ return this->data_->first[i];
}
template <typename T>
box1d image1d_b<T>::impl_bbox() const
{
assert(this->has_data());
- return this->data_->value3;
+ return this->data_->third;
}
template <typename T>
box1d image1d_b<T>::impl_points() const
{
assert(this->has_data());
- return this->data_->value3;
+ return this->data_->third;
}
template <typename T>
unsigned image1d_b<T>::border() const
{
assert(this->has_data());
- return this->data_->value2;
+ return this->data_->second;
}
# endif
Index: oln/core/2d/neighb2d.hh
--- oln/core/2d/neighb2d.hh (revision 875)
+++ oln/core/2d/neighb2d.hh (working copy)
@@ -40,6 +40,15 @@
typedef neighb_<dpoint2d> neighb2d;
+# ifdef OLN_ENABLE_DEFAULT
+
+ // Default is c4.
+ template <typename D>
+ bool init_(neighb2d* this_, const D&);
+
+# endif // OLN_ENABLE_DEFAULT
+
+
namespace internal
{
@@ -100,12 +109,24 @@
# ifndef OLN_INCLUDE_ONLY
+# ifdef OLN_ENABLE_DEFAULT
+
+ /// Default is c4.
+ template <typename D>
+ bool init_(neighb2d* this_, const D&)
+ {
+ *this_ = c4;
+ return true;
+ }
+
+# endif // OLN_ENABLE_DEFAULT
+
const neighb2d c4 = internal::mk_c4();
const neighb2d c8 = internal::mk_c8();
const neighb2d c2r = internal::mk_c2_row();
const neighb2d c2c = internal::mk_c2_col();
-# endif
+# endif // OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/2d/array2d.hh
--- oln/core/2d/array2d.hh (revision 875)
+++ oln/core/2d/array2d.hh (working copy)
@@ -99,6 +99,7 @@
precondition(imax >= imin and jmax >= jmin);
ilen_ = imax - imin + 1;
jlen_ = jmax - jmin + 1;
+ // FIXME: Test that ilen_ and jlen_ are not huge!
allocate_();
}
@@ -110,6 +111,7 @@
jlen_(jlen)
{
precondition(ilen > 0 and jlen > 0);
+ // FIXME: Test that ilen_ and jlen_ are not huge!
imax_ = imin_ + ilen_;
jmax_ = jmin_ + ilen_;
allocate_();
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 875)
+++ oln/core/2d/image2d.hh (working copy)
@@ -104,6 +104,8 @@
box2d impl_points() const;
};
+ template <typename T, typename D>
+ bool init_(image2d<T>* this_, const D& dat);
# ifndef OLN_INCLUDE_ONLY
@@ -217,6 +219,18 @@
return this->bbox();
}
+ template <typename T, typename D>
+ bool init_(image2d<T>* this_, const D& dat)
+ {
+ precondition(not this_->has_data());
+ box2d b;
+ bool box_ok = init(b, with, dat);
+ postcondition(box_ok);
+ this_->data__() = new typename image2d<T>::data(b.pmin().row(), b.pmin().col(),
+ b.pmax().row(), b.pmax().col());
+ return box_ok;
+ }
+
# endif
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 875)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -152,6 +152,8 @@
unsigned border() const;
};
+ template <typename T, typename D>
+ bool init_(image2d_b<T>* this_, const D& dat);
# ifndef OLN_INCLUDE_ONLY
@@ -262,6 +264,18 @@
return this->data_->border;
}
+ template <typename T, typename D>
+ bool init_(image2d_b<T>* this_, const D& dat)
+ {
+ precondition(not this_->has_data());
+ box2d b;
+ bool box_ok = init(b, with, dat);
+ postcondition(box_ok);
+ unsigned border = 2; // FIXME: Use init!
+ this_->data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border);
+ return box_ok;
+ }
+
# endif
Index: oln/core/2d/box2d.hh
--- oln/core/2d/box2d.hh (revision 875)
+++ oln/core/2d/box2d.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_CORE_2D_BOX2D_HH
# define OLN_CORE_2D_BOX2D_HH
+# include <oln/core/concept/point_set.hh> // for internal::tag::box_t
# include <oln/core/2d/point2d.hh>
@@ -46,13 +47,13 @@
namespace internal
{
- template <typename C>
- void init__(box2d& b,
- const initializer_< pair< nrows_t<C>, ncols_t<C> > >& data);
-
- template <typename C>
- void init__(box2d& b,
- const initializer_< triplet< from_t<point2d>, nrows_t<C>, ncols_t<C> > >& data);
+ template <typename U>
+ bool init__(tag::box_t, box2d& b,
+ const pair< nrows_t<U>, ncols_t<U> >& data);
+
+ template <typename U>
+ bool init__(tag::box_t, box2d& b,
+ const triplet< from_t<point2d>, nrows_t<U>, ncols_t<U> >& data);
} // end of namespace oln::internal
@@ -70,29 +71,31 @@
namespace internal
{
- template <typename C>
- void init__(box2d& b,
- const initializer_< pair< nrows_t<C>, ncols_t<C> > >& data)
- {
- C nrows = data->value1.value;
- C ncols = data->value2.value;
- precondition(nrows > 0 and ncols > 0);
+ template <typename U>
+ bool init__(tag::box_t, box2d& b,
+ const pair< nrows_t<U>, ncols_t<U> >& data)
+ {
+ unsigned nrows = data.first.value;
+ unsigned ncols = data.second.value;
+ precondition(nrows != 0 and ncols != 0);
b.pmin().row() = 0;
b.pmin().col() = 0;
b.pmax().row() = nrows - 1;
b.pmax().col() = ncols - 1;
+ return true;
}
- template <typename C>
- void init__(box2d& b,
- const initializer_< triplet< from_t<point2d>, nrows_t<C>, ncols_t<C> > >& data)
- {
- C nrows = data->value2.value;
- C ncols = data->value3.value;
- precondition(nrows > 0 and ncols > 0);
- b.pmin() = data->value1.value;
+ template <typename U>
+ bool init__(tag::box_t, box2d& b,
+ const triplet< from_t<point2d>, nrows_t<U>, ncols_t<U> >& data)
+ {
+ unsigned nrows = data.second.value;
+ unsigned ncols = data.third.value;
+ precondition(nrows != 0 and ncols != 0);
+ b.pmin() = data.first.value;
b.pmax().row() = b.pmin().row() + nrows - 1;
b.pmax().col() = b.pmin().col() + ncols - 1;
+ return true;
}
} // end of namespace oln::internal
Index: oln/core/2d/point2d.hh
--- oln/core/2d/point2d.hh (revision 875)
+++ oln/core/2d/point2d.hh (working copy)
@@ -31,7 +31,6 @@
# include <oln/core/2d/grid2d.hh>
# include <oln/core/internal/point2d.hh>
-# include <oln/core/init.hh>
namespace oln
@@ -60,25 +59,18 @@
};
- /// init__
- namespace internal
- {
- template <typename C>
- void init__(point2d& p,
- const initializer_< pair< row_t<C>, col_t<C> > >& data);
- }
-
-
/// Usual 2D point class.
class point2d : public internal::point2d_< point2d >
{
+ typedef internal::initializer_<
+ internal::pair< internal::row_t<int>, internal::col_t<int> >
+ > row_col_t;
public:
/// Ctors.
point2d();
- point2d(int row, int col);
- template <typename D>
- point2d(const internal::initializer_<D>& data);
+ point2d(int row, int col); // FIXME: Remove!
+ point2d(const row_col_t& dat);
};
@@ -89,27 +81,16 @@
{
}
- point2d::point2d(int row, int col)
+ point2d::point2d(int row, int col) // FIXME: Remove!
{
this->row() = row;
this->col() = col;
}
- template <typename D>
- point2d::point2d(const internal::initializer_<D>& data)
+ point2d::point2d(const point2d::row_col_t& dat)
{
- internal::init__(*this, data);
- }
-
- namespace internal
- {
- template <typename C>
- void init__(point2d& p,
- const initializer_< pair< row_t<C>, col_t<C> > >& data)
- {
- p.row() = data->value1.value; // FIXME: first
- p.col() = data->value2.value; // FIXME: second
- }
+ this->row() = dat->first.value;
+ this->col() = dat->second.value;
}
# endif
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 875)
+++ oln/core/equipment.hh (working copy)
@@ -30,7 +30,7 @@
# include <mlc/contract.hh>
# include <oln/stc/scoop.hh> // FIXME: Remove "oln/" later.
-
+# include <oln/core/init.hh>
# define oln_typename_shortcut__(Type, Alias) typename Type::Alias
Index: oln/core/gen/box.hh
--- oln/core/gen/box.hh (revision 875)
+++ oln/core/gen/box.hh (working copy)
@@ -32,7 +32,6 @@
# include <oln/core/concept/point.hh>
# include <oln/core/concept/iterator_on_points.hh>
# include <oln/core/internal/point_set_base.hh>
-# include <oln/core/init.hh>
namespace oln
@@ -64,15 +63,6 @@
};
- /// init__
- namespace internal
- {
- template <typename P>
- void init__(box_<P>& b,
- const initializer_< pair< from_t<P>, to_t<P> > >& data);
- }
-
-
/// Generic box class based on a point class.
template <typename P>
@@ -81,6 +71,11 @@
{
typedef box_<P> current;
typedef internal::point_set_base_<current> super;
+
+ typedef internal::initializer_<
+ internal::pair< internal::from_t<P>, internal::to_t<P> >
+ > from_to_t;
+
public:
stc_using(point);
@@ -94,6 +89,8 @@
box_();
box_(const P& pmin, const P& pmax);
+ box_(const from_to_t& data);
+
template <typename D>
box_(const internal::initializer_<D>& data);
@@ -227,10 +224,18 @@
}
template <typename P>
+ box_<P>::box_(const typename box_<P>::from_to_t& dat)
+ {
+ this->pmin_ = dat->first.value;
+ this->pmax_ = dat->second.value;
+ }
+
+ template <typename P>
template <typename D>
box_<P>::box_(const internal::initializer_<D>& data)
{
- internal::init__(*this, data);
+ bool box_ok = internal::init__(internal::tag::box_t(), *this, data.value());
+ postcondition(box_ok);
}
template <typename P>
@@ -293,23 +298,6 @@
}
- // -------------------- init__
-
-
- namespace internal
- {
-
- template <typename P>
- void init__(box_<P>& b,
- const initializer_< pair< from_t<P>, to_t<P> > >& data)
- {
- b.pmin() = data->value1.value;
- b.pmax() = data->value2.value;
- }
-
- }
-
-
// -------------------- box_fwd_piter_<P>
Index: oln/core/gen/op.hh
--- oln/core/gen/op.hh (revision 875)
+++ oln/core/gen/op.hh (working copy)
@@ -140,6 +140,8 @@
public:
op_();
op_(L& l, R& r);
+ template <typename D>
+ op_(const internal::initializer_<D>& data);
}; // end of op_<L, OpName, R>
@@ -158,6 +160,14 @@
{
}
+ template <typename L, typename OpName, typename R>
+ template <typename D>
+ op_<L, OpName, R>::op_(const internal::initializer_<D>& data)
+ {
+ bool op_ok = this->super::init__(data);
+ postcondition(op_ok);
+ }
+
# endif
# undef super
Index: oln/core/gen/single_value_image.hh
--- oln/core/gen/single_value_image.hh (revision 875)
+++ oln/core/gen/single_value_image.hh (working copy)
@@ -120,7 +120,7 @@
single_value_image<Ps, T>::impl_owns_(const typename single_value_image<Ps, T>::point& p) const
{
assert(this->has_data());
- return this->data_->value1.has(p);
+ return this->data_->first.has(p);
}
template <typename Ps, typename T>
@@ -128,7 +128,7 @@
single_value_image<Ps, T>::impl_has(const typename single_value_image<Ps, T>::point& p) const
{
assert(this->has_data());
- return this->data_->value1.has(p);
+ return this->data_->first.has(p);
}
template <typename Ps, typename T>
@@ -136,7 +136,7 @@
single_value_image<Ps, T>::impl_read(const typename single_value_image<Ps, T>::point&) const
{
assert(this->has_data());
- return this->data_->value2;
+ return this->data_->second;
}
template <typename Ps, typename T>
@@ -144,7 +144,7 @@
single_value_image<Ps, T>::impl_points() const
{
assert(this->has_data());
- return this->data_->value1;
+ return this->data_->first;
}
template <typename Ps, typename T>
@@ -152,7 +152,7 @@
single_value_image<Ps, T>::change_value(const T& new_value)
{
assert(this->has_data());
- this->data_->value2 = new_value;
+ this->data_->second = new_value;
}
# endif // OLN_INCLUDE_ONLY
Index: oln/core/internal/initializer.hh
--- oln/core/internal/initializer.hh (revision 875)
+++ oln/core/internal/initializer.hh (working copy)
@@ -37,12 +37,24 @@
{
template <typename S>
- struct bad_initialization_of_
+ struct no_proper_initialization_found_for_
+ {
+ template <typename D>
+ struct with_data_being_;
+ };
+
+ template <typename S>
+ struct bad_initialization_call_for_
{
template <typename D>
struct with_;
};
+ template <typename S>
+ struct initialization_call_instead_of_assignment_
+ {
+ };
+
} // end of namespace oln::ERROR
@@ -55,19 +67,25 @@
struct initializer_
{
initializer_(const D& data);
- const D& operator*() const;
const D* operator->() const;
+ const D& value() const;
protected:
D data_;
};
+ // Decl: explicit error when not defined.
template <typename Tag, typename Subject, typename D>
- void init__(const Tag& t, Subject& s, const initializer_<D>& d);
+ bool init__(const Tag& t, Subject& s, const D& d);
- template <typename Subject, typename D>
- void init__(Subject& s, const initializer_<D>& d);
+ // Guard: init is not for assignment.
+ template <typename Tag, typename D>
+ bool init__(const Tag& t, D& subject, const D& data);
+
+ // Guard: explicit error cause wrong type of last arg.
+ template <typename Tag, typename Subject, typename D>
+ bool init__(const Tag& t, Subject& s, const initializer_<D>& d);
@@ -79,29 +97,40 @@
{}
template <typename D>
+ const D*
+ initializer_<D>::operator->() const
+ {
+ return &(this->data_);
+ }
+
+ template <typename D>
const D&
- initializer_<D>::operator*() const
+ initializer_<D>::value() const
{
return this->data_;
}
- template <typename D>
- const D*
- initializer_<D>::operator->() const
+ template <typename Tag, typename D>
+ bool init__(const Tag&, D& subject, const D& data)
{
- return &(this->data_);
+ mlc::abort_<Tag, typename ERROR::initialization_call_instead_of_assignment_<D> >::check();
+ return false;
}
template <typename Tag, typename Subject, typename D>
- void init__(const Tag&, Subject&, const initializer_<D>&)
+ bool init__(const Tag&, Subject&, const D&)
{
- mlc::abort_<D, typename ERROR::bad_initialization_of_<Subject>::template with_<D> >::check();
+ mlc::abort_<Tag, typename ERROR::no_proper_initialization_found_for_<Subject>
+ ::template with_data_being_<D> >::check();
+ return false;
}
- template <typename Subject, typename D>
- void init__(Subject&, const initializer_<D>&)
+ template <typename Tag, typename Subject, typename D>
+ bool init__(const Tag&, Subject& s, const initializer_<D>& d)
{
- mlc::abort_<D, typename ERROR::bad_initialization_of_<Subject>::template with_<D> >::check();
+ mlc::abort_<Tag, typename ERROR::bad_initialization_call_for_<Subject>
+ ::template with_<D> >::check();
+ return false;
}
# endif // OLN_INCLUDE_ONLY
Index: oln/core/internal/utils.hh
--- oln/core/internal/utils.hh (revision 875)
+++ oln/core/internal/utils.hh (working copy)
@@ -61,12 +61,12 @@
{
pair()
{}
- pair(T1 value1, T2 value2)
- : value1(value1),
- value2(value2)
+ pair(T1 first, T2 second)
+ : first(first),
+ second(second)
{}
- T1 value1;
- T2 value2;
+ T1 first;
+ T2 second;
};
@@ -77,14 +77,14 @@
{
triplet()
{}
- triplet(T1 value1, T2 value2, T3 value3)
- : value1(value1),
- value2(value2),
- value3(value3)
- {}
- T1 value1;
- T2 value2;
- T3 value3;
+ triplet(T1 first, T2 second, T3 third)
+ : first(first),
+ second(second),
+ third(third)
+ {}
+ T1 first;
+ T2 second;
+ T3 third;
};
@@ -95,16 +95,16 @@
{
quartet()
{}
- quartet(T1 value1, T2 value2, T3 value3, T4 value4)
- : value1(value1),
- value2(value2),
- value3(value3),
- value4(value4)
- {}
- T1 value1;
- T2 value2;
- T3 value3;
- T4 value4;
+ quartet(T1 first, T2 second, T3 third, T4 fourth)
+ : first(first),
+ second(second),
+ third(third),
+ fourth(fourth)
+ {}
+ T1 first;
+ T2 second;
+ T3 third;
+ T4 fourth;
};
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 875)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
# define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
+# include <oln/core/concept/neighborhood.hh>
# include <oln/core/gen/op.hh>
# include <oln/core/gen/dpoints_piter.hh>
# include <oln/core/internal/image_base.hh>
@@ -36,6 +37,13 @@
namespace oln
{
+# define current \
+ special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N >
+
+ // Instant value.
+ oln_decl_instant_value(nbh);
+
+
/// Fwd decls.
template <typename Exact> struct Image;
template <typename Exact> struct Neighborhood;
@@ -43,7 +51,7 @@
/// Super type.
template <typename I, typename N>
- struct super_trait_< internal::special_op_<stc::is<Image>, I, plus, stc::is<Neighborhood>, N> >
+ struct super_trait_< internal::current >
{
typedef internal::image_extension_< op_<I, plus, N> > ret;
};
@@ -51,7 +59,7 @@
/// Virtual types.
template <typename I, typename N>
- struct vtypes< internal::special_op_<stc::is<Image>, I, plus, stc::is<Neighborhood>, N> >
+ struct vtypes< internal::current >
{
typedef op_<I, plus, N> Exact;
typedef stc_type(I, point) point__;
@@ -94,11 +102,30 @@
special_op_(I& ima, N& n);
};
+ } // end of namespace oln::internal
+
+
+ // init
+
+ template <typename I, typename N, typename D>
+ bool init_(internal::current* target, const D& dat);
+
+ template <typename N, typename I>
+ bool init(Neighborhood<N>& target,
+ with_t,
+ const internal::current& dat);
+
+ template <typename I, typename N>
+ bool init(Image<I>& target,
+ with_t,
+ const internal::current& dat);
+
+
# ifndef OLN_INCLUDE_ONLY
-# define current \
- special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N >
+ namespace internal
+ {
template <typename I, typename N>
current::special_op_()
@@ -116,7 +143,7 @@
current::impl_image()
{
assert(this->has_data());
- return this->data_->value1;
+ return this->data_->first;
}
template <typename I, typename N>
@@ -124,7 +151,7 @@
current::impl_image() const
{
assert(this->has_data());
- return this->data_->value1;
+ return this->data_->first;
}
template <typename I, typename N>
@@ -132,14 +159,47 @@
current::impl_nbhood() const
{
assert(this->has_data());
- return this->data_->value2;
+ return this->data_->second;
}
-# undef current
+ } // end of namespace oln::internal
+
+
+ // init
+
+ // FIXME: N is nbh?
+
+ template <typename I, typename N, typename D>
+ bool init_(internal::current* this_, const D& dat)
+ {
+ precondition(not this_->has_data());
+ this_->data__() = new typename op_<I, plus, N>::data;
+ bool ima_ok = init(this_->data__()->first, with, dat);
+ bool nbh_ok = init(this_->data__()->second, with, dat);
+ postcondition(ima_ok);
+ postcondition(nbh_ok);
+ return ima_ok and nbh_ok;
+ }
+
+ template <typename N, typename I>
+ bool init_(Neighborhood<N>* this_,
+ const internal::current& data)
+ {
+ *this_ = data.nbhood();
+ return true;
+ }
+
+ template <typename I, typename N>
+ bool init(Image<I>* this_,
+ const internal::current& data)
+ {
+ *this_ = data.image();
+ return true;
+ }
# endif // OLN_INCLUDE_ONLY
- } // end of namespace oln::internal
+# undef current
} // end of namespace oln
Index: oln/core/internal/instant_value.hh
--- oln/core/internal/instant_value.hh (revision 875)
+++ oln/core/internal/instant_value.hh (working copy)
@@ -31,16 +31,26 @@
# define oln_decl_instant_value(Name) \
\
+namespace internal \
+{ \
+ \
template <typename V> \
-struct Name##_t : public internal::instant_value_< Name##_t, V> \
+ struct Name##_t : public instant_value_< Name##_t, V> \
{ \
Name##_t(const V& v) { this->value = v; } \
}; \
\
+ namespace tag \
+ { \
+ struct Name##_t {}; \
+ } \
+ \
+} \
+ \
template <typename V> \
-Name##_t<V> Name(const V& v) \
+internal::Name##_t<V> Name(const V& v) \
{ \
- return Name##_t<V>(v); \
+ return internal::Name##_t<V>(v); \
} \
\
struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
@@ -61,8 +71,10 @@
V value;
/*
+ // FIXME: do not compile with g++-3!!!
+
template <typename W>
- operator M<W>() const; // FIXME: do not compile with g++-3!!!
+ operator M<W>() const;
*/
};
@@ -70,6 +82,8 @@
# ifndef OLN_INCLUDE_ONLY
/*
+ // FIXME: do not compile with g++-3!!!
+
template <template<class> class M, typename V>
template <typename W>
instant_value_<M,V>::operator M<W>() const
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 875)
+++ oln/core/internal/image_base.hh (working copy)
@@ -53,6 +53,11 @@
+ // Instant value.
+ oln_decl_instant_value(ima);
+
+
+
/// Fwd decls.
namespace internal
@@ -215,6 +220,9 @@
bool has_data() const;
+ // pseudo-private:
+ tracked_ptr<data>& data__();
+
protected:
image_base_();
@@ -323,6 +331,14 @@
{
}
+ template <typename Exact>
+ tracked_ptr<typename image_base_<Exact>::data>&
+ image_base_<Exact>::data__()
+ {
+ // there is no test here since it is OK even if data_ is unset
+ return this->data_;
+ }
+
/// primitive_image_<Exact>
template <typename Exact>
@@ -407,12 +423,41 @@
}
-# endif
+# endif // OLN_INCLUDE_ONLY
} // end of namespace oln::internal
+
+ // init
+
+
+ template <typename P, typename I>
+ bool init_(box_<P>* this_, const internal::image_base_<I>& data);
+
+ template <typename Target, typename I>
+ bool init_(Target* this_, const internal::single_image_morpher_<I>& data);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename P, typename I>
+ bool init_(box_<P>* this_, const internal::image_base_<I>& data)
+ {
+ *this_ = data.bbox();
+ return true;
+ }
+
+ template <typename Target, typename I>
+ bool init_(Target* this_, const internal::single_image_morpher_<I>& data)
+ {
+ return init(*this_, with, data.image());
+ }
+
+# endif // OLN_INCLUDE_ONLY
+
+
} // end of namespace oln
1
0