Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add generalised_point concept.
* tests/core/sparse_image.cc,
* tests/core/rle_image.cc: remove print from tests.
* oln/core/rle/rle_pset.hh, oln/core/concept/iterator_on_points.hh,
* oln/core/gen/dpoints_piter.hh, oln/core/internal/box.hh,
* oln/core/internal/piter_adaptor.hh: there are now derived from iterator_on_point_base
class.
* oln/core/concept/iterator.hh: add virtual for diamond inheritance.
* oln/core/concept/point.hh: remove useless traits declarations.
(there are now declare in generalised_point_class).
* oln/core/concept/generalised_point.hh: New, generalised_point class.
* oln/core/internal/image_base.hh: remove dead code.
* oln/core/internal/iterator_on_points_base.hh: New iterator_on_point_base class for
factorize some code on point iterators.
oln/core/concept/generalised_point.hh | 68 ++++++++++++++++++
oln/core/concept/iterator.hh | 2
oln/core/concept/iterator_on_points.hh | 5 +
oln/core/concept/point.hh | 12 +--
oln/core/gen/dpoints_piter.hh | 9 +-
oln/core/internal/box.hh | 9 +-
oln/core/internal/image_base.hh | 2
oln/core/internal/iterator_on_points_base.hh | 97 +++++++++++++++++++++++++++
oln/core/internal/piter_adaptor.hh | 8 +-
oln/core/rle/rle_pset.hh | 14 +--
tests/core/rle_image.cc | 45 ------------
tests/core/sparse_image.cc | 37 ----------
12 files changed, 196 insertions(+), 112 deletions(-)
Index: tests/core/sparse_image.cc
--- tests/core/sparse_image.cc (revision 911)
+++ tests/core/sparse_image.cc (working copy)
@@ -6,37 +6,6 @@
#include <oln/core/sparse/sparse_image.hh>
#include <oln/core/encode/sparse_encode.hh>
-template <typename Ps>
-void test(const Ps& pset)
-{
- typename Ps::fwd_piter it (pset);
-
- for (it.start(); it.is_valid(); it.next())
- std::cout << it.to_point() << std::endl;
-}
-
-template <typename Ps>
-void rtest(const Ps& pset)
-{
- typename Ps::bkd_piter it (pset);
-
- for (it.start(); it.is_valid(); it.next())
- std::cout << it.to_point() << std::endl;
-}
-
-
- template <typename I>
- void print(I& ima)
-{
- typename I::piter it (ima.points());
-
- for (it.start(); it.is_valid(); it.next())
- {
- std::cout << (oln::point2d) it << std::endl;
- std::cout << ima(it) << std::endl;
- }
-}
-
int main()
{
@@ -46,7 +15,6 @@
oln::sparse_image<oln::point2d, int> sparse2;
ima2d(oln::point2d(0, 4)) = 5;
- oln::debug::print(ima2d);
std::vector<int> values;
int a =5;
@@ -58,12 +26,7 @@
sparse.insert(q, 3, values);
- oln::debug::print(sparse);
-
- std::cout << "encode sparse" << std::endl;
sparse2 = sparse_encode(ima2d);
- oln::debug::print(sparse2);
-
return 0;
}
Index: tests/core/rle_image.cc
--- tests/core/rle_image.cc (revision 911)
+++ tests/core/rle_image.cc (working copy)
@@ -7,38 +7,6 @@
#include <oln/core/encode/rle_encode.hh>
-template <typename Ps>
-void test(const Ps& pset)
-{
- typename Ps::fwd_piter it (pset);
-
- for (it.start(); it.is_valid(); it.next())
- std::cout << it.to_point() << std::endl;
-}
-
-template <typename Ps>
-void rtest(const Ps& pset)
-{
- typename Ps::bkd_piter it (pset);
-
- for (it.start(); it.is_valid(); it.next())
- std::cout << it.to_point() << std::endl;
-}
-
-
- template <typename I>
- void print(I& ima)
-{
- typename I::piter it (ima.points());
-
- for (it.start(); it.is_valid(); it.next())
- {
- std::cout << (oln::point2d) it << std::endl;
- std::cout << ima(it) << std::endl;
- }
-}
-
-
int main()
{
oln::point2d p(0,1), q(2,2), r(3, 0);
@@ -51,24 +19,11 @@
rle.insert(p, 5, 4);
rle.insert(q, 8, 9);
- std::cout << my_set.has(q) << std::endl;
- test(my_set);
- std::cout << "reverse" << std::endl;
- rtest(my_set);
- std::cout << "ima" << std::endl;
- print(rle);
- oln::debug::print(rle);
- std::cout << rle.points().npoints() << std::endl;
-
- std::cout << "encode rle" << std::endl;
oln::image2d<int> ima2d (1, 5);
ima2d(oln::point2d(0, 4)) = 5;
- oln::debug::print(ima2d);
-
rle2 = rle_encode(ima2d);
- oln::debug::print(rle2);
return 0;
}
Index: oln/core/rle/rle_pset.hh
--- oln/core/rle/rle_pset.hh (revision 911)
+++ oln/core/rle/rle_pset.hh (working copy)
@@ -35,7 +35,7 @@
# include <oln/core/internal/point_set_base.hh>
-# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
# include <oln/core/gen/fbbox.hh>
@@ -190,7 +190,7 @@
struct super_trait_< rle_pset_fwd_piter_<P> >
{
typedef rle_pset_fwd_piter_<P> current;
- typedef Iterator_on_Points<current> ret;
+ typedef internal::iterator_on_points_base<current> ret;
};
// Virtual types
@@ -208,9 +208,9 @@
** P must be a point type
*/
template <typename P>
- class rle_pset_fwd_piter_ : public Iterator_on_Points<rle_pset_fwd_piter_<P>
>
+ class rle_pset_fwd_piter_ : public
internal::iterator_on_points_base<rle_pset_fwd_piter_<P> >
{
- typedef Iterator_on_Points< rle_pset_fwd_piter_<P> > super;
+ typedef internal::iterator_on_points_base< rle_pset_fwd_piter_<P> >
super;
typedef rle_pset_fwd_piter_<P> current;
public:
stc_using(point);
@@ -328,7 +328,7 @@
struct super_trait_< rle_pset_bkd_piter_<P> >
{
typedef rle_pset_bkd_piter_<P> current;
- typedef Iterator_on_Points<current> ret;
+ typedef internal::iterator_on_points_base<current> ret;
};
// Virtual type
@@ -345,9 +345,9 @@
** P must be a point type
*/
template <typename P>
- class rle_pset_bkd_piter_ : public Iterator_on_Points<rle_pset_bkd_piter_<P>
>
+ class rle_pset_bkd_piter_ : public
internal::iterator_on_points_base<rle_pset_bkd_piter_<P> >
{
- typedef Iterator_on_Points< rle_pset_bkd_piter_<P> > super;
+ typedef internal::iterator_on_points_base< rle_pset_bkd_piter_<P> >
super;
typedef rle_pset_bkd_piter_<P> current;
public:
stc_using(point);
Index: oln/core/concept/iterator_on_points.hh
--- oln/core/concept/iterator_on_points.hh (revision 911)
+++ oln/core/concept/iterator_on_points.hh (working copy)
@@ -30,6 +30,8 @@
# define OLN_CORE_CONCEPT_ITERATOR_ON_POINTS_HH
# include <ostream>
+
+# include <oln/core/concept/generalised_point.hh>
# include <oln/core/concept/iterator.hh>
# include <oln/core/concept/point.hh>
@@ -40,7 +42,8 @@
/// Concept-class "Iterator_on_Points".
template <typename Exact>
- struct Iterator_on_Points : public Iterator<Exact>
+ struct Iterator_on_Points : public Iterator<Exact>,
+ virtual public Generalised_Point<Exact>
{
stc_typename(point);
Index: oln/core/concept/iterator.hh
--- oln/core/concept/iterator.hh (revision 911)
+++ oln/core/concept/iterator.hh (working copy)
@@ -44,7 +44,7 @@
/// Concept-class "Iterator".
template <typename Exact>
- struct Iterator : public Any<Exact>
+ struct Iterator : virtual public Any<Exact>
{
void start();
void next();
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 911)
+++ oln/core/concept/point.hh (working copy)
@@ -30,11 +30,14 @@
# define OLN_CORE_CONCEPT_POINT_HH
# include <mlc/value.hh>
+
+# include <oln/core/concept/generalised_point.hh>
# include <oln/core/concept/grid.hh>
# include <oln/core/concept/operators.hh>
+
namespace oln
{
/// Instant value.
@@ -44,14 +47,9 @@
/// Concept-class "Point".
template <typename Exact>
- struct Point : public Any<Exact>
+ struct Point : public Generalised_Point<Exact>
{
- stc_typename(grid);
- stc_typename(dim);
- stc_typename(coord);
- stc_typename(dpoint);
-
- enum { n = mlc_value(dim) };
+ stc_using_from(Generalised_Point, dpoint);
/// Operator ==.
bool op_equal_(const Exact& rhs) const;
Index: oln/core/concept/generalised_point.hh
--- oln/core/concept/generalised_point.hh (revision 0)
+++ oln/core/concept/generalised_point.hh (revision 0)
@@ -0,0 +1,68 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
+# define OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
+
+namespace oln
+{
+
+ /// FIXME: Instant value.
+ // oln_decl_instant_value(point);
+
+
+ // Generalised_Point concept
+
+ template <typename Exact>
+ struct Generalised_Point : virtual public Any<Exact>
+ {
+ stc_typename(grid);
+ stc_typename(dim);
+ stc_typename(coord);
+ stc_typename(dpoint);
+
+ enum { n = mlc_value(dim) };
+
+ protected:
+ Generalised_Point();
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Generalised_Point<Exact>::Generalised_Point()
+ {
+ };
+
+
+# endif // OLN_INCLUDE_ONLY
+
+}
+
+#endif // !OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 911)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -31,6 +31,7 @@
# include <oln/core/concept/window.hh>
# include <oln/core/concept/neighborhood.hh>
# include <oln/core/concept/image.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
# include <oln/core/internal/dpoints_piter_impl.hh>
@@ -51,7 +52,7 @@
struct super_trait_< dpoints_fwd_piter_<P> >
{
typedef dpoints_fwd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
@@ -65,7 +66,7 @@
// Forward point iterator class on a set of dpoints.
template <typename P>
- class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P>
>,
+ class dpoints_fwd_piter_ : public internal::iterator_on_points_base<
dpoints_fwd_piter_<P> >,
public internal::dpoints_fwd_piter_impl_<P>
{
public:
@@ -98,7 +99,7 @@
struct super_trait_< dpoints_bkd_piter_<P> >
{
typedef dpoints_bkd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
@@ -112,7 +113,7 @@
/// Backward point iterator class on a set of dpoints.
template <typename P>
- class dpoints_bkd_piter_ : public Iterator_on_Points< dpoints_bkd_piter_<P>
>,
+ class dpoints_bkd_piter_ : public internal::iterator_on_points_base<
dpoints_bkd_piter_<P> >,
public internal::dpoints_bkd_piter_impl_<P>
{
public:
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 911)
+++ oln/core/internal/box.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_CORE_INTERNAL_BOX_HH
# include <oln/core/internal/point_set_base.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
namespace oln
@@ -116,14 +117,14 @@
struct super_trait_< box_fwd_piter_<B> >
{
typedef box_fwd_piter_<B> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
template <typename B>
struct super_trait_<box_bkd_piter_<B> >
{
typedef box_bkd_piter_<B> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
@@ -145,7 +146,7 @@
/// Class box_fwd_piter_<P>.
template <typename B>
- class box_fwd_piter_ : public Iterator_on_Points< box_fwd_piter_<B> >,
+ class box_fwd_piter_ : public internal::iterator_on_points_base<
box_fwd_piter_<B> >,
private mlc::assert_< mlc_is_a(B, Point_Set) >
{
typedef box_fwd_piter_<B> current;
@@ -171,7 +172,7 @@
/// Class box_bkd_piter_<B>.
template <typename B>
- class box_bkd_piter_ : public Iterator_on_Points< box_bkd_piter_<B> >,
+ class box_bkd_piter_ : public internal::iterator_on_points_base<
box_bkd_piter_<B> >,
private mlc::assert_< mlc_is_a(B, Point_Set) >
{
typedef box_bkd_piter_<B> current;
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 911)
+++ oln/core/internal/image_base.hh (working copy)
@@ -148,8 +148,6 @@
// Final.
typedef stc::final< stc::is<Image> > category;
- // FIXME:
- //typedef stc::final< box_<point__> > box;
typedef stc::final <typename pset__::box> box;
typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< oln_dpoint(point__) > dpoint;
Index: oln/core/internal/piter_adaptor.hh
--- oln/core/internal/piter_adaptor.hh (revision 911)
+++ oln/core/internal/piter_adaptor.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
# define OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
-# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
namespace oln
@@ -43,7 +43,7 @@
template <typename Exact>
struct super_trait_< internal::piter_adaptor_<Exact> >
{
- typedef Iterator_on_Points<Exact> ret;
+ typedef internal::iterator_on_points_base<Exact> ret;
};
@@ -65,9 +65,9 @@
// defined over other types of iterator on points.
template <typename Exact>
- class piter_adaptor_ : public Iterator_on_Points<Exact>
+ class piter_adaptor_ : public internal::iterator_on_points_base<Exact>
{
- typedef Iterator_on_Points<Exact> super;
+ typedef internal::iterator_on_points_base<Exact> super;
public:
stc_using(point);
Index: oln/core/internal/iterator_on_points_base.hh
--- oln/core/internal/iterator_on_points_base.hh (revision 0)
+++ oln/core/internal/iterator_on_points_base.hh (revision 0)
@@ -0,0 +1,97 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_BASE_HH
+# define OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_BASE_HH
+
+# include <oln/core/concept/iterator_on_points.hh>
+
+namespace oln
+{
+
+ // implementation
+
+
+ // Forward Declarations
+
+ namespace internal {
+ template <typename Exact>
+ struct iterator_on_points_base;
+ };
+
+ // Super type
+
+ template <typename Exact>
+ struct super_trait_< internal::iterator_on_points_base<Exact> >
+ {
+ typedef Iterator_on_Points<Exact> ret;
+ };
+
+ // Virtual types
+
+ template <typename Exact>
+ struct vtypes< internal::iterator_on_points_base<Exact> >
+ {
+ typedef stc::abstract point;
+
+ typedef stc_deferred(point) point__;
+ typedef stc::final<typename point__::grid> grid;
+ typedef stc::final<typename point__::coord> coord;
+ typedef stc::final<typename point__::dim> dim;
+ typedef stc::final<typename point__::dpoint> dpoint;
+ };
+
+
+
+namespace internal
+{
+ // iterator_on_points_base class
+
+ template <typename Exact>
+ class iterator_on_points_base : public Iterator_on_Points<Exact>
+ {
+
+ protected:
+ iterator_on_points_base();
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ iterator_on_points_base<Exact>::iterator_on_points_base()
+ {
+ }
+
+# endif // !OLN_INCLUDE_ONLY
+}
+
+
+
+}
+
+#endif // !OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_BASE_HH