
https://svn.lrde.epita.fr/svn/oln/trunk/static Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Fix mini-oln. * samples/mini-oln/mini-oln.cc: Remove useless forward declarations. s/mlc::undefined/stc::abstract/ Aesthetic changes. (oln::Image_with_neighborhood): New abstraction. (oln::point3d): Fix base class. (oln::image_with_nbh): Remove (useless). (oln::niter2d, oln::neighborhood2d): New. (oln::set_super_type< image_morpher<E> >, oln::image_morpher<E>): Fix base class. (oln::image_morpher<E>::delegatee_t): Query the virtual type from the exact type. (oln::set_super_type< plus<I, N> >): Fix base class. (oln::vtypes< plus<I, N> >::nbh_type) (oln::vtypes< plus<I, N> >::niter_type): New vtypes. (oln::plus::plus): Call the ctor of the base class. (oln::plus::impl_nbh): New. (main): New tests. mini-oln.cc | 226 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 111 insertions(+), 115 deletions(-) Index: samples/mini-oln/mini-oln.cc --- samples/mini-oln/mini-oln.cc (revision 738) +++ samples/mini-oln/mini-oln.cc (working copy) @@ -35,6 +35,10 @@ #include <stc/scoop.hh> +/*-------------. +| Equipement. | +`-------------*/ + // Helper macros. #define oln_type_of_(FromType, Alias) \ find_vtype<FromType, oln::typedef_:: Alias##_type>::ret @@ -46,59 +50,49 @@ stc_scoop_equipment_for_namespace(oln); mlc_case_equipment_for_namespace(oln); - - -/*-------------. - | Mini-Olena. | - `-------------*/ - -// -------------------- // -// Vtypes declaration. // -// -------------------- // - +// Virtual types declaration. namespace oln { mlc_decl_typedef(point_type); - mlc_decl_typedef(iter_type); mlc_decl_typedef(value_type); - mlc_decl_typedef(niter_type); mlc_decl_typedef(nbh_type); + mlc_decl_typedef(niter_type); } + // --------------------- // // Forward declarations. // // --------------------- // +// FIXME: Remove. namespace oln { struct point2d; struct point3d; } + +/*---------------. +| Abstractions. | +`---------------*/ + +namespace oln +{ // ------- // // Point. // // ------- // -namespace oln -{ template <typename E> struct Point : public stc::any<E> { }; -} - // ---------- // // Iterator. // // ---------- // -namespace oln -{ - template <typename E> - struct Iterator; - template <typename E> struct Iterator : public stc::any<E> { @@ -125,18 +119,12 @@ return this->exact().impl_op_point_type(); } }; -} // ------- // // Image. // // ------- // -namespace oln -{ - template <typename E> - struct Image; - template <typename E> struct Image : public stc::any<E> { @@ -153,15 +141,12 @@ return this->exact().impl_has(p); } }; -} // --------- // // Image2d. // // --------- // -namespace oln -{ template <typename E> struct Image2d : public Image<E> { @@ -184,15 +169,12 @@ return this->exact().impl_ncols_get(); } }; -} -// ---------- // + // --------- // // Image 3d. // -// ---------- // + // --------- // -namespace oln -{ template <typename E> struct Image3d : public Image<E> { @@ -220,17 +202,44 @@ return this->exact().impl_nslis_get(); } }; + + + // ------------------------- // + // Image_with_neighborhood. // + // ------------------------- // + + template <typename E> + struct Image_with_neighborhood : public Image<E> + { + typedef oln_type_of(E, nbh) nbh_t; + + // FIXME: Implement. + nbh_t nbh() const + { + return this->exact().impl_nbh(); } + }; +} // End of namespace oln. + +/*---------. +| Bridge. | +`---------*/ + +namespace oln +{ // -------- // // Switch. // // -------- // -namespace oln -{ + // Tag. struct switch_image_base; + // Forward declarations. + struct point2d; + struct point3d; + template <typename E> struct case_<switch_image_base, E, 1> : public mlc::where_ < mlc::eq_ <oln_type_of(E, point), point2d> > @@ -250,15 +259,12 @@ { typedef Image<E> ret; }; -} // ------------ // // Image base. // // ------------ // -namespace oln -{ template <typename E> struct image_base; @@ -271,12 +277,12 @@ template <typename E> struct vtypes< image_base<E> > { - typedef mlc::undefined point_type; - typedef mlc::undefined iter_type; - typedef mlc::undefined value_type; + typedef stc::abstract point_type; + typedef stc::abstract iter_type; + typedef stc::abstract value_type; - typedef mlc::undefined niter_type; - typedef mlc::undefined nbh_type; + typedef mlc::none niter_type; + typedef mlc::none nbh_type; }; template <typename E> @@ -286,35 +292,38 @@ { } }; -} +} // End of namespace oln. -// ------- // -// points. // -// ------- // +/*------------------. +| Implementations. | +`------------------*/ namespace oln { + // -------- // + // Points. // + // -------- // + struct point2d : public Point<point2d> { int row; int col; }; - struct point3d : public Point<point2d> + struct point3d : public Point<point3d> { int row; int col; int sli; }; -} + // ------------ // -// iterator2d. // + // Iterator2d. // // ------------ // -namespace oln -{ + // Forward declarations. struct iterator2d; template <typename T> @@ -375,15 +384,12 @@ int ncols; point_t p; }; -} -// --------- // -// image2d. // -// --------- // + // ---------- // + // Image 2d. // + // ---------- // -namespace oln -{ template <typename T> struct image2d; @@ -442,66 +448,43 @@ int nrows; int ncols; }; -} - -// ---------------- // -// image_with_nbh. // -// ---------------- // -namespace oln -{ - struct image_with_nbh; + // ----------------- // + // Neighborhood 2d. // + // ----------------- // - template<> - struct set_super_type<image_with_nbh> - { - typedef image_base<image_with_nbh> ret; - }; + struct niter2d {}; - template <> - struct vtypes<image_with_nbh> + struct neighborhood2d { - typedef mlc::undefined niter_type; - typedef mlc::undefined nbh_type; + typedef niter2d niter_type; }; - struct image_with_nbh : public image_base< image_with_nbh > - { - typedef oln_type_of_(image_with_nbh, nbh) niter_t; - typedef oln_type_of_(image_with_nbh, niter) nbh_t; - - image_with_nbh() - { - } - }; -} // --------------- // -// image_morpher. // + // Image morpher. // // --------------- // -namespace oln -{ template <typename E> struct image_morpher; template<typename E> struct set_super_type< image_morpher<E> > { - typedef image_base< image_morpher<E> > ret; + typedef image_base<E> ret; }; template <typename E> struct vtypes< image_morpher<E> > { - typedef mlc::undefined delegatee_type; + typedef stc::abstract delegatee_type; }; template <typename E> - struct image_morpher : public image_base< image_morpher<E> > + struct image_morpher : public image_base<E> { - typedef oln_type_of(image_morpher, delegatee) delegatee_t; + typedef oln_type_of(E, delegatee) delegatee_t; image_morpher(delegatee_t& ref_ima) : ref_ima (ref_ima) @@ -515,20 +498,17 @@ protected: delegatee_t& ref_ima; }; -} -// ------ // -// plus. // -// ------ // + // ------------------------- // + // Image with neighborhood. // + // ------------------------- // -namespace oln -{ template <typename I, typename N> struct plus; template <typename I, typename N> - struct set_super_type< image_morpher<plus<I, N> > > + struct set_super_type< plus<I, N> > { typedef image_morpher< plus <I, N> > ret; }; @@ -537,29 +517,43 @@ struct vtypes< plus<I, N> > { typedef I delegatee_type; + typedef N nbh_type; + // For the sake of simplicity, the niter type is obtained directly + // from the neighborhood type itself (without using a virtual + // type). + typedef typename N::niter_type niter_type; }; template <typename I, typename N> struct plus : public image_morpher<plus<I, N> > { + typedef plus<I, N> self_t; + typedef image_morpher< self_t > super_t; + plus(I& ima, N& nbh) : + super_t (ima), nbh (nbh) { } + N impl_nbh() const + { + return nbh; + } + protected: N& nbh; }; - // Helper. + /// Helper. template <typename I, typename N> plus<I, N> operator+(I& lhs, N& rhs) { plus<I, N> res(lhs, rhs); return res; } -} +} // End of namespace oln. /*--------------. @@ -570,22 +564,24 @@ { using namespace oln; - typedef plus<image2d<int>, image_with_nbh> my_ima; - - point2d p2d; - point3d p3d; - - image2d<int> ima(10, 10); - image_with_nbh ima_nb; - - iterator2d it2d(ima); - - // my_ima p = ima + ima_nb; -} + point2d p; + typedef image2d<int> ima_t; + ima_t ima1(10, 10); + iterator2d it(ima1); + typedef neighborhood2d nbh_t; + // A type of image with neighborhood2d. + typedef plus<ima_t, nbh_t> ima_wih_nbh_t; + neighborhood2d nbh; + ima_wih_nbh_t ima2(ima1, nbh); + // Another way to build an image with neigborhood. + ima_wih_nbh_t ima3 = ima1 + nbh; + point3d q; + // ... +}
participants (1)
-
Roland Levillain