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
05 Sep '06
2006-09-05 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Test on abstract::pset alternative code for static inheritance.
* oln/core/abstract/entry.hh: New proposition for entry class in
static hierarchies. This is a test file that should be removed
after stc update.
* oln/core/typedefs.hh (fixed_type, ra_type, bbox_type): New
typedef declarations.
* oln/core/abstract/bbox.hh (fwd_piter_, bkd_piter_): Remove
these forward declarations.
(ext_vtype): Remove.
(vtypes): New.
(ra_type, fixed_type, bbox_type): New associated types.
(bbox): Change inheritance from abstract::pset to an entry class.
(bbox): Remove all methods except print from this class; the
methods are dispatched into abstract::bboxed_pset and
gen::bbox_<P>.
(bbox): Likewise for attributes.
(print): Reject code to subclasses.
(impl_bbox): New method.
* oln/core/abstract/pset.hh: Include entry.hh.
(fwd_piter_type, bkd_piter_type): New associated types.
(bbox_type, ra_type, fixed_type): Likewise
(pset): Add virtual to inheritance.
(~pset): Extend check code.
(fixed_pset, ra_pset, bboxed_pset): New sub-abstractions.
(pset_fixed_hierarchy, pset_ra_hierarchy, pset_bboxed_hierarchy):
New hierarchy tags.
* oln/core/gen/bbox.hh: Update.
(operator=): New.
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 521)
+++ oln/core/typedefs.hh (working copy)
@@ -109,6 +109,14 @@
// --------------------------------------------------------------------
+ /*-----------------.
+ | category::pset. |
+ `------------------*/
+
+ mlc_decl_typedef(fixed_type);
+ mlc_decl_typedef(ra_type);
+
+
/*------------------.
| category::image. |
`------------------*/
@@ -137,6 +145,7 @@
mlc_decl_typedef(delegated_type);
mlc_decl_typedef(size_type);
+ mlc_decl_typedef(bbox_type);
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
Index: oln/core/abstract/bbox.hh
===================================================================
--- oln/core/abstract/bbox.hh (revision 521)
+++ oln/core/abstract/bbox.hh (working copy)
@@ -40,8 +40,6 @@
// Forward declaration.
namespace abstract { template <typename E> class bbox; }
- template <typename point> class fwd_piter_;
- template <typename point> class bkd_piter_;
// Super type declaration.
@@ -52,150 +50,32 @@
};
-
+ /// Virtual types associated to oln::abstract::bbox<E>.
template <typename E>
- struct ext_vtype< abstract::bbox<E>, typedef_::fwd_piter_type >
+ struct vtypes< abstract::bbox<E> >
{
- private:
- typedef oln_type_of(E, point) P;
- public:
- typedef fwd_piter_<P> ret;
+ typedef mlc::true_ ra_type;
+ typedef mlc::true_ fixed_type;
+ typedef E bbox_type;
};
- template <typename E>
- struct ext_vtype< abstract::bbox<E>, typedef_::bkd_piter_type >
- {
- private:
- typedef oln_type_of(E, point) P;
- public:
- typedef bkd_piter_<P> ret;
- };
-
namespace abstract
{
/// Abstract bbox (bounding box) class.
template <typename E>
- class bbox : public abstract::pset<E>
+ class bbox : public entry< abstract::pset, E> // NEW! former was: abstract::pset<E>
{
- typedef E exact_t;
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, coord) coord_t;
- typedef oln_type_of(point_t, dim) dim;
- enum { n = mlc_value(dim) };
-
public:
-
- unsigned npoints() const
- {
- unsigned count = 1;
- for (unsigned i = 0; i < n; ++i)
- count *= size(i);
- return count;
- }
- const point_t& pmin() const
- {
- precondition(is_valid_);
- return pmin_;
- }
-
- coord_t pmin(unsigned i) const
- {
- precondition(is_valid_ and i < n);
- return pmin_[i];
- }
-
- const point_t& pmax() const
- {
- precondition(is_valid_);
- return pmax_;
- }
-
- coord_t pmax(unsigned i) const
- {
- precondition(is_valid_ and i < n);
- return pmax_[i];
- }
-
- unsigned size(unsigned i) const
- {
- precondition(is_valid_ and i < n);
- return pmax_[i] - pmin_[i] + 1;
- }
-
- void flush()
- {
- is_valid_ = false;
- }
-
- void init_with(const point_t& p)
- {
- precondition(not is_valid_);
- pmin_ = p;
- pmax_ = p;
- is_valid_ = true;
- }
-
- void update_with(const point_t& p)
- {
- precondition(is_valid_);
- for (unsigned i = 0; i < n; ++i)
- if (p[i] < pmin_[i])
- pmin_[i] = p[i];
- else if (p[i] > pmax_[i])
- pmax_[i] = p[i];
- }
-
- void take(const point_t& p)
- {
- if (not is_valid_)
- {
- init_with(p);
- return;
- }
- for (unsigned i = 0; i < n; ++i)
- if (p[i] < pmin_[i])
- pmin_[i] = p[i];
- else if (p[i] > pmax_[i])
- pmax_[i] = p[i];
- }
-
- // FIXME: Add "update : (rhs : exact)"
-
- bool has(const point_t& p) const
- {
- precondition(is_valid_);
- for (unsigned i = 0; i < n; ++i)
- if (p[i] < pmin_[i] or p[i] > pmax_[i])
- return false;
- return true;
- }
-
- bool includes(const exact_t& rhs) const
- {
- precondition(is_valid_ and rhs.is_valid());
- for (unsigned i = 0; i < n; ++i)
- if (rhs.pmin()[i] < pmin_[i] or rhs.pmax()[i] > pmax_[i])
- return false;
- return true;
- }
-
- bool is_valid() const
- {
- return is_valid_;
- }
-
void print(std::ostream& ostr) const
{
- ostr << "{ pmin=" << pmin_
- << ", pmax=" << pmax_
- << ", valid=" << is_valid_
- << " }";
+ this->exact().impl_print(ostr);
}
-
+
friend
std::ostream& operator<<(std::ostream& ostr, const abstract::bbox<E>& bb)
{
@@ -203,57 +83,19 @@
return ostr;
}
- // FIXME: Add the scool code below.
-
-// invariant {
-// n > 1
-// is_valid => (pmax >= pmin) // FIXME: More.
-// }
-
-// (=) const : (rhs : exact) -> bool =
-// {
-// precondition(@is_valid and rhs.is_valid)
-// return @pmin = rhs.pmin and @pmax = rhs.pmax
-// }
-
-// (+=) : (dp : dpoint const ref) -> exact =
-// {
-// precondition(is_valid)
-// pmin += dp
-// pmax += dp
-// }
-
-// (-=) : (dp : dpoint const ref) -> exact =
-// {
-// precondition(is_valid)
-// pmin -= dp
-// pmax -= dp
-// }
-
+ const E& impl_bbox() const
+ {
+ return this->exact();
+ }
+
protected:
- point_t pmin_;
- point_t pmax_;
- bool is_valid_;
-
bbox()
{
- flush();
}
- bbox(const point_t& pmin, const point_t& pmax)
- : pmin_(pmin),
- pmax_(pmax)
- {
- for (unsigned i = 0; i < n; ++i)
- precondition(pmax[i] >= pmin[i]);
- is_valid_ = true;
- }
-
~bbox()
{
- flush();
-
mlc::assert_defined_< point_t >::check();
// typedef oln_type_of(E, fwd_piter) fwd_piter_t;
@@ -267,7 +109,6 @@
// mlc::assert_< mlc::eq_< oln_type_of(bkd_piter_t, grid),
// oln_type_of(point_t, grid) > >::check();
-
}
}; // end of class oln::abstract::bbox<E>
Index: oln/core/abstract/entry.hh
===================================================================
--- oln/core/abstract/entry.hh (revision 0)
+++ oln/core/abstract/entry.hh (revision 0)
@@ -0,0 +1,118 @@
+// Copyright (C) 2005, 2006 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 OLENA_CORE_ABSTRACT_ENTRY_HH
+# define OLENA_CORE_ABSTRACT_ENTRY_HH
+
+# include <oln/core/typedefs.hh>
+
+
+namespace oln
+{
+
+ template < template <class> class abstraction,
+ unsigned num >
+ struct hierarchy
+ {
+ };
+
+
+ namespace internal
+ {
+
+ // fwd decl
+ template < template <class> class abstraction, typename E, unsigned num >
+ struct entry_node;
+
+ template < template <class> class abstraction,
+ typename E,
+ unsigned num,
+ typename another_hierarchy = mlc::false_ >
+ struct next_entry_node
+ {
+ // here: no other hierarchy
+ };
+
+ template < template <class> class abstraction,
+ typename E,
+ unsigned num >
+ struct next_entry_node < abstraction,
+ E,
+ num,
+ mlc::true_>
+
+ : // plug to client sub-abstractions
+ public virtual oln::switch_< hierarchy<abstraction, num>, E >::ret,
+
+ // here: another hierarchy (number is 'num + 1')
+ public entry_node<abstraction, E, num + 1>
+ {
+ };
+
+
+ template < template <class> class abstraction,
+ typename E,
+ unsigned num >
+ struct entry_node
+ : public next_entry_node< abstraction,
+ E,
+ num,
+ typename mlc::is_defined_< oln::case_< oln::hierarchy<abstraction, num>,
+ E, 1 > >::eval >
+ {
+ };
+
+ } // end of namespace oln::internal
+
+
+
+ template < template <class> class abstraction,
+ unsigned num,
+ typename E >
+ struct default_case_ < oln::hierarchy<abstraction, num>,
+ E >
+ {
+ typedef abstraction<E> ret;
+ };
+
+
+
+ template < template <class> class abstraction,
+ typename E >
+ struct entry : public internal::entry_node<abstraction, E, 1>
+ {
+ protected:
+ entry()
+ {
+ }
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_ENTRY_HH
Index: oln/core/abstract/pset.hh
===================================================================
--- oln/core/abstract/pset.hh (revision 521)
+++ oln/core/abstract/pset.hh (working copy)
@@ -33,7 +33,9 @@
# include <oln/core/type.hh>
# include <oln/core/typedefs.hh>
+# include <oln/core/abstract/entry.hh> // NEW!
+
namespace oln
{
@@ -47,27 +49,22 @@
struct vtypes< abstract::pset<E> >
{
typedef mlc::undefined point_type;
-// typedef mlc::undefined fwd_piter_type;
-// typedef mlc::undefined bkd_piter_type;
+ typedef mlc::undefined fwd_piter_type;
+ typedef mlc::undefined bkd_piter_type;
+
+ typedef mlc::none bbox_type;
+ typedef mlc::undefined ra_type;
+ typedef mlc::undefined fixed_type;
};
-// template <typename E>
-// struct single_vtype< abstract::pset<E>, typedef_::coord_type >
-// : type_of_< oln_type_of(E, point), typedef_::coord_type >
-// {};
+ template <typename E>
+ struct ext_vtype< abstract::pset<E>, typedef_::coord_type >
+ {
+ typedef oln_type_of(E, point) P;
+ typedef oln_type_of(P, coord) ret;
+ };
-
-// template <typename E>
-// struct ext_vtype< abstract::pset<E>, typedef_::coord_type >
-// {
-// private:
-// typedef oln_type_of(E, point) P;
-// public:
-// typedef oln_type_of(P, coord) ret;
-// };
-
-
template <typename E>
struct ext_vtype< abstract::pset<E>, typedef_::grid_type >
{
@@ -81,10 +78,13 @@
/// Abstract point class.
template <typename E>
- class pset : public stc::any__simple<E>,
- public oln::type
+ class pset : public virtual stc::any__simple<E>,
+ public virtual oln::type
{
+ public:
+ // ...
+
protected:
pset()
@@ -93,13 +93,12 @@
~pset()
{
mlc::assert_defined_< oln_type_of(E, point) >::check();
+ mlc::assert_defined_< oln_type_of(E, fwd_piter) >::check();
+ mlc::assert_defined_< oln_type_of(E, bkd_piter) >::check();
+
mlc::assert_defined_< oln_type_of(E, coord) >::check();
+ mlc::assert_defined_< oln_type_of(E, grid) >::check();
- // FIXME: BUG! Trouble with circular dependencies.
-
-// mlc::assert_defined_< fwd_piter_t >::check();
-// mlc::assert_defined_< bkd_piter_t >::check();
-
// mlc::assert_< mlc::eq_< oln_type_of(fwd_piter_t, grid),
// oln_type_of(point_t, grid) > >::check();
@@ -110,9 +109,138 @@
}; // end of class oln::abstract::pset<E>
+
+ template <typename E>
+ class fixed_pset : public virtual pset<E>
+ {
+ public:
+
+ unsigned npoints() const
+ {
+ return this->exact().impl_npoints();
+ }
+
+ protected:
+ fixed_pset()
+ {}
+ };
+
+
+
+ template <typename E>
+ class ra_pset : public virtual pset<E>
+ {
+ typedef oln_type_of(E, point) point_t;
+
+ public:
+
+ bool has(const point_t& p) const
+ {
+ return this->exact().impl_has(p);
+ }
+
+ protected:
+ ra_pset()
+ {}
+ };
+
+
+
+ template <typename E>
+ class bboxed_pset : public virtual pset<E>
+ {
+ typedef oln_type_of(E, point) point_t;
+ typedef oln_type_of(E, bbox) bbox_t;
+
+ typedef oln_type_of(point_t, coord) coord_t;
+ typedef oln_type_of(point_t, dim) dim_t;
+ enum { n = mlc_value(dim_t) };
+
+ public:
+
+ const bbox_t& bbox() const
+ {
+ return this->exact().impl_box();
+ }
+
+ bool is_valid() const
+ {
+ return this->exact().impl_is_valid();
+ }
+
+ const point_t& pmin() const
+ {
+ precondition(this->is_valid());
+ return pmin_;
+ }
+
+ coord_t pmin(unsigned i) const
+ {
+ precondition(this->is_valid() and i < n);
+ return pmin_[i];
+ }
+
+ const point_t& pmax() const
+ {
+ precondition(this->is_valid());
+ return pmax_;
+ }
+
+ coord_t pmax(unsigned i) const
+ {
+ precondition(this->is_valid() and i < n);
+ return pmax_[i];
+ }
+
+ unsigned len(unsigned i) const
+ {
+ precondition(this->is_valid() and i < n);
+ return pmax_[i] - pmin_[i] + 1;
+ }
+
+ protected:
+
+ bboxed_pset()
+ {}
+
+ point_t pmin_, pmax_;
+ };
+
+
} // end of namespace oln::abstract
+
+ typedef hierarchy<abstract::pset, 1> pset_fixed_hierarchy;
+ typedef hierarchy<abstract::pset, 2> pset_ra_hierarchy;
+ typedef hierarchy<abstract::pset, 3> pset_bboxed_hierarchy;
+
+
+ template <typename E>
+ struct case_ < pset_fixed_hierarchy, E, 1 >
+ : where_< mlc::eq_< oln_type_of(E, fixed), mlc::true_ > >
+ {
+ typedef abstract::fixed_pset<E> ret;
+ };
+
+
+ template <typename E>
+ struct case_ < pset_ra_hierarchy, E, 1 >
+ : where_< mlc::eq_< oln_type_of(E, ra), mlc::true_ > >
+ {
+ typedef abstract::ra_pset<E> ret;
+ };
+
+
+ template <typename E>
+ struct case_ < pset_bboxed_hierarchy, E, 1 >
+ : where_< mlc::neq_< oln_type_of(E, bbox), mlc::none > >
+ {
+ typedef abstract::bboxed_pset<E> ret;
+ };
+
+
+
} // end of namespace oln
Index: oln/core/gen/bbox.hh
===================================================================
--- oln/core/gen/bbox.hh (revision 521)
+++ oln/core/gen/bbox.hh (working copy)
@@ -56,11 +56,8 @@
struct vtypes< bbox_<point> >
{
typedef point point_type;
-// typedef fwd_piter_<point> fwd_piter_type;
-// typedef bkd_piter_<point> bkd_piter_type;
- typedef typename point::coord_t coord_type;
- // FIXME: BUG! typedef oln_type_of(point, grid) grid_type;
- // FIXME: BUG! typedef typename point::grid_t grid_type;
+ typedef fwd_piter_<point> fwd_piter_type;
+ typedef bkd_piter_<point> bkd_piter_type;
};
@@ -73,17 +70,142 @@
typedef bbox_<point> self_t;
typedef abstract::bbox<self_t> super_t;
+ typedef oln_type_of(point, coord) coord_t;
+
+ typedef oln_type_of(point_t, dim) dim;
+ enum { n = mlc_value(dim) };
+
public:
bbox_()
- {
- }
+ {
+ flush();
+ }
bbox_(const point_t& pmin, const point_t& pmax)
- : super_t(pmin, pmax)
- {
- }
+ {
+ this->pmin_ = pmin;
+ this->pmax_ = pmax;
+ is_valid_ = true;
+ for (unsigned i = 0; i < n; ++i)
+ precondition(pmax[i] >= pmin[i]);
+ }
+
+ bbox_(const self_t& rhs)
+ {
+ // FIXME: Remove these 3 lines?
+ precondition(rhs.is_valid());
+ for (unsigned i = 0; i < n; ++i)
+ precondition(rhs.pmax_[i] >= rhs.pmin_[i]);
+
+ this->pmin_ = rhs.pmin_;
+ this->pmax_ = rhs.pmax_;
+ is_valid_ = rhs.is_valid_;
+
+ for (unsigned i = 0; i < n; ++i)
+ postcondition(this->pmax_[i] >= this->pmin_[i]);
+ }
+
+ self_t& operator=(const self_t& rhs)
+ {
+ // FIXME: Remove these 3 lines?
+ precondition(rhs.is_valid());
+ for (unsigned i = 0; i < n; ++i)
+ precondition(rhs.pmax_[i] >= rhs.pmin_[i]);
+
+ this->pmin_ = rhs.pmin_;
+ this->pmax_ = rhs.pmax_;
+ is_valid_ = rhs.is_valid_;
+
+ for (unsigned i = 0; i < n; ++i)
+ postcondition(this->pmax_[i] >= this->pmin_[i]);
+
+ return *this;
+ }
+
+ unsigned impl_npoints() const
+ {
+ unsigned count = 1;
+ for (unsigned i = 0; i < n; ++i)
+ count *= this->len(i);
+ return count;
+ }
+
+ bool impl_has(const point_t& p) const
+ {
+ precondition(is_valid_);
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < this->pmin_[i] or p[i] > this->pmax_[i])
+ return false;
+ return true;
+ }
+
+ void flush()
+ {
+ is_valid_ = false;
+ }
+
+ void init_with(const point_t& p)
+ {
+ precondition(not is_valid_);
+ this->pmin_ = p;
+ this->pmax_ = p;
+ is_valid_ = true;
+ }
+
+ void update_with(const point_t& p)
+ {
+ precondition(is_valid_);
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < this->pmin_[i])
+ this->pmin_[i] = p[i];
+ else if (p[i] > this->pmax_[i])
+ this->pmax_[i] = p[i];
+ }
+
+ void take(const point_t& p)
+ {
+ if (not is_valid_)
+ {
+ init_with(p);
+ return;
+ }
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < this->pmin_[i])
+ this->pmin_[i] = p[i];
+ else if (p[i] > this->pmax_[i])
+ this->pmax_[i] = p[i];
+ }
+
+ // FIXME: Add "update : (rhs : exact)"
+
+ bool includes(const self_t& rhs) const
+ {
+ precondition(is_valid_ and rhs.is_valid());
+ for (unsigned i = 0; i < n; ++i)
+ if (rhs.pmin()[i] < this->pmin_[i] or rhs.pmax()[i] > this->pmax_[i])
+ return false;
+ return true;
+ }
+
+ bool impl_is_valid() const
+ {
+ return is_valid_;
+ }
+
+ void impl_print(std::ostream& ostr) const
+ {
+ ostr << "{ pmin=" << this->pmin_
+ << ", pmax=" << this->pmax_
+ << ", valid=" << is_valid_
+ << " }";
+ }
+
+ protected:
+
+ bool is_valid_;
+
}; // end of class oln::bbox_<point>
1
0
On 2006-09-04, Roland Levillain <roland(a)lrde.epita.fr> wrote:
> Thierry GERAUD <theo(a)lrde.epita.fr> writes:
>
>> 2006-09-01 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
>>
>> Add bboxes and iterators.
>>
>> * oln/core/abstract/piter.hh: New.
>> * oln/core/abstract/bbox.hh: New.
>> * oln/core/abstract/iter.hh: New.
>> * oln/core/abstract/pset.hh: New.
>> * oln/core/2d/aliases.hh: New.
>> * oln/core/gen/fwd_piter.hh: New.
>> * oln/core/gen/bkd_piter.hh: New.
>> * oln/core/gen/bbox.hh: New.
>
> [...]
>
>> Index: oln/core/abstract/piter.hh
>> ===================================================================
>> --- oln/core/abstract/piter.hh (revision 0)
>> +++ oln/core/abstract/piter.hh (revision 0)
>> @@ -0,0 +1,100 @@
>> +// Copyright (C) 2001, 2003, 2004, 2005, 2006 EPITA Research and
>> +// Development Laboratory
>
> Hm... This file is brand new, the copyright header shouldn't mention
> years other than 2006. Of course, if a previous file of Olena was
> used as a basis for this file, its years of copyright should be
> added. (Likewise for other new files.)
>
>
You might want to use this script:
https://svn.lrde.epita.fr/svn/transformers/trunk/config/gplize.sh
--
SIGOURE Benoit aka Tsuna (SUSv3 compliant)
_____ "On a long enough timeline, the survival rate
/EPITA\ Promo 2008.CSI for everyone drops to zero" -- Jack.
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Adjust virtual types class names.
* oln/core/abstract/image.hh,
* oln/core/abstract/image_dimension.hh,
* oln/core/abstract/image_typeness.hh,
* oln/core/abstract/grid.hh, oln/core/1d/grid1d.hh,
* oln/core/2d/grid2d.hh, oln/core/3d/grid3d.hh,
* tests/image_entry.cc (vtypes): Rename as...
(vtypes_in_category): ...this.
* oln/core/abstract/image.hh, oln/core/abstract/grid.hh,
* tests/image_entry.cc (packed_vtypes): Rename as...
(packed_vtypes_in_category): ...this.
* oln/core/abstract/point.hh, oln/core/abstract/dpoint.hh,
* oln/core/abstract/piter.hh, oln/core/abstract/pset.hh,
* oln/core/gen/bbox.hh,
* oln/core/gen/bkd_piter.hh, oln/core/gen/fwd_piter.hh,
* oln/core/2d/point2d.hh, oln/core/2d/dpoint2d.hh (vtypes_):
Rename as...
(vtypes).
* oln/core/abstract/pset.hh, oln/core/abstract/bbox.hh
(ext_vtype_): Rename as...
(ext_vtype): ...this.
oln/core/1d/grid1d.hh | 2 +-
oln/core/2d/dpoint2d.hh | 2 +-
oln/core/2d/grid2d.hh | 2 +-
oln/core/2d/point2d.hh | 2 +-
oln/core/3d/grid3d.hh | 2 +-
oln/core/abstract/bbox.hh | 4 ++--
oln/core/abstract/dpoint.hh | 2 +-
oln/core/abstract/grid.hh | 8 ++++----
oln/core/abstract/image.hh | 17 +++++++++++------
oln/core/abstract/image_dimension.hh | 8 ++++----
oln/core/abstract/image_typeness.hh | 16 ++++++++--------
oln/core/abstract/image_typeness_integre.hh | 8 ++++----
oln/core/abstract/internal/image_impl.hh | 6 +++---
oln/core/abstract/piter.hh | 2 +-
oln/core/abstract/point.hh | 2 +-
oln/core/abstract/pset.hh | 8 ++++----
oln/core/gen/bbox.hh | 2 +-
oln/core/gen/bkd_piter.hh | 2 +-
oln/core/gen/fwd_piter.hh | 2 +-
tests/image_entry.cc | 5 +++--
20 files changed, 54 insertions(+), 48 deletions(-)
Index: tests/image_entry.cc
--- tests/image_entry.cc (revision 520)
+++ tests/image_entry.cc (working copy)
@@ -48,7 +48,7 @@
/// Virtual types associated to my::image.
template<>
- struct vtypes<category::image, my::image>
+ struct vtypes_in_category<category::image, my::image>
{
// The switch for image_dimension (above image_entry) plugs the
// inheritance relation to the right abstract::image_dimension
@@ -105,5 +105,6 @@
// Print my::image's vtypes.
// FIXME: To be removed in the final version.
- oln::packed_vtypes<oln::category::image, my::image>::echo (std::cout);
+ oln::packed_vtypes_in_category< oln::category::image,
+ my::image >::echo (std::cout);
}
Index: oln/core/abstract/image.hh
--- oln/core/abstract/image.hh (revision 520)
+++ oln/core/abstract/image.hh (working copy)
@@ -57,7 +57,7 @@
/// Virtual types associated to oln::abstract::image.
template <typename I>
- struct vtypes< category::image, abstract::image<I> >
+ struct vtypes_in_category< category::image, abstract::image<I> >
{
typedef I exact_type;
@@ -96,9 +96,10 @@
/// Packing of the virtual types of any image class.
template <typename I>
- struct packed_vtypes<category::image, I>
+ struct packed_vtypes_in_category<category::image, I>
{
- // Internally defined virtual types.
+ /// Virtual types defined internally.
+ /// \{
typedef oln_type_of(I, exact) exact_type;
typedef oln_type_of(I, grid) grid_type;
@@ -133,16 +134,20 @@
// typedef oln_type_of(I, image_constness) image_constness_type;
// typedef oln_type_of(I, image_rawness) image_rawness_type;
// --------------------------------------------------------------------
+ /// \}
- // Defined externally virtual types.
+ /// Virtual types defined as extensions.
+ /// \{
typedef oln_type_of(I, image_dimension) image_dimension_type;
typedef oln_type_of(I, image_typeness) image_typeness_type;
+ /// \}
/// Pretty-printing.
static void echo(std::ostream& ostr)
{
ostr
- << "vtypes_of(oln::category::image, " << mlc_to_string(I) << ") ="
+ << "vtypes_in_category(oln::category::image, "
+ << mlc_to_string(I) << ") ="
<< std::endl
<< "{" << std::endl
<< " exact_type = " << mlc_to_string(exact_type) << std::endl
@@ -441,7 +446,7 @@
virtual ~image()
{
- packed_vtypes<category::image, E>::ensure();
+ packed_vtypes_in_category<category::image, E>::ensure();
// FIXME: static check fails because "pointer to member conversion via virtual base"...
// mlc_check_method_impl(E, const size_type&, size, , const);
// mlc_check_method_impl(E, unsigned long, npoints, , const);
Index: oln/core/abstract/piter.hh
--- oln/core/abstract/piter.hh (revision 520)
+++ oln/core/abstract/piter.hh (working copy)
@@ -51,7 +51,7 @@
/// Virtual types associated to abstract::piter<E>.
template <typename E>
- struct vtypes_< abstract::piter<E> >
+ struct vtypes< abstract::piter<E> >
{
typedef mlc::undefined point_type;
};
Index: oln/core/abstract/grid.hh
--- oln/core/abstract/grid.hh (revision 520)
+++ oln/core/abstract/grid.hh (working copy)
@@ -59,7 +59,7 @@
/// Virtual types associated to oln::abstract::image.
template <typename G>
- struct vtypes< category::grid, abstract::grid<G> >
+ struct vtypes_in_category< category::grid, abstract::grid<G> >
{
typedef mlc::undefined point_type;
typedef mlc::none dpoint_type;
@@ -70,7 +70,7 @@
template <typename G>
- struct packed_vtypes<category::grid, G>
+ struct packed_vtypes_in_category<category::grid, G>
{
typedef oln_grd_type_of(G, point) point_type;
typedef oln_grd_type_of(G, dpoint) dpoint_type;
@@ -81,7 +81,7 @@
static void echo(std::ostream& ostr)
{
ostr
- << "vtypes(oln::category::grid, " << mlc_to_string(G) << ") ="
+ << "vtypes_in_category(oln::category::grid, " << mlc_to_string(G) << ") ="
<< std::endl
<< "{" << std::endl
<< " point_type = " << mlc_to_string(point_type) << std::endl
@@ -114,7 +114,7 @@
~grid()
{
- packed_vtypes<category::grid, E>::ensure();
+ packed_vtypes_in_category<category::grid, E>::ensure();
}
};
Index: oln/core/abstract/image_dimension.hh
--- oln/core/abstract/image_dimension.hh (revision 520)
+++ oln/core/abstract/image_dimension.hh (working copy)
@@ -184,15 +184,15 @@
/*----------------------------------.
-| Dimension external virtual type. |
+| Dimension extended virtual type. |
`----------------------------------*/
-// FIXME: Is this external vtype really useful?
+// FIXME: Is this extended vtype really useful?
namespace oln
{
- /// Image dimension type as an external vtype of abstract::image.
+ /// Image dimension type as an extended vtype of abstract::image.
template <typename I>
- struct ext_vtype< category::image,
+ struct ext_vtype_in_category< category::image,
abstract::image<I>,
// FIXME: Get rid of this typedef_:: qualifier.
typedef_::image_dimension_type >
Index: oln/core/abstract/image_typeness_integre.hh
--- oln/core/abstract/image_typeness_integre.hh (revision 520)
+++ oln/core/abstract/image_typeness_integre.hh (working copy)
@@ -104,7 +104,7 @@
{
// Definition of the super class corresponding to this case.
typedef stc::abstraction_as_type<abstract::binary_image> super_type;
- // Definition of the external virtual type (same as the super
+ // Definition of the extended virtual type (same as the super
// class in this case).
typedef super_type image_typeness_type;
};
@@ -120,7 +120,7 @@
typedef
stc::abstraction_as_type<abstract::internal::grey_level_image_>
super_type;
- // Definition of the external virtual type.
+ // Definition of the extended virtual type.
typedef stc::abstraction_as_type<abstract::grey_level_image>
image_typeness_type;
};
@@ -135,7 +135,7 @@
// abstract::label_image and abstract::not_binary_image).
typedef stc::abstraction_as_type<abstract::internal::label_image_>
super_type;
- // Definition of the external virtual type.
+ // Definition of the extended virtual type.
typedef stc::abstraction_as_type<abstract::label_image>
image_typeness_type;
};
@@ -150,7 +150,7 @@
// abstract::color_image and abstract::not_binary_image).
typedef stc::abstraction_as_type<abstract::internal::color_image_>
super_type;
- // Definition of the external virtual type.
+ // Definition of the extended virtual type.
typedef stc::abstraction_as_type<abstract::color_image>
image_typeness_type;
};
Index: oln/core/abstract/point.hh
--- oln/core/abstract/point.hh (revision 520)
+++ oln/core/abstract/point.hh (working copy)
@@ -54,7 +54,7 @@
/// Virtual types associated to abstract::point<E>.
template <typename E>
- struct vtypes_< abstract::point<E> >
+ struct vtypes< abstract::point<E> >
{
typedef mlc::undefined grid_type;
typedef mlc::undefined dpoint_type;
Index: oln/core/abstract/bbox.hh
--- oln/core/abstract/bbox.hh (revision 520)
+++ oln/core/abstract/bbox.hh (working copy)
@@ -54,7 +54,7 @@
template <typename E>
- struct ext_vtype_< abstract::bbox<E>, typedef_::fwd_piter_type >
+ struct ext_vtype< abstract::bbox<E>, typedef_::fwd_piter_type >
{
private:
typedef oln_type_of(E, point) P;
@@ -63,7 +63,7 @@
};
template <typename E>
- struct ext_vtype_< abstract::bbox<E>, typedef_::bkd_piter_type >
+ struct ext_vtype< abstract::bbox<E>, typedef_::bkd_piter_type >
{
private:
typedef oln_type_of(E, point) P;
Index: oln/core/abstract/dpoint.hh
--- oln/core/abstract/dpoint.hh (revision 520)
+++ oln/core/abstract/dpoint.hh (working copy)
@@ -52,7 +52,7 @@
/// Virtual types associated to abstract::dpoint<E>.
template <typename E>
- struct vtypes_< abstract::dpoint<E> >
+ struct vtypes< abstract::dpoint<E> >
{
typedef mlc::undefined grid_type;
typedef mlc::undefined point_type;
Index: oln/core/abstract/pset.hh
--- oln/core/abstract/pset.hh (revision 520)
+++ oln/core/abstract/pset.hh (working copy)
@@ -44,7 +44,7 @@
/// Virtual types associated to oln::bbox_nd<point>.
template <typename E>
- struct vtypes_< abstract::pset<E> >
+ struct vtypes< abstract::pset<E> >
{
typedef mlc::undefined point_type;
// typedef mlc::undefined fwd_piter_type;
@@ -53,13 +53,13 @@
// template <typename E>
-// struct vtype_< abstract::pset<E>, typedef_::coord_type >
+// struct single_vtype< abstract::pset<E>, typedef_::coord_type >
// : type_of_< oln_type_of(E, point), typedef_::coord_type >
// {};
// template <typename E>
-// struct extension_vtype_< abstract::pset<E>, typedef_::coord_type >
+// struct ext_vtype< abstract::pset<E>, typedef_::coord_type >
// {
// private:
// typedef oln_type_of(E, point) P;
@@ -69,7 +69,7 @@
template <typename E>
- struct ext_vtype_< abstract::pset<E>, typedef_::grid_type >
+ struct ext_vtype< abstract::pset<E>, typedef_::grid_type >
{
typedef oln_type_of(E, point) P;
typedef oln_type_of(P, grid) ret;
Index: oln/core/abstract/image_typeness.hh
--- oln/core/abstract/image_typeness.hh (revision 520)
+++ oln/core/abstract/image_typeness.hh (working copy)
@@ -252,7 +252,7 @@
{
// Definition of the super class corresponding to this case.
typedef stc::abstraction_as_type<abstract::binary_image> super_type;
- // Definition of the external virtual type (same as the super
+ // Definition of the extended virtual type (same as the super
// class in this case).
typedef super_type image_typeness_type;
};
@@ -270,7 +270,7 @@
// abstract::grey_level_image and abstract::not_binary_image).
typedef stc::abstraction_as_type<abstract::internal::grey_level_image_>
super_type;
- // Definition of the external virtual type.
+ // Definition of the extended virtual type.
typedef stc::abstraction_as_type<abstract::grey_level_image>
image_typeness_type;
};
@@ -289,7 +289,7 @@
// abstract::data_image and abstract::not_binary_image).
typedef stc::abstraction_as_type<abstract::internal::data_image_>
super_type;
- // Definition of the external virtual type.
+ // Definition of the extended virtual type.
typedef stc::abstraction_as_type<abstract::data_image>
image_typeness_type;
};
@@ -300,21 +300,21 @@
/*---------------------------------.
-| Typeness external virtual type. |
+| Typeness extended virtual type. |
`---------------------------------*/
-// FIXME: Is this external vtype really useful?
+// FIXME: Is this extended vtype really useful?
namespace oln
{
- /// Image ``typeness'' as an external vtype of abstract::image.
+ /// Image ``typeness'' as an extended vtype of abstract::image.
template <typename I>
- struct ext_vtype< category::image,
+ struct ext_vtype_in_category< category::image,
abstract::image<I>,
// FIXME: Get rid of this typedef_:: qualifier.
typedef_::image_typeness_type >
{
// Use the same case as the one use in the inheritance-plugging
- // mechanism above, but retrieve the external vtype
+ // mechanism above, but retrieve the extended vtype
// (image_typename_type), not the super type.
typedef
typename oln::case_< oln::value_type_tag,
Index: oln/core/abstract/internal/image_impl.hh
--- oln/core/abstract/internal/image_impl.hh (revision 520)
+++ oln/core/abstract/internal/image_impl.hh (working copy)
@@ -85,10 +85,10 @@
delegated type (i.e. D = mlc::none), get_image_impl inherits
from oln::any_best_speed (trough get_image_impl_helper);
otherwise, get_image_impl is plugged to set_image_impl, a
- class than can specialized by the user.
+ class than can be specialized by the user.
- (*) This relation is not mandatory (set_image_impl is to be
- defined by the user), but it every specialization of
+ (*) This relation is not systematic (set_image_impl is to be
+ defined by the user), but every specialization of
set_image_impl *should* inherit from oln::any_best_speed. */
template <typename A, typename D, typename E>
Index: oln/core/1d/grid1d.hh
--- oln/core/1d/grid1d.hh (revision 520)
+++ oln/core/1d/grid1d.hh (working copy)
@@ -47,7 +47,7 @@
/// Virtual types associated to oln::grid1d.
template <>
- struct vtypes<category::grid, grid1d>
+ struct vtypes_in_category<category::grid, grid1d>
{
typedef point1d point_type;
typedef dpoint1d dpoint_type;
Index: oln/core/2d/dpoint2d.hh
--- oln/core/2d/dpoint2d.hh (revision 520)
+++ oln/core/2d/dpoint2d.hh (working copy)
@@ -47,7 +47,7 @@
/// Virtual types associated to oln::abstract::image.
template <typename C>
- struct vtypes_< dpoint2d_<C> >
+ struct vtypes< dpoint2d_<C> >
{
typedef grid2d grid_type;
typedef point2d point_type;
Index: oln/core/2d/grid2d.hh
--- oln/core/2d/grid2d.hh (revision 520)
+++ oln/core/2d/grid2d.hh (working copy)
@@ -47,7 +47,7 @@
/// Virtual types associated to oln::grid2d.
template <>
- struct vtypes<category::grid, grid2d>
+ struct vtypes_in_category<category::grid, grid2d>
{
typedef point2d point_type;
typedef dpoint2d dpoint_type;
Index: oln/core/2d/point2d.hh
--- oln/core/2d/point2d.hh (revision 520)
+++ oln/core/2d/point2d.hh (working copy)
@@ -45,7 +45,7 @@
/// Virtual types associated to oln::abstract::image.
template <typename C>
- struct vtypes_< point2d_<C> >
+ struct vtypes< point2d_<C> >
{
typedef grid2d grid_type;
typedef dpoint2d dpoint_type;
Index: oln/core/3d/grid3d.hh
--- oln/core/3d/grid3d.hh (revision 520)
+++ oln/core/3d/grid3d.hh (working copy)
@@ -47,7 +47,7 @@
/// Virtual types associated to oln::grid3d.
template <>
- struct vtypes<category::grid, grid3d>
+ struct vtypes_in_category<category::grid, grid3d>
{
typedef point3d point_type;
typedef dpoint3d dpoint_type;
Index: oln/core/gen/bkd_piter.hh
--- oln/core/gen/bkd_piter.hh (revision 520)
+++ oln/core/gen/bkd_piter.hh (working copy)
@@ -53,7 +53,7 @@
/// Virtual types associated to oln::bbox_<point>.
template <typename point>
- struct vtypes_< bkd_piter_<point> >
+ struct vtypes< bkd_piter_<point> >
{
typedef point point_type;
typedef oln_type_of(point, grid) grid_type;
Index: oln/core/gen/fwd_piter.hh
--- oln/core/gen/fwd_piter.hh (revision 520)
+++ oln/core/gen/fwd_piter.hh (working copy)
@@ -53,7 +53,7 @@
/// Virtual types associated to oln::fwd_piter_<point>.
template <typename point>
- struct vtypes_< fwd_piter_<point> >
+ struct vtypes< fwd_piter_<point> >
{
typedef point point_type;
typedef oln_type_of(point, grid) grid_type;
Index: oln/core/gen/bbox.hh
--- oln/core/gen/bbox.hh (revision 520)
+++ oln/core/gen/bbox.hh (working copy)
@@ -53,7 +53,7 @@
/// Virtual types associated to oln::bbox_<point>.
template <typename point>
- struct vtypes_< bbox_<point> >
+ struct vtypes< bbox_<point> >
{
typedef point point_type;
// typedef fwd_piter_<point> fwd_piter_type;
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/static
The corresponding patch for the Olena subproject follows.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Rename virtual types classes.
* stc/vtypes.hh (vtypes, single_vtype, ext_vtype): Rename as...
(vtypes_in_category, single_vtype_in_category, ext_vtype_in_category):
...this.
(vtypes_, single_vtype_, ext_vtype_): Rename as...
(vtypes, single_vtype, ext_vtype): ...this.
(packed_vtypes): Rename as...
(packed_vtypes_in_category): ...this.
(packed_vtypes_): Rename as...
(packed_vtypes): ...this
* tests/vtypes.cc, tests/vtypes-and-exact.cc,
* tests/vtypes-multiple-supers.cc: Adjust.
stc/vtypes.hh | 45 ++++++++++++++++++++--------------------
tests/vtypes-and-exact.cc | 18 ++++++++--------
tests/vtypes-multiple-supers.cc | 14 ++++++------
tests/vtypes.cc | 20 ++++++++---------
4 files changed, 49 insertions(+), 48 deletions(-)
Index: tests/vtypes-and-exact.cc
--- tests/vtypes-and-exact.cc (revision 519)
+++ tests/vtypes-and-exact.cc (working copy)
@@ -75,7 +75,7 @@
/// Packing of virtual types of any class belonging to the category my::cat.
template <typename T>
- struct packed_vtypes <category::my_cat, T>
+ struct packed_vtypes_in_category<category::my_cat, T>
{
typedef my_type_of(T, foo) foo_type;
typedef my_type_of(T, bar) bar_type;
@@ -100,7 +100,7 @@
/// Types associated to my::A.
template <typename Exact>
- struct vtypes< category::my_cat, A<Exact> >
+ struct vtypes_in_category< category::my_cat, A<Exact> >
{
// A native type.
typedef int foo_type;
@@ -121,8 +121,8 @@
~A()
{
- // packed_vtypes< category::my, A<Exact> > is not checked here,
- // since A's baz_type virtual type is undefined.
+ // packed_vtypes_in_category< category::my, A<Exact> > is not checked
+ // here, since A's baz_type virtual type is undefined.
}
};
@@ -144,7 +144,7 @@
/// Types associated to my::B.
template <typename Exact>
- struct vtypes< category::my_cat, B<Exact> >
+ struct vtypes_in_category< category::my_cat, B<Exact> >
{
// (foo is left untouched.)
@@ -158,7 +158,7 @@
/// An extended type associated to my::B.
template <typename Exact>
- struct ext_vtype<category::my_cat, B<Exact>, typedef_::yin_type>
+ struct ext_vtype_in_category<category::my_cat, B<Exact>, typedef_::yin_type>
{
typedef unsigned long ret;
};
@@ -176,7 +176,7 @@
// Check B's vtypes.
~B()
{
- packed_vtypes< category::my_cat, B<Exact> >::ensure();
+ packed_vtypes_in_category< category::my_cat, B<Exact> >::ensure();
}
};
@@ -193,7 +193,7 @@
/// Types associated to my::C.
template <>
- struct vtypes<category::my_cat, C>
+ struct vtypes_in_category<category::my_cat, C>
{
// A type defined only here (and not in the super class).
typedef double zorg_type;
@@ -209,7 +209,7 @@
// Check C's vtypes.
~C()
{
- packed_vtypes<category::my_cat, C>::ensure();
+ packed_vtypes_in_category<category::my_cat, C>::ensure();
}
};
Index: tests/vtypes-multiple-supers.cc
--- tests/vtypes-multiple-supers.cc (revision 519)
+++ tests/vtypes-multiple-supers.cc (working copy)
@@ -83,7 +83,7 @@
/// Packing of virtual types of any class belonging to the category my::cat.
template <typename T>
- struct packed_vtypes <category::my_cat, T>
+ struct packed_vtypes_in_category<category::my_cat, T>
{
typedef my_type_of(T, foo) foo_type;
@@ -103,7 +103,7 @@
/// Types associated to my::A.
template <>
- struct vtypes<category::my_cat, my::A>
+ struct vtypes_in_category<category::my_cat, my::A>
{
typedef int foo_type;
typedef alpha bar_type;
@@ -118,7 +118,7 @@
// Check A's vtypes.
~A()
{
- packed_vtypes<category::my_cat, A>::ensure();
+ packed_vtypes_in_category<category::my_cat, A>::ensure();
}
};
@@ -132,7 +132,7 @@
/// Types associated to my::B.
template <>
- struct vtypes<category::my_cat, B>
+ struct vtypes_in_category<category::my_cat, B>
{
typedef float foo_type;
typedef beta baz_type;
@@ -147,7 +147,7 @@
// Check B's vtypes.
~B()
{
- packed_vtypes<category::my_cat, B>::ensure();
+ packed_vtypes_in_category<category::my_cat, B>::ensure();
}
};
@@ -168,7 +168,7 @@
/// Types associated to my::C.
template <>
- struct vtypes<category::my_cat, C>
+ struct vtypes_in_category<category::my_cat, C>
{
// This typedef remove the ambiguity on the `foo' vtype: this vtype
// is provided by both A and B. Here, let `foo' take the value from
@@ -186,7 +186,7 @@
// Check C's vtypes.
~C()
{
- packed_vtypes<category::my_cat, C>::ensure();
+ packed_vtypes_in_category<category::my_cat, C>::ensure();
}
};
Index: tests/vtypes.cc
--- tests/vtypes.cc (revision 519)
+++ tests/vtypes.cc (working copy)
@@ -73,7 +73,7 @@
/// Packing of virtual types of any class belonging to the category my::cat.
template <typename T>
- struct packed_vtypes <category::my_cat, T>
+ struct packed_vtypes_in_category<category::my_cat, T>
{
typedef my_type_of(T, foo) foo_type;
typedef my_type_of(T, bar) bar_type;
@@ -97,7 +97,7 @@
/// Types associated to my::A.
template <>
- struct vtypes<category::my_cat, my::A>
+ struct vtypes_in_category<category::my_cat, my::A>
{
// A native type.
typedef int foo_type;
@@ -118,8 +118,8 @@
~A()
{
- // packed_vtypes<category::my, A> is not checked here, since A's
- // baz_type virtual type is undefined.
+ // packed_vtypes_in_category<category::my, A> is not checked here,
+ // since A's baz_type virtual type is undefined.
}
};
@@ -136,7 +136,7 @@
/// Types associated to my::B.
template <>
- struct vtypes<category::my_cat, B>
+ struct vtypes_in_category<category::my_cat, B>
{
// (foo is left untouched.)
@@ -150,7 +150,7 @@
/// An extended type associated to my::B.
template <>
- struct ext_vtype<category::my_cat, B, typedef_::yin_type>
+ struct ext_vtype_in_category<category::my_cat, B, typedef_::yin_type>
{
typedef unsigned long ret;
};
@@ -164,10 +164,10 @@
typedef my_type_of_(B, quux) quux_type;
typedef my_type_of_(B, yin) yin_type;
- // Check B's vtypes.
+ // Check B's vtype.
~B()
{
- packed_vtypes<category::my_cat, B>::ensure();
+ packed_vtypes_in_category<category::my_cat, B>::ensure();
}
};
@@ -189,7 +189,7 @@
/// Types associated to my::Z.
template <>
- struct vtypes<category::my_cat, Z>
+ struct vtypes_in_category<category::my_cat, Z>
{
// A type defined only here (and not in the super class).
typedef double zorg_type;
@@ -208,7 +208,7 @@
// Check C's vtypes.
~Z()
{
- packed_vtypes<category::my_cat, Z>::ensure();
+ packed_vtypes_in_category<category::my_cat, Z>::ensure();
}
};
Index: stc/vtypes.hh
--- stc/vtypes.hh (revision 519)
+++ stc/vtypes.hh (working copy)
@@ -265,7 +265,7 @@
/** */ \
/** Specialize this class for the desired \a from_type. */ \
template <typename category, typename from_type> \
- struct vtypes \
+ struct vtypes_in_category \
{ \
}; \
\
@@ -274,19 +274,19 @@
/** */ \
/** Specialize this class for the desired \a from_type. */ \
template <typename from_type> \
- struct vtypes_ \
+ struct vtypes \
{ \
}; \
\
/** Specialization of vtypes for types without category. */ \
template <typename from_type> \
- struct vtypes<void, from_type> : public vtypes_<from_type> \
+ struct vtypes_in_category<void, from_type> : public vtypes<from_type> \
{ \
}; \
\
/** End of the recursive construction of any vtypes hierarchy. */ \
template <typename category> \
- struct vtypes<category, mlc::none> \
+ struct vtypes_in_category<category, mlc::none> \
{ \
}; \
\
@@ -300,7 +300,7 @@
/** */ \
/** Specialize this class for the desired \a from_type. */ \
template <typename category, typename from_type, typename typedef_type> \
- struct ext_vtype \
+ struct ext_vtype_in_category \
{ \
}; \
\
@@ -309,21 +309,21 @@
/** */ \
/** Specialize this class for the desired \a from_type. */ \
template <typename from_type, typename typedef_type> \
- struct ext_vtype_ \
+ struct ext_vtype \
{ \
}; \
\
/** Specialization of ext_vtype for types without category. */ \
template <typename from_type, typename typedef_type> \
- struct ext_vtype<void, from_type, typedef_type> \
- : public ext_vtype_<from_type, typedef_type> \
+ struct ext_vtype_in_category<void, from_type, typedef_type> \
+ : public ext_vtype<from_type, typedef_type> \
{ \
}; \
\
/** End of the recursive construction of any ext_vtype<> */ \
/** hierarchy. */ \
template <typename category, typename typedef_type> \
- struct ext_vtype<category, mlc::none, typedef_type> \
+ struct ext_vtype_in_category<category, mlc::none, typedef_type> \
{ \
}; \
\
@@ -337,7 +337,7 @@
/** */ \
/** Specialize this class for the desired \a from_type. */ \
template <typename category, typename from_type, typename typedef_type> \
- struct single_vtype \
+ struct single_vtype_in_category \
{ \
}; \
\
@@ -346,21 +346,21 @@
/** */ \
/** Specialize this class for the desired \a from_type. */ \
template <typename from_type, typename typedef_type> \
- struct single_vtype_ \
+ struct single_vtype \
{ \
}; \
\
/** Specialization of single_vtype for types without category. */ \
template <typename from_type, typename typedef_type> \
- struct single_vtype<void, from_type, typedef_type> \
- : public single_vtype_<from_type, typedef_type> \
+ struct single_vtype_in_category<void, from_type, typedef_type> \
+ : public single_vtype<from_type, typedef_type> \
{ \
}; \
\
/** End of the recursive construction of any single_vtype<> */ \
/** hierarchy. */ \
template <typename category, typename typedef_type> \
- struct single_vtype<category, mlc::none, typedef_type> \
+ struct single_vtype_in_category<category, mlc::none, typedef_type> \
{ \
}; \
\
@@ -374,20 +374,21 @@
/** Optional packing structure, to be specialized by the user. */ \
/** See tests/vtypes.cc for an example of use. */ \
template <typename category, typename from_type> \
- struct packed_vtypes \
+ struct packed_vtypes_in_category \
{ \
}; \
\
/** Optional packing structure, to be specialized by the user. */ \
/** Version for types without category. */ \
template <typename from_type> \
- struct packed_vtypes_ \
+ struct packed_vtypes \
{ \
}; \
\
/** Specialization of packed_vtypes for types without category. */ \
template <typename from_type> \
- struct packed_vtypes<void, from_type> : public packed_vtypes_<from_type> \
+ struct packed_vtypes_in_category<void, from_type> : \
+ public packed_vtypes<from_type> \
{ \
}; \
\
@@ -439,7 +440,7 @@
from_type, typedef_type> \
{ \
/** Set of vtypes associated with FROM_TYPE. */ \
- typedef vtypes<category, from_type> types; \
+ typedef vtypes_in_category<category, from_type> types; \
/** Typedef in the current vtypes (may be mlc::not_found). */ \
typedef stc_internal_get_typedef(types, typedef_type) ret; \
}; \
@@ -452,7 +453,8 @@
from_type, typedef_type> \
{ \
/** Set of vtypes associated with FROM_TYPE. */ \
- typedef single_vtype<category, from_type, typedef_type> single_type; \
+ typedef single_vtype_in_category<category, from_type, typedef_type> \
+ single_type; \
/** Typedef in the current single_vtype (may be mlc::not_found). */ \
typedef mlc_ret(single_type) ret; \
}; \
@@ -465,7 +467,8 @@
from_type, typedef_type> \
{ \
/** Set of vtypes associated with FROM_TYPE. */ \
- typedef ext_vtype<category, from_type, typedef_type> ext_type; \
+ typedef ext_vtype_in_category<category, from_type, typedef_type> \
+ ext_type; \
/** Typedef in the current ext_vtype (may be mlc::not_found). */ \
typedef mlc_ret(ext_type) ret; \
}; \
@@ -473,8 +476,6 @@
\
/* FIXME: Do a basic scheme of the algorithm in pseudo-code. */ \
\
- /* FIXME: Check for mlc::undefined? */ \
- \
/* Forward declaration. */ \
template <typename method, typename category, \
typename from_list, typename typedef_type> \
1
0
2006-09-01 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add bboxes and iterators.
* oln/core/abstract/piter.hh: New.
* oln/core/abstract/bbox.hh: New.
* oln/core/abstract/iter.hh: New.
* oln/core/abstract/pset.hh: New.
* oln/core/2d/aliases.hh: New.
* oln/core/gen/fwd_piter.hh: New.
* oln/core/gen/bkd_piter.hh: New.
* oln/core/gen/bbox.hh: New.
* oln/core/2d/point2d.hh (point2d_): New ctor.
(point2d, dpoint2d, point2df, dpoint2df): Move typedefs to...
* oln/basics2d.hh: ...this new file.
* oln/core/typedefs.hh (oln_type_of_): New macro.
(include): Update.
(fwd_piter_type, bkd_piter_type): New decls.
* oln/core/abstract/point.hh (include): Update.
(vtypes_): New specialization.
* oln/core/abstract/dpoint.hh: Likewise.
* oln/core/abstract/point_nd.hh (include): Update.
(set_super_type): New specialization.
* oln/core/abstract/dpoint_nd.hh: Likewise.
Index: oln/core/typedefs.hh
===================================================================
--- oln/core/typedefs.hh (revision 512)
+++ oln/core/typedefs.hh (working copy)
@@ -32,10 +32,16 @@
# include <mlc/contract.hh>
# include <mlc/flags.hh>
+# include <mlc/is_a.hh>
# include <mlc/cmp.hh>
# include <mlc/typedef.hh>
+# include <mlc/value.hh>
+
+# include <stc/any.hh>
+# include <stc/exact.hh>
# include <stc/vtypes.hh>
+# include <oln/core/type.hh>
/*! \macro oln_type_of(OlnType, Alias)
@@ -47,8 +53,11 @@
# define oln_type_of(OlnType, Alias) \
stc_type_of(oln, void, OlnType, Alias)
+# define oln_type_of_(OlnType, Alias) \
+stc_type_of_(oln, void, OlnType, Alias)
+
namespace oln
{
@@ -87,8 +96,8 @@
// mlc_decl_typedef(bkd_iter_type);
// mlc_decl_typedef(piter_type);
-// mlc_decl_typedef(fwd_piter_type);
-// mlc_decl_typedef(bkd_piter_type);
+ mlc_decl_typedef(fwd_piter_type);
+ mlc_decl_typedef(bkd_piter_type);
// mlc_decl_typedef(qiter_type);
// mlc_decl_typedef(fwd_qiter_type);
Index: oln/core/abstract/piter.hh
===================================================================
--- oln/core/abstract/piter.hh (revision 0)
+++ oln/core/abstract/piter.hh (revision 0)
@@ -0,0 +1,100 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_ABSTRACT_PITER_HH
+# define OLENA_CORE_ABSTRACT_PITER_HH
+
+# include <oln/core/abstract/iter.hh>
+# include <oln/core/abstract/point.hh>
+
+
+namespace oln
+{
+
+
+ // Forward declaration.
+ namespace abstract { template <typename E> class piter; }
+
+
+ // Super type declaration.
+ template <typename E>
+ struct set_super_type< abstract::piter<E> >
+ {
+ typedef abstract::iter<E> ret;
+ };
+
+
+ /// Virtual types associated to abstract::piter<E>.
+ template <typename E>
+ struct vtypes_< abstract::piter<E> >
+ {
+ typedef mlc::undefined point_type;
+ };
+
+
+ namespace abstract
+ {
+
+ /// Abstract point iterator class.
+ template <typename E>
+ class piter : public abstract::iter<E>
+ {
+ typedef oln_type_of(E, point) point_t;
+
+ public:
+
+ operator point_t() const
+ {
+ precondition(this->is_valid());
+ return p_;
+ }
+
+ protected:
+
+ point_t p_;
+
+ piter()
+ {
+ }
+
+ ~piter()
+ {
+ mlc::assert_defined_< point_t >::check();
+ mlc::assert_< mlc_is_a(point_t, abstract::point) >::check();
+ }
+
+ }; // end of class oln::abstract::piter<E>
+
+
+ } // end of namespace oln::abstract
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_PITER_HH
Index: oln/core/abstract/point.hh
===================================================================
--- oln/core/abstract/point.hh (revision 512)
+++ oln/core/abstract/point.hh (working copy)
@@ -29,25 +29,17 @@
#ifndef OLENA_CORE_ABSTRACT_POINT_HH
# define OLENA_CORE_ABSTRACT_POINT_HH
-# include <mlc/assert.hh>
-# include <mlc/cmp.hh>
-
-# include <stc/any.hh>
-# include <stc/vtypes.hh>
-# include <stc/exact.hh>
-
-# include <oln/core/type.hh>
# include <oln/core/typedefs.hh>
+# include <oln/core/traits_id.hh>
# include <oln/core/abstract/dpoint.hh>
-# include <oln/core/traits_id.hh>
+namespace oln
+{
-namespace oln {
-
namespace ERROR
{
struct OPERANDS_ARE_NOT_COMPATIBLE;
@@ -56,9 +48,24 @@
- namespace abstract {
+ // Forward declaration.
+ namespace abstract { template <typename E> class point; }
+ /// Virtual types associated to abstract::point<E>.
+ template <typename E>
+ struct vtypes_< abstract::point<E> >
+ {
+ typedef mlc::undefined grid_type;
+ typedef mlc::undefined dpoint_type;
+ typedef mlc::undefined coord_type;
+ typedef mlc::undefined dim_type;
+ };
+
+
+ namespace abstract
+ {
+
/// Abstract point class.
template <typename E>
class point : public stc::any__simple<E>,
@@ -295,18 +302,20 @@
point()
{}
- ~point() {
+ ~point()
+ {
mlc::assert_defined_< oln_type_of(E, grid) >::check();
mlc::assert_defined_< oln_type_of(E, dpoint) >::check();
mlc::assert_defined_< oln_type_of(E, coord) >::check();
mlc::assert_defined_< oln_type_of(E, dim) >::check();
}
- };
+ }; // end of class oln::abstract::point<E>
+
+
} // end of namespace oln::abstract
-
} // end of namespace oln
Index: oln/core/abstract/bbox.hh
===================================================================
--- oln/core/abstract/bbox.hh (revision 0)
+++ oln/core/abstract/bbox.hh (revision 0)
@@ -0,0 +1,227 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_ABSTRACT_BBOX_HH
+# define OLENA_CORE_ABSTRACT_BBOX_HH
+
+# include <mlc/value.hh>
+# include <oln/core/type.hh>
+# include <oln/core/typedefs.hh>
+# include <oln/core/abstract/pset.hh>
+
+
+namespace oln
+{
+
+ // Forward declaration.
+ namespace abstract { template <typename E> class bbox; }
+
+
+ // Super type declaration.
+ template <typename E>
+ struct set_super_type< abstract::bbox<E> >
+ {
+ typedef abstract::pset<E> ret;
+ };
+
+
+ namespace abstract
+ {
+
+ /// Abstract bbox (bounding box) class.
+ template <typename E>
+ class bbox : public abstract::pset<E>
+ {
+ typedef E exact_t;
+ typedef oln_type_of(E, point) point_t;
+
+ typedef oln_type_of(point_t, dim) dim;
+ enum { n = mlc_value(dim) };
+
+ public:
+
+ unsigned npoints() const
+ {
+ unsigned count = 1;
+ for (unsigned i = 0; i < n; ++i)
+ count *= size(i);
+ return count;
+ }
+
+ const point_t& pmin() const
+ {
+ precondition(is_valid_);
+ return pmin_;
+ }
+
+ const point_t& pmax() const
+ {
+ precondition(is_valid_);
+ return pmax_;
+ }
+
+ unsigned size(unsigned i) const
+ {
+ precondition(is_valid_ and i < n);
+ return pmax_[i] - pmin_[i] + 1;
+ }
+
+ void flush()
+ {
+ is_valid_ = false;
+ }
+
+ void init_with(const point_t& p)
+ {
+ precondition(not is_valid_);
+ pmin_ = p;
+ pmax_ = p;
+ is_valid_ = true;
+ }
+
+ void update_with(const point_t& p)
+ {
+ precondition(is_valid_);
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < pmin_[i])
+ pmin_[i] = p[i];
+ else if (p[i] > pmax_[i])
+ pmax_[i] = p[i];
+ }
+
+ void take(const point_t& p)
+ {
+ if (not is_valid_)
+ {
+ init_with(p);
+ return;
+ }
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < pmin_[i])
+ pmin_[i] = p[i];
+ else if (p[i] > pmax_[i])
+ pmax_[i] = p[i];
+ }
+
+ // FIXME: Add "update : (rhs : exact)"
+
+ bool has(const point_t& p) const
+ {
+ precondition(is_valid_);
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < pmin_[i] or p[i] > pmax_[i])
+ return false;
+ return true;
+ }
+
+ bool includes(const exact_t& rhs) const
+ {
+ precondition(is_valid_ and rhs.is_valid());
+ for (unsigned i = 0; i < n; ++i)
+ if (rhs.pmin()[i] < pmin_[i] or rhs.pmax()[i] > pmax_[i])
+ return false;
+ return true;
+ }
+
+ // FIXME: Add the scool code below.
+
+// invariant {
+// n > 1
+// is_valid => (pmax >= pmin) // FIXME: More.
+// }
+
+// (=) const : (rhs : exact) -> bool =
+// {
+// precondition(@is_valid and rhs.is_valid)
+// return @pmin = rhs.pmin and @pmax = rhs.pmax
+// }
+
+// (+=) : (dp : dpoint const ref) -> exact =
+// {
+// precondition(is_valid)
+// pmin += dp
+// pmax += dp
+// }
+
+// (-=) : (dp : dpoint const ref) -> exact =
+// {
+// precondition(is_valid)
+// pmin -= dp
+// pmax -= dp
+// }
+
+ protected:
+
+ point_t pmin_;
+ point_t pmax_;
+ bool is_valid_;
+
+ bbox()
+ {
+ flush();
+ }
+
+ bbox(const point_t& pmin, const point_t& pmax)
+ : pmin_(pmin),
+ pmax_(pmax)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ precondition(pmax[i] >= pmin[i]);
+ is_valid_ = true;
+ }
+
+ ~bbox()
+ {
+ flush();
+
+ mlc::assert_defined_< point_t >::check();
+
+ typedef oln_type_of(E, fwd_piter) fwd_piter_t;
+ typedef oln_type_of(E, bkd_piter) bkd_piter_t;
+
+ mlc::assert_defined_< fwd_piter_t >::check();
+ mlc::assert_defined_< bkd_piter_t >::check();
+
+ mlc::assert_< mlc::eq_< oln_type_of(fwd_piter_t, grid),
+ oln_type_of(point_t, grid) > >::check();
+
+ mlc::assert_< mlc::eq_< oln_type_of(bkd_piter_t, grid),
+ oln_type_of(point_t, grid) > >::check();
+
+ }
+
+ }; // end of class oln::abstract::bbox<E>
+
+
+ } // end of namespace oln::abstract
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_BBOX_HH
Index: oln/core/abstract/dpoint.hh
===================================================================
--- oln/core/abstract/dpoint.hh (revision 512)
+++ oln/core/abstract/dpoint.hh (working copy)
@@ -29,13 +29,6 @@
#ifndef OLENA_CORE_ABSTRACT_DPOINT_HH
# define OLENA_CORE_ABSTRACT_DPOINT_HH
-# include <mlc/assert.hh>
-# include <mlc/cmp.hh>
-
-# include <stc/any.hh>
-# include <stc/vtypes.hh>
-
-# include <oln/core/type.hh>
# include <oln/core/typedefs.hh>
@@ -53,6 +46,22 @@
};
+ // Forward declaration.
+ namespace abstract { template <typename E> class dpoint; }
+
+
+ /// Virtual types associated to abstract::dpoint<E>.
+ template <typename E>
+ struct vtypes_< abstract::dpoint<E> >
+ {
+ typedef mlc::undefined grid_type;
+ typedef mlc::undefined point_type;
+ typedef mlc::undefined coord_type;
+ typedef mlc::undefined dim_type;
+ };
+
+
+
namespace abstract
{
Index: oln/core/abstract/iter.hh
===================================================================
--- oln/core/abstract/iter.hh (revision 0)
+++ oln/core/abstract/iter.hh (revision 0)
@@ -0,0 +1,89 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_ABSTRACT_ITER_HH
+# define OLENA_CORE_ABSTRACT_ITER_HH
+
+# include <oln/core/typedefs.hh>
+
+
+namespace oln
+{
+
+
+ namespace abstract
+ {
+
+ /// Abstract iterator class.
+ template <typename E>
+ class iter : public stc::any__simple<E>,
+ public oln::type
+ {
+ public:
+
+ void start()
+ {
+ this->exact().impl_start();
+ }
+
+ void next()
+ {
+ precondition(this->is_valid());
+ this->exact().impl_next();
+ }
+
+ void invalidate()
+ {
+ this->exact().impl_invalidate();
+ }
+
+ bool is_valid() const
+ {
+ return this->exact().impl_is_valid();
+ }
+
+ protected:
+
+ iter()
+ {
+ this->invalidate();
+ }
+
+ }; // end of class oln::abstract::iter<E>
+
+
+ } // end of namespace oln::abstract
+
+
+} // end of namespace oln
+
+
+#define for_all(i) for (i.start(); i.is_valid(); i.next())
+
+
+#endif // ! OLENA_CORE_ABSTRACT_ITER_HH
Index: oln/core/abstract/point_nd.hh
===================================================================
--- oln/core/abstract/point_nd.hh (revision 512)
+++ oln/core/abstract/point_nd.hh (working copy)
@@ -29,12 +29,10 @@
#ifndef OLENA_CORE_ABSTRACT_POINT_ND_HH
# define OLENA_CORE_ABSTRACT_POINT_ND_HH
-# include <mlc/value.hh>
-
# include <xtd/vec.hh>
# include <xtd/optraits.hh>
+# include <oln/core/traits_id.hh>
-# include <oln/core/traits_id.hh>
# include <oln/core/abstract/point.hh>
# include <oln/core/abstract/dpoint_nd.hh>
@@ -43,7 +41,6 @@
{
-
/// Function "point_ : (n, coord) -> point type".
template <unsigned n, typename C>
struct point_
@@ -53,6 +50,19 @@
+ // Forward declaration.
+ namespace abstract { template <typename E> class point_nd; }
+
+
+
+ // Super type declaration.
+ template <typename E>
+ struct set_super_type< abstract::point_nd<E> >
+ {
+ typedef abstract::point<E> ret;
+ };
+
+
namespace abstract
{
@@ -136,7 +146,8 @@
v_(v)
{}
- xtd::vec<n,coord_t> v_;
+ typedef xtd::vec<n,coord_t> vec_t;
+ vec_t v_;
};
} // end of namespace oln::abstract
Index: oln/core/abstract/pset.hh
===================================================================
--- oln/core/abstract/pset.hh (revision 0)
+++ oln/core/abstract/pset.hh (revision 0)
@@ -0,0 +1,95 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_ABSTRACT_PSET_HH
+# define OLENA_CORE_ABSTRACT_PSET_HH
+
+# include <stc/any.hh>
+# include <oln/core/type.hh>
+# include <oln/core/typedefs.hh>
+
+
+namespace oln
+{
+
+ /// Forward declaration.
+ namespace abstract { template <typename E> class pset; }
+
+
+
+ /// Virtual types associated to oln::bbox_nd<point>.
+ template <typename E>
+ struct vtypes_< abstract::pset<E> >
+ {
+ typedef mlc::undefined point_type;
+ typedef mlc::undefined fwd_piter_type;
+ typedef mlc::undefined bkd_piter_type;
+ // FIXME: Add grid.
+ };
+
+
+ namespace abstract
+ {
+
+ /// Abstract point class.
+ template <typename E>
+ class pset : public stc::any__simple<E>,
+ public oln::type
+ {
+
+ protected:
+
+ pset()
+ {}
+
+ ~pset()
+ {
+ mlc::assert_defined_< oln_type_of(E, point) >::check();
+
+ // FIXME: Trouble with circular dependencies.
+
+// mlc::assert_defined_< fwd_piter_t >::check();
+// mlc::assert_defined_< bkd_piter_t >::check();
+
+// mlc::assert_< mlc::eq_< oln_type_of(fwd_piter_t, grid),
+// oln_type_of(point_t, grid) > >::check();
+
+// mlc::assert_< mlc::eq_< oln_type_of(bkd_piter_t, grid),
+// oln_type_of(point_t, grid) > >::check();
+ }
+
+ }; // end of class oln::abstract::pset<E>
+
+
+ } // end of namespace oln::abstract
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_ABSTRACT_PSET_HH
Index: oln/core/abstract/dpoint_nd.hh
===================================================================
--- oln/core/abstract/dpoint_nd.hh (revision 512)
+++ oln/core/abstract/dpoint_nd.hh (working copy)
@@ -37,6 +37,18 @@
namespace oln
{
+ // Forward declaration.
+ namespace abstract { template <typename E> class dpoint_nd; }
+
+
+ // Super type declaration.
+ template <typename E>
+ struct set_super_type< abstract::dpoint_nd<E> >
+ {
+ typedef abstract::dpoint<E> ret;
+ };
+
+
namespace abstract
{
Index: oln/core/2d/aliases.hh
===================================================================
--- oln/core/2d/aliases.hh (revision 0)
+++ oln/core/2d/aliases.hh (revision 0)
@@ -0,0 +1,64 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_2D_ALIASES_HH
+# define OLENA_CORE_2D_ALIASES_HH
+
+
+namespace oln
+{
+
+ /// \{
+ /// Forward declarations.
+ template <typename C> class point2d_;
+ template <typename C> class dpoint2d_;
+ template <typename P> class bbox_;
+ template <typename P> class fwd_piter_;
+ template <typename P> class bkd_piter_;
+ class grid2d;
+ /// \}
+
+
+ /// \{
+ /// Alliases.
+ typedef point2d_<int> point2d;
+ typedef dpoint2d_<int> dpoint2d;
+
+ typedef bbox_<point2d> bbox2d;
+ typedef fwd_piter_<point2d> fwd_piter2d;
+ typedef bkd_piter_<point2d> bkd_piter2d;
+
+ typedef point2d_<float> point2df;
+ typedef dpoint2d_<float> dpoint2df;
+ /// \}
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_2D_ALIASES_HH
Index: oln/core/2d/point2d.hh
===================================================================
--- oln/core/2d/point2d.hh (revision 512)
+++ oln/core/2d/point2d.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLENA_CORE_2D_POINT2D_HH
# define OLENA_CORE_2D_POINT2D_HH
-# include <string>
-
# include <mlc/int.hh>
# include <oln/core/abstract/point_nd.hh>
@@ -39,28 +37,6 @@
/// \{
- /// Forward declarations.
- template <typename C> class point2d_;
- template <typename C> class dpoint2d_;
- class grid2d;
- /// \}
-
-
- /// \{
- /// Classical 2D point classes.
- typedef point2d_<int> point2d;
- typedef point2d_<float> point2df;
- /// \}
-
-
- /// \{
- /// Classical 2D point classes.
- typedef dpoint2d_<int> dpoint2d;
- typedef dpoint2d_<float> dpoint2df;
- /// \}
-
-
- /// \{
/// Specializations of functions point and dpoint : (n,coord) -> type for n = 2.
template <typename C> struct point_ <2, C> { typedef point2d_<C> ret; };
template <typename C> struct dpoint_ <2, C> { typedef dpoint2d_<C> ret; };
@@ -90,17 +66,26 @@
public:
+ // Cf. BUG! typedef oln_type_of(self_t, grid) grid_t;
+
/// Ctor.
point2d_()
{
}
/// Ctor.
- point2d_(const xtd::vec<2,coord_t>& v) :
- super_t(v)
+ point2d_(coord_t row, coord_t col)
{
+ v_[0] = row;
+ v_[1] = col;
}
+ /// Ctor.
+ point2d_(const xtd::vec<2,coord_t>& v)
+ : super_t(v)
+ {
+ }
+
coord_t row() const { return v_[0]; }
coord_t& row() { return v_[0]; }
Index: oln/core/gen/fwd_piter.hh
===================================================================
--- oln/core/gen/fwd_piter.hh (revision 0)
+++ oln/core/gen/fwd_piter.hh (revision 0)
@@ -0,0 +1,134 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_GEN_FWD_PITER_HH
+# define OLENA_CORE_GEN_FWD_PITER_HH
+
+# include <oln/core/abstract/piter.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/gen/bbox.hh>
+
+
+namespace oln
+{
+
+
+ // Forward declaration.
+ template <typename point> class fwd_piter_;
+
+
+ // Super type declaration.
+ template <typename point>
+ struct set_super_type< fwd_piter_<point> >
+ {
+ typedef fwd_piter_<point> self_t;
+ typedef abstract::piter<self_t> ret;
+ };
+
+
+ /// Virtual types associated to oln::fwd_piter_<point>.
+ template <typename point>
+ struct vtypes_< fwd_piter_<point> >
+ {
+ typedef point point_type;
+ typedef oln_type_of(point, grid) grid_type;
+ };
+
+
+
+ /// Abstract forward point iterator class.
+ template <typename point>
+ class fwd_piter_ : public abstract::piter< fwd_piter_<point> >,
+ private mlc::assert_< mlc_is_a(point, abstract::point) >
+ {
+ typedef fwd_piter_<point> self_t;
+ typedef abstract::piter<self_t> super_t;
+
+ using super_t::p_;
+
+ public:
+
+ fwd_piter_(const bbox_<point>& bb)
+ : bb_(bb)
+ {
+ nop_ = bb_.pmax();
+ ++nop_[0];
+
+ psup_ = bb_.pmax().vec();
+ for (unsigned i = 0; i < point::n; ++i)
+ ++psup_[i];
+ }
+
+ void impl_start()
+ {
+ p_ = bb_.pmin();
+ invariant(p_ <= nop_);
+ }
+
+ void impl_next()
+ {
+ invariant(p_ <= nop_);
+ ++p_[0];
+ unsigned i = 0;
+ while (i + 1 < point::n)
+ {
+ if (p_[i] == psup_[i])
+ {
+ p_[i] = bb_.pmin_[i];
+ ++p_[i+1];
+ }
+ ++i;
+ }
+ invariant(p_ <= nop_);
+ }
+
+ void impl_invalidate()
+ {
+ invariant(p_ <= nop_);
+ p_ = nop_;
+ }
+
+ bool impl_is_valid() const
+ {
+ invariant(p_ <= nop_);
+ return p_ != nop_;
+ }
+
+ protected:
+
+ bbox_<point> bb_;
+ point nop_;
+ point psup_;
+
+ }; // end of class oln::fwd_piter_<point>
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_GEN_FWD_PITER_HH
Index: oln/core/gen/bkd_piter.hh
===================================================================
--- oln/core/gen/bkd_piter.hh (revision 0)
+++ oln/core/gen/bkd_piter.hh (revision 0)
@@ -0,0 +1,143 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_GEN_BKD_PITER_HH
+# define OLENA_CORE_GEN_BKD_PITER_HH
+
+# include <oln/core/abstract/piter.hh>
+# include <oln/core/abstract/point.hh>
+# include <oln/core/gen/bbox.hh>
+
+
+namespace oln
+{
+
+
+ // Forward declaration.
+ template <typename point> class bkd_piter_;
+
+
+ // Super type declaration.
+ template <typename point>
+ struct set_super_type< bkd_piter_<point> >
+ {
+ typedef bkd_piter_<point> self_t;
+ typedef abstract::piter<self_t> ret;
+ };
+
+
+ /// Virtual types associated to oln::bbox_<point>.
+ template <typename point>
+ struct vtypes_< bkd_piter_<point> >
+ {
+ typedef point point_type;
+ typedef oln_type_of(point, grid) grid_type;
+ };
+
+
+
+ /// Abstract forward point iterator class.
+ template <typename point>
+ class bkd_piter_ : public abstract::piter< bkd_piter_<point> >,
+ private mlc::assert_< mlc_is_a(point, abstract::point) >
+ {
+ typedef bkd_piter_<point> self_t;
+ typedef abstract::piter<self_t> super_t;
+
+ using super_t::p_;
+
+ public:
+
+ bkd_piter_(const bbox_<point>& bb)
+ : bb_(bb)
+ {
+ nop_ = bb_.pmax();
+ ++nop_[0];
+
+ psup_ = bb_.pmax().vec();
+ for (unsigned i = 0; i < point::n; ++i)
+ ++psup_[i];
+ }
+
+ void impl_start()
+ {
+ p_ = bb_.pmin();
+ }
+
+ void impl_next()
+ {
+ assert(this->is_valid());
+ ++p_[0];
+ unsigned i = 0;
+ while (i + 1 < point::n)
+ {
+ if (p_[i] == psup_[i])
+ {
+ p_[i] = bb_.pmin_[i];
+ ++p_[i+1];
+ }
+ ++i;
+ }
+ }
+
+// def next =
+// {
+// precondition { is_valid }
+// }
+
+ void impl_invalidate()
+ {
+ assert(this->is_valid());
+ p_ = nop_;
+ }
+
+ bool impl_is_valid() const
+ {
+ return p_ != nop_;
+ }
+
+ protected:
+
+ bbox_<point> bb_;
+ point nop_;
+ point psup_;
+
+// invariant
+// {
+// p <= nop
+// }
+
+// make : [D : type] (data : D) = { @bb = data.bbox }
+
+ }; // end of class oln::bkd_piter_<point>
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_GEN_BKD_PITER_HH
Index: oln/core/gen/bbox.hh
===================================================================
--- oln/core/gen/bbox.hh (revision 0)
+++ oln/core/gen/bbox.hh (revision 0)
@@ -0,0 +1,92 @@
+// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 OLENA_CORE_GEN_BBOX_HH
+# define OLENA_CORE_GEN_BBOX_HH
+
+# include <oln/core/abstract/bbox.hh>
+# include <oln/core/abstract/point.hh>
+
+
+namespace oln
+{
+
+ // Forward declarations.
+ template <typename point> class bbox_;
+ template <typename point> class fwd_piter_;
+ template <typename point> class bkd_piter_;
+
+
+ // Super type declaration.
+ template <typename point>
+ struct set_super_type< bbox_<point> >
+ {
+ typedef bbox_<point> self_t;
+ typedef abstract::bbox<self_t> ret;
+ };
+
+
+ /// Virtual types associated to oln::bbox_<point>.
+ template <typename point>
+ struct vtypes_< bbox_<point> >
+ {
+ typedef point point_type;
+ typedef fwd_piter_<point> fwd_piter_type;
+ typedef bkd_piter_<point> bkd_piter_type;
+ // BUG! typedef oln_type_of(point, grid) grid_type;
+ // BUG! typedef typename point::grid_t grid_type;
+ };
+
+
+ /// Bounding box class based on a point class.
+ template <typename point>
+ class bbox_ : public abstract::bbox< bbox_<point> >,
+ private mlc::assert_< mlc_is_a(point, abstract::point) >
+ {
+ typedef point point_t;
+ typedef bbox_<point> self_t;
+ typedef abstract::bbox<self_t> super_t;
+
+ public:
+
+ bbox_()
+ {
+ }
+
+ bbox_(const point_t& pmin, const point_t& pmax)
+ : super_t(pmin, pmax)
+ {
+ }
+
+ }; // end of class oln::bbox_<point>
+
+
+} // end of namespace oln
+
+
+#endif // ! OLENA_CORE_GEN_BBOX_HH
Index: oln/basics2d.hh
===================================================================
--- oln/basics2d.hh (revision 0)
+++ oln/basics2d.hh (revision 0)
@@ -0,0 +1,42 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2006 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 OLENA_BASICS2D_HH
+# define OLENA_BASICS2D_HH
+
+
+# include <oln/core/2d/aliases.hh>
+
+# include <oln/core/2d/point2d.hh>
+# include <oln/core/2d/dpoint2d.hh>
+
+# include <oln/core/gen/bbox.hh>
+# include <oln/core/gen/fwd_piter.hh>
+# include <oln/core/gen/bkd_piter.hh>
+
+
+#endif // ! OLENA_BASICS2D_HH
2
1
04 Sep '06
2006-09-04 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Test how to define derived associated types in bbox hierarchy.
* oln/core/abstract/bbox.hh (ext_vtype_): New definitions of
fwd_piter_type and bkd_piter_type.
(~bbox): Comment possible recursive code.
* oln/core/gen/bbox.hh (vtypes_): Comment former definitions of
fwd_piter_type and bkd_piter_type.
* oln/core/abstract/pset.hh (ext_vtype_): New definition for
grid.
(fwd_piter_type, bkd_piter_type): Comment because they are now
externally defined.
Index: oln/core/abstract/bbox.hh
===================================================================
--- oln/core/abstract/bbox.hh (revision 518)
+++ oln/core/abstract/bbox.hh (working copy)
@@ -40,6 +40,8 @@
// Forward declaration.
namespace abstract { template <typename E> class bbox; }
+ template <typename point> class fwd_piter_;
+ template <typename point> class bkd_piter_;
// Super type declaration.
@@ -50,6 +52,26 @@
};
+
+ template <typename E>
+ struct ext_vtype_< abstract::bbox<E>, typedef_::fwd_piter_type >
+ {
+ private:
+ typedef oln_type_of(E, point) P;
+ public:
+ typedef fwd_piter_<P> ret;
+ };
+
+ template <typename E>
+ struct ext_vtype_< abstract::bbox<E>, typedef_::bkd_piter_type >
+ {
+ private:
+ typedef oln_type_of(E, point) P;
+ public:
+ typedef bkd_piter_<P> ret;
+ };
+
+
namespace abstract
{
@@ -234,17 +256,17 @@
mlc::assert_defined_< point_t >::check();
- typedef oln_type_of(E, fwd_piter) fwd_piter_t;
- typedef oln_type_of(E, bkd_piter) bkd_piter_t;
+// typedef oln_type_of(E, fwd_piter) fwd_piter_t;
+// typedef oln_type_of(E, bkd_piter) bkd_piter_t;
- mlc::assert_defined_< fwd_piter_t >::check();
- mlc::assert_defined_< bkd_piter_t >::check();
+// mlc::assert_defined_< fwd_piter_t >::check();
+// mlc::assert_defined_< bkd_piter_t >::check();
- mlc::assert_< mlc::eq_< oln_type_of(fwd_piter_t, grid),
- oln_type_of(point_t, grid) > >::check();
+// mlc::assert_< mlc::eq_< oln_type_of(fwd_piter_t, grid),
+// oln_type_of(point_t, grid) > >::check();
- mlc::assert_< mlc::eq_< oln_type_of(bkd_piter_t, grid),
- oln_type_of(point_t, grid) > >::check();
+// mlc::assert_< mlc::eq_< oln_type_of(bkd_piter_t, grid),
+// oln_type_of(point_t, grid) > >::check();
}
Index: oln/core/abstract/pset.hh
===================================================================
--- oln/core/abstract/pset.hh (revision 518)
+++ oln/core/abstract/pset.hh (working copy)
@@ -47,13 +47,35 @@
struct vtypes_< abstract::pset<E> >
{
typedef mlc::undefined point_type;
- typedef mlc::undefined fwd_piter_type;
- typedef mlc::undefined bkd_piter_type;
- typedef mlc::undefined coord_type;
- // FIXME: Add grid.
+// typedef mlc::undefined fwd_piter_type;
+// typedef mlc::undefined bkd_piter_type;
};
+// template <typename E>
+// struct vtype_< abstract::pset<E>, typedef_::coord_type >
+// : type_of_< oln_type_of(E, point), typedef_::coord_type >
+// {};
+
+
+// template <typename E>
+// struct extension_vtype_< abstract::pset<E>, typedef_::coord_type >
+// {
+// private:
+// typedef oln_type_of(E, point) P;
+// public:
+// typedef oln_type_of(P, coord) ret;
+// };
+
+
+ template <typename E>
+ struct ext_vtype_< abstract::pset<E>, typedef_::grid_type >
+ {
+ typedef oln_type_of(E, point) P;
+ typedef oln_type_of(P, grid) ret;
+ };
+
+
namespace abstract
{
@@ -71,8 +93,9 @@
~pset()
{
mlc::assert_defined_< oln_type_of(E, point) >::check();
+ mlc::assert_defined_< oln_type_of(E, coord) >::check();
- // FIXME: Trouble with circular dependencies.
+ // FIXME: BUG! Trouble with circular dependencies.
// mlc::assert_defined_< fwd_piter_t >::check();
// mlc::assert_defined_< bkd_piter_t >::check();
Index: oln/core/gen/bbox.hh
===================================================================
--- oln/core/gen/bbox.hh (revision 518)
+++ oln/core/gen/bbox.hh (working copy)
@@ -56,11 +56,11 @@
struct vtypes_< bbox_<point> >
{
typedef point point_type;
- typedef fwd_piter_<point> fwd_piter_type;
- typedef bkd_piter_<point> bkd_piter_type;
+// typedef fwd_piter_<point> fwd_piter_type;
+// typedef bkd_piter_<point> bkd_piter_type;
typedef typename point::coord_t coord_type;
- // BUG! typedef oln_type_of(point, grid) grid_type;
- // BUG! typedef typename point::grid_t grid_type;
+ // FIXME: BUG! typedef oln_type_of(point, grid) grid_type;
+ // FIXME: BUG! typedef typename point::grid_t grid_type;
};
1
0
04 Sep '06
https://svn.lrde.epita.fr/svn/oln/trunk/static
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a third kind of structure for virtual types to avoid endless
recursions when their definitions involve the knowledge of the
exact type of the class these virtual types belong to.
* static/stc/vtypes.hh (single_vtype, single_vtype_): New template
class.
(internal::tag::single): New.
(internal::tag::external): Rename as...
(internal::tag::extended): ...this.
(get_vtype_helper): Adjust and extended for internal::tag::single.
(select_typedef): Extended retrieval algorithm.
(type_of_): Likewise.
Check the return type of the algorithm.
More documentation.
s/external/extended/.
* static/tests/vtypes.cc: Conform to the new terminology.
* static/tests/vtypes-multiple-supers.cc: Adjust.
* tests/vtypes-and-exact.cc: Likewise.
Aesthetic changes.
(main): Exercize stc::is_any_.
* static/stc/valist_aggregator.hh (valist_aggregator): Use virtual
inheritance.
stc/valist_aggregator.hh | 29 ++--
stc/vtypes.hh | 258 +++++++++++++++++++++++++++++++---------
tests/vtypes-and-exact.cc | 14 +-
tests/vtypes-multiple-supers.cc | 2
tests/vtypes.cc | 2
5 files changed, 231 insertions(+), 74 deletions(-)
Index: stc/vtypes.hh
--- stc/vtypes.hh (revision 517)
+++ stc/vtypes.hh (working copy)
@@ -72,6 +72,8 @@
struct FIRST_PARAMETER_OF_rec_get_vtype_from_list_IS_NOT_A_TAG;
struct THIRD_PARAMETER_OF_rec_get_vtype_from_list_IS_NOT_A_LIST;
+ struct NO_VALID_RETURN_TYPE_FOR_type_of_;
+
} // end of namespace stc::ERROR
} // end of namespace stc
@@ -223,6 +225,42 @@
/* Virtual types. */ \
/* --------------- */ \
\
+ /** \brief Definition of virtual types. */ \
+ /** */ \
+ /** There a three kinds of structures for virtual types: */ \
+ /** - internal vtypes (\a vtypes); */ \
+ /** - single vtypes (\a single_vtype); */ \
+ /** - extended vtypes (\a ext_vtype); */ \
+ /** */ \
+ /** A \a vtype structure can store one or several internal vtypes, */ \
+ /** whereas a \a single_vtype or an \a ext_vtype structure can hold */ \
+ /** one and only one vtype. */ \
+ /** */ \
+ /** See tests/tour.cc and tests/vtypes.cc for examples of use. */ \
+ /** */ \
+ /** A virtual type definition within a \a vtype structure cannot use */ \
+ /** the form `stc_type_of(Exact, ...)', which would cause endless */ \
+ /** recursions in the class hierarchy. Instead, such definitions */ \
+ /** should be placed in \a single_vtype or \a ext_vtype structure. */ \
+ /** */ \
+ /** Definitions of single vtypes can be ``announced'' in the */ \
+ /** corresponding internal vtypes structure, using the \a */ \
+ /** mlc::undefined tag (i.e., a vtype defined as \a mlc::undefined in */ \
+ /** \a vtypes can be re-defined in a \a single_vtype). */ \
+ /** */ \
+ /** Apart from this exception, a vtype shall be defined at most by */ \
+ /** one of the three structures explained above. */ \
+ /** */ \
+ /** To put in a nushell, internal vtypes are the default way to define */ \
+ /** the vtypes of a class (except those of the form */ \
+ /** `stc_type_of(Exact, ...)'); single vtypes are used to transcend */ \
+ /** this limitation; and extended vtypes are used to add new vtypes to */ \
+ /** a class besides its initial vtypes. */ \
+ \
+ \
+ /* Internal vtypes. */ \
+ /* \{ */ \
+ \
/** \brief Internal virtual types associated to \a from_type. */ \
/** */ \
/** Specialize this class for the desired \a from_type. */ \
@@ -252,7 +290,13 @@
{ \
}; \
\
- /** \brief An external virtual type associated to \a from_type. */ \
+ /* \} */ \
+ \
+ \
+ /* Extended vtype. */ \
+ /* \{ */ \
+ \
+ /** \brief An extended virtual type associated to \a from_type. */ \
/** */ \
/** Specialize this class for the desired \a from_type. */ \
template <typename category, typename from_type, typename typedef_type> \
@@ -260,7 +304,7 @@
{ \
}; \
\
- /** \brief An external virtual type associated to \a from_type. */ \
+ /** \brief An extended virtual type associated to \a from_type. */ \
/** Version for types without category. */ \
/** */ \
/** Specialize this class for the desired \a from_type. */ \
@@ -283,8 +327,52 @@
{ \
}; \
\
+ /* \} */ \
+ \
+ \
+ /* Single vtype. */ \
+ /* \{ */ \
+ \
+ /** \brief A single virtual type associated to \a from_type. */ \
+ /** */ \
+ /** Specialize this class for the desired \a from_type. */ \
+ template <typename category, typename from_type, typename typedef_type> \
+ struct single_vtype \
+ { \
+ }; \
+ \
+ /** \brief A single virtual type associated to \a from_type. */ \
+ /** Version for types without category. */ \
+ /** */ \
+ /** Specialize this class for the desired \a from_type. */ \
+ template <typename from_type, typename typedef_type> \
+ struct single_vtype_ \
+ { \
+ }; \
+ \
+ /** Specialization of single_vtype for types without category. */ \
+ template <typename from_type, typename typedef_type> \
+ struct single_vtype<void, from_type, typedef_type> \
+ : public single_vtype_<from_type, typedef_type> \
+ { \
+ }; \
+ \
+ /** End of the recursive construction of any single_vtype<> */ \
+ /** hierarchy. */ \
+ template <typename category, typename typedef_type> \
+ struct single_vtype<category, mlc::none, typedef_type> \
+ { \
+ }; \
+ \
+ /* \} */ \
+ \
+ \
+ /* -------------------------- */ \
+ /* Packing of virtual types. */ \
+ /* -------------------------- */ \
+ \
/** Optional packing structure, to be specialized by the user. */ \
- /** See tests/vtypes.hh for an example of use. */ \
+ /** See tests/vtypes.cc for an example of use. */ \
template <typename category, typename from_type> \
struct packed_vtypes \
{ \
@@ -292,7 +380,6 @@
\
/** Optional packing structure, to be specialized by the user. */ \
/** Version for types without category. */ \
- /** See tests/vtypes.hh for an example of use. */ \
template <typename from_type> \
struct packed_vtypes_ \
{ \
@@ -327,8 +414,10 @@
\
/** Tag for retrieval within internal vtypes. */ \
struct internal : public method {}; \
- /** Tag for retrieval within external vtypes. */ \
- struct external : public method {}; \
+ /** Tag for retrieval within single vtypes. */ \
+ struct single : public method {}; \
+ /** Tag for retrieval within extended vtypes. */ \
+ struct extended : public method {}; \
\
} /** end of stc::internal::tag */ \
\
@@ -356,15 +445,28 @@
}; \
\
/** Specialization of get_vtypes for retrievals within */ \
- /** external vtypes. */ \
+ /** single vtypes. */ \
+ template <typename category, \
+ typename from_type, typename typedef_type> \
+ struct get_vtype_helper<tag::single, category, \
+ from_type, typedef_type> \
+ { \
+ /** Set of vtypes associated with FROM_TYPE. */ \
+ typedef single_vtype<category, from_type, typedef_type> single_type; \
+ /** Typedef in the current single_vtype (may be mlc::not_found). */ \
+ typedef mlc_ret(single_type) ret; \
+ }; \
+ \
+ /** Specialization of get_vtypes for retrievals within */ \
+ /** extended vtypes. */ \
template <typename category, \
typename from_type, typename typedef_type> \
- struct get_vtype_helper<tag::external, category, \
+ struct get_vtype_helper<tag::extended, category, \
from_type, typedef_type> \
{ \
/** Set of vtypes associated with FROM_TYPE. */ \
typedef ext_vtype<category, from_type, typedef_type> ext_type; \
- /** Typedef in the current vtypes (may be mlc::not_found). */ \
+ /** Typedef in the current ext_vtype (may be mlc::not_found). */ \
typedef mlc_ret(ext_type) ret; \
}; \
\
@@ -518,50 +620,78 @@
}; \
\
\
- /* ------------------------------------- */ \
- /* External/internal typedef selection. */ \
- /* ------------------------------------- */ \
+ /* -------------------------------------------- */ \
+ /* Internal/single/extended typedef selection. */ \
+ /* -------------------------------------------- */ \
\
/** \brief Typedef selector. */ \
/** */ \
/** A virtual type is considered valid if and only if it has been */ \
- /** found as an internal vtype or (exclusive) as an external vtype. */ \
+ /** found as an internal vtype or (exclusive) as an extended vtype. */ \
/** Other cases (no definition or a double definition) are invalid. */ \
/** */ \
/** \{ */ \
/** Fwd decl. */ \
- template <bool external_typedef_p, bool internal_typedef_p, \
- typename external_typedef, typename internal_typedef> \
+ template \
+ < typename internal_vtype_candidate, bool found_as_internal_vtype, \
+ typename single_vtype_candidate, bool found_as_single_vtype, \
+ typename extended_vtype_candidate, bool found_as_extended_vtype > \
struct select_typedef; \
\
- /** The typedef is found in both an external and an internal */ \
- /** type definitions: error. */ \
- template <typename external_typedef, typename internal_typedef> \
- struct select_typedef<true, true, external_typedef, internal_typedef> \
- { \
- /* No ret member. */ \
- }; \
- \
- /** The typedef is found neither in an external nor in an */ \
- /** internal type definition: error. */ \
- template <typename external_typedef, typename internal_typedef> \
- struct select_typedef<false, false, external_typedef, internal_typedef> \
- { \
- /* No ret member. */ \
- }; \
- \
- /** The typedef is found in an extternal definition only: good. */ \
- template <typename external_typedef, typename internal_typedef> \
- struct select_typedef<true, false, external_typedef, internal_typedef> \
+ /** The typedef is defined as an internal vtype only: good. */ \
+ template <typename internal_vtype_candidate, \
+ typename single_vtype_candidate, \
+ typename extended_vtype_candidate> \
+ struct select_typedef<internal_vtype_candidate, true, \
+ single_vtype_candidate, false, \
+ extended_vtype_candidate, false> \
+ { \
+ typedef internal_vtype_candidate ret; \
+ }; \
+ \
+ /** The typedef is defined as a single vtype only: good. */ \
+ template <typename internal_vtype_candidate, \
+ typename single_vtype_candidate, \
+ typename extended_vtype_candidate> \
+ struct select_typedef<internal_vtype_candidate, false, \
+ single_vtype_candidate, true, \
+ extended_vtype_candidate, false> \
+ { \
+ typedef single_vtype_candidate ret; \
+ }; \
+ \
+ /** The typedef is defined as an extended vtype only: good. */ \
+ template <typename internal_vtype_candidate, \
+ typename single_vtype_candidate, \
+ typename extended_vtype_candidate> \
+ struct select_typedef<internal_vtype_candidate, false, \
+ single_vtype_candidate, false, \
+ extended_vtype_candidate, true> \
+ { \
+ typedef extended_vtype_candidate ret; \
+ }; \
+ \
+ /** Special case. The typedef is <b>declared</b> as mlc::undefined */ \
+ /** in internal vtypes, and <b>defined</b> as a single vtype: good. */ \
+ template <typename single_vtype_candidate, \
+ typename extended_vtype_candidate> \
+ struct select_typedef<mlc::undefined, true, \
+ single_vtype_candidate, true, \
+ extended_vtype_candidate, false> \
+ { \
+ typedef single_vtype_candidate ret; \
+ }; \
+ \
+ /** Other cases: error (the typedef is not defined or defined more */ \
+ /** than once, hence \a mlc::not_found is returned). */ \
+ template \
+ < typename internal_vtype_candidate, bool found_as_internal_vtype, \
+ typename single_vtype_candidate, bool found_as_single_vtype, \
+ typename extended_vtype_candidate, bool found_as_extended_vtype > \
+ struct select_typedef \
{ \
- typedef external_typedef ret; \
- }; \
- \
- /** The typedef is found in an internal definition only: good. */ \
- template <typename external_typedef, typename internal_typedef> \
- struct select_typedef<false, true, external_typedef, internal_typedef> \
- { \
- typedef internal_typedef ret; \
+ /* Error, not valid typedef found. */ \
+ typedef mlc::not_found ret; \
}; \
/** \} */ \
\
@@ -575,29 +705,47 @@
/* Get the exact type of \a from_type. */ \
typedef stc_to_exact(from_type) from_exact_type; \
\
- /* Look for the typedef in internal types. */ \
+ /* Look for the typedef in internal vtypes. */ \
typedef typename \
internal::rec_get_vtype<internal::tag::internal, category, \
from_exact_type, typedef_type>::ret \
- internal_typedef; \
- /* Look for the typedef as an external type. */ \
+ internal_vtype_candidate; \
+ /* Look for the typedef as a single vtype definition. */ \
typedef typename \
- internal::rec_get_vtype<internal::tag::external, category, \
+ internal::rec_get_vtype<internal::tag::single, category, \
from_exact_type, typedef_type>::ret \
- external_typedef; \
+ single_vtype_candidate; \
+ /* Look for the typedef as an extended vtype. */ \
+ typedef typename \
+ internal::rec_get_vtype<internal::tag::extended, category, \
+ from_exact_type, typedef_type>::ret \
+ extended_vtype_candidate; \
\
- /* Did we found the virtual type? */ \
- static const bool found_internal_p = \
- mlc_bool(mlc::is_found_<internal_typedef>); \
- static const bool found_external_p = \
- mlc_bool(mlc::is_found_<external_typedef>); \
+ /* Did we found the virtual type in any of the vtypes structures? */ \
+ static const bool found_as_internal_vtype = \
+ mlc_bool(mlc::is_found_<internal_vtype_candidate>); \
+ static const bool found_as_single_vtype = \
+ mlc_bool(mlc::is_found_<single_vtype_candidate>); \
+ static const bool found_as_extended_vtype = \
+ mlc_bool(mlc::is_found_<extended_vtype_candidate>); \
+ \
+ /* Find an eligible typedef. */ \
+ typedef typename \
+ internal::select_typedef< \
+ internal_vtype_candidate, found_as_internal_vtype, \
+ single_vtype_candidate, found_as_single_vtype, \
+ extended_vtype_candidate, found_as_extended_vtype \
+ >::ret candidate; \
\
typedef typename \
- internal::select_typedef<found_external_p, found_internal_p, \
- external_typedef, internal_typedef>::ret ret; \
+ mlc::assert_and_return_< \
+ mlc_neq(candidate, mlc::not_found), \
+ candidate, \
+ stc::ERROR::NO_VALID_RETURN_TYPE_FOR_type_of_ \
+ >::ret ret; \
}; \
\
- struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+ struct e_n_d__w_i_t_h___s_e_m_i_c_o_l_o_n
/*---------------------.
Index: tests/vtypes.cc
--- tests/vtypes.cc (revision 517)
+++ tests/vtypes.cc (working copy)
@@ -148,7 +148,7 @@
typedef long quux_type;
};
- /// An external type associated to my::B.
+ /// An extended type associated to my::B.
template <>
struct ext_vtype<category::my_cat, B, typedef_::yin_type>
{
Index: tests/vtypes-multiple-supers.cc
--- tests/vtypes-multiple-supers.cc (revision 517)
+++ tests/vtypes-multiple-supers.cc (working copy)
@@ -33,7 +33,7 @@
// This test focuses on the support of virtual types in hierachies
// with multiple inheritance.
-// FIXME: To do: Check external vtypes, too.
+// FIXME: To do: Check extended vtypes, too.
/// Helper macros.
/// \{
Index: tests/vtypes-and-exact.cc
--- tests/vtypes-and-exact.cc (revision 517)
+++ tests/vtypes-and-exact.cc (working copy)
@@ -100,13 +100,12 @@
/// Types associated to my::A.
template <typename Exact>
- struct vtypes< category::my_cat, my::A<Exact> >
+ struct vtypes< category::my_cat, A<Exact> >
{
// A native type.
typedef int foo_type;
- // A Metalic value, used here is to ensure that
- // mlc::abstract::values are accepted as virtual types, as well as
- // any other type).
+ // A Metalic value, used here to ensure that mlc::abstract::values
+ // are accepted as virtual types, as well as any other type).
typedef mlc::int_<42> bar_type;
// An undefined type.
typedef mlc::undefined baz_type;
@@ -157,7 +156,7 @@
typedef long quux_type;
};
- /// An external type associated to my::B.
+ /// An extended type associated to my::B.
template <typename Exact>
struct ext_vtype<category::my_cat, B<Exact>, typedef_::yin_type>
{
@@ -228,6 +227,11 @@
mlc::assert_<mlc_is_a_(C, A)>::check();
mlc::assert_<mlc_is_a_(C, B)>::check();
+ // Ensure stc::is_any_ works properly.
+ mlc::assert_< stc::is_any_< A<C> > >::check();
+ mlc::assert_< stc::is_any_< B<C> > >::check();
+ mlc::assert_< stc::is_any_< C > >::check();
+
// Check exact types of A<C> and B<C>.
mlc::assert_<mlc_eq(stc_to_exact_(A<C>), C)>::check();
mlc::assert_<mlc_eq(stc_to_exact_(B<C>), C)>::check();
Index: stc/valist_aggregator.hh
--- stc/valist_aggregator.hh (revision 517)
+++ stc/valist_aggregator.hh (working copy)
@@ -71,28 +71,30 @@
/// Version for 2 super classes.
template <typename E1, typename E2>
struct valist_aggregator< mlc::valist_ <E1,E2> > :
- public E1, public E2
+ virtual public E1, virtual public E2
{
};
/// Version for 3 super classes.
template <typename E1, typename E2, typename E3>
struct valist_aggregator< mlc::valist_ <E1,E2,E3 > > :
- public E1, public E2, public E3
+ virtual public E1, virtual public E2, virtual public E3
{
};
/// Version for 4 super classes.
template <typename E1, typename E2, typename E3, typename E4>
struct valist_aggregator< mlc::valist_ <E1,E2,E3,E4> > :
- public E1, public E2, public E3, public E4
+ virtual public E1, virtual public E2, virtual public E3,
+ virtual public E4
{
};
/// Version for 5 super classes.
template <typename E1, typename E2, typename E3, typename E4, typename E5>
struct valist_aggregator< mlc::valist_ <E1,E2,E3,E4,E5> > :
- public E1, public E2, public E3, public E4, public E5
+ virtual public E1, virtual public E2, virtual public E3,
+ virtual public E4, virtual public E5
{
};
@@ -100,8 +102,8 @@
template <typename E1, typename E2, typename E3, typename E4, typename E5,
typename E6>
struct valist_aggregator< mlc::valist_ <E1,E2,E3,E4,E5,E6> > :
- public E1, public E2, public E3, public E4, public E5,
- public E6
+ virtual public E1, virtual public E2, virtual public E3,
+ virtual public E4, virtual public E5, virtual public E6
{
};
@@ -109,8 +111,9 @@
template <typename E1, typename E2, typename E3, typename E4, typename E5,
typename E6, typename E7>
struct valist_aggregator< mlc::valist_ <E1,E2,E3,E4,E5,E6,E7> > :
- public E1, public E2, public E3, public E4, public E5,
- public E6, public E7
+ virtual public E1, virtual public E2, virtual public E3,
+ virtual public E4, virtual public E5, virtual public E6,
+ virtual public E7
{
};
@@ -118,8 +121,9 @@
template <typename E1, typename E2, typename E3, typename E4, typename E5,
typename E6, typename E7, typename E8>
struct valist_aggregator< mlc::valist_ <E1,E2,E3,E4,E5,E6,E7,E8> > :
- public E1, public E2, public E3, public E4, public E5,
- public E6, public E7, public E8
+ virtual public E1, virtual public E2, virtual public E3,
+ virtual public E4, virtual public E5, virtual public E6,
+ virtual public E7, virtual public E8
{
};
@@ -127,8 +131,9 @@
template <typename E1, typename E2, typename E3, typename E4, typename E5,
typename E6, typename E7, typename E8, typename E9>
struct valist_aggregator< mlc::valist_ <E1,E2,E3,E4,E5,E6,E7,E8,E9> > :
- public E1, public E2, public E3, public E4, public E5,
- public E6, public E7, public E8, public E9
+ virtual public E1, virtual public E2, virtual public E3,
+ virtual public E4, virtual public E5, virtual public E6,
+ virtual public E7, virtual public E8, virtual public E9
{
};
/// \}
1
0
04 Sep '06
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add a wrapper around mlc::assert_ returning a given type.
* mlc/assert.hh (assert_and_return_): New class.
assert.hh | 27 +++++++++++++++++++++++++++
contract.hh | 1 +
2 files changed, 28 insertions(+)
Index: mlc/assert.hh
--- mlc/assert.hh (revision 516)
+++ mlc/assert.hh (working copy)
@@ -226,6 +226,33 @@
};
+
+ /*! \class mlc::assert_and_return_<bexpr, ret_type, err>
+ **
+ ** Check a static property over \a bexpr, and return \a ret_type as \a ret
+ ** in case of success. Otherwise, raise a compile-time error.
+ ** \a err can be used to report a meaningful error message to the
+ ** programmer.
+ **
+ ** This is a convenient class used to improve the readability of meta
+ ** programs.
+ */
+
+ template <typename bexpr, typename ret_type, typename err = no_error_message>
+ struct assert_and_return_ :
+ public virtual internal::check_<bexpr, typename bexpr::is_true>
+ {
+ public:
+ /// The return type of this assert_and_return_ statement.
+ typedef ret_type ret;
+
+ virtual ~assert_and_return_() {}
+
+ protected:
+ assert_and_return_() {}
+ };
+
+
} // end of namespace mlc
Index: mlc/contract.hh
--- mlc/contract.hh (revision 516)
+++ mlc/contract.hh (working copy)
@@ -41,6 +41,7 @@
# define precondition(expr) assert(expr)
# define postcondition(expr) assert(expr)
+// FIXME: Shouln't we move these macros into Static?
# define mlc_check_method_impl(WHERE, RETURN, NAME, ARG, CONST) \
{ \
1
0
2006-09-01 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* xtd/optraits.hh
(xtd_op_eq_trait_, xtd_op_neq_trait_): New.
(xtd_op_less_trait_, xtd_op_leq_trait_): New.
(xtd_op_greater_trait_, xtd_op_geq_trait_): New.
* xtd/vec.hh: Replace assert by contract macros.
(operator<<): New.
(lexi_less_t, lexi_less): New.
2
1
2006-09-01 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* oln/core/abstract/piter.hh (to_point): New.
* oln/core/abstract/bbox.hh (pmin, pmax): New overloaded methods.
(is_valid, print, operator<<): New.
* oln/core/abstract/iter.hh (iter): Change inheritance from
any__simple to any__best_memory to fix trouble with multiple
inheritance.
(ctor): Remove dangerous call to invalidate.
* oln/core/abstract/point_nd.hh (operator<<): New.
(impl_less): Update.
* oln/core/abstract/pset.hh (coord_type): New.
* oln/core/2d/point2d.hh (coord_t): Move to public so that this
associated type is directly accessible from...
* oln/core/gen/bbox.hh (vtypes): ...this set of types.
* oln/core/gen/fwd_piter.hh (psup_): Remove.
(bbox): New accessor.
(impl_next): Rewrite.
(print, operator<<): New.
(invariant): Strengthen.
* oln/core/gen/bkd_piter.hh: Likewise.
Index: oln/core/abstract/piter.hh
===================================================================
--- oln/core/abstract/piter.hh (revision 515)
+++ oln/core/abstract/piter.hh (working copy)
@@ -74,6 +74,12 @@
return p_;
}
+ point_t to_point() const
+ {
+ precondition(this->is_valid());
+ return p_;
+ }
+
protected:
point_t p_;
Index: oln/core/abstract/bbox.hh
===================================================================
--- oln/core/abstract/bbox.hh (revision 515)
+++ oln/core/abstract/bbox.hh (working copy)
@@ -59,6 +59,7 @@
{
typedef E exact_t;
typedef oln_type_of(E, point) point_t;
+ typedef oln_type_of(E, coord) coord_t;
typedef oln_type_of(point_t, dim) dim;
enum { n = mlc_value(dim) };
@@ -79,12 +80,24 @@
return pmin_;
}
+ coord_t pmin(unsigned i) const
+ {
+ precondition(is_valid_ and i < n);
+ return pmin_[i];
+ }
+
const point_t& pmax() const
{
precondition(is_valid_);
return pmax_;
}
+ coord_t pmax(unsigned i) const
+ {
+ precondition(is_valid_ and i < n);
+ return pmax_[i];
+ }
+
unsigned size(unsigned i) const
{
precondition(is_valid_ and i < n);
@@ -148,6 +161,26 @@
return true;
}
+ bool is_valid() const
+ {
+ return is_valid_;
+ }
+
+ void print(std::ostream& ostr) const
+ {
+ ostr << "{ pmin=" << pmin_
+ << ", pmax=" << pmax_
+ << ", valid=" << is_valid_
+ << " }";
+ }
+
+ friend
+ std::ostream& operator<<(std::ostream& ostr, const abstract::bbox<E>& bb)
+ {
+ bb.print(ostr);
+ return ostr;
+ }
+
// FIXME: Add the scool code below.
// invariant {
Index: oln/core/abstract/iter.hh
===================================================================
--- oln/core/abstract/iter.hh (revision 515)
+++ oln/core/abstract/iter.hh (working copy)
@@ -41,7 +41,7 @@
/// Abstract iterator class.
template <typename E>
- class iter : public stc::any__simple<E>,
+ class iter : public stc::any__best_memory<E>,
public oln::type
{
public:
@@ -71,7 +71,6 @@
iter()
{
- this->invalidate();
}
}; // end of class oln::abstract::iter<E>
Index: oln/core/abstract/point_nd.hh
===================================================================
--- oln/core/abstract/point_nd.hh (revision 515)
+++ oln/core/abstract/point_nd.hh (working copy)
@@ -97,7 +97,7 @@
bool impl_less(const self_t& rhs) const
{
- return xtd::lexi(v_, rhs.vec());
+ return xtd::lexi_less(v_, rhs.vec());
}
E& impl_plus_equal(const dpoint_t& rhs)
@@ -153,7 +153,15 @@
} // end of namespace oln::abstract
+ template <typename E>
+ std::ostream& operator<<(std::ostream& ostr, const abstract::point_nd<E>& p)
+ {
+ ostr << p.vec();
+ return ostr;
+ }
+
+
/// abstract::point_nd + abstract::dpoint_nd
template <typename P, typename D>
struct case_ < xtd::op_plus, mlc::pair_<P,D>,
Index: oln/core/abstract/pset.hh
===================================================================
--- oln/core/abstract/pset.hh (revision 515)
+++ oln/core/abstract/pset.hh (working copy)
@@ -49,6 +49,7 @@
typedef mlc::undefined point_type;
typedef mlc::undefined fwd_piter_type;
typedef mlc::undefined bkd_piter_type;
+ typedef mlc::undefined coord_type;
// FIXME: Add grid.
};
Index: oln/core/2d/point2d.hh
===================================================================
--- oln/core/2d/point2d.hh (revision 515)
+++ oln/core/2d/point2d.hh (working copy)
@@ -60,13 +60,13 @@
{
typedef point2d_<C> self_t;
typedef abstract::point_nd<self_t> super_t;
- typedef oln_type_of(self_t, coord) coord_t;
using super_t::v_;
public:
// Cf. BUG! typedef oln_type_of(self_t, grid) grid_t;
+ typedef oln_type_of(self_t, coord) coord_t;
/// Ctor.
point2d_()
Index: oln/core/gen/fwd_piter.hh
===================================================================
--- oln/core/gen/fwd_piter.hh (revision 515)
+++ oln/core/gen/fwd_piter.hh (working copy)
@@ -78,52 +78,65 @@
{
nop_ = bb_.pmax();
++nop_[0];
-
- psup_ = bb_.pmax().vec();
- for (unsigned i = 0; i < point::n; ++i)
- ++psup_[i];
}
-
+
+ const bbox_<point>& bbox() const
+ {
+ return bb_;
+ }
+
void impl_start()
{
p_ = bb_.pmin();
- invariant(p_ <= nop_);
+ invariant(implies(p_ != nop_, bb_.has(p_)));
}
void impl_next()
{
- invariant(p_ <= nop_);
- ++p_[0];
- unsigned i = 0;
- while (i + 1 < point::n)
+ invariant(implies(p_ != nop_, bb_.has(p_)));
+ for (int i = point::n - 1; i >= 0; --i)
+ if (p_[i] == bb_.pmax(i))
+ p_[i] = bb_.pmin(i);
+ else
{
- if (p_[i] == psup_[i])
- {
- p_[i] = bb_.pmin_[i];
- ++p_[i+1];
- }
- ++i;
+ ++p_[i];
+ break;
}
- invariant(p_ <= nop_);
+ if (p_ == bb_.pmin())
+ p_ = nop_;
}
void impl_invalidate()
{
- invariant(p_ <= nop_);
+ invariant(implies(p_ != nop_, bb_.has(p_)));
p_ = nop_;
}
bool impl_is_valid() const
{
- invariant(p_ <= nop_);
+ invariant(implies(p_ != nop_, bb_.has(p_)));
return p_ != nop_;
}
+ void print(std::ostream& ostr) const
+ {
+ ostr << "{ bb=" << bb_
+ << ", p=" << p_
+ << ", nop=" << nop_
+ << " }";
+ }
+
+ friend
+ std::ostream& operator<<(std::ostream& ostr, const fwd_piter_<point>& i)
+ {
+ i.print(ostr);
+ return ostr;
+ }
+
protected:
bbox_<point> bb_;
point nop_;
- point psup_;
}; // end of class oln::fwd_piter_<point>
Index: oln/core/gen/bkd_piter.hh
===================================================================
--- oln/core/gen/bkd_piter.hh (revision 515)
+++ oln/core/gen/bkd_piter.hh (working copy)
@@ -75,65 +75,54 @@
bkd_piter_(const bbox_<point>& bb)
: bb_(bb)
- {
- nop_ = bb_.pmax();
- ++nop_[0];
+ {
+ nop_ = bb_.pmin();
+ --nop_[0];
+ }
- psup_ = bb_.pmax().vec();
- for (unsigned i = 0; i < point::n; ++i)
- ++psup_[i];
- }
+ const bbox_<point>& bbox() const
+ {
+ return bb_;
+ }
void impl_start()
- {
- p_ = bb_.pmin();
- }
+ {
+ p_ = bb_.pmax();
+ invariant(implies(p_ != nop_, bb_.has(p_)));
+ }
void impl_next()
- {
- assert(this->is_valid());
- ++p_[0];
- unsigned i = 0;
- while (i + 1 < point::n)
- {
- if (p_[i] == psup_[i])
- {
- p_[i] = bb_.pmin_[i];
- ++p_[i+1];
- }
- ++i;
- }
- }
+ {
+ invariant(implies(p_ != nop_, bb_.has(p_)));
+ for (int i = point::n - 1; i >= 0; --i)
+ if (p_[i] == bb_.pmin(i))
+ p_[i] = bb_.pmax(i);
+ else
+ {
+ --p_[i];
+ break;
+ }
+ if (p_ == bb_.pmax())
+ p_ = nop_;
+ }
-// def next =
-// {
-// precondition { is_valid }
-// }
-
void impl_invalidate()
- {
- assert(this->is_valid());
- p_ = nop_;
- }
+ {
+ invariant(implies(p_ != nop_, bb_.has(p_)));
+ p_ = nop_;
+ }
bool impl_is_valid() const
- {
- return p_ != nop_;
- }
+ {
+ invariant(implies(p_ != nop_, bb_.has(p_)));
+ return p_ != nop_;
+ }
protected:
bbox_<point> bb_;
point nop_;
- point psup_;
-// invariant
-// {
-// p <= nop
-// }
-
-// make : [D : type] (data : D) = { @bb = data.bbox }
-
}; // end of class oln::bkd_piter_<point>
Index: oln/core/gen/bbox.hh
===================================================================
--- oln/core/gen/bbox.hh (revision 515)
+++ oln/core/gen/bbox.hh (working copy)
@@ -58,6 +58,7 @@
typedef point point_type;
typedef fwd_piter_<point> fwd_piter_type;
typedef bkd_piter_<point> bkd_piter_type;
+ typedef typename point::coord_t coord_type;
// BUG! typedef oln_type_of(point, grid) grid_type;
// BUG! typedef typename point::grid_t grid_type;
};
1
0