Commit 3a5c881c authored by Roland Levillain's avatar Roland Levillain
Browse files

Fix mini-oln and its Concept-C++ counterpart.

	* samples/mini-oln/mini-oln.cc,
	(oln::Image_with_neighborhood::niter_t): New typedef.
	(oln::iterator2d::impl_op_point_t)
	(oln::iterator2d::impl_op_paren): Rename as...
	(oln::iterator2d::impl_op_point_type)
	(oln::iterator2d::impl_op_parens): ...this.

	* samples/mini-oln/mini-oln.cc,
	* samples/mini-oln/concept-c++/mini-oln.cc:
	(oln::Image::operator(), oln::Image2d::operator())
	(oln::Image3d::operator()):  Fix the delegations.
	(oln::set_super_type< image_base<E> >::ret): Set to mlc::none.
	(oln::image2d::self_t): New typedef.
	(oln::image2d::point_t, oln::image2d::iter_t)
	(oln::image2d::value_t): Fix typedefs.

	* samples/mini-oln/concept-c++/mini-oln.cc: s/where/requires/
	(needed by recent revisions of SVN ConceptGCC).
	Declare typedefs used
	as virtual types at the beginning of the file
	(concepts): Rename namespace as...
	(oln::concepts): ...this.
	Group together abstractions on the one hand, and implementations
	on the other hand.
	(oln::image_with_nbh): Rename class as...
	(oln::Image_with_neighborhood): ...this.
	(oln::vtypes< Iterator<E> >, oln::vtypes< Image<E> >)
	(oln::vtypes<image_with_nbh>)
	(oln::set_super_type<Image2d>, oln::set_super_type<Image3d>,
	(oln::set_super_type<image_with_nbh>): Remove (useless and
	semantically wrong definitions).
	(oln::Iterator::point_t, oln::Image::point_t, Image::value_t)
	(oln::Image2d::point_t, oln::Image2d::value_t)
	(oln::Image3d::point_t, oln::Image3d::value_t)
	(oln::Image_with_neighborhood::nbh_t)
	(oln::Image_with_neighborhood::niter_t): Fix typedefs.
	(oln::Image::iter_t, oln::Image2d::iter_t, oln::Image3d::iter_t):
	Remove typedefs.
	(oln::Iterator::start, oln::Iterator::next)
	(oln::Iterator::is_valid, oln::Iterator::point_t)
	(oln::Image::has)
	(oln::Image2d::nrows_get, oln::Image2d::ncols_get)
	(oln::Image3d::nrows_get, oln::Image3d::ncols_get)
	(oln::Image3d::nslis_get, oln::Image_with_neighborhood nbh): Fix
	the delegations.

	* samples/mini-oln/concept-c++/mini-oln.cc
	(oln::image_dimension_switch): Inherit oln::Image<E> by default.
	(oln::vtypes< image_base<E> >::point_type)
	(oln::vtypes< image_base<E> >::iter_type)
	(oln::vtypes< image_base<E> >::value_type): Set to stc::abstract.
	(oln::vtypes< image_base<E> >::niter_type)
	(oln::vtypes< image_base<E> >::nbh_type): New typedefs.
	(oln::image_base::point_t, oln::image_base::iter_t)
	(oln::image_base::value_t): Remove typedefs.
	(oln::image_base::operator(), oln::image_base::has): Remove
	methods.
	(oln::image_base::image_base): Add ctor.

	* samples/mini-oln/concept-c++/mini-oln.cc
	(oln::set_super_type<iterator2d>::ret): Set to mlc::none.
	(oln::set_super_type<iterator2d>::start)
	(oln::set_super_type<iterator2d>::next)
	(oln::set_super_type<iterator2d>::is_valid)
	(oln::set_super_type<iterator2d>::operator point_t): Rename as...
	(oln::set_super_type<iterator2d>::impl_start)
	(oln::set_super_type<iterator2d>::impl_next)
	(oln::set_super_type<iterator2d>::impl_is_valid)
	(oln::set_super_type<iterator2d>::impl_op_point_type): ...these.
	(oln::image2d::operator(), oln::image2d::nrows_get)
	(oln::image2d::ncols_get, oln::image2d::has): Rename as...
	(oln::image2d::impl_op_parens, oln::image2d::impl_nrows_get)
	(oln::image2d::impl_ncols_get, oln::image2d::impl_has): Rename as...
	(oln::neighborhood2d): New class.
	(oln::set_super_type< image_morpher<E> >::ret): Set to
	image_base<E>.
	(oln::vtypes< image_morpher<E> >::delegatee_t): Set to
	stc::abstract.
	(oln::image_morpher): Inherit from image_base<E>.
	(oln::image_morpher::delegatee_t): Fix this typedef.
	(oln::set_super_type< image_morpher < plus<I, N> > >): Turn
	into...
	(oln::set_super_type< plus<I, N> >): ...this.
	(oln::vtypes< plus<I, N> >::delegatee_t): Rename as...
	(oln::vtypes< plus<I, N> >::delegatee_type): ...this.
	(oln::vtypes< plus<I, N> >::nbh_type)
	(oln::vtypes< plus<I, N> >::niter_type): New typedefs.
	(oln::plus::self_t, oln::plus::super_t): New typedefs.
	(oln::plus::plus): Pass the equipped image to the ctor of the super
	class.
	(oln::plus::impl_nbh): New accessor.
	(main): Rewrite the test.

	* samples/mini-oln/concept-c++/Makefile.am: Disable mini-oln.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@841 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 1785bfd4
2007-03-01 Roland Levillain <roland@lrde.epita.fr>
Fix mini-oln and its Concept-C++ counterpart.
* samples/mini-oln/mini-oln.cc,
(oln::Image_with_neighborhood::niter_t): New typedef.
(oln::iterator2d::impl_op_point_t)
(oln::iterator2d::impl_op_paren): Rename as...
(oln::iterator2d::impl_op_point_type)
(oln::iterator2d::impl_op_parens): ...this.
* samples/mini-oln/mini-oln.cc,
* samples/mini-oln/concept-c++/mini-oln.cc:
(oln::Image::operator(), oln::Image2d::operator())
(oln::Image3d::operator()): Fix the delegations.
(oln::set_super_type< image_base<E> >::ret): Set to mlc::none.
(oln::image2d::self_t): New typedef.
(oln::image2d::point_t, oln::image2d::iter_t)
(oln::image2d::value_t): Fix typedefs.
* samples/mini-oln/concept-c++/mini-oln.cc: s/where/requires/
(needed by recent revisions of SVN ConceptGCC).
Declare typedefs used
as virtual types at the beginning of the file
(concepts): Rename namespace as...
(oln::concepts): ...this.
Group together abstractions on the one hand, and implementations
on the other hand.
(oln::image_with_nbh): Rename class as...
(oln::Image_with_neighborhood): ...this.
(oln::vtypes< Iterator<E> >, oln::vtypes< Image<E> >)
(oln::vtypes<image_with_nbh>)
(oln::set_super_type<Image2d>, oln::set_super_type<Image3d>,
(oln::set_super_type<image_with_nbh>): Remove (useless and
semantically wrong definitions).
(oln::Iterator::point_t, oln::Image::point_t, Image::value_t)
(oln::Image2d::point_t, oln::Image2d::value_t)
(oln::Image3d::point_t, oln::Image3d::value_t)
(oln::Image_with_neighborhood::nbh_t)
(oln::Image_with_neighborhood::niter_t): Fix typedefs.
(oln::Image::iter_t, oln::Image2d::iter_t, oln::Image3d::iter_t):
Remove typedefs.
(oln::Iterator::start, oln::Iterator::next)
(oln::Iterator::is_valid, oln::Iterator::point_t)
(oln::Image::has)
(oln::Image2d::nrows_get, oln::Image2d::ncols_get)
(oln::Image3d::nrows_get, oln::Image3d::ncols_get)
(oln::Image3d::nslis_get, oln::Image_with_neighborhood nbh): Fix
the delegations.
* samples/mini-oln/concept-c++/mini-oln.cc
(oln::image_dimension_switch): Inherit oln::Image<E> by default.
(oln::vtypes< image_base<E> >::point_type)
(oln::vtypes< image_base<E> >::iter_type)
(oln::vtypes< image_base<E> >::value_type): Set to stc::abstract.
(oln::vtypes< image_base<E> >::niter_type)
(oln::vtypes< image_base<E> >::nbh_type): New typedefs.
(oln::image_base::point_t, oln::image_base::iter_t)
(oln::image_base::value_t): Remove typedefs.
(oln::image_base::operator(), oln::image_base::has): Remove
methods.
(oln::image_base::image_base): Add ctor.
* samples/mini-oln/concept-c++/mini-oln.cc
(oln::set_super_type<iterator2d>::ret): Set to mlc::none.
(oln::set_super_type<iterator2d>::start)
(oln::set_super_type<iterator2d>::next)
(oln::set_super_type<iterator2d>::is_valid)
(oln::set_super_type<iterator2d>::operator point_t): Rename as...
(oln::set_super_type<iterator2d>::impl_start)
(oln::set_super_type<iterator2d>::impl_next)
(oln::set_super_type<iterator2d>::impl_is_valid)
(oln::set_super_type<iterator2d>::impl_op_point_type): ...these.
(oln::image2d::operator(), oln::image2d::nrows_get)
(oln::image2d::ncols_get, oln::image2d::has): Rename as...
(oln::image2d::impl_op_parens, oln::image2d::impl_nrows_get)
(oln::image2d::impl_ncols_get, oln::image2d::impl_has): Rename as...
(oln::neighborhood2d): New class.
(oln::set_super_type< image_morpher<E> >::ret): Set to
image_base<E>.
(oln::vtypes< image_morpher<E> >::delegatee_t): Set to
stc::abstract.
(oln::image_morpher): Inherit from image_base<E>.
(oln::image_morpher::delegatee_t): Fix this typedef.
(oln::set_super_type< image_morpher < plus<I, N> > >): Turn
into...
(oln::set_super_type< plus<I, N> >): ...this.
(oln::vtypes< plus<I, N> >::delegatee_t): Rename as...
(oln::vtypes< plus<I, N> >::delegatee_type): ...this.
(oln::vtypes< plus<I, N> >::nbh_type)
(oln::vtypes< plus<I, N> >::niter_type): New typedefs.
(oln::plus::self_t, oln::plus::super_t): New typedefs.
(oln::plus::plus): Pass the equipped image to the ctor of the super
class.
(oln::plus::impl_nbh): New accessor.
(main): Rewrite the test.
* samples/mini-oln/concept-c++/Makefile.am: Disable mini-oln.
2007-02-15 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Add some slides that present the SCOOP 2 paradigm.
......@@ -971,3 +1070,6 @@
(stc_set_pseudosuper, stc_pseudosuper, stc_pseudosuper_): New
macros.
* tests/properties.cc: Adjust.
LocalWords: typedefs oln ncols nrows typedef
\ No newline at end of file
......@@ -14,8 +14,10 @@ AM_CXXFLAGS = $(TESTS_CXXFLAGS)
# Hacky.
CXX = @CONCEPTCXX@
check_PROGRAMS = mini-oln
# FIXME: Disabled, since ConceptGCC fails to compile this sample
# (dying with an Internal Compiler Error).
mini_oln_SOURCES = mini-oln.cc
# check_PROGRAMS = mini-oln
# mini_oln_SOURCES = mini-oln.cc
TESTS = $(check_PROGRAMS)
# TESTS = $(check_PROGRAMS)
......@@ -37,9 +37,13 @@
#include <stc/scoop.hh>
/*-------------.
| Equipement. |
`-------------*/
// Helper macros.
#define oln_type_of_(FromType, Alias) \
oln::find_vtype<FromType, oln::typedef_:: Alias##_type>::ret
find_vtype<FromType, oln::typedef_:: Alias##_type>::ret
#define oln_type_of(FromType, Alias) \
typename oln_type_of_(FromType, Alias)
......@@ -48,418 +52,370 @@
stc_scoop_equipment_for_namespace(oln);
mlc_case_equipment_for_namespace(oln);
// Virtual types declaration.
namespace oln
{
mlc_decl_typedef(point_type);
mlc_decl_typedef(iter_type);
mlc_decl_typedef(value_type);
mlc_decl_typedef(nbh_type);
mlc_decl_typedef(niter_type);
}
/*-----------.
| Concepts. |
`-----------*/
namespace concepts
namespace oln
{
// These concepts are not automatic (i.e., prefixed with `auto'),
// since we cannot rely on type signatures for them. For instance,
// using only structural conformance, oln::point3d could be a model
// of concepts::Point2d!
concept Point2d<typename P>
{
typename coord_type;
// For simplicity purpose, the canonical model of
// concepts::Point2d -- oln::point2d -- does not expose its
// interface through methods (that's bad OO software engineering
// practice, but hey, we're just prototyping here). Therefore we
// cannot express sigatures on row and col accesses, since C++0x
// concepts forbid attribute (member) signatures.
};
concept Point3d<typename P>
namespace concepts
{
typename coord_type;
// Same remark as above for concepts::Point2d regarding member
// signatures.
};
// These concepts are not automatic (i.e., prefixed with `auto'),
// since we cannot rely on type signatures for them. For instance,
// using only structural conformance, oln::point3d could be a model
// of concepts::Point2d!
concept Point2d<typename P>
{
typename coord_type;
// For simplicity purpose, the canonical model of
// concepts::Point2d -- oln::point2d -- does not expose its
// interface through methods (that's bad OO software engineering
// practice, but hey, we're just prototyping here). Therefore we
// cannot express sigatures on row and col accesses, since C++0x
// concepts forbid attribute (member) signatures.
};
auto concept Image<typename I>
{
typename point_t;
typename iter_t;
typename value_t;
concept Point3d<typename P>
{
typename coord_type;
// Same remark as above for concepts::Point2d regarding member
// signatures.
};
auto concept Image<typename I>
{
typename point_t;
typename iter_t;
typename value_t;
// ConceptGCC doesn't support operator signatures yet.
// ConceptGCC doesn't support operator signatures yet.
#if 0
value_t& I::operator ()(point_t&);
value_t& I::operator ()(point_t&);
#endif
bool I::has(const point_t&) const;
};
bool I::has(const point_t&) const;
};
auto concept Image2d<typename I> : Image<I>
{
int I::nrows_get() const;
int I::ncols_get() const;
};
auto concept Image2d<typename I> : Image<I>
{
int I::nrows_get() const;
int I::ncols_get() const;
};
auto concept Image3d<typename I> : Image<I>
{
int I::nrows_get() const;
int I::ncols_get() const;
int I::nslis_get() const;
};
}
auto concept Image3d<typename I> : Image<I>
{
int I::nrows_get() const;
int I::ncols_get() const;
int I::nslis_get() const;
};
} // End of namespace oln::concepts.
} // End of namespace oln.
/*-------------.
| Mini-Olena. |
`-------------*/
// ------- //
// Point. //
// ------- //
/*---------------.
| Abstractions. |
`---------------*/
namespace oln
{
// ------- //
// Point. //
// ------- //
template <typename E>
struct Point : public stc::any<E>
{
};
struct point2d : public Point<point2d>
{
typedef int coord_type;
coord_type row;
coord_type col;
};
struct point3d : public Point<point2d>
{
typedef int coord_type;
coord_type row;
coord_type col;
coord_type sli;
};
}
namespace concepts
{
concept_map Point2d<oln::point2d>
{
typedef oln::point2d::coord_type coord_type;
};
concept_map Point3d<oln::point3d>
{
typedef oln::point2d::coord_type coord_type;
};
}
// ---------- //
// Iterator. //
// ---------- //
namespace oln
{
template <typename E>
struct Iterator;
mlc_decl_typedef(point_type);
template <typename E>
struct vtypes< Iterator<E> >
{
typedef mlc::undefined point_type;
};
// ---------- //
// Iterator. //
// ---------- //
template <typename E>
struct Iterator : public stc::any<E>
{
typedef oln_type_of(Iterator, point) point_t;
typedef oln_type_of(E, point) point_t;
void start()
{
this->exact().start();
this->exact().impl_start();
}
void next()
{
this->exact().next();
this->exact().impl_next();
}
bool is_valid() const
{
return this->exact().is_valid();
};
return this->exact().impl_is_valid();
}
// auto
operator point_t()
operator point_t() const
{
return this->exact().operator point_t();
return this->exact().impl_op_point_type();
}
};
}
// ------- //
// Image. //
// ------- //
namespace oln
{
template <typename E>
struct Image;
mlc_decl_typedef(iter_type);
mlc_decl_typedef(value_type);
template <typename E>
struct vtypes< Image<E> >
{
typedef mlc::undefined point_type;
typedef mlc::undefined iter_type;
typedef mlc::undefined value_type;
};
// ------- //
// Image. //
// ------- //
template <typename E>
struct Image : public stc::any<E>
{
typedef oln_type_of(Image, point) point_t;
typedef oln_type_of(Image, iter) iter_t;
typedef oln_type_of(Image, value) value_t;
typedef oln_type_of(E, point) point_t;
typedef oln_type_of(E, value) value_t;
value_t& operator ()(point_t& p)
{
return this->exact().operator ()(p);
return this->exact().impl_op_parens(p);
}
bool has(const point_t& p) const
{
return this->exact().has(p);
return this->exact().impl_has(p);
}
};
}
// --------- //
// Image2d. //
// --------- //
namespace oln
{
struct Image2d;
// --------- //
// Image2d. //
// --------- //
template<>
struct set_super_type<Image2d>
{
typedef Image<Image2d> ret;
};
struct Image2d : public Image<Image2d>
template <typename E>
struct Image2d : public Image<E>
{
typedef oln_type_of_(Image2d, point) point_t;
typedef oln_type_of_(Image2d, iter) iter_t;
typedef oln_type_of_(Image2d, value) value_t;
typedef oln_type_of(E, point) point_t;
typedef oln_type_of(E, value) value_t;
// FIXME: delete?
value_t& operator ()(point_t& p)
{
return this->exact().operator ()(p);
return this->exact().impl_op_parens(p);
}
int nrows_get() const
{
return this->exact().nrows_get();
return this->exact().impl_nrows_get();
}
int ncols_get() const
{
return this->exact().ncols_get();
return this->exact().impl_ncols_get();
}
};
}
// ---------- //
// Image 3d. //
// ---------- //
namespace oln
{
struct Image3d;
template<>
struct set_super_type<Image3d>
{
typedef Image<Image3d> ret;
};
// --------- //
// Image3d. //
// --------- //
struct Image3d : public Image<Image3d>
template <typename E>
struct Image3d : public Image<E>
{
typedef oln_type_of_(Image3d, point) point_t;
typedef oln_type_of_(Image3d, iter) iter_t;
typedef oln_type_of_(Image3d, value) value_t;
typedef oln_type_of(E, point) point_t;
typedef oln_type_of(E, value) value_t;
// FIXME: delete?
value_t& operator ()(point_t& p)
{
return this->exact().operator ()(p);
return this->exact().impl_op_parens(p);
}
int nrows_get() const
{
return this->exact().nrows_get();
return this->exact().impl_nrows_get();
}
int ncols_get() const
{
return this->exact().ncols_get();
return this->exact().impl_ncols_get();
}
int nslis_get() const
{
return this->exact().nslis_get();
return this->exact().impl_nslis_get();
}
};
}
// ------------------------- //
// Image with neighborhood. //
// ------------------------- //
namespace oln
{
struct image_with_nbh;
mlc_decl_typedef(niter_type);
mlc_decl_typedef(nbh_type);
// ------------------------- //
// Image_with_neighborhood. //
// ------------------------- //
template<>
struct set_super_type<image_with_nbh>
{
typedef Image<image_with_nbh> ret;
};
template <>
struct vtypes<image_with_nbh>
{
typedef mlc::undefined niter_type;
typedef mlc::undefined nbh_type;
};
struct image_with_nbh : public Image<image_with_nbh>
template <typename E>
struct Image_with_neighborhood : public Image<E>
{
typedef oln_type_of_(image_with_nbh, niter) niter_t;
typedef oln_type_of_(image_with_nbh, nbh) nbh_t;
typedef oln_type_of(E, nbh) nbh_t;
typedef oln_type_of(E, niter) niter_t;
// FIXME: Implement.
#if 0
nbh_t nbh() const
{
return this->exact().impl_nbh();
}
#endif
};
}
} // End of namespace oln.
// -------- //
// Switch. //
// -------- //
/*---------.
| Bridge. |
`---------*/
namespace oln
{
// Fwd. decl.
template <typename E>
class image_dimension_switch;
// -------- //
// Switch. //
// -------- //
// Forward declaration.
template <typename E> struct image_dimension_switch;
// Default version, abort.
// Default version.
template <typename E>
class image_dimension_switch : mlc::abort_<E>
struct image_dimension_switch : public oln::Image<E>
{
image_dimension_switch()
{
std::cout << "image_dimension_switch<E>" << std::endl;
}
};
// Concept-based overloading for Image2d.
template <typename E> where concepts::Point2d< oln_type_of(E, point) >
class image_dimension_switch<E> : public oln::Image2d
template <typename E>
requires concepts::Point2d< oln_type_of(E, point) >
struct image_dimension_switch<E> : public oln::Image2d<E>
{
public:
image_dimension_switch()
{
std::cout << "image_dimension_switch<E> "
<< "where concepts::Point2d<oln_type_of(E, point)>"
<< "requires oln::concepts::Point2d<oln_type_of(E, point)>"
<< std::endl;
}
};
// Concept-based overloading for Image3d.
template <typename E> where concepts::Point3d< oln_type_of(E, point) >
class image_dimension_switch<E> : public oln::Image3d
template <typename E>
requires concepts::Point3d< oln_type_of(E, point) >
struct image_dimension_switch<E> : public oln::Image3d<E>