https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Cleanup site proxy materials.
* TODO: Remove; obsolete.
* mln/trait/solve_binary.hh: Use exact.
* mln/trait/solve_unary.hh: Likewise.
* mln/core/exact.hh (mln_exact): Disambiguate.
(exact): Use macro as return.
* mln/core/concept/site_proxy.hh: Remove redundant code,
use exact and cleanup.
core/concept/site_proxy.hh | 95 ++++++++++++++++-----------------------------
core/exact.hh | 14 ++----
trait/solve_binary.hh | 12 +++--
trait/solve_unary.hh | 8 ++-
4 files changed, 54 insertions(+), 75 deletions(-)
Index: mln/trait/solve_binary.hh
--- mln/trait/solve_binary.hh (revision 2028)
+++ mln/trait/solve_binary.hh (working copy)
@@ -37,6 +37,7 @@
*/
# include <mln/core/category.hh>
+# include <mln/core/exact.hh>
# include <mln/metal/equal.hh>
# include <mln/metal/if.hh>
# include <mln/metal/ret.hh>
@@ -294,13 +295,16 @@
template < template <class, class> class Name,
typename L,
typename R >
- struct solve_binary : internal::helper_solve_binary_< Name,
- typename mln::category<L>::ret, L,
- typename mln::category<R>::ret, R >
+ struct solve_binary
{
+ typedef mln_exact(L) L_;
+ typedef mln_exact(R) R_;
+ typedef typename mln::category<L_>::ret CatL;
+ typedef typename mln::category<R_>::ret CatR;
+ typedef internal::helper_solve_binary_< Name, CatL, L, CatR, R > meta_code;
+ typedef typename meta_code::ret ret;
};
-
} // end of namespace mln::trait
} // end of namespace mln
Index: mln/trait/solve_unary.hh
--- mln/trait/solve_unary.hh (revision 2028)
+++ mln/trait/solve_unary.hh (working copy)
@@ -37,6 +37,7 @@
*/
# include <mln/core/category.hh>
+# include <mln/core/exact.hh>
# include <mln/metal/equal.hh>
# include <mln/metal/if.hh>
# include <mln/metal/ret.hh>
@@ -166,9 +167,12 @@
// FIXME: Postfix solve_unary with a '-'(?)
template < template <class> class Name,
typename T >
- struct solve_unary : internal::helper_solve_unary_< Name,
- typename mln::category<T>::ret, T > // FIXME: typedef!
+ struct solve_unary
{
+ typedef mln_exact(T) E;
+ typedef typename mln::category<E>::ret Cat;
+ typedef internal::helper_solve_unary_< Name, Cat, E > meta_code;
+ typedef typename meta_code::ret ret;
};
} // end of namespace mln::trait
Index: mln/core/exact.hh
--- mln/core/exact.hh (revision 2028)
+++ mln/core/exact.hh (working copy)
@@ -36,7 +36,7 @@
/// FIXME: Doc!
-#define mln_exact(T) typename internal::exact_<T>::ret
+#define mln_exact(T) typename mln::internal::exact_<T>::ret
@@ -57,12 +57,10 @@
/// \{
template <typename T>
- typename internal::exact_<T>::ret*
- exact(T* ptr);
+ mln_exact(T)* exact(T* ptr);
template <typename T>
- typename internal::exact_<T>::ret&
- exact(T& ref);
+ mln_exact(T)& exact(T& ref);
/// \}
@@ -73,16 +71,14 @@
template <typename T>
inline
- typename internal::exact_<T>::ret*
- exact(T* ptr)
+ mln_exact(T)* exact(T* ptr)
{
return internal::exact_<T>::run(ptr);
}
template <typename T>
inline
- typename internal::exact_<T>::ret&
- exact(T& ref)
+ mln_exact(T)& exact(T& ref)
{
return *exact(&ref);
}
Index: mln/core/concept/site_proxy.hh
--- mln/core/concept/site_proxy.hh (revision 2028)
+++ mln/core/concept/site_proxy.hh (working copy)
@@ -49,6 +49,7 @@
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
@@ -81,34 +82,52 @@
- // Meta-routine to get the site type from either a site or a site
- // proxy.
-
+ // Fwd decl.
template <typename P> struct site_from;
- template <typename P, bool is_proxy = true>
+ namespace deep
+ {
+
+ template <typename P, bool is_site_proxy = true>
struct helper_site_from
{
- typedef typename P::subject P_;
- typedef typename site_from<P_>::ret ret;
+ typedef typename P::subject S;
+ // Recursion.
+ typedef typename mln::internal::site_from<S>::ret ret;
+ // Routine.
+ static const ret& on(const P& p)
+ {
+ return p.to_site();
+ }
};
- template <typename P>
- struct helper_site_from<P, false>
+ template <typename O>
+ struct helper_site_from<O, /* is_site_proxy = */ false>
+ {
+ // Stop Recursion.
+ typedef O ret;
+ // Routine.
+ static const ret& on(const O& obj)
{
- typedef P ret;
+ return obj;
+ }
};
+ } // end of namespace internal::deep
+
+
+ /// Meta-routine to get the site type from a type \p P that can be
+ /// either a site proxy or a site.
template <typename P>
struct site_from
{
- enum { is_proxy = mlc_is_a(P, Site_Proxy)::value };
- typedef typename helper_site_from< P, is_proxy >::ret ret;
+ typedef mln_exact(P) E;
+ enum { is_site_proxy = mlc_is_a(E, Site_Proxy)::value };
+ typedef typename deep::helper_site_from< E, is_site_proxy >::ret ret;
};
- // Access to site reference.
-
+ /// Access to site reference.
template <typename O>
const typename site_from<O>::ret&
to_site(const O& obj);
@@ -171,57 +190,13 @@
// Access to site reference.
- namespace deep
- {
-
- template <bool b> struct to_site_;
-
- template <>
- struct to_site_< /* is proxy = */ true >
- {
- template <typename P>
- const typename site_from<P>::ret&
- doit(const Site_Proxy<P>& p) const
- {
- return exact(p).to_site();
- }
- };
-
- template <>
- struct to_site_< /* is proxy = */ false >
- {
- template <typename O>
- const O&
- doit(const O& obj) const
- {
- return obj;
- }
- };
-
- // FIXME: was:
-
-// template <typename P>
-// const typename site_from<P>::ret&
-// to_site(const Site_Proxy<P>& p)
-// {
-// return exact(p).to_site();
-// }
-
-// template <typename P>
-// const typename site_from<P>::ret&
-// to_site(const Object<P>& p)
-// {
-// return exact(p);
-// }
-
- } // end of namespace internal::deep
-
template <typename O>
const typename site_from<O>::ret&
to_site(const O& obj)
{
- enum { is_proxy = mlc_is_a(O, Site_Proxy)::value };
- return deep::to_site_< is_proxy >().doit(obj);
+ typedef mln_exact(O) E;
+ enum { is_site_proxy = mlc_is_a(E, Site_Proxy)::value };
+ return deep::helper_site_from<E, is_site_proxy>::on(exact(obj));
}
} // end of namespace mln::internal