https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Handle multiple super-categories.
* mln/trait/solve.hh (super_category_): New to handle multiple
super-categories.
* tests/trait_super.cc: New.
* mln/core/w_window.hh (sym): Fix; my fault!
* mln/core/win/hline2d.hh: Add FIXME for Simon.
* mln/accu/min.hh: Add FIXME for Matthieu.
* mln/value/builtin.hh (Integer, Symbolic, Floating): New.
(category): Specialize for some builtins.
mln/accu/min.hh | 19 ++++++
mln/core/w_window.hh | 2
mln/core/win/hline2d.hh | 14 ++++
mln/trait/solve.hh | 52 ++++++++++++++--
mln/value/builtin.hh | 46 ++++++++++++--
tests/trait_super.cc | 152 ++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 272 insertions(+), 13 deletions(-)
Index: tests/trait_super.cc
--- tests/trait_super.cc (revision 0)
+++ tests/trait_super.cc (revision 0)
@@ -0,0 +1,152 @@
+// Copyright (C) 2007 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.
+
+/*! \file tests/trait_super.cc
+ *
+ * \brief Tests on mln::trait::solve.
+ */
+
+#include <mln/trait/op_uminus.hh>
+#include <mln/core/concept/object.hh>
+#include <mln/value/int_u8.hh>
+
+
+namespace my
+{
+
+
+ // Value.
+
+ template <typename E> struct Value;
+
+ template <> struct Value<void> { typedef mln::Object<void> super; };
+
+ template <typename E>
+ struct Value
+ {
+ typedef Value<void> category;
+ protected:
+ Value() {}
+ };
+
+
+ // Integer.
+
+ template <typename E> struct Integer;
+
+ template <> struct Integer<void> { typedef Value<void> super; };
+
+ template <typename E>
+ struct Integer
+ {
+ typedef Integer<void> category;
+ };
+
+ template <>
+ struct Integer<int>
+ {
+ typedef Integer<void> category;
+ int i;
+ Integer(int i) : i(i) {}
+ };
+
+
+ // Built_In.
+
+ template <typename E> struct Built_In;
+
+ template <> struct Built_In<void> { typedef void* super; }; // cause
several posible
+
+
+ // test.
+
+ struct test // like a built-in: no inheritance!
+ {
+ void is_test() {}
+ };
+
+
+// template <typename I>
+// void foo(const Integer<I>&)
+// {
+// std::cout << "Int" << std::endl;
+// }
+
+// template <typename I>
+// void foo(const Value<I>&)
+// {
+// std::cout << "Value" << std::endl;
+// }
+
+} // my
+
+
+
+namespace mln
+{
+
+ template <>
+ struct category< my::test >
+ {
+ typedef my::Built_In<void> ret;
+ typedef my::Integer<void> super;
+ };
+
+// template <>
+// struct category< int >
+// {
+// typedef my::Built_In<void> ret;
+// typedef my::Integer<void> super;
+// };
+
+ namespace trait
+ {
+
+ template <typename T>
+ struct set_unary_< op_uminus, my::Integer, T >
+ {
+ typedef bool ret;
+ };
+
+ } // mln::trait
+
+} // mln
+
+
+int main()
+{
+ using namespace mln;
+
+ mln_trait_op_uminus_(my::test) tmp;
+ tmp = true;
+
+// int i;
+// my::foo<int>(i);
+
+// mln_trait_op_plus_(value::int_u8, int) t;
+// void* v = t;
+}
Index: mln/trait/solve.hh
--- mln/trait/solve.hh (revision 1246)
+++ mln/trait/solve.hh (working copy)
@@ -87,13 +87,37 @@
{
};
+
+ template < template <class> class Category, typename T,
+ typename Super_Category >
+ struct super_category_;
+
+ template < template <class> class Category, typename T,
+ template <class> class Super_Category >
+ struct super_category_< Category, T,
+ Super_Category<void> >
+ {
+ typedef Super_Category<void> ret; // One super category: keep it.
+ };
+
+ template < template <class> class Category, typename T >
+ struct super_category_< Category, T,
+ void* > // Meaning: several super categories exist, depending on T.
+ {
+ typedef typename mln::category< T >::super ret; // Specific call depending on T.
+ };
+
} // end of namespace mln::trait::internal
template < template <class> class Name,
template <class> class Category_T, typename T >
- struct set_unary_ : internal::set_unary_super_< Name,
- typename Category_T<void>::super, T >
+ struct set_unary_
+ :
+ internal::set_unary_super_< Name,
+ typename internal::super_category_< Category_T, T,
+ typename Category_T<void>::super >::ret,
+ T >
{
};
@@ -125,6 +149,14 @@
{
};
+ template < template <class> class Name,
+ template <class> class Category_T, typename T >
+ struct helper_solve_unary_< Name,
+ Category_T<void*>, T > : helper_choose_unary_< Name,
+ Category_T, T >
+ {
+ };
+
} // end of namespace mln::trait::internal
@@ -245,13 +277,21 @@
// Construct a treillis in a static recursive way!
typedef typename internal::set_binary_super_< Name,
- typename Category_L<void>::super, L,
- Category_R<void>, R >::ret
+ typename internal::super_category_< Category_L,
+ L,
+ typename Category_L<void>::super >::ret,
+ L,
+ Category_R<void>,
+ R >::ret
L_ret;
typedef typename internal::set_binary_super_< Name,
- Category_L<void>, L,
- typename Category_R<void>::super, R >::ret
+ Category_L<void>,
+ L,
+ typename internal::super_category_< Category_R,
+ R,
+ typename Category_R<void>::super >::ret,
+ R >::ret
R_ret;
typedef typename internal::merge_binary_ret_< L_ret, R_ret >::ret ret;
Index: mln/core/w_window.hh
--- mln/core/w_window.hh (revision 1246)
+++ mln/core/w_window.hh (working copy)
@@ -257,7 +257,7 @@
{
w_window<D,W> tmp;
for (unsigned i = 0; i < this->ndpoints(); ++i)
- tmp.insert(this->w(i), this->dp(i));
+ tmp.insert(this->w(i), - this->dp(i));
*this = tmp;
return *this;
}
Index: mln/core/win/hline2d.hh
--- mln/core/win/hline2d.hh (revision 1246)
+++ mln/core/win/hline2d.hh (working copy)
@@ -61,6 +61,20 @@
}
};
+
+// // FIXME for Simon
+
+// // Was:
+// struct hline2d : public Window< hline2d >,
+// public internal::dpoints_base_< dpoint2d, hline2d >
+// {};
+
+// // Will be:
+// template <typename M, unsigned i, typename C >
+// struct line : public Window< line<M,i,C> >,
+// public internal::dpoints_base_< dpoint_<M, C>, line<M,i,C> >
+// {};
+
} // end of namespace mln::win
} // end of namespace mln
Index: mln/accu/min.hh
--- mln/accu/min.hh (revision 1246)
+++ mln/accu/min.hh (working copy)
@@ -85,6 +85,25 @@
};
+
+// // FIXME: Sample code.
+
+// template <typename V>
+// struct p_min_ : public p_< min_<V> >
+// {
+// };
+
+// struct p_min : public Meta_Accumulator< p_min >
+// {
+// template <typename V>
+// struct with
+// {
+// typedef p_min_<V> ret;
+// };
+// };
+
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename V>
Index: mln/value/builtin.hh
--- mln/value/builtin.hh (revision 1246)
+++ mln/value/builtin.hh (working copy)
@@ -43,15 +43,49 @@
// The case of built-in types.
template <typename E>
- struct Built_In
+ struct Built_In;
+
+ template <>
+ struct Built_In<void>
+ {
+ typedef void* super; // Every builtin belongs to a sub-category of Value but we do
not know which one.
+ };
+
+
+ template <typename E> struct Symbolic;
+
+ template <>
+ struct Symbolic<void>
{
- typedef Value<void> super; // Builtins belong to a sub-category of values.
+ typedef Value<void> super;
};
- template <> struct category< int > { typedef Built_In<void> ret;
};
- template <> struct category< unsigned > { typedef Built_In<void> ret;
};
- template <> struct category< float > { typedef Built_In<void> ret;
};
- template <> struct category< double > { typedef Built_In<void> ret;
};
+
+ template <typename E> struct Integer;
+
+ template <>
+ struct Integer<void>
+ {
+ typedef Value<void> super;
+ };
+
+
+ template <typename E> struct Floating;
+
+ template <>
+ struct Floating<void>
+ {
+ typedef Value<void> super;
+ };
+
+
+ template <> struct category< bool > { typedef Built_In<void>
ret; typedef Symbolic<void> super; };
+
+ template <> struct category< int > { typedef Built_In<void>
ret; typedef Integer<void> super; };
+ template <> struct category< unsigned > { typedef Built_In<void>
ret; typedef Integer<void> super; };
+
+ template <> struct category< float > { typedef Built_In<void>
ret; typedef Floating<void> super; };
+ template <> struct category< double > { typedef Built_In<void>
ret; typedef Floating<void> super; };
// FIXME: ...