last-svn-commit-1-g5c414c5 Fix invalid value type names in dump format.

* milena/mln/value/internal/make_generic_name.hh: New. * milena/mln/value/int_u.hh, * milena/mln/value/label.hh, * milena/mln/value/rgb.hh: Make use of the new routine to print a correct type names in dump format. --- milena/ChangeLog | 11 ++++ milena/mln/value/int_u.hh | 53 ++++++++++++++++++-- .../internal/{integer.hh => make_generic_name.hh} | 40 ++++++++------- milena/mln/value/label.hh | 22 +++++++- milena/mln/value/rgb.hh | 8 ++- 5 files changed, 108 insertions(+), 26 deletions(-) copy milena/mln/value/internal/{integer.hh => make_generic_name.hh} (67%) diff --git a/milena/ChangeLog b/milena/ChangeLog index b3cd42e..5b5cba3 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,14 @@ +2010-02-16 Guillaume Lazzara <z@lrde.epita.fr> + + Fix invalid value type names in dump format. + + * milena/mln/value/internal/make_generic_name.hh: New. + + * milena/mln/value/int_u.hh, + * milena/mln/value/label.hh, + * milena/mln/value/rgb.hh: Make use of the new routine to print a + correct type names in dump format. + 2009-11-18 Guillaume Lazzara <z@lrde.epita.fr> * doc/white_paper/white_paper.tex: Fix an invalid URL. diff --git a/milena/mln/value/int_u.hh b/milena/mln/value/int_u.hh index 7f12c75..906dc29 100644 --- a/milena/mln/value/int_u.hh +++ b/milena/mln/value/int_u.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -41,6 +42,7 @@ # include <mln/trait/value_.hh> # include <mln/debug/format.hh> +# include <mln/value/internal/make_generic_name.hh> namespace mln @@ -98,7 +100,8 @@ namespace mln static const char* name() { - static std::string s = std::string("int_u").append(1, n + '0'); + static std::string + s = mln::value::internal::make_generic_name("int_u", n); return s.c_str(); } @@ -107,6 +110,23 @@ namespace mln } // end of namespace mln::trait + namespace convert + { + + namespace over_load + { + + // int_u -> unsigned. + template <unsigned n> + void + from_to_(const value::int_u<n>& from, unsigned& to_); + + + } // end of namespace mln::convert::over_load + + } // end of namespace mln::convert + + namespace value { @@ -178,9 +198,33 @@ namespace mln template <unsigned n> std::istream& operator>>(std::istream& istr, int_u<n>& i); + } // end of namespace mln::value # ifndef MLN_INCLUDE_ONLY + namespace convert + { + + namespace over_load + { + + // int_u -> unsigned. + template <unsigned n> + inline + void + from_to_(const value::int_u<n>& from, unsigned& to_) + { + to_ = from; + } + + } // end of namespace mln::convert::over_load + + } // end of namespace mln::convert + + + namespace value + { + template <unsigned n> inline int_u<n>::int_u() @@ -277,11 +321,12 @@ namespace mln return istr >> i.handle_(); } -# endif // ! MLN_INCLUDE_ONLY - } // end of namespace mln::value +# endif // ! MLN_INCLUDE_ONLY + } // end of namespace mln #endif // ! MLN_VALUE_INT_U_HH + diff --git a/milena/mln/value/internal/integer.hh b/milena/mln/value/internal/make_generic_name.hh similarity index 67% copy from milena/mln/value/internal/integer.hh copy to milena/mln/value/internal/make_generic_name.hh index 7925139..a48c04e 100644 --- a/milena/mln/value/internal/integer.hh +++ b/milena/mln/value/internal/make_generic_name.hh @@ -1,4 +1,4 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,34 +23,39 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifndef MLN_VALUE_INTERNAL_INTEGER_HH -# define MLN_VALUE_INTERNAL_INTEGER_HH +#ifndef MLN_VALUE_INTERNAL_MAKE_GENERIC_NAME_HH +# define MLN_VALUE_INTERNAL_MAKE_GENERIC_NAME_HH -/*! \file - * - * \brief Define a generic class for integer values. - */ +/// \file +/// +/// Construct a type name as string. -# include <mln/value/concept/scalar.hh> +# include <cstring> +# include <sstream> namespace mln { - namespace trait - { - // FIXME - } // end of namespace mln::trait - namespace value { namespace internal { - template <typename E> - struct Integer : public Scalar<E> + /// Construct a type name as string. + std::string make_generic_name(const char *name, int quantification); + +# ifndef MLN_INCLUDE_ONLY + + std::string make_generic_name(const char *name, int quantification) { - }; + std::stringstream out; + out << name; + out << quantification; + return out.str(); + } + +# endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::value::internal @@ -58,5 +63,4 @@ namespace mln } // end of namespace mln - -#endif // ! MLN_VALUE_INTERNAL_INTEGER_HH +#endif // ! MLN_VALUE_INTERNAL_MAKE_GENERIC_NAME_HH diff --git a/milena/mln/value/label.hh b/milena/mln/value/label.hh index a88d4a3..7491ae5 100644 --- a/milena/mln/value/label.hh +++ b/milena/mln/value/label.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -38,6 +39,7 @@ # include <mln/value/internal/convert.hh> # include <mln/value/internal/encoding.hh> +# include <mln/value/internal/make_generic_name.hh> namespace mln { @@ -79,7 +81,8 @@ namespace mln static const char* name() { - static std::string s = std::string("label_").append(1, n + '0'); + static std::string + s = mln::value::internal::make_generic_name("label_", n); return s.c_str(); } @@ -100,6 +103,12 @@ namespace mln void from_to_(const value::int_u<n>& from, value::label<n>& to_); + // label -> int_u. + template <unsigned n> + void + from_to_(const value::label<n>& from, value::int_u<n>& to_); + + // int_u -> label. template <unsigned n, unsigned m> void @@ -204,6 +213,15 @@ namespace mln to_ = from; } + // label -> int_u. + template <unsigned n> + void + from_to_(const value::label<n>& from, value::int_u<n>& to_) + { + to_ = from; + } + + // int_u<n> -> label<m> with n < m. template <unsigned n, unsigned m> inline diff --git a/milena/mln/value/rgb.hh b/milena/mln/value/rgb.hh index 4a41577..d63a558 100644 --- a/milena/mln/value/rgb.hh +++ b/milena/mln/value/rgb.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development +// Laboratory (LRDE) // // This file is part of Olena. // @@ -34,6 +35,8 @@ # include <mln/value/int_u.hh> # include <mln/algebra/vec.hh> +# include <mln/value/internal/make_generic_name.hh> + namespace mln { @@ -220,7 +223,8 @@ namespace mln static const char* name() { - static std::string s = std::string("rgb").append(1, n + '0'); + static std::string + s = mln::value::internal::make_generic_name("rgb", n); return s.c_str(); } -- 1.5.6.5
participants (1)
-
Guillaume Lazzara