
* mln/accu/internal/couple.hh: new class. --- milena/ChangeLog | 6 + milena/mln/accu/internal/couple.hh | 184 ++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 0 deletions(-) create mode 100644 milena/mln/accu/internal/couple.hh diff --git a/milena/ChangeLog b/milena/ChangeLog index 5944d9b..be240e1 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,9 @@ +2009-03-19 Guillaume Lazzara <lazzara@lrde.epita.fr> + + Add accu::couple. + + * mln/accu/internal/couple.hh: new class. + 2009-03-18 Guillaume Lazzara <lazzara@lrde.epita.fr> Add transform::distance_and_influence_zone_geodesic. diff --git a/milena/mln/accu/internal/couple.hh b/milena/mln/accu/internal/couple.hh new file mode 100644 index 0000000..d4678a6 --- /dev/null +++ b/milena/mln/accu/internal/couple.hh @@ -0,0 +1,184 @@ +// 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_ACCU_INTERNAL_COUPLE_HH +# define MLN_ACCU_INTERNAL_COUPLE_HH + +/// \file mln/accu/couple.hh +/// +/// Base implementation of a couple of accumulators. + +# include <utility> + +# include <mln/core/concept/accumulator.hh> +# include <mln/accu/internal/base.hh> + +# include <mln/metal/equal.hh> + + +namespace mln +{ + + namespace accu + { + + namespace internal + { + + /// Base implementation of a couple of accumulators. + /// + /// The parameter \c T is the type of values. + /// + /// \todo Check that, when T is not provided, A1 and A2 have the same value. + template <typename A1, typename A2, typename R, typename E> + struct couple + : base<R,E>, + mlc_equal(mln_argument(A1), mln_argument(A2))::check_t + { + typedef mln_argument(A1) argument; + + /// Manipulators. + /// \{ + void init(); + void take_as_init(const argument& t); + void take(const argument& t); + void take(const E& other); + /// \} + + /// Check whether this accu is able to return a result. + /// Always true here. + bool is_valid() const; + + A1& first(); + A2& second(); + const A1& first() const; + const A2& second() const; + + protected: + couple(); + + A1 a1_; + A2 a2_; + }; + + +# ifndef MLN_INCLUDE_ONLY + + template <typename A1, typename A2, typename R, typename E> + inline + couple<A1,A2,R,E>::couple() + { + init(); + } + + template <typename A1, typename A2, typename R, typename E> + inline + void + couple<A1,A2,R,E>::init() + { + a1_.init(); + a2_.init(); + } + + template <typename A1, typename A2, typename R, typename E> + inline + void + couple<A1,A2,R,E>::take_as_init(const argument& t) + { + a1_.take_as_init(t); + a2_.take_as_init(t); + } + + template <typename A1, typename A2, typename R, typename E> + inline + void + couple<A1,A2,R,E>::take(const argument& t) + { + a1_.take(t); + a2_.take(t); + } + + template <typename A1, typename A2, typename R, typename E> + inline + void + couple<A1,A2,R,E>::take(const E& other) + { + a1_.take(other.a1_); + a2_.take(other.a2_); + } + + template <typename A1, typename A2, typename R, typename E> + inline + bool + couple<A1,A2,R,E>::is_valid() const + { + return a1_.is_valid() && a2_.is_valid(); + } + + template <typename A1, typename A2, typename R, typename E> + inline + A1& + couple<A1,A2,R,E>::first() + { + return a1_; + } + + template <typename A1, typename A2, typename R, typename E> + inline + const A1& + couple<A1,A2,R,E>::first() const + { + return a1_; + } + + template <typename A1, typename A2, typename R, typename E> + inline + A2& + couple<A1,A2,R,E>::second() + { + return a2_; + } + + template <typename A1, typename A2, typename R, typename E> + inline + const A2& + couple<A1,A2,R,E>::second() const + { + return a2_; + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace mln::accu::internal + + } // end of namespace mln::accu + +} // end of namespace mln + + +#endif // ! MLN_ACCU_INTERNAL_COUPLE_HH -- 1.5.6.5
participants (1)
-
Guillaume Lazzara