https://svn.lrde.epita.fr/svn/oln/trunk/static
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Fix mini-oln.
* samples/mini-oln/mini-oln.cc: Move all Olena classes into the
namespace `oln'.
(main): Adjust.
(oln::image2d::has): Make it const.
Remove semicolons following the closing parenthesis of a
namespace.
Aesthetic changes.
* stc/scoop.hh: Replace every occurrence of `where' (as a template
parameter) with `location', to comply with the upcoming C++0x
standard.
samples/mini-oln/mini-oln.cc | 162 ++++++++++++++++++++++++++++++-------------
stc/scoop.hh | 30 +++----
2 files changed, 131 insertions(+), 61 deletions(-)
Index: samples/mini-oln/mini-oln.cc
--- samples/mini-oln/mini-oln.cc (revision 729)
+++ samples/mini-oln/mini-oln.cc (working copy)
@@ -25,6 +25,14 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+/* \file samples/mini-oln/mini-oln.cc
+ \brief A proof of concept of Static using a mini-version of Olena.
+
+ Compile with:
+
+ g++ -I../../../{metalic,static,extended,olena} mini-oln.cc
+*/
+
#include <vector>
#include <mlc/case.hh>
@@ -44,7 +52,17 @@
mlc_case_equipment_for_namespace(oln);
-// Point
+
+/*-------------.
+| Mini-Olena. |
+`-------------*/
+
+// ------- //
+// Point. //
+// ------- //
+
+namespace oln
+{
template <typename E>
struct Point : public stc::any<E>
{
@@ -62,13 +80,18 @@
int col;
int sli;
};
+}
-// Iterator
-template <typename E>
-struct Iterator;
+
+// ---------- //
+// Iterator. //
+// ---------- //
namespace oln
{
+ template <typename E>
+ struct Iterator;
+
mlc_decl_typedef(point_type);
template <typename E>
@@ -76,7 +99,6 @@
{
typedef mlc::undefined point_type;
};
-};
template <typename E>
struct Iterator : public stc::any<E>
@@ -104,13 +126,18 @@
return this->exact().operator point_t();
}
};
+}
-// Image
-template <typename E>
-struct Image;
+
+// ------- //
+// Image. //
+// ------- //
namespace oln
{
+ template <typename E>
+ struct Image;
+
mlc_decl_typedef(iter_type);
mlc_decl_typedef(value_type);
@@ -121,7 +148,6 @@
typedef mlc::undefined iter_type;
typedef mlc::undefined value_type;
};
-};
template <typename E>
struct Image : public stc::any<E>
@@ -139,8 +165,13 @@
{
this->exact().has(p);
}
-
};
+}
+
+
+// --------- //
+// Image2d. //
+// --------- //
namespace oln
{
@@ -151,7 +182,6 @@
{
typedef Image<Image2d> ret;
};
-};
struct Image2d : public Image<Image2d>
{
@@ -174,6 +204,12 @@
this->exact().ncols_get();
}
};
+}
+
+
+// ---------- //
+// Image 3d. //
+// ---------- //
namespace oln
{
@@ -184,7 +220,6 @@
{
typedef Image<Image3d> ret;
};
-};
struct Image3d : public Image<Image3d>
{
@@ -212,12 +247,17 @@
this->exact().nslis_get();
}
};
+}
-// Image with neighborhood
-struct image_with_nbh;
+
+// ------------------------- //
+// Image with neighborhood. //
+// ------------------------- //
namespace oln
{
+ struct image_with_nbh;
+
mlc_decl_typedef(niter_type);
mlc_decl_typedef(nbh_type);
@@ -233,7 +273,6 @@
typedef mlc::undefined niter_type;
typedef mlc::undefined nbh_type;
};
-};
struct image_with_nbh : public Image<image_with_nbh>
{
@@ -242,28 +281,35 @@
nbh_t nbh() const
{
- //FIXME
+ // FIXME.
}
};
+}
-// Switch
-struct switch_image_base;
+
+// -------- //
+// Switch. //
+// -------- //
namespace oln
{
+ struct switch_image_base;
+
namespace error
{
struct ERROR_image_base;
};
template <typename I>
- struct case_<switch_image_base, I, 1> : public mlc::where_ < mlc::eq_ <I,
point2d> >
+ struct case_<switch_image_base, I, 1> :
+ public mlc::where_ < mlc::eq_ <I, point2d> >
{
typedef Image2d ret;
};
template <typename I>
- struct case_<switch_image_base, I, 2> : public mlc::where_ < mlc::eq_ <I,
point3d> >
+ struct case_<switch_image_base, I, 2> :
+ public mlc::where_ < mlc::eq_ <I, point3d> >
{
typedef Image3d ret;
};
@@ -273,17 +319,18 @@
{
typedef mlc::undefined ret;
};
-};
-
+}
+// ------------ //
+// Image base. //
+// ------------ //
-// Image base
+namespace oln
+{
template <typename E>
struct image_base;
-namespace oln
-{
template<typename E>
struct set_super_type<image_base<E> >
{
@@ -297,7 +344,6 @@
typedef mlc::undefined iter_type;
typedef mlc::undefined value_type;
};
-};
template <typename E>
struct image_base : public oln::switch_<switch_image_base, E>::ret
@@ -316,15 +362,20 @@
this->exact().has(p);
}
};
+}
+
-// Iterator 2d
+// ------------ //
+// iterator2d. //
+// ------------ //
+
+namespace oln
+{
struct iterator2d;
template <typename T>
struct image2d;
-namespace oln
-{
template<>
struct set_super_type<iterator2d>
{
@@ -336,7 +387,6 @@
{
typedef point2d point_type;
};
-};
struct iterator2d : public Iterator<iterator2d>
{
@@ -381,14 +431,19 @@
int ncols;
point_t p;
};
+}
-// image2d
-template <typename T>
-struct image2d;
+
+// --------- //
+// image2d. //
+// --------- //
namespace oln
{
template<typename T>
+ struct image2d;
+
+ template<typename T>
struct set_super_type<image2d<T> >
{
typedef image_base<image2d<T> > ret;
@@ -397,10 +452,9 @@
template <typename T>
struct vtypes<image2d<T> >
{
- typedef point2d point_t;
- typedef iterator2d iter_t;
- typedef T value_t;
- };
+ typedef point2d point_type;
+ typedef iterator2d iter_type;
+ typedef T value_type;
};
template <typename T>
@@ -433,7 +487,7 @@
return ncols;
}
- bool has(point_t& p)
+ bool has(point_t& p) const
{
assert(!!data);
return p.row >= 0 && p.row < nrows && p.col >= 0 &&
p.col < ncols;
@@ -444,14 +498,19 @@
int nrows;
int ncols;
};
+}
-// image_morpher
-template <typename E>
-struct 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;
@@ -462,7 +521,6 @@
{
typedef mlc::undefined delegatee_t;
};
-};
template <typename E>
struct image_morpher : public image_base<image_morpher<E> >
@@ -481,14 +539,19 @@
protected:
delegatee_t& ref_ima;
};
+}
-//image_plus_neighborhood
-template <typename I, typename N>
-struct plus;
+
+// ------ //
+// plus. //
+// ------ //
namespace oln
{
template <typename I, typename N>
+ struct plus;
+
+ template <typename I, typename N>
struct set_super_type<image_morpher<plus<I, N> > >
{
typedef image_morpher<plus <I, N> > ret;
@@ -499,7 +562,6 @@
{
typedef I delegatee_t;
};
-};
template <typename I, typename N>
struct plus : public image_morpher<plus<I, N> >
@@ -513,17 +575,25 @@
N& nbh;
};
+ // Helper.
template <typename I, typename N>
plus<I, N> operator +(I& lhs, N& rhs)
{
plus<I, N> res(lhs, rhs);
return res;
}
+}
+/*--------------.
+| Client code. |
+`--------------*/
+
int main()
{
+ using namespace oln;
+
typedef plus<image2d<int>, image_with_nbh> my_ima;
point2d p2d;
Index: stc/scoop.hh
--- stc/scoop.hh (revision 729)
+++ stc/scoop.hh (working copy)
@@ -185,7 +185,7 @@
template <typename from, typename target> \
struct find; \
\
- template <typename from, typename target, typename where, typename res> \
+ template <typename from, typename target, typename location, typename res> \
struct helper_find; \
\
\
@@ -470,12 +470,12 @@
/* \
* first_stm(from, target) \
* \
- * returns a pair (Where, Value) with Value being: \
+ * returns a pair (Location, Value) with Value being: \
* - stc::abstract \
* - stc::not_delegated \
* - mlc::not_found \
* - a type T \
- * and Where being the class where the stm is found. \
+ * and Location being the class where the stm is found. \
* \
* \
* helper_first_stm(curr, target, stm) \
@@ -656,21 +656,21 @@
\
\
/* \
- * helper_find(from, target, where, res) \
+ * helper_find(from, target, location, res) \
* \
* \
* \
*/ \
\
- template <typename from, typename target, typename where> \
- struct helper_find < from, target, where, \
+ template <typename from, typename target, typename location> \
+ struct helper_find < from, target, location, \
/* if res == */ mlc::not_found > \
{ \
typedef typename delegator_find<from, target>::ret ret; \
}; \
\
- template <typename from, typename target, typename where> \
- struct helper_find < from, target, where, \
+ template <typename from, typename target, typename location> \
+ struct helper_find < from, target, location, \
/* if res == */ stc::abstract > \
{ \
typedef typename delegator_find<from, target>::ret res_d; \
@@ -678,23 +678,23 @@
: mlc::assert_< mlc::is_found_<res_d>, \
ERROR::vtype_declared_but_not_defined \
< ERROR::_for_vtype_<target>, \
- ERROR::_declaration_is_in_<where>, \
+ ERROR::_declaration_is_in_<location>, \
ERROR::_definition_is_looked_up_from_<from> > > \
- /* FIXME: error("<target> declared in <where> but not defined at
<from>"); */ \
+ /* FIXME: error("<target> declared in <location> but not defined
at <from>"); */ \
{ \
typedef res_d ret; \
}; \
typedef typename check_::ret ret; \
}; \
\
- template <typename from, typename target, typename where> \
- struct helper_find < from, target, where, \
+ template <typename from, typename target, typename location> \
+ struct helper_find < from, target, location, \
/* if res == */ stc::not_delegated > \
{ \
typedef typename superior_find<from, target>::ret ret; \
}; \
\
- template <typename from, typename target, typename where, typename res> \
+ template <typename from, typename target, typename location, typename res> \
struct helper_find /* otherwise */ \
{ \
typedef res ret; \
@@ -726,10 +726,10 @@
struct find /* otherwise */ \
{ \
typedef typename first_stm<from, target>::ret stm; \
- typedef mlc_elt(stm, 1) where; \
+ typedef mlc_elt(stm, 1) location; \
typedef mlc_elt(stm, 2) res; \
typedef typename helper_find<from, target, \
- where, res>::ret ret; \
+ location, res>::ret ret; \
}; \
\
\