https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add int_s, an histogram class, and distributed sort.
* tests/int_s8.cc: New.
* tests/int_u8.cc: Augment.
* mln/histo/sort.hh: New.
* mln/histo/data.hh: New.
* mln/histo/compute.hh: New.
* mln/accu/histo.hh: Fix doc.
* mln/accu/median.hh: Fix doc.
* mln/value/int_s8.hh: New.
* mln/value/int_u16.hh: New.
* mln/value/int_u8.hh: New.
* mln/value/int_s.hh: New.
* mln/value/int_u.hh (zero, one): New.
(encoding_): Move to...
* mln/value/internal/encoding.hh: ...this new file.
* tests/median.cc,
* tests/fast_median.cc,
* tests/main.cc,
* tests/hmedian.cc,
* tests/erosion.cc,
* tests/naive_median.cc,
* tests/vset.cc,
* tests/histo.cc,
* mln/io/save_pgm.hh,
* mln/io/load_pgm.hh: Update.
mln/accu/histo.hh | 2
mln/accu/median.hh | 2
mln/histo/compute.hh | 95 +++++++++++++++++++++++
mln/histo/data.hh | 149 +++++++++++++++++++++++++++++++++++++
mln/histo/sort.hh | 147 ++++++++++++++++++++++++++++++++++++
mln/io/load_pgm.hh | 2
mln/io/save_pgm.hh | 2
mln/value/int_s.hh | 163 +++++++++++++++++++++++++++++++++++++++++
mln/value/int_s8.hh | 55 +++++++++++++
mln/value/int_u.hh | 79 ++++++++++++-------
mln/value/int_u16.hh | 55 +++++++++++++
mln/value/int_u8.hh | 55 +++++++++++++
mln/value/internal/encoding.hh | 86 +++++++++++++++++++++
tests/erosion.cc | 2
tests/fast_median.cc | 2
tests/histo.cc | 26 ++++++
tests/hmedian.cc | 2
tests/int_s8.cc | 51 ++++++++++++
tests/int_u8.cc | 9 ++
tests/main.cc | 9 +-
tests/median.cc | 2
tests/naive_median.cc | 2
tests/vset.cc | 2
23 files changed, 951 insertions(+), 48 deletions(-)
Index: tests/median.cc
--- tests/median.cc (revision 1036)
+++ tests/median.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/level/median.hh>
#include <mln/level/approx/median.hh>
Index: tests/int_s8.cc
--- tests/int_s8.cc (revision 0)
+++ tests/int_s8.cc (revision 0)
@@ -0,0 +1,51 @@
+// 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/int_s.cc
+ *
+ * \brief Tests on mln::value::int_s.
+ */
+
+#include <mln/value/int_s.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_s;
+
+ {
+ int_s<7> i = 3;
+ i = 2;
+ mln_assertion(i = 2);
+ mln_assertion(i != 3);
+
+ mln_assertion(-i = -2);
+ mln_assertion(-3 * i = -6);
+ }
+
+}
Index: tests/int_u8.cc
--- tests/int_u8.cc (revision 1036)
+++ tests/int_u8.cc (working copy)
@@ -30,7 +30,7 @@
* \brief Tests on mln::value::int_u8.
*/
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
@@ -39,6 +39,7 @@
using namespace mln;
using value::int_u8;
+ {
int_u8 i = 3;
i = 2;
mln_assertion(i = 2);
@@ -47,3 +48,9 @@
mln_assertion(-i = -2);
mln_assertion(-3 * i = -6);
}
+
+ {
+ int_u8 i = 128;
+ std::cout << i + i << std::endl;
+ }
+}
Index: tests/fast_median.cc
--- tests/fast_median.cc (revision 1036)
+++ tests/fast_median.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/debug/iota.hh>
#include <mln/debug/println.hh>
#include <mln/level/fast_median.hh>
Index: tests/main.cc
--- tests/main.cc (revision 1036)
+++ tests/main.cc (working copy)
@@ -39,13 +39,12 @@
#include <mln/morpho/erosion.hh>
#include <mln/morpho/Rd.hh>
+#include <mln/value/int_u8.hh>
-typedef unsigned char int_u8;
-
-// static int_u8 cos_sin(const mln::point2d& p)
+// static value::int_u8 cos_sin(const mln::point2d& p)
// {
-// return (int_u8)(255 * std::cos(float(p.row())) * std::sin(float(p.col())));
+// return (value::int_u8)(255 * std::cos(float(p.row())) * std::sin(float(p.col())));
// }
@@ -54,7 +53,7 @@
using namespace mln;
const unsigned size = 1000;
- image2d_b<int_u8> f(size, size);
+ image2d_b<value::int_u8> f(size, size);
morpho::Rd(f, f, c8());
}
Index: tests/hmedian.cc
--- tests/hmedian.cc (revision 1036)
+++ tests/hmedian.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/level/median.hh>
#include <mln/level/compare.hh>
Index: tests/erosion.cc
--- tests/erosion.cc (revision 1036)
+++ tests/erosion.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/level/fill.hh>
#include <mln/morpho/erosion.hh>
Index: tests/naive_median.cc
--- tests/naive_median.cc (revision 1036)
+++ tests/naive_median.cc (working copy)
@@ -36,7 +36,7 @@
#include <mln/io/load_pgm.hh>
#include <mln/io/save_pgm.hh>
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/level/naive/median.hh>
Index: tests/vset.cc
--- tests/vset.cc (revision 1036)
+++ tests/vset.cc (working copy)
@@ -30,7 +30,7 @@
* \brief Tests on mln::value::set_<T>.
*/
-#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
#include <mln/value/set.hh>
Index: tests/histo.cc
--- tests/histo.cc (revision 1036)
+++ tests/histo.cc (working copy)
@@ -27,17 +27,27 @@
/*! \file tests/histo.cc
*
- * \brief Tests on mln::value::histo<S>.
+ * \brief Tests on mln::accu::histo<S> and mln::histo::data<S>.
*/
+#include <iterator>
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/debug/iota.hh>
#include <mln/accu/histo.hh>
+#include <mln/histo/compute.hh>
+#include <mln/histo/sort.hh>
int main()
{
using namespace mln;
+ using value::int_u8;
+ {
accu::histo< value::set<bool> > h;
for (unsigned i = 0; i < 5; ++i)
@@ -49,3 +59,17 @@
mln_assertion(h[0] * 10 + h[1] = 51);
mln_assertion(h(false) * 10 + h(true) = 51);
}
+
+ {
+ image2d_b<int_u8> ima(3, 3);
+ debug::iota(ima);
+ histo::data< value::set<int_u8> > h = histo::compute(ima);
+ std::cout << h << std::endl;
+
+ std::vector<point2d> vec = histo::sort_points_decreasing(ima);
+ std::copy(vec.begin(), vec.end(),
+ std::ostream_iterator<point2d>(std::cout, " "));
+ std::cout << std::endl;
+ }
+
+}
Index: mln/histo/sort.hh
--- mln/histo/sort.hh (revision 0)
+++ mln/histo/sort.hh (revision 0)
@@ -0,0 +1,147 @@
+// 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.
+
+#ifndef MLN_HISTO_SORT_HH
+# define MLN_HISTO_SORT_HH
+
+/*! \file mln/histo/sort.hh
+ *
+ * \brief Routine to sort an histogram.
+ */
+
+# include <vector>
+
+# include <mln/core/concept/image.hh>
+# include <mln/histo/compute.hh>
+
+
+namespace mln
+{
+
+ namespace histo
+ {
+
+ /// Sort points of image \p input by decreasing values.
+ template <typename I>
+ std::vector<mln_point(I)> sort_points_decreasing(const Image<I>&
input);
+
+ /// Sort points of image \p input by increasing values.
+ template <typename I>
+ std::vector<mln_point(I)> sort_points_increasing(const Image<I>&
input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points_decreasing(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+
+ typedef mln_vset(I) S;
+ const S& vset = input.values();
+ const unsigned n = vset.nvalues();
+
+ // h
+ histo::data<S> h = compute(input);
+
+ // preparing output data
+ std::vector<unsigned> loc(vset.nvalues());
+ loc[n-1] = 0;
+ for (unsigned i = n - 2; i != 0; --i)
+ loc[i] = loc[i+1] + h[i+1];
+
+ // computing output data
+ std::vector<mln_point(I)> vec(input.npoints());
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ vec[loc[vset.index_of(input(p))]++] = p;
+
+ return vec;
+ }
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points_increasing(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+
+ typedef mln_vset(I) S;
+ const S& vset = input.values();
+ const unsigned n = vset.nvalues();
+
+ // h
+ histo::data<S> h = compute(input);
+
+ // preparing output data
+ std::vector<unsigned> loc(vset.nvalues());
+ loc[0] = 0;
+ for (unsigned i = 1; i != n; ++i)
+ loc[i] = loc[i-1] + h[i-1];
+
+ // computing output data
+ std::vector<mln_point(I)> vec(input.npoints());
+ mln_fwd_piter(I) p(input.domain());
+ for_all(p)
+ vec[loc[vset.index_of(input(p))]++] = p;
+
+ return vec;
+ }
+
+ } // end of namespace mln::histo::impl
+
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points_decreasing(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ mln_precondition(exact(input).values().nvalues() > 1); // FIXME
+ return impl::sort_points_decreasing(exact(input));
+ }
+
+
+ template <typename I>
+ std::vector<mln_point(I)>
+ sort_points_increasing(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ mln_precondition(exact(input).values().nvalues() > 1); // FIXME
+ return impl::sort_points_increasing(exact(input));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::histo
+
+} // end of namespace mln
+
+
+#endif // ! MLN_HISTO_SORT_HH
Index: mln/histo/data.hh
--- mln/histo/data.hh (revision 0)
+++ mln/histo/data.hh (revision 0)
@@ -0,0 +1,149 @@
+// 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.
+
+#ifndef MLN_HISTO_DATA_HH
+# define MLN_HISTO_DATA_HH
+
+/*! \file mln/histo/data.hh
+ *
+ * \brief Define a generic histogram class.
+ */
+
+# include <vector>
+# include <algorithm>
+
+# include <mln/core/concept/value_set.hh>
+
+
+namespace mln
+{
+
+ namespace histo
+ {
+
+
+ /*! Generic histogram class over a value set with type \c S.
+ */
+ template <typename S>
+ struct data
+ {
+ typedef mln_value(S) value;
+
+ data(const Value_Set<S>& s);
+
+ void clear();
+
+ std::size_t operator()(const value& v) const;
+ std::size_t& operator()(const value& v);
+
+ const std::vector<std::size_t>& vec() const;
+ const S& vset() const;
+ std::size_t operator[](unsigned i) const;
+
+ protected:
+
+ const S& s_;
+ std::vector<std::size_t> h_;
+ };
+
+
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const data<S>&
h);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S>
+ data<S>::data(const Value_Set<S>& s)
+ : s_(exact(s)),
+ h_(s_.nvalues(), 0)
+ {
+ clear();
+ }
+
+ template <typename S>
+ void
+ data<S>::clear()
+ {
+ std::fill(h_.begin(), h_.end(), 0);
+ }
+
+ template <typename S>
+ std::size_t
+ data<S>::operator()(const value& v) const
+ {
+ return h_[s_.index_of(v)];
+ }
+
+ template <typename S>
+ std::size_t&
+ data<S>::operator()(const value& v)
+ {
+ return h_[s_.index_of(v)];
+ }
+
+ template <typename S>
+ const S&
+ data<S>::vset() const
+ {
+ return s_;
+ }
+
+ template <typename S>
+ std::size_t
+ data<S>::operator[](unsigned i) const
+ {
+ mln_precondition(i < s_.nvalues());
+ return h_[i];
+ }
+
+ template <typename S>
+ const std::vector<std::size_t>&
+ data<S>::vec() const
+ {
+ return h_;
+ }
+
+ template <typename S>
+ std::ostream& operator<<(std::ostream& ostr, const data<S>&
h)
+ {
+ mln_viter(S) v(h.vset());
+ for_all(v)
+ if (h(v) != 0)
+ ostr << v << ':' << h(v) << ' ';
+ return ostr;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::histo
+
+} // end of namespace mln
+
+
+#endif // ! MLN_HISTO_DATA_HH
Index: mln/histo/compute.hh
--- mln/histo/compute.hh (revision 0)
+++ mln/histo/compute.hh (revision 0)
@@ -0,0 +1,95 @@
+// 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.
+
+#ifndef MLN_HISTO_COMPUTE_HH
+# define MLN_HISTO_COMPUTE_HH
+
+/*! \file mln/histo/compute.hh
+ *
+ * \brief Routine to compute an histogram.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/histo/data.hh>
+
+
+namespace mln
+{
+
+ namespace histo
+ {
+
+ /// Compute the histogram of image \p input.
+ template <typename I>
+ data<mln_vset(I)> compute(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ data<mln_vset(I)> compute(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ data<mln_vset(I)> h(input.values());
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ ++h(input(p));
+ return h;
+ }
+
+ template <typename I>
+ data<mln_vset(I)> compute(const Fast_Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ data<mln_vset(I)> h(input.values());
+ mln_pixter(const I) p(input);
+ for_all(p)
+ ++h(*p);
+ return h;
+ }
+
+ } // end of namespace mln::histo::impl
+
+
+ template <typename I>
+ data<mln_vset(I)> compute(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ return impl::compute(exact(input));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::histo
+
+} // end of namespace mln
+
+
+#endif // ! MLN_HISTO_COMPUTE_HH
Index: mln/io/save_pgm.hh
--- mln/io/save_pgm.hh (revision 1036)
+++ mln/io/save_pgm.hh (working copy)
@@ -33,7 +33,7 @@
# include <fstream>
# include <mln/core/image2d_b.hh>
-# include <mln/value/int_u.hh>
+# include <mln/value/int_u8.hh>
namespace mln
Index: mln/io/load_pgm.hh
--- mln/io/load_pgm.hh (revision 1036)
+++ mln/io/load_pgm.hh (working copy)
@@ -34,7 +34,7 @@
# include <string>
# include <mln/core/image2d_b.hh>
-# include <mln/value/int_u.hh>
+# include <mln/value/int_u8.hh>
namespace mln
Index: mln/accu/histo.hh
--- mln/accu/histo.hh (revision 1036)
+++ mln/accu/histo.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/accu/histo.hh
*
- * \brief Define a couple of generic histogram classes.
+ * \brief Define a generic histogram accumulator class.
*/
# include <vector>
Index: mln/accu/median.hh
--- mln/accu/median.hh (revision 1036)
+++ mln/accu/median.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/accu/median.hh
*
- * \brief Define FIXME
+ * \brief Define a generic median accumulator class.
*/
# include <mln/core/concept/accumulator.hh>
Index: mln/value/int_s8.hh
--- mln/value/int_s8.hh (revision 0)
+++ mln/value/int_s8.hh (revision 0)
@@ -0,0 +1,55 @@
+// 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.
+
+#ifndef MLN_VALUE_INT_S8_HH
+# define MLN_VALUE_INT_S8_HH
+
+/*! \file mln/value/int_s8.hh
+ *
+ * \brief Define the alias value::int_s8.
+ */
+
+# include <mln/value/int_s.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Alias for signed 8 bit integers.
+ typedef int_s<8> int_s8;
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_S8_HH
Index: mln/value/int_u16.hh
--- mln/value/int_u16.hh (revision 0)
+++ mln/value/int_u16.hh (revision 0)
@@ -0,0 +1,55 @@
+// 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.
+
+#ifndef MLN_VALUE_INT_U16_HH
+# define MLN_VALUE_INT_U16_HH
+
+/*! \file mln/value/int_u16.hh
+ *
+ * \brief Define the alias value::int_u16.
+ */
+
+# include <mln/value/int_u.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Alias for unsigned 16 bit integers.
+ typedef int_u<16> int_u16;
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_U16_HH
Index: mln/value/int_u8.hh
--- mln/value/int_u8.hh (revision 0)
+++ mln/value/int_u8.hh (revision 0)
@@ -0,0 +1,55 @@
+// 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.
+
+#ifndef MLN_VALUE_INT_U8_HH
+# define MLN_VALUE_INT_U8_HH
+
+/*! \file mln/value/int_u8.hh
+ *
+ * \brief Define the alias value::int_u8.
+ */
+
+# include <mln/value/int_u.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /// Alias for unsigned 8 bit integers.
+ typedef int_u<8> int_u8;
+
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_U8_HH
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 0)
+++ mln/value/int_s.hh (revision 0)
@@ -0,0 +1,163 @@
+// 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.
+
+#ifndef MLN_VALUE_INT_S_HH
+# define MLN_VALUE_INT_S_HH
+
+/*! \file mln/value/int_s.hh
+ *
+ * \brief Define a generic class for signed integers.
+ */
+
+# include <mln/metal/math.hh>
+# include <mln/value/internal/value_like.hh>
+# include <mln/value/internal/encoding.hh>
+# include <mln/value/props.hh>
+# include <mln/value/set.hh>
+# include <mln/debug/format.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /*! \brief Signed integer value class.
+ *
+ * The parameter is \c n the number of encoding bits.
+ */
+ template <unsigned n>
+ struct int_s
+ : public internal::value_like_< typename
internal::encoding_int_s_<n>::ret,
+ int_s<n> >
+ {
+ protected:
+ typedef internal::value_like_< typename
internal::encoding_int_s_<n>::ret,
+ int_s<n> > super;
+
+ public:
+
+ /// Encoding associated type.
+ typedef typename super::enc enc;
+
+ /// Constructor without argument.
+ int_s();
+
+ /// Constructor from an integer.
+ int_s(int i);
+
+ /// Negation.
+ int_s<n> operator-() const;
+
+ /// Zero value.
+ static const int_s<n> zero;
+
+ /// Unit value.
+ static const int_s<n> one;
+ };
+
+
+
+ template <unsigned n>
+ struct props< int_s<n> >
+ {
+ static const int_s<n> max; // = 2^(n-1) - 1
+ static const int_s<n> min; // = - max
+ static const std::size_t card = metal::pow<2, n>::value;
+ static const unsigned nbits = n;
+ typedef data_kind kind;
+ };
+
+
+ // Safety.
+ template <> struct int_s<0>;
+ template <> struct int_s<1>;
+
+
+
+ /*! \brief Print an signed integer \p i into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] i An signed integer.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const int_s<n>&
i);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n>
+ int_s<n>::int_s()
+ {
+ }
+
+ template <unsigned n>
+ int_s<n>::int_s(int i)
+ {
+ mln_precondition(i >= mln_min(enc));
+ mln_precondition(i <= mln_max(enc));
+ this->v_ = enc(i);
+ }
+
+ template <unsigned n>
+ int_s<n> int_s<n>::operator-() const
+ {
+ return - this->v_;
+ }
+
+ template <unsigned n>
+ const int_s<n> int_s<n>::zero = 0;
+
+ template <unsigned n>
+ const int_s<n> int_s<n>::one = 1;
+
+ template <unsigned n>
+ const int_s<n>
+ props< int_s<n> >::min = 1 - metal::pow<2, n - 1>::value;
+
+ template <unsigned n>
+ const int_s<n>
+ props< int_s<n> >::max = metal::pow<2, n - 1>::value - 1;
+
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const int_s<n>&
i)
+ {
+ return ostr << debug::format(i.to_equiv());
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_S_HH
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1036)
+++ mln/value/int_u.hh (working copy)
@@ -35,8 +35,10 @@
# include <mln/metal/math.hh>
# include <mln/value/internal/value_like.hh>
+# include <mln/value/internal/encoding.hh>
# include <mln/value/props.hh>
# include <mln/value/set.hh>
+# include <mln/debug/format.hh>
namespace mln
@@ -46,25 +48,18 @@
{
- namespace internal
- {
- template <unsigned n> struct encoding_;
- template <> struct encoding_<8> { typedef unsigned char ret; };
- }
-
-
/*! \brief Unsigned integer value class.
*
* The parameter is \c n the number of encoding bits.
*/
template <unsigned n>
- struct int_u_
- : public internal::value_like_< typename internal::encoding_<n>::ret,
- int_u_<n> >
+ struct int_u
+ : public internal::value_like_< typename
internal::encoding_int_u_<n>::ret,
+ int_u<n> >
{
protected:
- typedef internal::value_like_< typename internal::encoding_<n>::ret,
- int_u_<n> > super;
+ typedef internal::value_like_< typename
internal::encoding_int_u_<n>::ret,
+ int_u<n> > super;
public:
@@ -72,60 +67,82 @@
typedef typename super::enc enc;
/// Constructor without argument.
- int_u_();
+ int_u();
/// Constructor from an integer.
- int_u_(int i);
+ int_u(int i);
+
+ /// Zero value.
+ static const int_u<n> zero;
+
+ /// Unit value.
+ static const int_u<n> one;
};
+ // Safety.
+ template <> struct int_u<0>;
+ template <> struct int_u<1>;
+
template <unsigned n>
- struct props< int_u_<n> > : public props< typename
internal::encoding_<n>::ret >
+ struct props< int_u<n> >
{
- static const unsigned nbits = n;
static const std::size_t card = metal::pow<2, n>::value;
+ static const int_u<n> min; // = 0
+ static const int_u<n> max; // = card - 1
+ static const unsigned nbits = n;
+ typedef data_kind kind;
};
- /// Alias for unsigned 8bit integers.
- typedef int_u_<8> int_u8;
-
- /// Alias for the set of unsigned 8bit integers.
- typedef set<int_u8> int_u8_set;
-
-
-
- /*! \brief Print an int_u8 \p i into the output stream \p ostr.
+ /*! \brief Print an unsigned integer \p i into the output stream \p ostr.
*
* \param[in,out] ostr An output stream.
- * \param[in] i An int_u8.
+ * \param[in] i An unsigned integer.
*
* \return The modified output stream \p ostr.
*/
- std::ostream& operator<<(std::ostream& ostr, const int_u8& i);
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const int_u<n>&
i);
# ifndef MLN_INCLUDE_ONLY
template <unsigned n>
- int_u_<n>::int_u_()
+ int_u<n>::int_u()
{
}
template <unsigned n>
- int_u_<n>::int_u_(int i)
+ int_u<n>::int_u(int i)
{
mln_precondition(i >= 0);
mln_precondition(i <= mln_max(enc));
this->v_ = enc(i);
}
- std::ostream& operator<<(std::ostream& ostr, const int_u8& i)
+ template <unsigned n>
+ const int_u<n> int_u<n>::zero = 0;
+
+ template <unsigned n>
+ const int_u<n> int_u<n>::one = 1;
+
+
+ template <unsigned n>
+ const int_u<n>
+ props< int_u<n> >::min = 0;
+
+ template <unsigned n>
+ const int_u<n>
+ props< int_u<n> >::max = metal::pow<2, n>::value - 1;
+
+ template <unsigned n>
+ std::ostream& operator<<(std::ostream& ostr, const int_u<n>&
i)
{
- return ostr << unsigned(i.to_equiv());
+ return ostr << debug::format(i.to_equiv());
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/value/internal/encoding.hh
--- mln/value/internal/encoding.hh (revision 0)
+++ mln/value/internal/encoding.hh (revision 0)
@@ -0,0 +1,86 @@
+// 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.
+
+#ifndef MLN_VALUE_INTERNAL_ENCODING_HH
+# define MLN_VALUE_INTERNAL_ENCODING_HH
+
+/*! \file mln/value/internal/encoding.hh
+ *
+ * \brief Define some information about how to encode some value types.
+ */
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ namespace internal
+ {
+
+ template <unsigned n> struct encoding_int_u_;
+
+ template <> struct encoding_int_u_<8> { typedef unsigned char ret;
};
+ template <> struct encoding_int_u_<16> { typedef unsigned short ret;
};
+ template <> struct encoding_int_u_<32> { typedef unsigned int ret; };
// FIXME!!!
+ template <> struct encoding_int_u_<64> { typedef unsigned long ret; };
// FIXME!!!
+
+ template <> struct encoding_int_u_<99> { typedef void ret; }; //
stopper
+
+ template <unsigned n>
+ struct encoding_int_u_
+ {
+ typedef typename encoding_int_u_<n+1>::ret ret;
+ };
+
+
+
+ template <unsigned n> struct encoding_int_s_;
+
+ template <> struct encoding_int_s_<8> { typedef signed char ret; };
+ template <> struct encoding_int_s_<16> { typedef signed short ret; };
+ template <> struct encoding_int_s_<32> { typedef signed int ret; };
// FIXME!!!
+ template <> struct encoding_int_s_<64> { typedef signed long ret; };
// FIXME!!!
+
+ template <> struct encoding_int_s_<99> { typedef void ret; }; //
stopper
+
+ template <unsigned n>
+ struct encoding_int_s_
+ {
+ typedef typename encoding_int_s_<n+1>::ret ret;
+ };
+
+
+ } // end of namespace mln::value::internal
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INTERNAL_ENCODING_HH