
* mln/convert/from_to.hxx, * mln/fun/i2v/array.hh: add two from_to; - from_to(util::array, fun::i2v::array) - from_to(std::vector, fun::i2v::array) * mln/convert/to.hh, * doc/examples/labeling_algo.cc: cleanup. --- milena/ChangeLog | 12 ++++ milena/doc/examples/labeling_algo.cc | 9 ++-- milena/mln/convert/from_to.hxx | 24 ++++++++ milena/mln/convert/to.hh | 13 ++--- milena/mln/fun/i2v/array.hh | 100 ++++++++++++++++++++++++++++++++-- 5 files changed, 142 insertions(+), 16 deletions(-) diff --git a/milena/ChangeLog b/milena/ChangeLog index 428323d..ebb4700 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,5 +1,17 @@ 2008-11-18 Guillaume Lazzara <z@lrde.epita.fr> + Add a new from_to for fun::i2v::array. + + * mln/convert/from_to.hxx, + * mln/fun/i2v/array.hh: add two from_to; + - from_to(util::array, fun::i2v::array) + - from_to(std::vector, fun::i2v::array) + + * mln/convert/to.hh, + * doc/examples/labeling_algo.cc: cleanup. + +2008-11-18 Guillaume Lazzara <z@lrde.epita.fr> + Fix wrong declaration of global variables. * mln/core/alias/dpoint1d.hh, diff --git a/milena/doc/examples/labeling_algo.cc b/milena/doc/examples/labeling_algo.cc index 9e6deb0..2eafdd6 100644 --- a/milena/doc/examples/labeling_algo.cc +++ b/milena/doc/examples/labeling_algo.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2007 EPITA Research and Development Laboratory +// Copyright (C) 2007, 2008 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 @@ -25,10 +25,9 @@ // reasons why the executable file might be covered by the GNU General // Public License. -/*! \file doc/examples/labeling_algo.cc - * - * \brief Test on mln::geom::seeds2tiling. - */ +/// \file doc/examples/labeling_algo.cc +/// +/// Test on mln::geom::seeds2tiling. # include <mln/core/image/image2d.hh> # include <mln/core/image/sub_image.hh> diff --git a/milena/mln/convert/from_to.hxx b/milena/mln/convert/from_to.hxx index bb3b39b..1876401 100644 --- a/milena/mln/convert/from_to.hxx +++ b/milena/mln/convert/from_to.hxx @@ -36,6 +36,8 @@ # include <mln/core/def/all.hh> # include <mln/core/grids.hh> +//FIXME: have a forward declaration. +# include <vector> namespace mln { @@ -65,6 +67,16 @@ namespace mln template <unsigned d, typename C> class h_vec; } + namespace fun { + namespace i2v { + template <typename T> class array; + } + } + + namespace util { + template <typename T> class array; + } + namespace value { template <unsigned n> struct rgb; } @@ -206,6 +218,18 @@ namespace mln void from_to(const w_window<D,W>& from, Image<I>& to); + + + // util::array<T> -> fun::i2v::array<T> + template <typename T> + void + from_to(const util::array<T>& from, fun::i2v::array<T>& to); + + // std::vector<T> -> fun::i2v::array<T> + template <typename T> + void + from_to(const std::vector<T>& from, fun::i2v::array<T>& to); + } // end of namespace mln::convert } // end of namespace mln diff --git a/milena/mln/convert/to.hh b/milena/mln/convert/to.hh index ad7bab3..bb67593 100644 --- a/milena/mln/convert/to.hh +++ b/milena/mln/convert/to.hh @@ -1,5 +1,5 @@ // Copyright (C) 2008 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 @@ -28,12 +28,11 @@ #ifndef MLN_CONVERT_TO_HH # define MLN_CONVERT_TO_HH -/*! \file mln/convert/to.hh - * - * \brief General conversion procedure given the destination type. - * - * \todo Prefer a static check that fails in the "unknown" case. - */ +/// \file mln/convert/to.hh +/// +/// General conversion procedure given the destination type. +/// +/// \todo Prefer a static check that fails in the "unknown" case. # include <mln/core/routine/exact.hh> # include <mln/metal/equal.hh> diff --git a/milena/mln/fun/i2v/array.hh b/milena/mln/fun/i2v/array.hh index a791ec6..a97bf33 100644 --- a/milena/mln/fun/i2v/array.hh +++ b/milena/mln/fun/i2v/array.hh @@ -28,19 +28,53 @@ #ifndef MLN_FUN_I2V_ARRAY_HH # define MLN_FUN_I2V_ARRAY_HH -/*! \file mln/fun/i2v/array.hh - * - * \brief FIXME. - */ +/// \file mln/fun/i2v/array.hh +/// +/// Function mapping an Id i to a value v. # include <vector> # include <algorithm> # include <mln/core/concept/function.hh> +# include <mln/util/array.hh> namespace mln { + + /// Forward declaration. + namespace fun + { + + namespace i2v + { + + template <typename T> + class array; + + } // end of namespace mln::fun::i2v + + } // end of namespace mln::fun + + + + namespace convert + { + + template <typename T> + inline + void + from_to(const util::array<T>& from, fun::i2v::array<T>& to); + + template <typename T> + inline + void + from_to(const std::vector<T>& from, fun::i2v::array<T>& to); + + } // end of namespace mln::convert + + + namespace fun { @@ -54,9 +88,23 @@ namespace mln typedef T result; + /// Constructors + /// \{ + + /// Default. array(); + /// Constructs a function with \p nvalues. array(unsigned n); + /// Used in from_to(). Constructs that function from an util::array. + /// Always prefer using from_to instead of this constructor. + array(const util::array<T>& from); + /// Used in from_to(). Constructs that function from an std::vector. + /// Always prefer using from_to instead of this constructor. + array(const std::vector<T>& from); + + /// \} + void resize(unsigned n); unsigned size() const; @@ -74,6 +122,34 @@ namespace mln # ifndef MLN_INCLUDE_ONLY + + // convert::from_to + + namespace convert + { + + template <typename T> + inline + void + from_to(const util::array<T>& from, fun::i2v::array<T>& to) + { + to = fun::i2v::array<T>(from); + } + + template <typename T> + inline + void + from_to(const std::vector<T>& from, fun::i2v::array<T>& to) + { + to = fun::i2v::array<T>(from); + } + + } // end of namespace mln::convert + + + + /// fun::i2v::array + namespace fun { @@ -95,6 +171,22 @@ namespace mln template <typename T> inline + array<T>::array(const util::array<T>& from) + : v_(from.std_vector()) + { + + } + + template <typename T> + inline + array<T>::array(const std::vector<T>& from) + : v_(from) + { + + } + + template <typename T> + inline void array<T>::resize(unsigned n) { -- 1.5.6.5