Commit 649d49ab authored by Roland Levillain's avatar Roland Levillain
Browse files

Lay the foundation stone of abstract::image.

	* oln/core/abstract/any.hh, oln/core/typedefs.hh,
	* oln/core/abstract/image.hh,
	* oln/core/abstract/internal/image_impl.hh
	* oln/core/abstract/image_entry.hh
	* oln/core/abstract/image_dimension.hh: New files (imported from
	Olena proto-1.0, and modified).
	* oln/core/abstract/macros.hh: New file.
	* tests/image_entry.cc: New test.
	* Makefile.am, oln/Makefile.am, tests/Makefile.am: New files.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@462 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 9c31ec27
2006-04-21 Roland Levillain <roland@lrde.epita.fr>
Lay the foundation stone of abstract::image.
* oln/core/abstract/any.hh, oln/core/typedefs.hh,
* oln/core/abstract/image.hh,
* oln/core/abstract/internal/image_impl.hh
* oln/core/abstract/image_entry.hh
* oln/core/abstract/image_dimension.hh: New files (imported from
Olena proto-1.0, and modified).
* oln/core/abstract/macros.hh: New file.
* tests/image_entry.cc: New test.
* Makefile.am, oln/Makefile.am, tests/Makefile.am: New files.
## Process this file through Automake to create Makefile.in -*- Makefile -*-
SUBDIRS = oln tests
## Process this file through Automake to create Makefile.in -*- Makefile -*-
olndir = $(includedir)/oln
nobase_oln_HEADERS = \
core/typedefs.hh \
\
core/abstract/any.hh \
core/abstract/image.hh \
core/abstract/image_entry.hh \
core/abstract/image_dimension.hh \
core/abstract/macros.hh \
\
core/abstract/internal/image_impl.hh
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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 program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 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_ANY_HH
# define OLENA_CORE_ABSTRACT_ANY_HH
# include <mlc/any.hh>
# include <mlc/bool.hh>
# include <mlc/is_a.hh>
namespace oln {
namespace abstract {
template <typename E>
struct any : public mlc::any<E, mlc::dispatch_policy::simple>
{
protected:
typedef mlc::any<E, mlc::dispatch_policy::simple> super;
any(E* exact_ptr) : super(exact_ptr) {}
any() {}
};
template <typename E>
struct any_best_speed :
public mlc::any<E, mlc::dispatch_policy::best_speed>
{
protected:
typedef mlc::any<E, mlc::dispatch_policy::best_speed> super;
any_best_speed(E* exact_ptr = 0) : super(exact_ptr) {}
};
} // end of namespace oln::abstract
} // end of namespace oln
# define oln_is_any(Type) \
mlc::or_< mlc_is_a(Type, oln::abstract::any), \
mlc_is_a(Type, oln::abstract::any_best_speed) >
#endif // ! OLENA_CORE_ABSTRACT_ANY_HH
// Copyright (C) 2001, 2003, 2004, 2005, 2006 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 program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301 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_IMAGE_HH
# define OLENA_CORE_ABSTRACT_IMAGE_HH
# include <mlc/cmp.hh>
# include <mlc/to_string.hh>
# include <oln/core/abstract/internal/image_impl.hh>
namespace oln {
// fwd decl
template <typename I>
class value_box;
// fwd decls
namespace abstract
{
template <typename I> class image;
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// template <typename I> class image_without_nbh;
// template <typename I> class readonly_image;
// template <typename I> class raw_image;
// template <typename P> class point;
// --------------------------------------------------------------------
}
// Declare virtual types.
mlc_decl_typedef(grid_type);
/// Virtual types associated to oln::abstract::image.
template <typename I>
struct vtypes< category::image, abstract::image<I> >
{
typedef I exact_type;
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// typedef mlc::undefined grid_type;
// typedef mlc::undefined concrete_type;
// typedef mlc::undefined value_type;
// typedef mlc::undefined point_type;
// typedef mlc::undefined size_type;
// typedef mlc::undefined piter_type;
// typedef mlc::undefined fwd_piter_type;
// typedef mlc::undefined bkd_piter_type;
// typedef mlc::none value_storage_type;
// typedef mlc::none storage_type;
// --------------------------------------------------------------------
typedef mlc::none delegated_type;
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// typedef mlc::none neighb_type;
// typedef is_a<abstract::image_without_nbh> image_neighbness_type;
// typedef is_a<abstract::readonly_image> image_constness_type;
// typedef mlc::undefined image_rawness_type;
// --------------------------------------------------------------------
typedef mlc::undefined image_dimension_type;
};
// FIXME: This should be placed into stc/properties.hh.
template <typename Category, typename T>
struct packed_vtypes
{
// Empty.
};
/// Retrieval of any image type properties (FIXME: say 'packing').
template <typename I>
struct packed_vtypes < category::image, I >
{
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// typedef oln_type_of(I, grid) grid_type;
// typedef oln_type_of(I, concrete) concrete_type;
// typedef oln_type_of(I, value) value_type;
// typedef oln_type_of(I, point) point_type;
// typedef oln_type_of(I, size) size_type;
// typedef oln_type_of(I, piter) piter_type;
// typedef oln_type_of(I, fwd_piter) fwd_piter_type;
// typedef oln_type_of(I, bkd_piter) bkd_piter_type;
// typedef oln_type_of(I, value_storage) value_storage_type;
// typedef oln_type_of(I, storage) storage_type;
// --------------------------------------------------------------------
typedef oln_type_of(I, delegated) delegated_type;
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// typedef oln_type_of(I, neighb) neighb_type;
// typedef oln_type_of(I, image_neighbness) image_neighbness_type;
// typedef oln_type_of(I, image_constness) image_constness_type;
// typedef oln_type_of(I, image_rawness) image_rawness_type;
// --------------------------------------------------------------------
typedef oln_type_of(I, image_dimension) image_dimension_type;
//...
static void echo(std::ostream& ostr)
{
ostr
<< "props_of( oln::category::image, " << mlc_to_string(I) << " ) ="
<< std::endl
<< "{" << std::endl
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// << "\t grid_type = " << mlc_to_string(grid_type) << std::endl
// << "\t concrete_type = " << mlc_to_string(concrete_type) << std::endl
// << "\t value_type = " << mlc_to_string(value_type) << std::endl
// << "\t point_type = " << mlc_to_string(point_type) << std::endl
// << "\t size_type = " << mlc_to_string(size_type) << std::endl
// << "\t piter_type = " << mlc_to_string(piter_type) << std::endl
// << "\t fwd_piter_type = " << mlc_to_string(fwd_piter_type) << std::endl
// << "\t bkd_piter_type = " << mlc_to_string(bkd_piter_type) << std::endl
// << "\t value_storage_type = " << mlc_to_string(value_storage_type) << std::endl
// << "\t storage_type = " << mlc_to_string(storage_type) << std::endl
// ---------------------------------------------------------------------
<< "\t delegated_type = " << mlc_to_string(delegated_type) << std::endl
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// << "\t neighb_type = " << mlc_to_string(neighb_type) << std::endl
// << "\t image_neighbness_type = " << mlc_to_string(image_neighbness_type) << std::endl
// << "\t image_constness_type = " << mlc_to_string(image_constness_type) << std::endl
// << "\t image_rawness_type = " << mlc_to_string(image_rawness_type) << std::endl
// --------------------------------------------------------------------
<< "\t image_dimension_type = " << mlc_to_string(image_dimension_type) << std::endl
<< "}" << std::endl;
}
static void ensure()
{
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// mlc::is_ok_< grid_type >::ensure();
// mlc::is_ok_< concrete_type >::ensure();
// mlc::is_ok_< value_type >::ensure();
// mlc::is_ok_< point_type >::ensure();
// mlc::is_ok_< size_type >::ensure();
// mlc::is_ok_< piter_type >::ensure();
// mlc::is_ok_< fwd_piter_type >::ensure();
// mlc::is_ok_< bkd_piter_type >::ensure();
// mlc::is_ok_< value_storage_type >::ensure();
// mlc::is_ok_< storage_type >::ensure();x
// --------------------------------------------------------------------
mlc::is_ok_< delegated_type >::ensure();
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// mlc::is_ok_< neighb_type >::ensure();
// mlc::is_ok_< image_neighbness_type >::ensure();
// mlc::is_ok_< image_constness_type >::ensure();
// mlc::is_ok_< image_rawness_type >::ensure();
// --------------------------------------------------------------------
mlc::is_ok_< image_dimension_type >::ensure();
}
};
} // end of namespace oln
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// # include <oln/core/gen/internal/value_box.hh>
// --------------------------------------------------------------------
namespace oln
{
/*! \namespace oln::abstract
** \brief oln::abstract namespace.
*/
namespace abstract {
/*! \class abstract::image<E>
**
** The abstract::image class is the base class from whom derives
** every concrete image class. Basically, an image is a set of
** points and a set of values associated with those points.
**
** Parameter E is the exact type of image.
*/
template <typename E>
struct image : public internal::get_image_impl < image<E>, E >
{
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// /// 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.
**
** \return An object deriving from abstract::size. Ex: if the
** image is an image2d<something>, the returned object is a
** size2d.
*/
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// const size_type& size() const
// {
// return this->exact().impl_size();
// }
// --------------------------------------------------------------------
/*! \brief Return the number of points of the current image.
** Nota bene: this method is abstract-like.
**
** FIXME: this method should be deferred in an abstract subclass
** since its complexity can vary from a concrete image to another...
**
** \return A positive value. It can be 0 when the image size is
** not yet defined; ex: image2d<int> ima; cout << ima.npoints();
*/
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// unsigned long npoints() const
// {
// return this->exact().impl_npoints();
// }
// --------------------------------------------------------------------
/*! \brief Test if the point \a p belongs to the current image.
** Please note that a point of the outer boundary of an image
** does NOT belong to the image. Nota bene: this method is
** abstract-like.
**
** \return True if p belongs to the current image, false otherwise.
**
** \see hold_large
*/
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// bool hold(const point_type& p) const; // impl is in box.hh
// --------------------------------------------------------------------
/*! \brief Test if \a p is a proper point to access a value of
** the current image. When an image has an outer boundary, the
** points of this boundary have values and these values can be
** accessed. Nota bene: this method is polymorphic so it can be
** overriden in derived classes; by default, hold_large behaves
** like hold.
**
** FIXME: hold_large should come only for images WITH a border!
**
** \return True if (*this)[p] is ok, false otherwise.
**
** \see hold
*/
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// bool hold_large(const point_type& p) const
// {
// precondition(this->npoints() != 0);
// return this->exact().impl_hold_large(p);
// }
// --------------------------------------------------------------------
/*! \brief Default implementation for hold_large. If not
** overriden in derived class, it just calls hold(p).
**
** FIXME: hold_large should come only for images WITH a border!
**
** \return True if (*this)[p] is ok, false otherwise.
**
** \see hold_large
*/
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// bool impl_hold_large(const point_type& p) const
// {
// // it relies on 'impl_hold' to avoid counting one call to
// // 'hold' when the effective call is 'hold_large'
// return this->exact().impl_hold(p);
// }
// --------------------------------------------------------------------
/*------------------*
! concrete methods !
*------------------*/
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// template <typename P>
// void operator()(const oln::abstract::point<P>&) const
// {
// // FIXME: provide an explicit err msg, e.g., "(p) should not be used on an ima"
// }
// --------------------------------------------------------------------
/*! \brief Give access to the value stored at \a p in the
** current image. Precisely it returns a box that encloses this
** value. FIXME: say more about that box!
**
** \precondition this->hold_large(p)
**
** \see value_box
*/
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// value_box<const E> operator[](const point_type& p) const
// {
// precondition(this->npoints() != 0);
// precondition(this->hold_large(p));
// value_box<const E> tmp(this->exact(), p);
// return tmp;
// }
// --------------------------------------------------------------------
/*! \brief Gives access to the value stored at \a p in the
** current image. Precisely it returns a box that encloses this
** value.
**
** \precondition this->hold_large(p)
**
** \see value_box
*/
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// value_box<E> operator[](const point_type& p)
// {
// precondition(this->npoints() != 0);
// precondition(this->hold_large(p));
// value_box<E> tmp(this->exact(), p);
// return tmp;
// }
// --------------------------------------------------------------------
/*! \brief Destructor.
*/
virtual ~image()
{
// FIXME: static check fails because "pointer to member conversion via virtual base"...
// mlc_check_method_impl(E, const size_type&, size, , const);
// mlc_check_method_impl(E, unsigned long, npoints, , const);
// mlc_check_method_impl(E, bool, hold, const point_type&, const);
// mlc_check_method_impl(E, bool, hold_large, const point_type&, const);
// mlc_check_method_impl(E, const value_type, get, const point_type&, const);
// mlc_check_method_impl_2(E, void, resize_border, size_t, bool, const);
}
// explanation:
// ------------
// though it works (uncommented) with g++-3.3, it is commented
// for bwd compatibility purpose because of g++-2.95 that does not accept
// "partial specialization declared friend"...
/*
friend class oln::value_box<E>;
friend class oln::value_box<const E>;
private:
*/
/*! \brief Read-only access to the value stored 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) instead.
**
** \return The value stored at \a p.
**
** \see value_box, abstract::image<I>::operator[](point)
*/
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// const value_type get(const point_type& p) const; // impl is in box.hh
// --------------------------------------------------------------------
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// FIXME: patch!
// void resize_border(size_t new_border, bool copy_border = false) const
// {
// this->exact().impl_resize_border(new_border, copy_border);
// }
// --------------------------------------------------------------------
protected:
/*! \brief Constructor (protected, empty).
*/
image() {}
/*! \brief Cpy constructor (protected, empty).
*/
image(const image&) {}
/*! \brief Op= (protected, empty).
*/
void operator=(const image&) {}
};
// --------------------------------------------------------------------
// FIXME: To be enabled later.
// --------------------------------------------------------------------
// /*! \namespace oln::abstract::internal
// ** \brief oln::abstract::internal namespace.
// */
// namespace internal {
// 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 size_type& impl_size() const
// {
// const size_type& s = this->delegate().size();
// this->exact().impl_size_extra(s);
// return s;
// }
// unsigned long impl_npoints() const
// {
// unsigned long n = this->delegate().npoints();
// this->exact().impl_npoints_extra(n);
// return n;
// }
// bool impl_hold(const point_type& p) const
// {
// this->exact().impl_hold_extra(p);
// return this->delegate().hold(p);
// }
// bool impl_hold_large(const point_type& p) const
// {