https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add meta-code to access component types of value types.
* mln/trait/value/internal: New directory.
* mln/trait/value/internal/all.hh: New.
* mln/trait/value/internal/comp.hh: New.
* mln/trait/value/comp.hh: New.
* mln/trait/value/all.hh: Update.
* mln/trait/value_.hh,
* mln/trait/value/nature.hh: Upgrade doc style.
* mln/value/builtin/symbolics.hh,
* mln/value/builtin/floatings.hh,
* mln/value/builtin/integers.hh (trait_): Add dim.
* mln/value/builtin/carrays.hh: New.
* mln/value/builtin/all.hh: Update.
* mln/algebra/vec.hh (trait_): Add dim and comp.
* tests/trait/value/comp.cc: New.
* tests/trait/value/Makefile.am: Update.
mln/algebra/vec.hh | 7 +
mln/trait/value/all.hh | 14 ++-
mln/trait/value/comp.hh | 46 ++++++++++++
mln/trait/value/internal/all.hh | 39 ++++++++++
mln/trait/value/internal/comp.hh | 127 ++++++++++++++++++++++++++++++++++
mln/trait/value/nature.hh | 10 +-
mln/trait/value_.hh | 4 -
mln/value/builtin/all.hh | 13 +--
mln/value/builtin/carrays.hh | 83 ++++++++++++++++++++++
mln/value/builtin/floatings.hh | 12 ++-
mln/value/builtin/integers.hh | 5 -
mln/value/builtin/symbolics.hh | 5 -
tests/trait/value/Makefile.am | 2
tests/trait/value/comp.cc | 142 +++++++++++++++++++++++++++++++++++++++
14 files changed, 482 insertions(+), 27 deletions(-)
Index: mln/trait/value_.hh
--- mln/trait/value_.hh (revision 3543)
+++ mln/trait/value_.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
Index: mln/trait/value/all.hh
--- mln/trait/value/all.hh (revision 3543)
+++ mln/trait/value/all.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,10 +29,9 @@
#ifndef MLN_TRAIT_VALUE_ALL_HH
# define MLN_TRAIT_VALUE_ALL_HH
-/*! \file mln/trait/value/all.hh
- *
- * \brief FIXME
- */
+/// \file mln/trait/value/all.hh
+///
+/// Include all value traits.
namespace mln
@@ -54,5 +54,9 @@
# include <mln/trait/value/kind.hh>
# include <mln/trait/value/quant.hh>
+// Sub-directory.
+
+# include <mln/trait/value/internal/all.hh>
+
#endif // ! MLN_TRAIT_VALUE_ALL_HH
Index: mln/trait/value/nature.hh
--- mln/trait/value/nature.hh (revision 3543)
+++ mln/trait/value/nature.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,10 +29,9 @@
#ifndef MLN_TRAIT_VALUE_NATURE_HH
# define MLN_TRAIT_VALUE_NATURE_HH
-/*! \file mln/trait/value/nature.hh
- *
- * \brief Nature of values (for use in images).
- */
+/// \file mln/trait/value/nature.hh
+///
+/// Nature of values (for use in images).
# include <string>
Index: mln/trait/value/internal/all.hh
--- mln/trait/value/internal/all.hh (revision 0)
+++ mln/trait/value/internal/all.hh (revision 0)
@@ -0,0 +1,39 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_TRAIT_VALUE_INTERNAL_ALL_HH
+# define MLN_TRAIT_VALUE_INTERNAL_ALL_HH
+
+/// \file mln/trait/value/internal/all.hh
+///
+/// Include all internals for value traits.
+
+
+# include <mln/trait/value/internal/comp.hh>
+
+
+#endif // ! MLN_TRAIT_VALUE_INTERNAL_ALL_HH
Index: mln/trait/value/internal/comp.hh
--- mln/trait/value/internal/comp.hh (revision 0)
+++ mln/trait/value/internal/comp.hh (revision 0)
@@ -0,0 +1,127 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_TRAIT_VALUE_INTERNAL_COMP_HH
+# define MLN_TRAIT_VALUE_INTERNAL_COMP_HH
+
+/// \file mln/trait/value/internal/comp.hh
+///
+/// Include all internals for value traits.
+
+# include <mln/metal/bool.hh>
+# include <mln/metal/if.hh>
+
+
+
+# define mln_trait_value_comp(T, i) typename mln::trait::value::internal::comp< T, i
>::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+
+ // Forward declaration.
+ template <typename V> struct value_;
+
+
+ namespace value
+ {
+
+ namespace internal
+ {
+
+ // bind_comp< T, i >
+
+ template <typename Tr, unsigned i>
+ struct bind_comp;
+
+ template <typename Tr> struct bind_comp< Tr, 0 > { typedef typename
Tr::comp_0 ret; };
+ template <typename Tr> struct bind_comp< Tr, 1 > { typedef typename
Tr::comp_1 ret; };
+ template <typename Tr> struct bind_comp< Tr, 2 > { typedef typename
Tr::comp_2 ret; };
+ template <typename Tr> struct bind_comp< Tr, 3 > { typedef typename
Tr::comp_3 ret; };
+ template <typename Tr> struct bind_comp< Tr, 4 > { typedef typename
Tr::comp_4 ret; };
+ template <typename Tr> struct bind_comp< Tr, 5 > { typedef typename
Tr::comp_5 ret; };
+ template <typename Tr> struct bind_comp< Tr, 6 > { typedef typename
Tr::comp_6 ret; };
+ template <typename Tr> struct bind_comp< Tr, 7 > { typedef typename
Tr::comp_7 ret; };
+ template <typename Tr> struct bind_comp< Tr, 8 > { typedef typename
Tr::comp_8 ret; };
+ template <typename Tr> struct bind_comp< Tr, 9 > { typedef typename
Tr::comp_9 ret; };
+
+
+ // get_comp< T, i, dim >
+
+ template <typename C, typename Tr, unsigned i>
+ struct get_comp_helper
+ {
+ typedef C ret;
+ };
+
+ template <typename Tr, unsigned i>
+ struct get_comp_helper< void, Tr, i >
+ {
+ typedef typename bind_comp<Tr, i>::ret ret;
+ };
+
+ template <typename T, unsigned i, unsigned dim>
+ struct get_comp
+ {
+ typedef mln::trait::value_<T> Tr;
+ typedef typename Tr::comp C;
+ typedef typename get_comp_helper<C, Tr, i>::ret ret;
+ };
+
+ template <typename T>
+ struct get_comp< T, 0, 1 >
+ {
+ typedef T ret;
+ };
+
+
+ // comp< T, i >
+
+ template <typename T, unsigned i>
+ struct comp
+ : private metal::bool_< (i < mln::trait::value_<T>::dim) >::check_t
+ {
+ enum { dim = mln::trait::value_<T>::dim };
+ typedef typename get_comp<T, i, dim>::ret ret;
+ };
+
+ } // end of namespace mln::trait::value::internal
+
+ } // end of namespace mln::trait::value
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+
+#endif // ! MLN_TRAIT_VALUE_INTERNAL_COMP_HH
Index: mln/trait/value/comp.hh
--- mln/trait/value/comp.hh (revision 0)
+++ mln/trait/value/comp.hh (revision 0)
@@ -0,0 +1,46 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_TRAIT_VALUE_COMP_HH
+# define MLN_TRAIT_VALUE_COMP_HH
+
+/// \file mln/trait/value/comp.hh
+///
+/// Access to the i-th component type of a given type.
+
+# include <mln/trait/value/internal/comp.hh>
+
+
+
+# define mln_trait_value_comp(T, i) \
+ \
+ typename mln::trait::value::internal::comp< T, i >::ret
+
+
+
+
+#endif // ! MLN_TRAIT_VALUE_COMP_HH
Index: mln/value/builtin/symbolics.hh
--- mln/value/builtin/symbolics.hh (revision 3543)
+++ mln/value/builtin/symbolics.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -59,13 +60,13 @@
typedef value::kind::binary kind;
enum {
+ dim = 1,
nbits = 1,
card = 2
};
typedef value::quant::low quant;
static const char* name() { return "bool"; }
-
};
} // end of namespace mln::trait
Index: mln/value/builtin/carrays.hh
--- mln/value/builtin/carrays.hh (revision 0)
+++ mln/value/builtin/carrays.hh (revision 0)
@@ -0,0 +1,83 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_VALUE_BUILTIN_CARRAYS_HH
+# define MLN_VALUE_BUILTIN_CARRAYS_HH
+
+/// \file mln/value/builtin/carrays.hh
+///
+/// Traits definition for C arrays.
+
+# include <sstream>
+
+# include <mln/value/concept/built_in.hh>
+# include <mln/value/concept/vectorial.hh>
+# include <mln/trait/value_.hh>
+
+
+namespace mln
+{
+
+
+ template <unsigned n, typename T>
+ struct category< T[n] >
+ {
+ typedef value::Built_In< value::Vectorial<void> > ret;
+ };
+
+
+ namespace trait
+ {
+
+ template <unsigned n, typename T>
+ struct value_< T[n] >
+ {
+ enum {
+ dim = n,
+ nbits = n * value_<T>::nbits,
+ card = n * value_<T>::card
+ };
+ typedef T comp;
+
+ typedef value::nature::vectorial nature;
+ typedef mln_trait_value_kind(T) kind;
+ typedef value::quant::high quant;
+
+ static const char* name()
+ {
+ std::ostringstream s;
+ s << value_<T>::name() << '[' << n <<
']';
+ return s.str();
+ }
+ };
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_BUILTIN_CARRAYS_HH
Index: mln/value/builtin/floatings.hh
--- mln/value/builtin/floatings.hh (revision 3543)
+++ mln/value/builtin/floatings.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -60,10 +60,14 @@
namespace trait
{
+
+ // float.
+
template <>
struct value_< float >
{
enum {
+ dim = 1,
nbits = 8 * sizeof(float),
card = 0
};
@@ -95,10 +99,14 @@
};
+
+ // double.
+
template <>
struct value_< double >
{
enum {
+ dim = 1,
nbits = 8 * sizeof(double),
card = 0
};
Index: mln/value/builtin/all.hh
--- mln/value/builtin/all.hh (revision 3543)
+++ mln/value/builtin/all.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -28,15 +29,15 @@
#ifndef MLN_VALUE_BUILTIN_ALL_HH
# define MLN_VALUE_BUILTIN_ALL_HH
-/*! \file mln/value/builtin/all.hh
- *
- * \brief File that includes all materials related to built-in types.
- */
+/// \file mln/value/builtin/all.hh
+///
+/// File that includes all materials related to built-in types.
-# include <mln/value/builtin/symbolics.hh>
+# include <mln/value/builtin/carrays.hh>
# include <mln/value/builtin/integers.hh>
# include <mln/value/builtin/floatings.hh>
+# include <mln/value/builtin/symbolics.hh>
# include <mln/value/builtin/promotions.hh>
# include <mln/value/builtin/ops.hh>
Index: mln/value/builtin/integers.hh
--- mln/value/builtin/integers.hh (revision 3543)
+++ mln/value/builtin/integers.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -73,6 +73,7 @@
public:
enum {
+ dim = 1,
nbits = n,
card = mln_value_card_from_(n)
};
Index: mln/algebra/vec.hh
--- mln/algebra/vec.hh (revision 3543)
+++ mln/algebra/vec.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2006, 2008, 2009 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2006, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -81,11 +81,12 @@
typedef trait::value::kind::data kind;
enum {
+ dim = n,
nbits = n * mln_nbits(T),
card = n * mln_card(T)
};
+ typedef T comp;
typedef mln_value_quant_from_(card) quant;
-
typedef algebra::vec<n, mln_sum(T)> sum;
};
Index: tests/trait/value/comp.cc
--- tests/trait/value/comp.cc (revision 0)
+++ tests/trait/value/comp.cc (revision 0)
@@ -0,0 +1,142 @@
+// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+//
+// 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/value/comp.cc
+///
+/// Tests on mln_trait_value_comp.
+///
+/// \todo Add tests on some actual heterogeneous types.
+
+#include <mln/trait/value/comp.hh>
+
+#include <mln/value/int_u8.hh>
+#include <mln/algebra/vec.hh>
+
+
+
+
+template <typename T, unsigned i, typename C>
+void check_equal()
+{
+ mlc_equal(mln_trait_value_comp(T, i), C)::check();
+}
+
+
+template <typename T>
+void check_scalar()
+{
+ mlc_equal(mln_trait_value_comp(T, 0), T)::check();
+}
+
+
+template <typename T, typename C>
+void check_homogeneous()
+{
+ mlc_equal(mln_trait_value_comp(T, 0), C)::check();
+}
+
+
+namespace mln
+{
+
+ template <typename R, typename G, typename B>
+ struct my_rgb;
+
+ namespace trait
+ {
+
+ template <typename R, typename G, typename B>
+ struct value_< my_rgb<R,G,B> >
+ {
+ enum { dim = 3 };
+ typedef void comp;
+ typedef R comp_0;
+ typedef G comp_1;
+ typedef B comp_2;
+ };
+
+ } // mln::trait
+
+} // mln
+
+
+
+template <typename T,
+ typename C0, typename C1, typename C2>
+void check_heterogeneous()
+{
+ mlc_equal(mln_trait_value_comp(T, 0), C0)::check();
+ mlc_equal(mln_trait_value_comp(T, 1), C1)::check();
+ mlc_equal(mln_trait_value_comp(T, 2), C2)::check();
+}
+
+
+
+int main()
+{
+ using namespace mln;
+
+
+ // Scalars.
+
+ {
+ typedef mln::value::int_u8 T;
+ check_scalar<T>();
+ check_equal<T, 0, T>();
+ }
+ {
+ typedef int T;
+ check_scalar<T>();
+ check_equal<T, 0, T>();
+ }
+
+
+ // Homogeneous vectors.
+
+ {
+ typedef float C;
+ typedef algebra::vec<2, C> T;
+ check_homogeneous< T, C >();
+ check_equal< T, 0, C >();
+ check_equal< T, 1, C >();
+ }
+ {
+ typedef double C;
+ typedef C T[2];
+ check_homogeneous< T, C >();
+ check_equal< T, 0, C >();
+ check_equal< T, 1, C >();
+ }
+
+
+ // Heterogeneous types.
+
+ {
+ check_heterogeneous< my_rgb< bool, unsigned, float* >,
+ bool, unsigned, float* >();
+ }
+}
Index: tests/trait/value/Makefile.am
--- tests/trait/value/Makefile.am (revision 3543)
+++ tests/trait/value/Makefile.am (working copy)
@@ -3,8 +3,10 @@
include $(top_srcdir)/milena/tests/tests.mk
check_PROGRAMS = \
+ comp \
values
+comp_SOURCES = comp.cc
values_SOURCES = values.cc
TESTS = $(check_PROGRAMS)