Commit 260fc4a3 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Add the basics for pseudo sites; test on p_array.

	* tests/core/p_array.cc: New.
	* doc/technical: New.
	* doc/technical/designs: New.
	* doc/technical/designs/site_psite_piter: New.
	* doc/technical/designs/site_psite_piter/README: New.
	* mln/core/macros.hh (mln_subject, mln_subject_): New.
	* mln/core/point.hh: New comment.
	* mln/core/internal/point_set_base.hh: .
	* mln/core/internal/pseudo_site_base.hh: New.
	* mln/core/p_array_bb.hh: New.
	* mln/core/point2d.hh
	(site_const_impl, site_mutable_impl): New specialization.
	* mln/core/p_array.hh (p_array_psite): New.
	(npoints): Rename as...
	(nsites): ...this.
	(bbox, bb_, bb_needs_update_, hook_): Remove.
	(has): Update sig with the new psite type; adapt body.
	* mln/core/concept/proxy.hh: New.
	* mln/core/concept/point_set.hh: .
	* mln/core/concept/site_proxy.hh: New.
	* mln/core/concept/pseudo_site.hh: New.
	* mln/core/concept/site_iterator.hh: New.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008@1971 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 3e355fbd
2008-05-23 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Add the basics for pseudo sites; test on p_array.
* tests/core/p_array.cc: New.
* doc/technical: New.
* doc/technical/designs: New.
* doc/technical/designs/site_psite_piter: New.
* doc/technical/designs/site_psite_piter/README: New.
* mln/core/macros.hh (mln_subject, mln_subject_): New.
* mln/core/point.hh: New comment.
* mln/core/internal/point_set_base.hh: .
* mln/core/internal/pseudo_site_base.hh: New.
* mln/core/p_array_bb.hh: New.
* mln/core/point2d.hh
(site_const_impl, site_mutable_impl): New specialization.
* mln/core/p_array.hh (p_array_psite): New.
(npoints): Rename as...
(nsites): ...this.
(bbox, bb_, bb_needs_update_, hook_): Remove.
(has): Update sig with the new psite type; adapt body.
* mln/core/concept/proxy.hh: New.
* mln/core/concept/point_set.hh: .
* mln/core/concept/site_proxy.hh: New.
* mln/core/concept/pseudo_site.hh: New.
* mln/core/concept/site_iterator.hh: New.
2008-05-15 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Update site set concepts and generic box.
......
-*- outline -*-
* design
Object
^
|
Proxy
+ subject
^
|
Site_Proxy< Site, Exact >
+ site : type = Site
+ op site
^
______|______
| |
Pseudo_Site Site_Iterator
^ ^
| |
internal::psite_impl< Site, Exact >
// to be specialized...
^
______________/
/
pseudo_site_base_< Site, Exact >
internal::piter_impl
+ op psite, iff psite != site
^
___________________/
/
......@@ -39,6 +39,7 @@
# include <mln/core/concept/point_iterator.hh>
# include <mln/trait/site_sets.hh>
# include <mln/metal/not_equal.hh>
# include <mln/metal/is_a.hh>
namespace mln
......@@ -147,6 +148,8 @@ namespace mln
mlc_not_equal( mln_trait_site_set_bbox(E), mln::trait::undef )::check();
mlc_not_equal( mln_trait_site_set_contents(E), mln::trait::undef )::check();
mlc_not_equal( mln_trait_site_set_arity(E), mln::trait::undef )::check();
// FIXME: also test something like
// mlc_is_a( mln_trait_site_set_nsites(E), mln::trait::site_set::nsites::any )::check();
// Check associated types.
typedef mln_site(E) site;
......
// Copyright (C) 2008 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, 51 Franklin Street, Fifth Floor,
// 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 MLN_CORE_CONCEPT_PROXY_HH
# define MLN_CORE_CONCEPT_PROXY_HH
/*! \file mln/core/concept/proxy.hh
*
* \brief Definition of the concept of mln::Proxy.
*/
# include <mln/core/concept/object.hh>
# include <mln/trait/all.hh>
namespace mln
{
// Fwd decls.
template <typename E> struct Proxy;
/*
FIXME: Re-activate.
namespace trait
{
template < typename Op, typename P1, typename P2 >
struct set_binary_< Op, mln::Proxy, P1, mln::Proxy, P2 >
{
typedef mln_trait_binary(Op, mln_subject(P1), mln_subject(P2)) ret;
};
template < typename Op, typename P, typename O >
struct set_binary_< Op, mln::Proxy, P, mln::Object, O >
{
typedef mln_trait_binary(Op, mln_subject(P), O) ret;
};
template < typename Op, typename E, typename P >
struct set_binary_< Op, mln::Object, E, mln::Proxy, P >
{
typedef mln_trait_binary(Op, O, mln_subject(P)) ret;
};
template < typename Op, typename P >
struct set_binary_< Op, mln::Proxy, P >
{
typedef mln_trait_unary(Op, mln_subject(P)) ret;
};
} // end of namespace mln::trait
*/
/// Proxy category flag type.
template <>
struct Proxy<void>
{
typedef Object<void> super;
};
/*! \brief Base class for implementation classes of the notion of
* "proxy".
*/
template <typename E>
struct Proxy : public Object<E>
{
typedef Proxy<void> category;
/*
typedef subject;
typedef q_subject;
q_subject unproxy() const;
// FIXME:
// return "const subject&"?
// overload with not-const method?
// add op subject() const?
*/
protected:
Proxy();
};
namespace internal
{
// External way of getting an address of an object from/through a
// proxy. This is a recursive implementation since we can have a
// proxy of proxy, etc.
// Case 1: Not found so unproxy.
template <typename T, typename P>
void get_adr(const T *& ptr, const Proxy<P>& obj)
{
get_adr(ptr, exact(obj).unproxy());
}
template <typename T, typename P>
void get_adr( T *& ptr, Proxy<P>& obj)
{
get_adr(ptr, exact(obj).unproxy());
}
// Case 2: Found. (Note that T can also be a Proxy.)
template <typename T>
void get_adr(const T *& ptr, const Object<T>& obj)
{
ptr = & exact(obj);
}
template <typename T>
void get_adr( T *& ptr, Object<T>& obj)
{
ptr = & exact(obj);
}
// Case 3: Fail to found!
template <typename T, typename O>
void get_adr(const T *& ptr, const Object<O>& obj);
template <typename T, typename O>
void get_adr( T *& ptr, Object<O>& obj)
{
return 0;
}
// A proxy should convert towards its subject. And, if we have a
// proxy of proxy, it should also convert towards its subject of
// subject, and so on. It leads to a recursive implementation
// where conversions are automatically obtained through
// inheritance.
//
// E is a Proxy type; Subject is its subject type.
template <typename Subject, typename E> struct proxy_impl;
template <typename Subject, typename E, bool rec = true>
struct helper_proxy_impl : proxy_impl< mln_subject(Subject), E > // Rec.
{};
template <typename Subject, typename E>
struct helper_proxy_impl< Subject, E, false > // Stop rec.
{};
template <typename Subject, typename E>
struct proxy_impl : helper_proxy_impl< Subject, E,
mlc_is_a(Subject, Proxy)::value >
{
operator Subject() const
{
const Subject* adr;
get_adr(adr, mln::internal::force_exact<const E>(*this));
return *adr;
}
};
} // end of namespace mln::internal
// FIXME:...
// template <typename L, typename R>
// bool operator==(const Proxy<L>& lhs, const Proxy<R>& rhs);
template <typename P>
std::ostream& operator<<(std::ostream& ostr, const Proxy<P>& p);
# ifndef MLN_INCLUDE_ONLY
template <typename E>
inline
Proxy<E>::Proxy()
{
typedef mln_subject(E) subject;
typedef typename E::q_subject q_subject;
q_subject (E::*m)() const = & E::unproxy;
m = 0;
}
template <typename P>
std::ostream& operator<<(std::ostream& ostr, const Proxy<P>& p)
{
return ostr << exact(p).unproxy();
}
// FIXME: Code operators...
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_CORE_CONCEPT_PROXY_HH
// Copyright (C) 2008 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, 51 Franklin Street, Fifth Floor,
// 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 MLN_CORE_CONCEPT_PSEUDO_SITE_HH
# define MLN_CORE_CONCEPT_PSEUDO_SITE_HH
/*! \file mln/core/concept/pseudo_site.hh
*
* \brief Definition of the concept of mln::Pseudo_Site.
*/
# include <mln/core/concept/site_proxy.hh>
# include <mln/metal/is_a.hh>
namespace mln
{
// Fwd decl.
template <typename E> struct Pseudo_Site;
/// Pseudo_Site category flag type.
template <>
struct Pseudo_Site<void>
{
typedef Site_Proxy<void> super;
};
/*! \brief Base class for implementation classes of the notion of
* "pseudo site".
*
* FIXME: Explain...
*/
template <typename E>
struct Pseudo_Site : public Site_Proxy<E>
{
typedef Pseudo_Site<void> category;
protected:
Pseudo_Site();
};
# ifndef MLN_INCLUDE_ONLY
template <typename E>
Pseudo_Site<E>::Pseudo_Site()
{
// FIXME
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_CORE_CONCEPT_PSEUDO_SITE_HH
// Copyright (C) 2007, 2008 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, 51 Franklin Street, Fifth Floor,
// 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 MLN_CORE_CONCEPT_SITE_ITERATOR_HH
# define MLN_CORE_CONCEPT_SITE_ITERATOR_HH
/*! \file mln/core/concept/site_iterator.hh
*
* \brief Definition of the concept of mln::Site_Iterator.
*
* \todo Fix mln/core/concept/doc/site_iterator.hh
*/
# include <mln/core/concept/site_proxy.hh>
# include <mln/core/concept/iterator.hh> // To fetch the macros.
namespace mln
{
/*! \brief Base class for implementation of classes of iterator on
* points.
*
* An iterator on points is an iterator that browse over a set of
* points.
*
* \see mln::doc::Site_Iterator for a complete documentation of this class
* contents.
*/
template <typename E>
struct Site_Iterator : public Site_Proxy<E>
{
/*
bool is_valid() const;
void invalidate();
void start();
void next_();
*/
/*! \brief Go to the next element.
*
* \warning This is a final method; iterator classes should not
* re-defined this method. The actual "next" operation has to be
* defined through the \em next_ method.
*
* \pre The iterator is valid.
*/
void next(); // final
using Site_Proxy<E>::site;
/*! \brief Go to the next element.
*
* \warning This is a final method; iterator classes should not
* re-defined this method. The actual "next" operation has to be
* defined through the \em next_ method.
*
* \pre The iterator is valid.
*/
operator site() const;
protected:
Site_Iterator();
};
# ifndef MLN_INCLUDE_ONLY
template <typename E>
void
Site_Iterator<E>::next() // final
{
mln_precondition(exact(this)->is_valid());
exact(this)->next_();
}
template <typename E>
inline
Site_Iterator<E>::operator site() const
{
mln_precondition(exact(this)->is_valid());
return exact(this)->to_site();
}
template <typename E>
inline
Site_Iterator<E>::Site_Iterator()
{
bool (E::*m1)() const = & E::is_valid;
m1 = 0;
void (E::*m2)() = & E::invalidate;
m2 = 0;
void (E::*m3)() = & E::start;
m3 = 0;
void (E::*m4)() = & E::next_;
m4 = 0;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
#endif // ! MLN_CORE_CONCEPT_SITE_ITERATOR_HH
// Copyright (C) 2008 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, 51 Franklin Street, Fifth Floor,
// 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 MLN_CORE_CONCEPT_SITE_PROXY_HH
# define MLN_CORE_CONCEPT_SITE_PROXY_HH
/*! \file mln/core/concept/site_proxy.hh
*
* \brief Definition of the concept of mln::Site_Proxy.
*/
# include <mln/core/concept/proxy.hh>
# include <mln/metal/is_a.hh>
namespace mln
{
// Fwd decl.
template <typename E> struct Site_Proxy;
namespace internal
{
// Every "Site_Proxy" class should derive from site_impl. The
// couple of classes below are provided to be specialized so that
// an effective implementation (with the interface of the
// targetted site) can equip site proxy classes.
template <typename Site, typename E>
struct site_const_impl
{
// Default is none.
};
template <typename Site, typename E>
struct site_mutable_impl
{
// Default is none.
};
template <bool is_mutable, typename Site, typename E>
struct site_impl; // Is a selector w.r.t. to mutability.
template <typename Site, typename E>
struct site_impl</* is_mutable = */ true, Site, E> : site_mutable_impl<Site, E>
{
};
template <typename Site, typename E>
struct site_impl</* is_mutable = */ false, Site, E> : site_const_impl<Site, E>
{
};
// Meta-routine to get the site type from either a site or a site
// proxy.
template <typename P> struct site_from;
template <typename P, bool is_proxy = true>