proto-1.0 51: Add properties mechanism

Index: ChangeLog from Thierry Geraud <theo@lrde.epita.fr> * oln/core/entry.hh: Move to... * oln/core/abstract/entry.hh: ...here. * oln/core/properties.hh: New. * tests/core/tests/image1d: Adapt to properties management. * tests/core/tests/image2d: Likewise. * tests/core/tests/image3d: Likewise. * tests/core/tests/image_identity: Likewise. * tests/core/tests/setget: Likewise. * oln/fancy/print.hh: Likewise. * oln/fancy/iota.hh: Likewise. * oln/basics.hh: Likewise. * oln/makefile.src: Likewise. * oln/io/write_image_2d_pnm.hh: Likewise. * oln/io/read_image_2d_pnm.hh: Likewise. * oln/io/write_image.hh: Likewise. * oln/io/read_image.hh: Likewise. * oln/core/value_box.hh: Likewise. * oln/core/abstract/image_constness.hh: Likewise. * oln/core/abstract/image.hh: Likewise. * oln/core/abstract/piter.hh: Likewise. * oln/core/abstract/images.hh: Likewise. * oln/core/abstract/image_with_data.hh: Likewise. * oln/core/abstract/point.hh: Likewise. * oln/core/abstract/image_identity.hh: Likewise. * oln/core/abstract/data_storage.hh: Likewise. * oln/core/abstract/internal/image_impl.hh: Likewise. * oln/core/abstract/op.hh: Likewise. * oln/core/1d/array1d.hh: Likewise. * oln/core/1d/image1d.hh: Likewise. * oln/core/1d/fwd_piter1d.hh: Likewise. * oln/core/1d/point1d.hh: Likewise. * oln/core/coord.hh: Likewise. * oln/core/2d/array2d.hh: Likewise. * oln/core/2d/image2d.hh: Likewise. * oln/core/2d/fwd_piter2d.hh: Likewise. * oln/core/2d/point2d.hh: Likewise. * oln/core/3d/array3d.hh: Likewise. * oln/core/3d/image3d.hh: Likewise. * oln/core/3d/point3d.hh: Likewise. * oln/core/cats.hh: Remove because obsolete. * oln/core/props.hh: Likewise. * oln/core/macros.hh: Likewise. oln/basics.hh | 2 oln/core/1d/array1d.hh | 13 ++ oln/core/1d/fwd_piter1d.hh | 13 ++ oln/core/1d/image1d.hh | 47 ++++++---- oln/core/1d/point1d.hh | 16 ++- oln/core/2d/array2d.hh | 15 ++- oln/core/2d/fwd_piter2d.hh | 12 ++ oln/core/2d/image2d.hh | 35 ++++--- oln/core/2d/point2d.hh | 15 ++- oln/core/3d/array3d.hh | 13 ++ oln/core/3d/image3d.hh | 42 ++++----- oln/core/3d/point3d.hh | 13 ++ oln/core/abstract/data_storage.hh | 61 +++++++++++-- oln/core/abstract/entry.hh | 83 ++++++++++++++++++ oln/core/abstract/image.hh | 138 +++++++++++++++++++++---------- oln/core/abstract/image_constness.hh | 17 ++- oln/core/abstract/image_identity.hh | 28 +++++- oln/core/abstract/image_with_data.hh | 54 ++++++++++-- oln/core/abstract/images.hh | 3 oln/core/abstract/internal/image_impl.hh | 7 - oln/core/abstract/op.hh | 22 ++++ oln/core/abstract/piter.hh | 45 +++++++--- oln/core/abstract/point.hh | 41 ++++++--- oln/core/cats.hh | 79 ----------------- oln/core/coord.hh | 8 + oln/core/entry.hh | 66 -------------- oln/core/macros.hh | 86 ------------------- oln/core/properties.hh | 95 +++++++++++++++++++++ oln/core/props.hh | 77 ----------------- oln/core/value_box.hh | 37 ++++---- oln/fancy/iota.hh | 3 oln/fancy/print.hh | 5 - oln/io/read_image.hh | 4 oln/io/read_image_2d_pnm.hh | 27 ++---- oln/io/write_image.hh | 6 - oln/io/write_image_2d_pnm.hh | 3 oln/makefile.src | 6 - tests/core/tests/image1d | 2 tests/core/tests/image2d | 2 tests/core/tests/image3d | 2 tests/core/tests/image_identity | 11 +- tests/core/tests/setget | 6 - 42 files changed, 700 insertions(+), 560 deletions(-) Index: tests/core/tests/image1d --- tests/core/tests/image1d (revision 50) +++ tests/core/tests/image1d (working copy) @@ -13,7 +13,7 @@ template <typename I> -void foo(oln::abstract::image<I>& input, const oln_point_type(I)& p) +void foo(oln::abstract::image<I>& input, const oln_type_of(I, point)& p) { // FIXME: dummy code below // struct dummy {}; Index: tests/core/tests/image2d --- tests/core/tests/image2d (revision 50) +++ tests/core/tests/image2d (working copy) @@ -13,7 +13,7 @@ template <typename I> -void foo(oln::abstract::image<I>& input, const oln_point_type(I)& p) +void foo(oln::abstract::image<I>& input, const oln_type_of(I, point)& p) { // FIXME: dummy code below // struct dummy {}; Index: tests/core/tests/image3d --- tests/core/tests/image3d (revision 50) +++ tests/core/tests/image3d (working copy) @@ -13,7 +13,7 @@ template <typename I> -void foo(oln::abstract::image<I>& input, const oln_point_type(I)& p) +void foo(oln::abstract::image<I>& input, const oln_type_of(I, point)& p) { // FIXME: dummy code below // struct dummy {}; Index: tests/core/tests/image_identity --- tests/core/tests/image_identity (revision 50) +++ tests/core/tests/image_identity (working copy) @@ -10,14 +10,14 @@ namespace oln { template <typename I> - struct category_type< image_identity<I> > + struct set_category< image_identity<I> > { - typedef cat::image ret; + typedef category::image ret; }; template <typename I> - struct props <cat::image, image_identity<I> > - : public props<cat::image, I> + struct set_props < category::image, image_identity<I> > + : public get_props < category::image, I > { typedef I delegated_type; }; @@ -25,8 +25,7 @@ } template <typename I> -struct image_identity: - public oln::abstract::image_identity<I, image_identity<I> > +struct image_identity : public oln::abstract::image_identity<I, image_identity<I> > { typedef oln::abstract::image_identity<I, image_identity<I> > super_type; Index: tests/core/tests/setget --- tests/core/tests/setget (revision 50) +++ tests/core/tests/setget (working copy) @@ -7,13 +7,13 @@ struct dummy_image; template <> - struct category_type< dummy_image > + struct set_category< dummy_image > { - typedef cat::image ret; + typedef category::image ret; }; template <> - struct props <cat::image, dummy_image> + struct set_props < category::image, dummy_image > : public props_of <category::image> { typedef int size_type; typedef int point_type; Index: oln/fancy/print.hh --- oln/fancy/print.hh (revision 50) +++ oln/fancy/print.hh (working copy) @@ -40,6 +40,7 @@ # include <oln/core/2d/point2d.hh> # include <oln/core/coord.hh> + namespace oln { namespace fancy { @@ -106,7 +107,7 @@ // FIXME: lacks cleaning for (coord_t index = 0; index < input.size().nindices(); ++index) { - ostr << internal::pp<oln_value_type(E)>(input[point1d(index)]) << ' '; + ostr << internal::pp<oln_type_of(E, value)>(input[point1d(index)]) << ' '; } ostr << std::endl; } @@ -118,7 +119,7 @@ for (coord_t row = 0; row < input.size().nrows(); ++row) { for (coord_t col = 0; col < input.size().ncols(); ++col) - ostr << internal::pp<oln_value_type(E)>(input[point2d(row,col)]) << ' '; + ostr << internal::pp<oln_type_of(E, value)>(input[point2d(row,col)]) << ' '; ostr << std::endl; } } Index: oln/fancy/iota.hh --- oln/fancy/iota.hh (revision 50) +++ oln/fancy/iota.hh (working copy) @@ -28,7 +28,6 @@ #ifndef OLENA_FANCY_IOTA_HH # define OLENA_FANCY_IOTA_HH -# include <oln/core/macros.hh> # include <oln/core/abstract/image.hh> # include <oln/core/abstract/piter.hh> @@ -43,7 +42,7 @@ void iota(abstract::image<I>& inout) { unsigned counter = 0; - oln_piter_type(I) p(inout.size()); + oln_type_of(I, fwd_piter) p(inout.size()); for_all(p) inout[p] = ++counter; } Index: oln/basics.hh --- oln/basics.hh (revision 50) +++ oln/basics.hh (working copy) @@ -54,7 +54,7 @@ // oln:: # include <oln/core/coord.hh> -# include <oln/core/macros.hh> +# include <oln/core/properties.hh> # include <oln/core/value_box.hh> # include <oln/core/abstract/size.hh> Index: oln/makefile.src --- oln/makefile.src (revision 50) +++ oln/makefile.src (working copy) @@ -24,6 +24,7 @@ core/3d/point3d.hh \ core/3d/size3d.hh \ core/abstract/data_storage.hh \ + core/abstract/entry.hh \ core/abstract/image.hh \ core/abstract/image_constness.hh \ core/abstract/image_identity.hh \ @@ -34,11 +35,8 @@ core/abstract/piter.hh \ core/abstract/point.hh \ core/abstract/size.hh \ - core/cats.hh \ core/coord.hh \ - core/macros.hh \ - core/props.hh \ - core/entry.hh \ + core/properties.hh \ core/value_box.hh \ fancy/iota.hh \ fancy/print.hh \ Index: oln/io/write_image_2d_pnm.hh --- oln/io/write_image_2d_pnm.hh (revision 50) +++ oln/io/write_image_2d_pnm.hh (working copy) @@ -41,7 +41,6 @@ # include <ntg/color/color.hh> # include <oln/core/2d/image2d.hh> -# include <oln/core/macros.hh> # include <oln/core/abstract/op.hh> # include <oln/io/utils.hh> @@ -56,7 +55,7 @@ struct write_image_2d_raw : public oln::abstract::void_op<write_image_2d_raw<I> > { - typedef oln_value_type(I) value_type; + typedef oln_type_of(I, value) value_type; typedef ntg_io_type(value_type) io_type; const I& to_write_; Index: oln/io/read_image_2d_pnm.hh --- oln/io/read_image_2d_pnm.hh (revision 50) +++ oln/io/read_image_2d_pnm.hh (working copy) @@ -13,7 +13,6 @@ # include <ntg/color/color.hh> # include <oln/core/2d/image2d.hh> -# include <oln/core/macros.hh> # include <oln/core/abstract/op.hh> # include <oln/io/utils.hh> @@ -24,43 +23,39 @@ template <typename I> struct image2d; + // fwd decl namespace io { - namespace impl { - - template <typename I> - struct read_image_2d_raw; - + template <typename I> struct read_image_2d_raw; } - } + // category template <typename I> - struct category_type< io::impl::read_image_2d_raw<I> > + struct set_category < io::impl::read_image_2d_raw<I> > { - typedef cat::image ret; + typedef category::image ret; }; + // super_type template <typename I> - struct props <cat::image, io::impl::read_image_2d_raw<I> > - : public props<cat::image, I> + struct set_super_type < io::impl::read_image_2d_raw<I> > { - typedef I delegated_type; + typedef abstract::op<I, io::impl::read_image_2d_raw<I> > ret; }; - namespace io { namespace impl { template <typename I> - struct read_image_2d_raw: - oln::abstract::op<I, read_image_2d_raw<I> > + struct read_image_2d_raw : + public oln::abstract::op<I, read_image_2d_raw<I> > { typedef oln::abstract::op<I, read_image_2d_raw<I> > super_type; - typedef oln_value_type(I) value_type; + typedef oln_type_of(I, value) value_type; typedef ntg_io_type(value_type) io_type; mlc::box<I> image_; Index: oln/io/write_image.hh --- oln/io/write_image.hh (revision 50) +++ oln/io/write_image.hh (working copy) @@ -37,11 +37,11 @@ namespace io { - template <typename E> - void write(const abstract::image<E>& im, const std::string& name) + template <typename I> + void write(const abstract::image<I>& im, const std::string& name) { std::string ext; - oln_value_type(E) t; + oln_type_of(I, value) t; ext = internal::utils::extension(name); Index: oln/io/read_image.hh --- oln/io/read_image.hh (revision 50) +++ oln/io/read_image.hh (working copy) @@ -33,8 +33,6 @@ # include <mlc/box.hh> -# include <oln/core/macros.hh> - # include <oln/io/read_image_2d_pnm.hh> # include <oln/io/utils.hh> @@ -65,7 +63,7 @@ void do_read(abstract::image<I>& ima, const filename& name) { std::string ext; - const oln_value_type(I) t; + const oln_type_of(I, value) t; ext = internal::utils::extension(name.get()); Index: oln/core/entry.hh --- oln/core/entry.hh (revision 50) +++ oln/core/entry.hh (working copy) @@ -1,66 +0,0 @@ -// Copyright (C) 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_ENTRY_HH -# define OLENA_CORE_ENTRY_HH - -# include <oln/core/abstract/image_constness.hh> -# include <oln/core/abstract/image_dimension.hh> - - -namespace oln { - - template <template <typename> class Base> - struct prop_of - { - template <typename E> - struct inherits - { - typedef Base<E> ret; - }; - }; - - namespace abstract { - - template <typename E> - struct image_entry : - public props < cat::image, E >::image_constness - ::template inherits<E>::ret, - public props < cat::image, E >::image_dimension - ::template inherits<E>::ret - // ... - { - protected: - image_entry() {} - }; - - } - -} // end of namespace oln - - -#endif // ! OLENA_CORE_ENTRY_HH Index: oln/core/props.hh --- oln/core/props.hh (revision 50) +++ oln/core/props.hh (working copy) @@ -1,77 +0,0 @@ -// Copyright (C) 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_PROPS_HH -# define OLENA_CORE_PROPS_HH - -# include <mlc/types.hh> - -# include <oln/core/cats.hh> - -/*! \namespace oln -** \brief oln namespace. -*/ -namespace oln { - - - /*! \class default_props - ** - ** \brief Class that defines properties by default, so properties are - ** undefined. // FIXME: this doc should be modified... - ** - ** Practically all typedefs of default_props are thus set to - ** mlc::undefined_type. - ** - ** When props<E> is specialized, the programmer should derive that - ** specialization from another props<E'> or from default_props. - ** That ensures that an undefined property is set to mlc::undefined_type. - ** - ** \see props<E> - */ - template < typename category > - struct default_props; - - - /*! \class props<E> - ** - ** Declaration of the trait class for properties. - ** Parameter E is the targeted type. FIXME: rewrite doc. - */ - template <typename category, typename type> - struct props : public default_props <category> - {}; - - template <typename category, typename type> - struct props <category, const type> : public props <category, type> - {}; - - - -} // end of namespace oln - - -#endif // ! OLENA_CORE_PROPS_HH Index: oln/core/value_box.hh --- oln/core/value_box.hh (revision 50) +++ oln/core/value_box.hh (working copy) @@ -30,16 +30,11 @@ # include <iostream> -# include <oln/core/macros.hh> +# include <oln/core/properties.hh> -// the proper macro: -// for use in 'abstract::image::op[](point)' -# define oln_value_box_type(E) typename oln::value_box<E> - - /*! \namespace oln ** \brief oln namespace. */ @@ -78,7 +73,12 @@ public: + /// typedefs + typedef oln_type_of(I, value) value_type; + typedef oln_type_of(I, point) point_type; + + /*! \brief op= ** FIXME:... ** \return (*this) @@ -103,7 +103,7 @@ template <typename II> value_box& operator=(const value_box<II>& rhs) { - ima_.set(p_, rhs); // automatic conversion from rhs to oln_value_type(I) + ima_.set(p_, rhs); // automatic conversion from rhs to value_type return *this; } @@ -137,7 +137,7 @@ return value; } - operator const oln_value_type(I)() const + operator const value_type() const { return ima_.get(p_); } @@ -154,7 +154,7 @@ ** \return a value (const, temp) */ - const oln_value_type(I) value() const + const value_type value() const { return ima_.get(p_); } @@ -179,7 +179,7 @@ /// Ctor (restricted access). - value_box(abstract::image<I>& ima, const oln_point_type(I)& p) : + value_box(abstract::image<I>& ima, const point_type& p) : ima_(ima.exact()), p_(p) { @@ -190,7 +190,7 @@ *------------*/ I& ima_; - oln_point_type(I) p_; + point_type p_; }; @@ -213,6 +213,13 @@ public: + /// typedefs + + typedef oln_type_of(I, value) value_type; + typedef oln_type_of(I, point) point_type; + + + /*! \brief Assignment (op=) is declared but undefined. */ @@ -232,7 +239,7 @@ return value; } - operator const oln_value_type(I)() const + operator const value_type() const { return ima_.get(p_); } @@ -249,7 +256,7 @@ ** \return a value (const, temp) */ - const oln_value_type(I) value() const + const value_type value() const { return ima_.get(p_); } @@ -276,7 +283,7 @@ /// Ctor (restricted access). - value_box(const abstract::image<I>& ima, const oln_point_type(I)& p) : + value_box(const abstract::image<I>& ima, const point_type& p) : ima_(ima.exact()), p_(p) { @@ -287,7 +294,7 @@ *------------*/ const I& ima_; - oln_point_type(I) p_; + point_type p_; }; Index: oln/core/macros.hh --- oln/core/macros.hh (revision 50) +++ oln/core/macros.hh (working copy) @@ -1,86 +0,0 @@ -// Copyright (C) 2001, 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_MACROS_HH -# define OLENA_CORE_MACROS_HH - -# include <oln/core/cats.hh> -# include <oln/core/props.hh> - - - -// FIXME: some crucial (meta-)work to be done here! -// -// first, introduce a piece of meta-code to get the proper abstraction -// from parameter; e.g., if I is an abstract::image then abstraction -// is abstract::image else etc. -// -// second, in macro below, there should be an exact_type from I somewhere -// cause we cannot be sure that I is an exact type; just think about it... - - - - - -// for oln::abstract::image -//-------------------------- - -// unary macros - -# define oln_delegated_type(T) typename oln::props<oln_category_type(T),T>::delegated_type - -# define oln_size_type(T) typename oln::props<oln_category_type(T),T>::size_type -# define oln_point_type(T) typename oln::props<oln_category_type(T),T>::point_type -# define oln_dpoint_type(T) typename oln::props<oln_category_type(T),T>::dpoint_type -# define oln_value_type(T) typename oln::props<oln_category_type(T),T>::value_type -# define oln_iter_type(T) typename oln::props<oln_category_type(T),T>::iter_type - -# define oln_value_storage_type(T) typename oln::props<oln_category_type(T),T>::value_storage_type -# define oln_value_container_type(T) typename oln::props<oln_category_type(T),T>::value_container_type - -# define oln_piter_type(T) typename oln::props<oln_category_type(T),T>::piter_type -# define oln_fwd_piter_type(T) typename oln::props<oln_category_type(T),T>::fwd_piter_type - -// binary macros - -# define oln_ch_value_type(I,V) typename oln::props<oln_category_type(I),I>::ch_value_type<V>::ret - - -// for oln::abstract::data_storage - -# define oln_data_type(T) typename oln::props<oln_category_type(T),T>::data_type - - - -// generic macros -//---------------- - -# define oln_typeof( FROM_TYPE, WHAT_TYPE ) typename oln::props<oln_category_type(FROM_TYPE),FROM_TYPE>::WHAT_TYPE##_type - - - -#endif // ! OLENA_CORE_MACROS_HH Index: oln/core/abstract/image_constness.hh --- oln/core/abstract/image_constness.hh (revision 50) +++ oln/core/abstract/image_constness.hh (working copy) @@ -87,6 +87,11 @@ */ + /// typedef + + typedef oln_type_of(E, point) point_type; + + /*! \brief Write the value \a v at \a p in the current image. ** This method is used in value_box<I>. Client should not use ** this method but abstract::image<I>::operator[](point) @@ -96,7 +101,7 @@ */ template <typename V> - void set(const oln_point_type(E)& p, const V& v) + void set(const point_type& p, const V& v) { return this->exact().impl_set(p, v); } @@ -104,7 +109,7 @@ // FIXME: NEW: // template <typename A, typename V> -// void& set(const oln_point_type(E)& p, +// void& set(const point_type& p, // void (I::*method)(A), // const V& value) // { @@ -126,10 +131,12 @@ template <typename E> struct set_image_impl < readwrite_image<E>, E> : public virtual image_impl<E> { + /// typedefs typedef typename image_impl<E>::D D; + typedef oln_type_of(D, point) point_type; template <typename V> - void impl_set(const oln_point_type(D)& p, const V& v) + void impl_set(const point_type& p, const V& v) { this->exact().impl_set_ante(p, v); this->delegate().impl_set(p, v); @@ -139,10 +146,10 @@ // extra code; default is 'do nothing': template <typename V> - void impl_set_ante(const oln_point_type(D)&, const V&) {} + void impl_set_ante(const point_type&, const V&) {} template <typename V> - void impl_set_post(const oln_point_type(D)&, const V&) {} + void impl_set_post(const point_type&, const V&) {} }; } // end of namespace oln::abstract::internal Index: oln/core/abstract/entry.hh --- oln/core/abstract/entry.hh (revision 0) +++ oln/core/abstract/entry.hh (revision 0) @@ -0,0 +1,83 @@ +// Copyright (C) 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_ABSTRACT_ENTRY_HH +# define OLENA_CORE_ABSTRACT_ENTRY_HH + +# include <oln/core/abstract/image_constness.hh> +# include <oln/core/abstract/image_dimension.hh> + + +// FIXME: this file should move to oln/core/abstract/ + + +namespace oln { + + + // fwd decl + namespace abstract { + template <typename E> struct image_entry; + } + + // category + template <typename E> + struct set_category < abstract::image_entry<E> > + { + typedef category::image ret; + }; + + + + namespace abstract { + +// namespace internal { + +// template < typename isa, typename E > +// struct inherits +// { +// typedef typename isa::template instantiated_with<E>::ret ret; +// }; + +// } + + template <typename E> + struct image_entry : + // intrusive: + public oln_type_of_(E, image_constness) ::template instantiated_with<E>::ret, + public oln_type_of_(E, image_dimension) ::template instantiated_with<E>::ret + // ... + { + protected: + image_entry() {} + }; + + } + +} // end of namespace oln + + +#endif // ! OLENA_CORE_ABSTRACT_ENTRY_HH Index: oln/core/abstract/image.hh --- oln/core/abstract/image.hh (revision 50) +++ oln/core/abstract/image.hh (working copy) @@ -28,10 +28,10 @@ #ifndef OLENA_CORE_ABSTRACT_IMAGE_HH # define OLENA_CORE_ABSTRACT_IMAGE_HH +# include <mlc/types.hh> + # include <oln/core/abstract/internal/image_impl.hh> -# include <oln/core/cats.hh> -# include <oln/core/props.hh> -# include <oln/core/macros.hh> +# include <oln/core/properties.hh> # include <oln/core/value_box.hh> @@ -41,37 +41,72 @@ namespace oln { + // fwd decl + namespace abstract { + template <typename E> struct image; + template <typename E> struct readonly_image; + } - // FIXME: doc - template <> - struct default_props < cat::image > - { - typedef mlc::undefined_type delegated_type; + // category + template <typename E> + struct set_category< abstract::image<E> > { typedef category::image ret; }; - typedef mlc::undefined_type size_type; - typedef mlc::undefined_type point_type; - typedef mlc::undefined_type value_type; - typedef mlc::undefined_type piter_type; - typedef mlc::undefined_type fwd_piter_type; - typedef mlc::undefined_type value_storage_type; - typedef mlc::undefined_type value_container_type; + /// properties of any type in category::image - // FIXME: etc. + template <typename type> + struct props_of <category::image, type> + { + typedef mlc::true_type user_defined_; + + mlc_decl_prop(category::image, value_type); + mlc_decl_prop(category::image, point_type); + mlc_decl_prop(category::image, size_type); + mlc_decl_prop(category::image, fwd_piter_type); + mlc_decl_prop_with_default(category::image, value_storage_type, mlc::no_type); + mlc_decl_prop_with_default(category::image, storage_type, mlc::no_type); + mlc_decl_prop_with_default(category::image, delegated_type, mlc::no_type); - template <typename T> - struct ch_value_type + mlc_decl_prop_with_default(category::image, image_constness_type, is_a<abstract::readonly_image>); + mlc_decl_prop(category::image, image_dimension_type); + + //... + + static void echo(std::ostream& ostr) { - typedef mlc::undefined_type ret; - }; + ostr << "props_of(" // FIXME: << typeid(oln::category::image).name() + << ", " << typeid(type).name() << ") = {" + << " value_type = " << typeid(value_type).name() + << " point_type = " << typeid(point_type).name() + << " size_type = " << typeid(size_type).name() + << " fwd_piter_type = " << typeid(fwd_piter_type).name() + << " value_storage_type = " << typeid(value_storage_type).name() + << " storage_type = " << typeid(storage_type).name() + << " delegated_type = " << typeid(delegated_type).name() - protected: - default_props() {} + << " image_constness_type = " << typeid(image_constness_type).name() + << " image_dimension_type = " << typeid(image_dimension_type).name() + + << " }" << std::endl; + } + }; + mlc_register_prop(category::image, value_type); + mlc_register_prop(category::image, point_type); + mlc_register_prop(category::image, size_type); + mlc_register_prop(category::image, fwd_piter_type); + mlc_register_prop(category::image, value_storage_type); + mlc_register_prop(category::image, storage_type); + mlc_register_prop(category::image, delegated_type); + mlc_register_prop(category::image, image_constness_type); + mlc_register_prop(category::image, image_dimension_type); + + + /*! \namespace oln::abstract ** \brief oln::abstract namespace. */ @@ -92,20 +127,27 @@ struct image : public internal::get_image_impl < image<E>, E> { + /// typedefs + + typedef oln_type_of(E, size) size_type; + typedef oln_type_of(E, value) value_type; + typedef oln_type_of(E, point) point_type; + + /*------------------* ! abstract methods ! *------------------*/ - /*! \brief Return the size of the current image. Nota bene: this method is abstract-like.it - ** is a pseudo-abstract method. + /*! \brief Return the size of the current image. Nota bene: + ** this method is abstract-like.it is a pseudo-abstract method. ** ** \return An object deriving from abstract::size. Ex: if the ** image is an image2d<something>, the returned object is a ** size2d. */ - const oln_size_type(E)& size() const + const size_type& size() const { return this->exact().impl_size(); } @@ -137,7 +179,7 @@ ** \see hold_large */ - bool hold(const oln_point_type(E)& p) const + bool hold(const point_type& p) const { precondition(this->npoints() != 0); return this->exact().impl_hold(p); @@ -158,7 +200,7 @@ ** \see hold */ - bool hold_large(const oln_point_type(E)& p) const + bool hold_large(const point_type& p) const { precondition(this->npoints() != 0); return this->exact().impl_hold_large(p); @@ -175,7 +217,7 @@ ** \see hold_large */ - bool impl_hold_large(const oln_point_type(E)& p) const + bool impl_hold_large(const point_type& p) const { return this->hold(p); } @@ -196,11 +238,11 @@ ** \see value_box */ - oln_value_box_type(const E) operator[](const oln_point_type(E)& p) const + value_box<const E> operator[](const point_type& p) const { precondition(this->npoints() != 0); precondition(this->hold_large(p)); - oln_value_box_type(const E) tmp(this->exact(), p); + value_box<const E> tmp(this->exact(), p); return tmp; } @@ -214,11 +256,11 @@ ** \see value_box */ - oln_value_box_type(E) operator[](const oln_point_type(E)& p) + value_box<E> operator[](const point_type& p) { precondition(this->npoints() != 0); precondition(this->hold_large(p)); - oln_value_box_type(E) tmp(this->exact(), p); + value_box<E> tmp(this->exact(), p); return tmp; } @@ -251,7 +293,7 @@ ** \see value_box, abstract::image<I>::operator[](point) */ - const oln_value_type(E) get(const oln_point_type(E)& p) const + const value_type get(const point_type& p) const { return this->exact().impl_get(p); } @@ -282,13 +324,21 @@ template <typename E> struct set_image_impl < image<E>, E > : public virtual image_impl<E> { + + /// typedefs + typedef typename image_impl<E>::D D; + typedef oln_type_of(D, size) size_type; + typedef oln_type_of(D, point) point_type; + typedef oln_type_of(D, value) value_type; + + // delegations are "template methods" (Cf. the GOF's book) - const oln_size_type(D)& impl_size() const + const size_type& impl_size() const { - const oln_size_type(D)& s = this->delegate().size(); + const size_type& s = this->delegate().size(); this->exact().impl_size_extra(s); return s; } @@ -300,31 +350,31 @@ return n; } - bool impl_hold(const oln_point_type(D)& p) const + bool impl_hold(const point_type& p) const { this->exact().impl_hold_extra(p); return this->delegate().hold(p); } - bool impl_hold_large(const oln_point_type(D)& p) const + bool impl_hold_large(const point_type& p) const { this->exact().impl_hold_large_extra(p); return this->delegate().hold_large(p); } - oln_value_box_type(D) operator[](const oln_point_type(D)& p) const + value_box<D> operator[](const point_type& p) const { precondition(this->hold_large(p)); return this->delegate().operator[](p); } - oln_value_box_type(const D) operator[](const oln_point_type(D)& p) + value_box<const D> operator[](const point_type& p) { precondition(this->hold_large(p)); return this->delegate().operator[](p); } - const oln_value_type(D) impl_get(const oln_point_type(D)& p) const + const value_type impl_get(const point_type& p) const { this->exact().impl_get_extra(p); return this->delegate().impl_get(p); @@ -332,13 +382,13 @@ // extra code; default is "do nothing" - void impl_size_extra(const oln_size_type(D)& s) const {} + void impl_size_extra(const size_type& s) const {} void impl_npoints_extra(unsigned long n) const {} - void impl_hold_extra(const oln_point_type(D)& p) const {} - void impl_hold_large_extra(const oln_point_type(D)& p) const {} + void impl_hold_extra(const point_type& p) const {} + void impl_hold_large_extra(const point_type& p) const {} - void impl_get_extra(const oln_point_type(D)&) const {} + void impl_get_extra(const point_type&) const {} }; } // end of namespace oln::abstract::internal Index: oln/core/abstract/piter.hh --- oln/core/abstract/piter.hh (revision 50) +++ oln/core/abstract/piter.hh (working copy) @@ -33,9 +33,7 @@ # include <mlc/contract.hh> # include <oln/core/abstract/point.hh> -# include <oln/core/cats.hh> -# include <oln/core/props.hh> -# include <oln/core/macros.hh> +# include <oln/core/properties.hh> @@ -44,34 +42,55 @@ namespace oln { + // fwd decl namespace abstract { - template <typename E> struct piter; - } - + // category template <typename E> - struct category_type<abstract::piter<E> > { typedef cat::piter ret; }; + struct set_category< abstract::piter<E> > { typedef category::piter ret; }; - template <> - struct default_props < cat::piter > + /// properties of any type in category::piter + + template <typename type> + struct props_of < category::piter, type > { - typedef mlc::undefined_type point_type; - typedef mlc::undefined_type size_type; + typedef mlc::true_type user_defined_; + + mlc_decl_prop(category::piter, size_type); + mlc_decl_prop(category::piter, point_type); + + static void echo(std::ostream& ostr) + { + ostr << "props_of( category::piter, " + << typeid(type).name() << ") = {" + << " size_type = " << typeid(size_type).name() + << " point_type = " << typeid(point_type).name() << " }" << std::endl; + } + }; + mlc_register_prop(category::piter, size_type); + mlc_register_prop(category::piter, point_type); + + namespace abstract { template <typename E> struct piter : public mlc::any__best_speed<E> { + + /// typedefs + typedef piter<E> self_type; - typedef oln_point_type(E) point_type; - typedef oln_size_type(E) size_type; + typedef oln_type_of(E, size) size_type; + typedef oln_type_of(E, point) point_type; + + void start() { this->exact().impl_start(); Index: oln/core/abstract/images.hh --- oln/core/abstract/images.hh (revision 50) +++ oln/core/abstract/images.hh (working copy) @@ -36,7 +36,4 @@ # include <oln/core/abstract/image_constness.hh> -# include <oln/core/entry.hh> - - #endif // ! OLENA_CORE_ABSTRACT_IMAGES_HH Index: oln/core/abstract/image_with_data.hh --- oln/core/abstract/image_with_data.hh (revision 50) +++ oln/core/abstract/image_with_data.hh (working copy) @@ -31,15 +31,44 @@ # include <mlc/tracked_ptr.hh> -# include <oln/core/entry.hh> -# include <oln/core/macros.hh> +# include <oln/core/abstract/entry.hh> + /*! \namespace oln ** \brief oln namespace. */ namespace oln { + // fwd decl + namespace abstract { + template <typename E> class image_with_data; + } + + // category + template <typename E> + struct set_category < abstract::image_with_data<E> > + { + typedef category::image ret; + }; + + // super_type + template <typename E> + struct set_super_type < abstract::image_with_data<E> > + { + typedef abstract::image_entry<E> ret; + }; + + // props + template <typename E> + struct set_props < category::image, abstract::image_with_data<E> > : public props_of<category::image> + { + // intrusive property: + typedef is_a<abstract::readwrite_image> image_constness_type; + }; + + + /*! \namespace oln::abstract ** \brief oln::abstract namespace. */ @@ -59,7 +88,14 @@ public: + /// typedefs + typedef oln_type_of(E, size) size_type; + typedef oln_type_of(E, point) point_type; + typedef oln_type_of(E, value) value_type; + typedef oln_type_of(E, storage) storage_type; + + /*! \brief Implement abstract::image<E>::size() so return the ** size of the current image. ** @@ -68,7 +104,7 @@ ** size2d. */ - const oln_size_type(E)& impl_size() const + const size_type& impl_size() const { precondition(this->has_data()); return this->data_->size(); @@ -97,7 +133,7 @@ ** \return True if p belongs to the current image, false otherwise. */ - bool impl_hold(const oln_point_type(E)& p) const + bool impl_hold(const point_type& p) const { precondition(this->has_data()); return this->data_->hold(p); @@ -111,7 +147,7 @@ ** \return True if p belongs to the current image, false otherwise. */ - const oln_value_type(E) impl_get(const oln_point_type(E)& p) const + const value_type impl_get(const point_type& p) const { precondition(this->has_data()); return this->data_->get(p); @@ -123,7 +159,7 @@ */ template <typename V> - void impl_set(const oln_point_type(E)& p, const V& v) + void impl_set(const point_type& p, const V& v) { precondition(this->has_data()); this->data_->set(p, v); @@ -151,8 +187,8 @@ /*! \brief Constructor (protected) with memory allocation for ** data. */ - image_with_data(const oln_size_type(E)& size) : - data_(new oln_value_container_type(E)(size)) + image_with_data(const size_type& size) : + data_(new storage_type(size)) { } @@ -166,7 +202,7 @@ /*! \brief Data storage. */ - mlc::tracked_ptr<oln_value_container_type(E)> data_; + mlc::tracked_ptr<storage_type> data_; }; Index: oln/core/abstract/point.hh --- oln/core/abstract/point.hh (revision 50) +++ oln/core/abstract/point.hh (working copy) @@ -29,10 +29,9 @@ # define OLENA_CORE_ABSTRACT_POINT_HH # include <mlc/any.hh> +# include <mlc/bool.hh> -# include <oln/core/cats.hh> -# include <oln/core/props.hh> -# include <oln/core/macros.hh> +# include <oln/core/properties.hh> /*! \namespace oln @@ -41,24 +40,37 @@ namespace oln { - /// fwd decl + // fwd decl namespace abstract { template <typename E> struct point; } + // category + template <typename E> + struct set_category< abstract::point<E> > { typedef category::point ret; }; - /*! \class default_props< cat::point > - ** - ** Default properties for points. Specialization of - ** default_props<category>. - */ - template <> - struct default_props < cat::point > + + /// properties of any type in category::point + + template <typename type> + struct props_of < category::point, type > { - typedef mlc::undefined_type dpoint_type; + typedef mlc::true_type user_defined_; + + mlc_decl_prop(category::point, dpoint_type); + + static void echo(std::ostream& ostr) + { + ostr << "props_of( category::point, " + << typeid(type).name() << ") = {" + << " dpoint_type = " << typeid(dpoint_type).name() << " }" << std::endl; + } + }; + mlc_register_prop(category::point, dpoint_type); + /*! \namespace oln::abstract ** \brief oln::abstract namespace. */ @@ -95,9 +107,10 @@ return ! this->operator==(rhs); } - typedef oln_dpoint_type(E) dpoint_type; + // FIXME: doc... - // FIXME: doc + typedef oln_type_of(E, dpoint) dpoint_type; + const point operator+(const dpoint_type& dp) const { return this->exact().impl_plus(dp); Index: oln/core/abstract/image_identity.hh --- oln/core/abstract/image_identity.hh (revision 50) +++ oln/core/abstract/image_identity.hh (working copy) @@ -30,14 +30,38 @@ # include <mlc/box.hh> -# include <oln/core/entry.hh> +# include <oln/core/properties.hh> +# include <oln/core/abstract/entry.hh> + namespace oln { + + // fwd decl namespace abstract { + template <typename I, typename E> struct image_identity; + } + // category + template <typename I, typename E> + struct set_category< abstract::image_identity<I,E> > { + typedef category::image ret; + }; + + // props + template <typename I, typename E> + struct set_props < category::image, abstract::image_identity<I,E> > + : public get_props< category::image, I > + { + typedef I delegated_type; + }; + + + + namespace abstract { + template <typename I, typename E> - struct image_identity: public abstract::image_entry<E> + struct image_identity : public abstract::image_entry<E> { protected: Index: oln/core/abstract/data_storage.hh --- oln/core/abstract/data_storage.hh (revision 50) +++ oln/core/abstract/data_storage.hh (working copy) @@ -30,15 +30,57 @@ # include <mlc/any.hh> -# include <oln/core/macros.hh> +# include <oln/core/properties.hh> + namespace oln { + // fwd decl namespace abstract { + template <typename E> struct data_storage; + } + // category + template <typename E> + struct set_category< abstract::data_storage<E> > { typedef category::data_storage ret; }; + + + template <typename type> + struct props_of < category::data_storage, type > + { + typedef mlc::true_type user_defined_; + + mlc_decl_prop(category::data_storage, size_type); + mlc_decl_prop(category::data_storage, point_type); + mlc_decl_prop(category::data_storage, data_type); + + static void echo(std::ostream& ostr) + { + ostr << "props_of( category::data_storage, " + << typeid(type).name() << " ) = {" + << " size_type = " << typeid(size_type).name() + << " point_type = " << typeid(point_type).name() + << " data_type = " << typeid(data_type).name() << " }" << std::endl; + } + + }; + + mlc_register_prop(category::data_storage, size_type); + mlc_register_prop(category::data_storage, point_type); + mlc_register_prop(category::data_storage, data_type); + + + namespace abstract { + template <typename E> struct data_storage : public mlc::any__best_speed<E> { + // typedefs + + typedef oln_type_of(E, size) size_type; + typedef oln_type_of(E, point) point_type; + typedef oln_type_of(E, data) data_type; + // abstract methods bool has_data() const @@ -54,12 +96,12 @@ postcondition(! this->has_data()); } - const oln_size_type(E)& size() const + const size_type& size() const { return this->exact().impl_size(); } - void resize(const oln_size_type(E)& s) + void resize(const size_type& s) { this->exact().impl_resize(s); } @@ -71,29 +113,28 @@ return this->exact().impl_npoints(); } - bool hold(const oln_point_type(E)& p) const + bool hold(const point_type& p) const { if (! this->has_data()) return false; return this->exact().impl_hold(p); } - const oln_data_type(E) get(const oln_point_type(E)& p) const + const data_type get(const point_type& p) const { precondition(this->has_data()); precondition(this->hold_large(p)); return this->exact().impl_get(p); } - void set(const oln_point_type(E)& p, - const oln_data_type(E)& v) + void set(const point_type& p, const data_type& v) { precondition(this->has_data()); precondition(this->hold_large(p)); this->exact().impl_set(p, v); } - void set_data(const oln_data_type(E)& v) + void set_data(const data_type& v) { precondition(this->has_data()); this->exact().impl_set_data(v); @@ -101,14 +142,14 @@ // polymorphic method with default - bool hold_large(const oln_point_type(E)& p) const + bool hold_large(const point_type& p) const { if (! this->has_data()) return false; return this->exact().impl_hold_large(p); } - bool impl_hold_large(const oln_point_type(E)& p) const + bool impl_hold_large(const point_type& p) const { return this->exact().impl_hold(p); } Index: oln/core/abstract/internal/image_impl.hh --- oln/core/abstract/internal/image_impl.hh (revision 50) +++ oln/core/abstract/internal/image_impl.hh (working copy) @@ -30,8 +30,9 @@ # include <mlc/any.hh> -# include <oln/core/macros.hh> +# include <oln/core/properties.hh> + namespace oln { namespace abstract { @@ -45,7 +46,7 @@ // entry point: template <typename A, typename E> - struct get_image_impl : public get_image_impl_helper <A, oln_delegated_type(E), E> + struct get_image_impl : public get_image_impl_helper <A, oln_type_of(E, delegated), E> { }; @@ -67,7 +68,7 @@ template <typename E> struct image_impl : public mlc::any__best_speed<E> { - typedef oln_delegated_type(E) D; + typedef oln_type_of(E, delegated) D; D& delegate() { return this->exact().impl_delegate(); } const D& delegate() const { return this->exact().impl_delegate(); } }; Index: oln/core/abstract/op.hh --- oln/core/abstract/op.hh (revision 50) +++ oln/core/abstract/op.hh (working copy) @@ -32,14 +32,28 @@ namespace oln { + // fwd decl namespace abstract { + template <typename O, typename E> struct op; + } - template <typename I, typename E> - struct op : public oln::abstract::image_identity<I, E> + // category + template <typename O, typename E> + struct set_category< abstract::op<O,E> > { typedef category::image ret; }; + + // super_type + template <typename O, typename E> + struct set_super_type< abstract::op<O,E> > { typedef abstract::image_identity<O, E> ret; }; + + + namespace abstract { + + template <typename O, typename E> + struct op : public image_identity<O, E> { - typedef oln::abstract::image_identity<I, E> super_type; + typedef image_identity<O, E> super_type; - op(I& ref): super_type(ref) + op(O& ref) : super_type(ref) { this->exact_ptr = (E*)(void*)(this); } Index: oln/core/1d/array1d.hh --- oln/core/1d/array1d.hh (revision 50) +++ oln/core/1d/array1d.hh (working copy) @@ -36,13 +36,20 @@ namespace oln { + // fwd decl template <typename T> struct array1d; - template <typename T> - struct category_type< array1d<T> > { typedef cat::data_storage ret; }; + // category + template <typename T> + struct set_category< array1d<T> > { typedef category::data_storage ret; }; + // super_type + template <typename T> + struct set_super_type< array1d<T> > { typedef abstract::data_storage< array1d<T> > ret; }; + + // props template <typename T> - struct props < cat::data_storage, array1d<T> > // FIXME: add inheritance + struct set_props < category::data_storage, array1d<T> > : public props_of<category::data_storage> { typedef size1d size_type; typedef point1d point_type; Index: oln/core/1d/image1d.hh --- oln/core/1d/image1d.hh (revision 50) +++ oln/core/1d/image1d.hh (working copy) @@ -25,41 +25,44 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLENA_CORE_IMAGE1D_HH -# define OLENA_CORE_IMAGE1D_HH +#ifndef OLENA_CORE_1D_IMAGE1D_HH +# define OLENA_CORE_1D_IMAGE1D_HH # include <mlc/traits.hh> # include <oln/core/abstract/image_with_data.hh> # include <oln/core/1d/array1d.hh> +# include <oln/core/1d/fwd_piter1d.hh> + + /*! \namespace oln ** \brief oln namespace. */ namespace oln { + // fwd decl template <typename T> class image1d; - // category decl - template <typename T> struct category_type< image1d<T> > { typedef cat::image ret; }; + // category + template <typename T> + struct set_category< image1d<T> > { typedef category::image ret; }; + // super + template <typename T> + struct set_super_type < image1d<T> > + { + typedef abstract::image_with_data< image1d<T> > ret; + }; - /*! \class props< abstract::image, image1d<T> > - ** - ** Properties of common 1D images. Specialization of props<abstraction,type>. - ** Parameter T is the type of pixel values. - ** - ** \see image1d<T>, props<category,type> - */ template <typename T> - struct props < cat::image, image1d<T> > : public default_props < cat::image > + struct set_props < category::image, image1d<T> > : public props_of<category::image> { - // intrusive properties - typedef prop_of<abstract::readwrite_image> image_constness; - typedef prop_of<abstract::image1d> image_dimension; + // intrusive property: + typedef is_a<abstract::image1d> image_dimension_type; typedef mlc::no_type delegated_type; @@ -67,14 +70,18 @@ typedef point1d point_type; typedef T value_type; + typedef fwd_piter1d piter_type; + typedef fwd_piter1d fwd_piter_type; + // please note that value_storage_type means data_type // since image1d is an image_with_data - typedef mlc_encoding_type(T) value_storage_type; + typedef T value_storage_type; +// typedef mlc_encoding_type(T) value_storage_type; // please note that value_container_type means // data_container_type (or value_storage_container_type) // FIXME: find a better name... - typedef array1d<value_storage_type> value_container_type; + typedef array1d<value_storage_type> storage_type; // functions @@ -83,11 +90,13 @@ { typedef image1d<U> ret; }; - }; + + + /*! \class image1d<T> ** ** Common class for 1D images. Pixels values are stored in memory. @@ -126,4 +135,4 @@ } // end of namespace oln -#endif // ! OLENA_CORE_IMAGE1D_HH +#endif // ! OLENA_CORE_1D_IMAGE1D_HH Index: oln/core/1d/fwd_piter1d.hh --- oln/core/1d/fwd_piter1d.hh (revision 50) +++ oln/core/1d/fwd_piter1d.hh (working copy) @@ -33,22 +33,29 @@ # include <oln/core/abstract/piter.hh> # include <oln/core/1d/point1d.hh> # include <oln/core/1d/size1d.hh> -# include <oln/core/props.hh> namespace oln { + + // fwd decl struct fwd_piter1d; - template <> struct category_type< fwd_piter1d > { typedef cat::piter ret; }; + // category + template <> + struct set_category<fwd_piter1d> { typedef category::piter ret; }; + + // props template <> - struct props < cat::piter, fwd_piter1d > : public default_props< cat::piter > + struct set_props < category::piter, fwd_piter1d > : public props_of<category::piter> { typedef point1d point_type; typedef size1d size_type; }; + + struct fwd_piter1d : public abstract::piter< fwd_piter1d > { Index: oln/core/1d/point1d.hh --- oln/core/1d/point1d.hh (revision 50) +++ oln/core/1d/point1d.hh (working copy) @@ -32,8 +32,7 @@ # include <oln/core/abstract/point.hh> # include <oln/core/coord.hh> -# include <oln/core/cats.hh> -# include <oln/core/props.hh> +# include <oln/core/properties.hh> // FIXME: doc @@ -41,18 +40,27 @@ namespace oln { + struct point1d; struct dpoint1d; + // category template <> - struct category_type< point1d > { typedef cat::point ret; }; + struct set_category< point1d > { typedef category::point ret; }; + // super_type template <> - struct props < cat::point, point1d > : default_props< cat::point > + struct set_super_type< point1d > { typedef abstract::point< point1d > ret; }; + + // props + template <> + struct set_props < category::point, point1d > : public props_of<category::point> { typedef dpoint1d dpoint_type; }; + + struct point1d : public abstract::point< point1d > { point1d() Index: oln/core/coord.hh --- oln/core/coord.hh (revision 50) +++ oln/core/coord.hh (working copy) @@ -44,6 +44,8 @@ public: typedef int value_type; + static const value_type min_value = INT_MIN; + static const value_type max_value = INT_MAX; coord_t() : value_(undef_()) @@ -140,13 +142,13 @@ static const coord_t& infty() { - static coord_t infty_ = INT_MAX; + static coord_t infty_ = max_value; return infty_; } static const coord_t& _infty() { - static coord_t _infty_ = INT_MIN + 1; + static coord_t _infty_ = min_value + 1; return _infty_; } @@ -158,7 +160,7 @@ static const value_type undef_() { - return INT_MIN; + return min_value; } }; Index: oln/core/2d/array2d.hh --- oln/core/2d/array2d.hh (revision 50) +++ oln/core/2d/array2d.hh (working copy) @@ -35,14 +35,20 @@ namespace oln { + // fwd decl + template <typename T> struct array2d; - template <typename T> struct array2d; + // category template <typename T> - struct category_type< array2d<T> > { typedef cat::data_storage ret; }; + struct set_category< array2d<T> > { typedef category::data_storage ret; }; - + // super_type + template <typename T> + struct set_super_type< array2d<T> > { typedef abstract::data_storage< array2d<T> > ret; }; + + // props template <typename T> - struct props < cat::data_storage, array2d<T> > // FIXME: add inheritance + struct set_props < category::data_storage, array2d<T> > : public props_of<category::data_storage> { typedef size2d size_type; typedef point2d point_type; @@ -50,6 +56,7 @@ }; + template <typename T> class array2d : public abstract::data_storage< array2d<T> > { Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 50) +++ oln/core/2d/image2d.hh (working copy) @@ -35,6 +35,7 @@ # include <oln/core/2d/array2d.hh> # include <oln/core/2d/fwd_piter2d.hh> + /*! \namespace oln ** \brief oln namespace. */ @@ -48,28 +49,28 @@ void do_read(abstract::image<I>&, const filename&); } + + // fwd decl template <typename T> class image2d; - // category decl + // category template <typename T> - struct category_type< image2d<T> > { typedef cat::image ret; }; + struct set_category< image2d<T> > { typedef category::image ret; }; + // super + template <typename T> + struct set_super_type < image2d<T> > + { + typedef abstract::image_with_data< image2d<T> > ret; + }; - /*! \class props< abstract::image, image2d<T> > - ** - ** Properties of common 2D images. Specialization of props<abstraction,type>. - ** Parameter T is the type of pixel values. - ** - ** \see image2d<T>, props<category,type> - */ template <typename T> - struct props < cat::image, image2d<T> > : public default_props < cat::image > + struct set_props < category::image, image2d<T> > : public props_of<category::image> { - // intrusive properties - typedef prop_of<abstract::readwrite_image> image_constness; - typedef prop_of<abstract::image2d> image_dimension; + // intrusive property: + typedef is_a<abstract::image2d> image_dimension_type; typedef mlc::no_type delegated_type; @@ -82,12 +83,13 @@ // please note that value_storage_type means data_type // since image2d is an image_with_data - typedef mlc_encoding_type(T) value_storage_type; + typedef T value_storage_type; +// typedef mlc_encoding_type(T) value_storage_type; // please note that value_container_type means // data_container_type (or value_storage_container_type) // FIXME: find a better name... - typedef array2d<value_storage_type> value_container_type; + typedef array2d<value_storage_type> storage_type; // functions @@ -96,11 +98,12 @@ { typedef image2d<U> ret; }; - }; + + /*! \class image2d<T> ** ** Common class for 2D images. Pixels values are stored in memory. Index: oln/core/2d/fwd_piter2d.hh --- oln/core/2d/fwd_piter2d.hh (revision 50) +++ oln/core/2d/fwd_piter2d.hh (working copy) @@ -33,22 +33,28 @@ # include <oln/core/abstract/piter.hh> # include <oln/core/2d/point2d.hh> # include <oln/core/2d/size2d.hh> -# include <oln/core/props.hh> namespace oln { + // fwd decl struct fwd_piter2d; - template <> struct category_type<fwd_piter2d> { typedef cat::piter ret; }; + // category + template <> + struct set_category<fwd_piter2d> { typedef category::piter ret; }; + + // props template <> - struct props < cat::piter, fwd_piter2d > : public default_props<cat::piter> + struct set_props < category::piter, fwd_piter2d > : public props_of<category::piter> { typedef point2d point_type; typedef size2d size_type; }; + + struct fwd_piter2d : public abstract::piter< fwd_piter2d > { Index: oln/core/2d/point2d.hh --- oln/core/2d/point2d.hh (revision 50) +++ oln/core/2d/point2d.hh (working copy) @@ -30,10 +30,9 @@ # include <iostream> +# include <oln/core/properties.hh> # include <oln/core/abstract/point.hh> # include <oln/core/coord.hh> -# include <oln/core/cats.hh> -# include <oln/core/props.hh> // FIXME: doc! @@ -43,15 +42,23 @@ struct point2d; struct dpoint2d; + // category template <> - struct category_type< point2d > { typedef cat::point ret; }; + struct set_category< point2d > { typedef category::point ret; }; + // super_type template <> - struct props < cat::point, point2d > : default_props< cat::point > + struct set_super_type< point2d > { typedef abstract::point< point2d > ret; }; + + // props + template <> + struct set_props < category::point, point2d > : public props_of<category::point> { typedef dpoint2d dpoint_type; }; + + struct point2d : public abstract::point< point2d > { point2d() Index: oln/core/3d/array3d.hh --- oln/core/3d/array3d.hh (revision 50) +++ oln/core/3d/array3d.hh (working copy) @@ -36,13 +36,20 @@ namespace oln { + // fwd decl template <typename T> struct array3d; + + // category template <typename T> - struct category_type< array3d<T> > { typedef cat::data_storage ret; }; + struct set_category< array3d<T> > { typedef category::data_storage ret; }; - + // super_type + template <typename T> + struct set_super_type< array3d<T> > { typedef abstract::data_storage< array3d<T> > ret; }; + + // props template <typename T> - struct props < cat::data_storage, array3d<T> > // FIXME: add inheritance + struct set_props < category::data_storage, array3d<T> > : public props_of<category::data_storage> { typedef size3d size_type; typedef point3d point_type; Index: oln/core/3d/image3d.hh --- oln/core/3d/image3d.hh (revision 50) +++ oln/core/3d/image3d.hh (working copy) @@ -25,8 +25,8 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLENA_CORE_IMAGE3D_HH -# define OLENA_CORE_IMAGE3D_HH +#ifndef OLENA_CORE_3D_IMAGE3D_HH +# define OLENA_CORE_3D_IMAGE3D_HH # include <mlc/traits.hh> @@ -39,28 +39,27 @@ namespace oln { + // fwd decl template <typename T> class image3d; - // category decl - template <typename T> - struct category_type< image3d<T> > { typedef cat::image ret; }; + // category + template <typename T> + struct set_category< image3d<T> > { typedef category::image ret; }; + // super + template <typename T> + struct set_super_type < image3d<T> > + { + typedef abstract::image_with_data< image3d<T> > ret; + }; - /*! \class props< abstract::image, image3d<T> > - ** - ** Properties of common 3D images. Specialization of props<abstraction,type>. - ** Parameter T is the type of pixel values. - ** - ** \see image3d<T>, props<category,type> - */ template <typename T> - struct props < cat::image, image3d<T> > : public default_props < cat::image > + struct set_props < category::image, image3d<T> > : public props_of<category::image> { - // intrusive properties - typedef prop_of<abstract::readwrite_image> image_constness; - typedef prop_of<abstract::image3d> image_dimension; + // intrusive property: + typedef is_a<abstract::image3d> image_dimension_type; typedef mlc::no_type delegated_type; @@ -68,14 +67,18 @@ typedef point3d point_type; typedef T value_type; +// typedef fwd_piter3d piter_type; +// typedef fwd_piter3d fwd_piter_type; + // please note that value_storage_type means data_type // since image3d is an image_with_data - typedef mlc_encoding_type(T) value_storage_type; + typedef T value_storage_type; +// typedef mlc_encoding_type(T) value_storage_type; // please note that value_container_type means // data_container_type (or value_storage_container_type) // FIXME: find a better name... - typedef array3d<value_storage_type> value_container_type; + typedef array3d<value_storage_type> storage_type; // functions @@ -84,7 +87,6 @@ { typedef image3d<U> ret; }; - }; @@ -127,4 +129,4 @@ } // end of namespace oln -#endif // ! OLENA_CORE_IMAGE3D_HH +#endif // ! OLENA_CORE_3D_IMAGE3D_HH Index: oln/core/3d/point3d.hh --- oln/core/3d/point3d.hh (revision 50) +++ oln/core/3d/point3d.hh (working copy) @@ -35,14 +35,21 @@ namespace oln { - struct dpoint3d; // FIXME: not implemented!! + struct point3d; + struct dpoint3d; + // category template <> - struct category_type< point3d > { typedef cat::point ret; }; + struct set_category< point3d > { typedef category::point ret; }; + // super_type template <> - struct props < cat::point, point3d > : default_props< cat::point > + struct set_super_type< point3d > { typedef abstract::point< point3d > ret; }; + + // props + template <> + struct set_props < category::point, point3d > : public props_of<category::point> { typedef dpoint3d dpoint_type; }; Index: oln/core/cats.hh --- oln/core/cats.hh (revision 50) +++ oln/core/cats.hh (working copy) @@ -1,79 +0,0 @@ -// Copyright (C) 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_CATS_HH -# define OLENA_CORE_CATS_HH - -# include <mlc/types.hh> - - -/*! \macro FIXME:doc -*/ - -# define oln_category_type(T) typename oln::category_type<T>::ret - - - -/*! \namespace oln -** \brief oln namespace. -*/ -namespace oln { - - - /*! \class category_type<T> - ** - ** FIXME: doc - ** - */ - template <typename T> - struct category_type - { - typedef mlc::undefined_type ret; - }; - - - /*! \namespace oln::cat - ** \brief oln::cat namespace. - */ - namespace cat { - - struct image; - struct data_storage; - struct piter; - struct point; - struct size; - // FIXME:... - - } // end of namespace oln::cat - - -} // end of namespace oln - - - - -#endif // ! OLENA_CORE_CATS_HH Index: oln/core/properties.hh --- oln/core/properties.hh (revision 0) +++ oln/core/properties.hh (revision 0) @@ -0,0 +1,95 @@ +// Copyright (C) 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_PROPERTIES_HH +# define OLENA_CORE_PROPERTIES_HH + +# include <mlc/properties.hh> + + +/*! \namespace oln +** \brief oln namespace. +*/ +namespace oln +{ + + namespace category + { + struct data_storage; + struct image; + struct point; + struct size; + struct piter; + struct niter; + // FIXME: ... + } + + namespace target + { + struct data_type; + struct value_type; + struct value_storage_type; + struct storage_type; + struct point_type; + struct dpoint_type; + struct fwd_piter_type; + struct iter_type; + struct delegated_type; + struct size_type; + + struct image_constness_type; + struct image_dimension_type; + // FIXME: ... + } + + mlc_equip_namespace_for_properties(); + + + // FIXME: change name? + template <template <typename> class abstraction> + struct is_a // abstraction + { + template <typename E> + struct instantiated_with // E + { + typedef abstraction<E> ret; + }; + }; + + +} // end of namespace oln + + + +/// macro to retrieve a type (TARGET) from a class (oln::TYPE) + +# define oln_type_of(TYPE, TARGET) mlc_type_of(oln, TYPE, TARGET) +# define oln_type_of_(TYPE, TARGET) mlc_type_of_(oln, TYPE, TARGET) + + + +#endif // ! OLENA_CORE_PROPERTIES_HH
participants (1)
-
Thierry GERAUD