Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* oln/makefile.src: Add compose.hh.
* oln/core/compose.hh: New.
core/compose.hh | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
makefile.src | 3
2 files changed, 172 insertions(+), 1 deletion(-)
Index: oln/makefile.src
--- oln/makefile.src (revision 76)
+++ oln/makefile.src (working copy)
@@ -45,8 +45,9 @@
core/abstract/point.hh \
core/abstract/size.hh \
core/abstract/neighborhood.hh \
- core/abstract/window.hh \
+ core/abstract/struct_elt.hh \
core/coord.hh \
+ core/compose.hh \
core/properties.hh \
core/value_box.hh \
fancy/iota.hh \
Index: oln/core/compose.hh
--- oln/core/compose.hh (revision 0)
+++ oln/core/compose.hh (revision 0)
@@ -0,0 +1,170 @@
+// Copyright (C) 2001, 2004 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, 59 Temple Place - Suite 330, 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_COMPOSE_HH
+# define OLENA_CORE_COMPOSE_HH
+
+# include <functional>
+
+namespace oln {
+
+ namespace internal {
+
+ /*! \class compose_uu_
+ **
+ ** The operator () of this class performs a composition between
+ ** two unary functors \a F1 & \a F2.
+ */
+
+ template< class F1, class F2 >
+ struct compose_uu_ :
+ public std::unary_function <typename F2::argument_type,
+ typename F1::result_type>
+ {
+ typedef compose_uu_ self_type;
+
+ typename self_type::result_type
+ operator()(typename self_type::argument_type arg) const
+ {
+ return f1_(f2_(arg));
+ }
+
+ compose_uu_(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
+
+ private:
+
+ const F1 f1_;
+ const F2 f2_;
+
+ };
+
+ /*! \class compose_ub_
+ **
+ ** The operator () of this class performs a composition between
+ ** a unary functor \a F1 and a binary functor \a F2.
+ */
+
+
+ template< class F1, class F2 >
+ struct compose_ub_ :
+ public std::binary_function <typename F2::first_argument_type,
+ typename F2::second_argument_type,
+ typename F1::result_type>
+ {
+ typedef compose_ub_ self_type;
+
+ typename self_type::result_type
+ operator()(typename self_type::first_argument_type arg1,
+ typename self_type::second_argument_type arg2) const
+ {
+ return f1_(f2_(arg1, arg2));
+ }
+
+ compose_ub_(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
+
+ private:
+
+ const F1 f1_;
+ const F2 f2_;
+
+ };
+
+ /*! \class compose_bu_
+ **
+ ** The operator () of this class performs a composition between
+ ** a binary functor \a F1 and an unary functor \a F2.
+ */
+
+ template< class F1, class F2 >
+ struct compose_bu_ :
+ public std::binary_function <typename F2::argument_type,
+ typename F2::argument_type,
+ typename F1::result_type>
+ {
+ typedef compose_bu_ self_type;
+
+ typename self_type::result_type
+ operator()(typename self_type::first_argument_type arg1,
+ typename self_type::second_argument_type arg2) const
+ {
+ return f1_(f2_(arg1), f2_(arg2));
+ }
+
+ compose_bu_(const F1& f1, const F2& f2) : f1_(f1), f2_(f2) {}
+
+ private:
+
+ const F1 f1_;
+ const F2 f2_;
+
+ };
+
+ }
+
+
+ /// Compose two unary functors \a F1 & \a F2.
+ template<class UF1, class UF2>
+ internal::compose_uu_<UF1, UF2>
+ compose_uu(const UF1& f1, const UF2& f2)
+ {
+ return internal::compose_uu_<UF1, UF2>(f1, f2);
+ }
+
+ /// Compose a unary functor \a F1 with a binary functor \a F2.
+ template<class UF1, class BF2>
+ internal::compose_ub_<UF1, BF2>
+ compose_ub(const UF1& f1, const BF2& f2)
+ {
+ return internal::compose_ub_<UF1, BF2>(f1, f2);
+ }
+
+ /// Compose a binary functor \a F1 and an unary functor \a F2.
+ template<class BF1, class UF2>
+ internal::compose_bu_<BF1, UF2>
+ compose_bu(const BF1& f1, const UF2& f2)
+ {
+ return internal::compose_bu_<BF1, UF2>(f1, f2);
+ }
+
+ /*! \class f_identity
+ **
+ ** This functor returns its argument.
+ */
+
+ template<class T>
+ struct f_identity : std::unary_function<T, T>
+ {
+ T
+ operator()(T t) const
+ {
+ return t;
+ }
+ };
+
+} // end of oln
+
+#endif // OLENA_CORE_COMPOSE_HH
Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* tests/core/tests/neighborhood2d: New.
* oln/core/abstract/neighborhood.hh: New.
* oln/core/2d/neighborhood2d.hh: New.
* oln/core/properties.hh: Add `neighborhood' category.
oln/core/2d/neighborhood2d.hh | 133 ++++++++++++++++++++++++++
oln/core/abstract/neighborhood.hh | 192 ++++++++++++++++++++++++++++++++++++++
oln/core/properties.hh | 1
tests/core/tests/neighborhood2d | 17 +++
4 files changed, 343 insertions(+)
Index: tests/core/tests/neighborhood2d
--- tests/core/tests/neighborhood2d (revision 0)
+++ tests/core/tests/neighborhood2d (revision 0)
@@ -0,0 +1,17 @@
+#include <oln/core/2d/neighborhood2d.hh>
+
+#include <ntg/all.hh>
+
+#include <cassert>
+
+using namespace oln;
+using namespace ntg;
+
+int main()
+{
+ neighborhood2d w1;
+ w1.add(dpoint2d(0, 5));
+ w1.add(dpoint2d(0, 5));
+ neighborhood2d w2 = neighb_c8();
+ return 0;
+}
Index: oln/core/abstract/neighborhood.hh
--- oln/core/abstract/neighborhood.hh (revision 0)
+++ oln/core/abstract/neighborhood.hh (revision 0)
@@ -0,0 +1,192 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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_NEIGHBORHOOD_HH
+# define OLENA_CORE_NEIGHBORHOOD_HH
+
+# include <mlc/types.hh>
+# include <oln/core/properties.hh>
+# include <oln/core/coord.hh>
+# include <oln/core/abstract/dpoint.hh>
+# include <vector>
+# include <utility>
+# include <iostream>
+
+namespace oln {
+
+ // fwd decl
+ namespace abstract {
+ template<class Exact>
+ struct neighborhood;
+ }
+
+ // category
+ template <typename E>
+ struct set_category< abstract::neighborhood<E> >
+ {
+ typedef category::neighborhood ret;
+ };
+
+ /// properties of any type in category::neighborhood
+
+ template <typename type>
+ struct props_of <category::neighborhood, type>
+ {
+ typedef mlc::true_type user_defined_;
+
+ mlc_decl_prop(category::neighborhood, dpoint_type);
+ mlc_decl_prop(category::neighborhood, size_type);
+
+ static void echo(std::ostream& ostr)
+ {
+ ostr << "props_of( category::neighborhood, "
+ << typeid(type).name() << ") = {"
+ << " size_type = " << typeid(size_type).name() << "," << std::endl
+ << " dpoint_type = " << typeid(dpoint_type).name() << " }" << std::endl;
+ }
+
+ };
+
+ mlc_register_prop(category::neighborhood, dpoint_type);
+ mlc_register_prop(category::neighborhood, size_type);
+
+
+ namespace abstract {
+
+ /*!
+ ** Structuring elements (set of dpoints).
+ **
+ ** This abstract class defines several virtual methods for its
+ ** subclasses. Its goal is to deal with a set of 'move' points.
+ */
+ template<class E>
+ class neighborhood : public mlc::any__best_memory<E>
+ {
+
+ public:
+
+ typedef oln_type_of(E, dpoint) dpoint_type;
+
+ typedef E exact_type;
+
+ static std::string
+ name()
+ {
+ return std::string("neighborhood<") + exact_type::name() + ">";
+ }
+
+ bool
+ has(const abstract::dpoint<dpoint_type>& dp) const
+ {
+ return this->exact().impl_has(dp.exact());
+ }
+
+ unsigned
+ card() const
+ {
+ return this->exact().impl_card();
+ }
+
+ exact_type&
+ add(const dpoint_type& dp)
+ {
+ return this->exact().impl_add(dp);
+ }
+
+ dpoint_type
+ dp(unsigned i) const
+ {
+ return this->exact().impl_at(i);
+ }
+
+ const dpoint_type
+ operator[](unsigned i) const
+ {
+ return this->exact().impl_at(i);
+ }
+
+ protected:
+
+ bool
+ impl_has(const dpoint_type& dp) const
+ {
+ return std::find(dp_.begin(), dp_.end(), dp) != dp_.end();
+ }
+
+ exact_type&
+ impl_add(const dpoint_type& dp)
+ {
+ if (!(impl_has(dp)))
+ {
+ this->dp_.push_back(dp);
+ this->dp_.push_back(-dp);
+ }
+ return this->exact();
+ }
+
+ unsigned
+ impl_card() const
+ {
+ return dp_.size();
+ }
+
+ const dpoint_type
+ impl_at(unsigned i) const
+ {
+ precondition(i < this->card());
+ return dp_[i];
+ }
+
+ neighborhood() : dp_()
+ {};
+
+ neighborhood(unsigned size) : dp_()
+ {
+ dp_.reserve(size);
+ };
+
+ std::vector<dpoint_type> dp_;
+
+ };
+ } // end of abstract
+
+} // end of oln
+
+template<class E>
+std::ostream&
+operator<<(std::ostream& o, const oln::abstract::neighborhood<E>& se)
+{
+ unsigned c = se.card();
+ o << "[";
+ for (unsigned i = 0; i < c; ++i)
+ o << se.dp(i);
+ o << "]";
+ return o;
+}
+
+
+#endif // ! OLENA_CORE_NEIGHBORHOOD_HH
Index: oln/core/2d/neighborhood2d.hh
--- oln/core/2d/neighborhood2d.hh (revision 0)
+++ oln/core/2d/neighborhood2d.hh (revision 0)
@@ -0,0 +1,133 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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_NEIGHBORHOOD2D_HH
+# define OLENA_CORE_NEIGHBORHOOD2D_HH
+
+# include <oln/core/2d/dpoint2d.hh>
+# include <oln/core/2d/size2d.hh>
+# include <oln/core/coord.hh>
+# include <oln/core/abstract/struct_elt.hh>
+
+namespace oln {
+
+ class neighborhood2d; // forward declaration
+
+ // category
+ template <>
+ struct set_category< neighborhood2d > { typedef category::struct_elt ret; };
+
+ // super_type
+ template <>
+ struct set_super_type< neighborhood2d >
+ {
+ typedef abstract::struct_elt< neighborhood2d > ret;
+ };
+
+ template <>
+ struct set_props< category::struct_elt, neighborhood2d >
+ : public props_of<category::struct_elt>
+ {
+ typedef dpoint2d dpoint_type;
+ typedef size2d size_type;
+ };
+
+ class neighborhood2d : public abstract::struct_elt<neighborhood2d>
+ {
+
+ public:
+
+ typedef abstract::struct_elt<neighborhood2d> super_type;
+
+ /*!
+ ** \brief Construct a neighborhood of 2 dimensions.
+ */
+ neighborhood2d() : super_type()
+ {}
+
+ /*!
+ ** \brief Construct a neighborhood of 2 dimensions.
+ ** \arg size The number of element.
+ */
+ neighborhood2d(unsigned size) : super_type(size)
+ {}
+
+ /*!
+ ** \brief Construct a neighborhood of 2 dimensions from several points.
+ ** \arg n The number of element.
+ ** \arg crd The coordinates of the elements
+ */
+ neighborhood2d(unsigned n, const coord_t crd[]) : super_type(n)
+ {
+ for (unsigned i = 0; i < 2 * n; i += 2)
+ this->add(dpoint_type(crd[i], crd[i+1]));
+ }
+
+ neighborhood2d&
+ add(const dpoint_type& dp)
+ {
+ return this->exact().impl_add(dp);
+ }
+
+ neighborhood2d&
+ add(coord_t row, coord_t col)
+ {
+ dpoint_type dp(row, col);
+ return add(dp);
+ }
+
+
+ /// Return the name of the type.
+ static std::string
+ name()
+ {
+ return std::string("neighborhood2d");
+ }
+
+ protected:
+
+ };
+
+ inline const neighborhood2d&
+ neighb_c4()
+ {
+ static const coord_t crd[] = { 0,1, 1,0 };
+ static const neighborhood2d neighb(2, crd);
+ return neighb;
+ }
+
+ inline const neighborhood2d&
+ neighb_c8()
+ {
+ static const coord_t crd[] = { 0,1, 1,1, 1,0, 1,-1 };
+ static const neighborhood2d neighb(4, crd);
+ return neighb;
+ }
+
+} // end of oln
+
+#endif // OLENA_CORE_NEIGHBORHOOD2D_HH
Index: oln/core/properties.hh
--- oln/core/properties.hh (revision 74)
+++ oln/core/properties.hh (working copy)
@@ -42,6 +42,7 @@
struct data_storage;
struct image;
struct struct_elt;
+ struct neighborhood;
struct point;
struct size;
struct piter;
Index: ChangeLog
from Simon Odou <simon(a)lrde.epita.fr>
* tests/core/tests/window2d: New.
* oln/core/abstract/struct_elt.hh: New.
* oln/core/2d/window2d.hh: New.
* oln/core/properties.hh: Add `struct_elt' category.
oln/core/2d/window2d.hh | 172 ++++++++++++++++++++++++++++++++++++
oln/core/abstract/struct_elt.hh | 189 ++++++++++++++++++++++++++++++++++++++++
oln/core/properties.hh | 1
tests/core/tests/window2d | 17 +++
4 files changed, 379 insertions(+)
Index: tests/core/tests/window2d
--- tests/core/tests/window2d (revision 0)
+++ tests/core/tests/window2d (revision 0)
@@ -0,0 +1,17 @@
+#include <oln/core/2d/window2d.hh>
+
+#include <ntg/all.hh>
+
+#include <cassert>
+
+using namespace oln;
+using namespace ntg;
+
+int main()
+{
+ window2d w1;
+ w1.add(dpoint2d(0, 5));
+ w1.add(dpoint2d(0, 5));
+ window2d w2 = win_c8p();
+ return 0;
+}
Index: oln/core/abstract/struct_elt.hh
--- oln/core/abstract/struct_elt.hh (revision 0)
+++ oln/core/abstract/struct_elt.hh (revision 0)
@@ -0,0 +1,189 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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_STRUCT_ELT_HH
+# define OLENA_CORE_STRUCT_ELT_HH
+
+# include <mlc/types.hh>
+# include <oln/core/properties.hh>
+# include <oln/core/coord.hh>
+# include <oln/core/abstract/dpoint.hh>
+# include <vector>
+# include <utility>
+# include <iostream>
+
+namespace oln {
+
+ // fwd decl
+ namespace abstract {
+ template<class Exact>
+ struct struct_elt;
+ }
+
+ // category
+ template <typename E>
+ struct set_category< abstract::struct_elt<E> >
+ {
+ typedef category::struct_elt ret;
+ };
+
+ /// properties of any type in category::struct_elt
+
+ template <typename type>
+ struct props_of <category::struct_elt, type>
+ {
+ typedef mlc::true_type user_defined_;
+
+ mlc_decl_prop(category::struct_elt, dpoint_type);
+ mlc_decl_prop(category::struct_elt, size_type);
+
+ static void echo(std::ostream& ostr)
+ {
+ ostr << "props_of( category::struct_elt, "
+ << typeid(type).name() << ") = {"
+ << " size_type = " << typeid(size_type).name() << "," << std::endl
+ << " dpoint_type = " << typeid(dpoint_type).name() << " }" << std::endl;
+ }
+
+ };
+
+ mlc_register_prop(category::struct_elt, dpoint_type);
+ mlc_register_prop(category::struct_elt, size_type);
+
+
+ namespace abstract {
+
+ /*!
+ ** Structuring elements (set of dpoints).
+ **
+ ** This abstract class defines several virtual methods for its
+ ** subclasses. Its goal is to deal with a set of 'move' points.
+ */
+ template<class E>
+ class struct_elt : public mlc::any__best_memory<E>
+ {
+
+ public:
+
+ typedef oln_type_of(E, dpoint) dpoint_type;
+
+ typedef E exact_type;
+
+ static std::string
+ name()
+ {
+ return std::string("struct_elt<") + exact_type::name() + ">";
+ }
+
+ bool
+ has(const abstract::dpoint<dpoint_type>& dp) const
+ {
+ return this->exact().impl_has(dp.exact());
+ }
+
+ unsigned
+ card() const
+ {
+ return this->exact().impl_card();
+ }
+
+ exact_type&
+ add(const dpoint_type& dp)
+ {
+ return this->exact().impl_add(dp);
+ }
+
+ dpoint_type
+ dp(unsigned i) const
+ {
+ return this->exact().impl_at(i);
+ }
+
+ const dpoint_type
+ operator[](unsigned i) const
+ {
+ return this->exact().impl_at(i);
+ }
+
+ protected:
+
+ bool
+ impl_has(const dpoint_type& dp) const
+ {
+ return std::find(dp_.begin(), dp_.end(), dp) != dp_.end();
+ }
+
+ exact_type&
+ impl_add(const dpoint_type& dp)
+ {
+ if (!(impl_has(dp)))
+ this->dp_.push_back(dp);
+ return this->exact();
+ }
+
+ unsigned
+ impl_card() const
+ {
+ return dp_.size();
+ }
+
+ const dpoint_type
+ impl_at(unsigned i) const
+ {
+ precondition(i < this->card());
+ return dp_[i];
+ }
+
+ struct_elt() : dp_()
+ {};
+
+ struct_elt(unsigned size) : dp_()
+ {
+ dp_.reserve(size);
+ };
+
+ std::vector<dpoint_type> dp_;
+
+ };
+ } // end of abstract
+
+} // end of oln
+
+template<class E>
+std::ostream&
+operator<<(std::ostream& o, const oln::abstract::struct_elt<E>& se)
+{
+ unsigned c = se.card();
+ o << "[";
+ for (unsigned i = 0; i < c; ++i)
+ o << se.dp(i);
+ o << "]";
+ return o;
+}
+
+
+#endif // ! OLENA_CORE_STRUCT_ELT_HH
Index: oln/core/2d/window2d.hh
--- oln/core/2d/window2d.hh (revision 0)
+++ oln/core/2d/window2d.hh (revision 0)
@@ -0,0 +1,172 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005 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, 59 Temple Place - Suite 330, 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_WINDOW2D_HH
+# define OLENA_CORE_WINDOW2D_HH
+
+# include <oln/core/2d/dpoint2d.hh>
+# include <oln/core/2d/size2d.hh>
+# include <oln/core/coord.hh>
+# include <oln/core/abstract/struct_elt.hh>
+
+namespace oln {
+
+ class window2d; // forward declaration
+
+ // category
+ template <>
+ struct set_category< window2d > { typedef category::struct_elt ret; };
+
+ // super_type
+ template <>
+ struct set_super_type< window2d >
+ {
+ typedef abstract::struct_elt< window2d > ret;
+ };
+
+ template <>
+ struct set_props< category::struct_elt, window2d >
+ : public props_of<category::struct_elt>
+ {
+ typedef dpoint2d dpoint_type;
+ typedef size2d size_type;
+ };
+
+ class window2d : public abstract::struct_elt<window2d>
+ {
+
+ public:
+
+ typedef abstract::struct_elt<window2d> super_type;
+
+ /*!
+ ** \brief Construct a window of 2 dimensions.
+ */
+ window2d() : super_type()
+ {}
+
+ /*!
+ ** \brief Construct a window of 2 dimensions.
+ ** \arg size The number of element.
+ */
+ window2d(unsigned size) : super_type(size)
+ {}
+
+ /*!
+ ** \brief Construct a window of 2 dimensions from several points.
+ ** \arg n The number of element.
+ ** \arg crd The coordinates of the elements
+ */
+ window2d(unsigned n, const coord_t crd[]) : super_type(n)
+ {
+ for (unsigned i = 0; i < 2 * n; i += 2)
+ this->add(dpoint_type(crd[i], crd[i+1]));
+ }
+
+ window2d&
+ add(const dpoint_type& dp)
+ {
+ return this->exact().impl_add(dp);
+ }
+
+ window2d&
+ add(coord_t row, coord_t col)
+ {
+ dpoint_type dp(row, col);
+ return add(dp);
+ }
+
+
+ /// Return the name of the type.
+ static std::string
+ name()
+ {
+ return std::string("window2d");
+ }
+
+ protected:
+
+ };
+
+
+ // std win
+
+ /*!
+ ** \brief Create a window (2 dimensions) of 4 elements.
+ ** \return The new window.
+ */
+ inline const window2d&
+ win_c4_only()
+ {
+ static const coord_t crd[] = { -1,0, 0,-1, 0,1, 1,0 };
+ static const window2d win(4, crd);
+ return win;
+ }
+
+ /*!
+ ** \brief Create a window (2 dimensions) of 5 elements.
+ ** \return The new window.
+ **
+ ** It's the same than win_c4_only() plus the 0,0 point.
+ */
+ inline const window2d&
+ win_c4p()
+ {
+ static const coord_t crd[] = { -1,0, 0,-1, 0,0, 0,1, 1,0 };
+ static const window2d win(5, crd);
+ return win;
+ }
+
+ /*!
+ ** \brief Create a window (2 dimensions) of 8 elements.
+ ** \return The new window.
+ */
+ inline const window2d&
+ win_c8_only()
+ {
+ static const coord_t crd[] = { -1,-1, -1,0, -1,1, 0,-1, 0,1, 1,-1, 1,0, 1,1 };
+ static const window2d win(8, crd);
+ return win;
+ }
+
+ /*!
+ ** \brief Create a window (2 dimensions) of 9 elements.
+ ** \return The new window.
+ **
+ ** It's the same than win_c8_only more the 0,0 point.
+ */
+ inline const window2d&
+ win_c8p()
+ {
+ static const coord_t crd[] = { -1,-1, -1,0, -1,1, 0,-1, 0,0, 0,1, 1,-1, 1,0, 1,1 };
+ static const window2d win(9, crd);
+ return win;
+ }
+
+} // end of oln
+
+#endif // OLENA_CORE_WINDOW2D_HH
Index: oln/core/properties.hh
--- oln/core/properties.hh (revision 73)
+++ oln/core/properties.hh (working copy)
@@ -41,6 +41,7 @@
{
struct data_storage;
struct image;
+ struct struct_elt;
struct point;
struct size;
struct piter;