https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add materials to handle values in milena.
* tests/vset.cc: New.
* tests/int_u8.cc: New.
* TODO: New.
* mln/core/concept/value_set.hh: New.
* mln/core/concept/viter.hh: New.
* mln/core/concept/doc/value_set.hh: New.
* mln/core/concept/doc/viter.hh: New.
* mln/core/concept/value.hh: New.
* mln/value/vset.hh: New.
* mln/value/viter.hh: New.
* mln/value/int_u.hh: New.
* mln/value/internal: New.
* mln/value/internal/value_like.hh: New.
* doc/Doxyfile.in (PREDEFINED): Add mln_viter et al.
* mln/core/macros.hh: Sort.
(mln_enc, mln_equiv): New.
* mln/value/props.hh (mln_card, card): New.
TODO | 25 ++++
doc/Doxyfile.in | 3
mln/core/concept/doc/value_set.hh | 79 +++++++++++++
mln/core/concept/doc/viter.hh | 58 +++++++++
mln/core/concept/value.hh | 73 ++++++++++++
mln/core/concept/value_set.hh | 88 ++++++++++++++
mln/core/concept/viter.hh | 104 +++++++++++++++++
mln/core/macros.hh | 97 ++++++++++++----
mln/value/int_u.hh | 130 ++++++++++++++++++++++
mln/value/internal/value_like.hh | 135 ++++++++++++++++++++++
mln/value/props.hh | 14 ++
mln/value/viter.hh | 224 ++++++++++++++++++++++++++++++++++++++
mln/value/vset.hh | 104 +++++++++++++++++
tests/int_u8.cc | 49 ++++++++
tests/vset.cc | 63 ++++++++++
15 files changed, 1220 insertions(+), 26 deletions(-)
Index: tests/vset.cc
--- tests/vset.cc (revision 0)
+++ tests/vset.cc (revision 0)
@@ -0,0 +1,63 @@
+// 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/vset.cc
+ *
+ * \brief Tests on mln::vset.
+ */
+
+#include <mln/value/int_u.hh>
+#include <mln/value/vset.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef bool T;
+ // typedef value::int_u8 T;
+ // typedef short T;
+
+ typedef value::vset_<T> S;
+ S s;
+
+ {
+ S::fwd_viter v(s);
+ for_all(v)
+ std::cout << v << ' ';
+ std::cout << std::endl;
+ }
+
+ {
+ S::bkd_viter v(s);
+ for_all(v)
+ std::cout << v << ' ';
+ std::cout << std::endl;
+ }
+
+}
Index: tests/int_u8.cc
--- tests/int_u8.cc (revision 0)
+++ tests/int_u8.cc (revision 0)
@@ -0,0 +1,49 @@
+// 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_u8.cc
+ *
+ * \brief Tests on mln::value::int_u8.
+ */
+
+#include <mln/value/int_u.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ int_u8 i = 3;
+ i = 2;
+ mln_assertion(i = 2);
+ mln_assertion(i != 3);
+
+ mln_assertion(-i = -2);
+ mln_assertion(-3 * i = -6);
+}
Index: doc/Doxyfile.in
--- doc/Doxyfile.in (revision 1001)
+++ doc/Doxyfile.in (working copy)
@@ -1051,6 +1051,9 @@
"mln_niter(T)=typename T::niter" \
"mln_fwd_niter(T)=typename T::fwd_niter" \
"mln_bkd_niter(T)=typename T::bkd_niter" \
+ "mln_viter(T)=typename T::viter" \
+ "mln_fwd_viter(T)=typename T::fwd_viter" \
+ "mln_bkd_viter(T)=typename T::bkd_viter" \
"mln_value(T)=typename T::value" \
"mln_rvalue(T)=typename T::rvalue" \
"mln_lvalue(T)=typename T::lvalue" \
Index: TODO
--- TODO (revision 0)
+++ TODO (revision 0)
@@ -0,0 +1,25 @@
+ -*- outline -*-
+
+
+* compilation
+
+g++-4.1 -I.. int_u8.cc -Wall -Wextra -Wconversion
+
+
+* value
+
+Value_Set
+props { ... }
+notion of lowq
++ values() : vset dans Image ?
+
+
+* function
+
+Function_p2v
+Function_p2b
+Function_v2w
+
+F apply(I, F)
+O transform(I, F)
+
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1001)
+++ mln/core/macros.hh (working copy)
@@ -33,63 +33,108 @@
* \brief Definition of the set of milena macros.
*/
-/// Shortcut to access the point type associated to T.
-# define mln_point(T) typename T::point
-/// Shortcut to access the dpoint type associated to T.
-# define mln_dpoint(T) typename T::dpoint
+// b
-/// Shortcut to access the psite type associated to T.
-# define mln_psite(T) typename T::psite
+/// Shortcut to access the bkd_niter type associated to T.
+# define mln_bkd_niter(T) typename T::bkd_niter
-/// Shortcut to access the pset type associated to T.
-# define mln_pset(T) typename T::pset
+/// Shortcut to access the bkd_piter type associated to T.
+# define mln_bkd_piter(T) typename T::bkd_piter
+
+/// Shortcut to access the bkd_qiter type associated to T.
+# define mln_bkd_qiter(T) typename T::bkd_qiter
+
+/// Shortcut to access the bkd_viter type associated to T.
+# define mln_bkd_viter(T) typename T::bkd_viter
/// Shortcut to access the box type associated to T.
# define mln_box(T) typename T::box
+
+// c
+
/// Shortcut to access the coord type associated to T.
# define mln_coord(T) typename T::coord
-/// Shortcut to access the piter type associated to T.
-# define mln_piter(T) typename T::piter
+// d
+
+/// Shortcut to access the dpoint type associated to T.
+# define mln_dpoint(T) typename T::dpoint
+
+
+// e
+
+/// Shortcut to access the encoding type associated to T.
+# define mln_enc(T) typename T::enc
+
+/// Shortcut to access the equivalent type associated to T.
+# define mln_equiv(T) typename T::equiv
+
+
+// f
+
+/// Shortcut to access the fwd_niter type associated to T.
+# define mln_fwd_niter(T) typename T::fwd_niter
/// Shortcut to access the fwd_piter type associated to T.
# define mln_fwd_piter(T) typename T::fwd_piter
-/// Shortcut to access the bkd_piter type associated to T.
-# define mln_bkd_piter(T) typename T::bkd_piter
+/// Shortcut to access the fwd_qiter type associated to T.
+# define mln_fwd_qiter(T) typename T::fwd_qiter
+
+/// Shortcut to access the fwd_viter type associated to T.
+# define mln_fwd_viter(T) typename T::fwd_viter
+
+// l
+
+
+/// Shortcut to access the lvalue type associated to T.
+# define mln_lvalue(T) typename T::lvalue
+
+
+// p
+
+/// Shortcut to access the piter type associated to T.
+# define mln_piter(T) typename T::piter
+
+/// Shortcut to access the pset type associated to T.
+# define mln_pset(T) typename T::pset
+
+/// Shortcut to access the psite type associated to T.
+# define mln_psite(T) typename T::psite
+
+/// Shortcut to access the point type associated to T.
+# define mln_point(T) typename T::point
+
+
+// q
/// Shortcut to access the qiter type associated to T.
# define mln_qiter(T) typename T::qiter
-/// Shortcut to access the fwd_qiter type associated to T.
-# define mln_fwd_qiter(T) typename T::fwd_qiter
-
-/// Shortcut to access the bkd_qiter type associated to T.
-# define mln_bkd_qiter(T) typename T::bkd_qiter
+// n
/// Shortcut to access the niter type associated to T.
# define mln_niter(T) typename T::niter
-/// Shortcut to access the fwd_niter type associated to T.
-# define mln_fwd_niter(T) typename T::fwd_niter
-/// Shortcut to access the bkd_niter type associated to T.
-# define mln_bkd_niter(T) typename T::bkd_niter
+// r
+
+/// Shortcut to access the rvalue type associated to T.
+# define mln_rvalue(T) typename T::rvalue
+// v
+
/// Shortcut to access the value type associated to T.
# define mln_value(T) typename T::value
-/// Shortcut to access the rvalue type associated to T.
-# define mln_rvalue(T) typename T::rvalue
-
-/// Shortcut to access the lvalue type associated to T.
-# define mln_lvalue(T) typename T::lvalue
+/// Shortcut to access the viter type associated to T.
+# define mln_viter(T) typename T::viter
Index: mln/core/concept/value_set.hh
--- mln/core/concept/value_set.hh (revision 0)
+++ mln/core/concept/value_set.hh (revision 0)
@@ -0,0 +1,88 @@
+// 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_CORE_CONCEPT_VALUE_SET_HH
+# define MLN_CORE_CONCEPT_VALUE_SET_HH
+
+/*! \file mln/core/concept/value_set.hh
+ * \brief Definition of the concept of mln::Value_Set.
+ */
+
+# include <mln/core/concept/viter.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Base class for implementation classes of sets of values.
+ *
+ * \see mln::doc::Value_Set for a complete documentation of this
+ * class contents.
+ */
+ template <typename E>
+ struct Value_Set : public Object<E>
+ {
+ /*
+ typedef value;
+ typedef viter;
+ typedef fwd_viter;
+ typedef bkd_viter;
+
+ bool has(const value& v) const;
+ value operator[](std::size_t i) const;
+ std::size_t nvalues() const;
+ */
+
+ protected:
+ Value_Set();
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Value_Set<E>::Value_Set()
+ {
+ typedef mln_value(E) value;
+ typedef mln_viter(E) viter;
+ typedef mln_fwd_viter(E) fwd_viter;
+ typedef mln_bkd_viter(E) bkd_viter;
+
+ bool (E::*m1)(const value&) const = & E::has;
+ m1 = 0;
+ value (E::*m2)(std::size_t) const = & E::operator[];
+ m2 = 0;
+ std::size_t (E::*m3)() const = & E::nvalues;
+ m3 = 0;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_VALUE_SET_HH
Index: mln/core/concept/viter.hh
--- mln/core/concept/viter.hh (revision 0)
+++ mln/core/concept/viter.hh (revision 0)
@@ -0,0 +1,104 @@
+// 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_CORE_CONCEPT_VITER_HH
+# define MLN_CORE_CONCEPT_VITER_HH
+
+/*! \file mln/core/concept/viter.hh
+ *
+ * \brief Definition of the concept of mln::Viter.
+ */
+
+# include <mln/core/concept/iterator.hh>
+# include <mln/core/concept/genpoint.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Base class for implementation of classes of iterator on
+ * values.
+ *
+ * An iterator on values is an iterator that browse over a set of
+ * values.
+ *
+ * \see mln::doc::Viter for a complete documentation of this class
+ * contents.
+ */
+ template <typename E>
+ struct Viter : public Iterator<E>
+ {
+ /*
+ typedef value;
+ operator value() const;
+ */
+
+ protected:
+ Viter();
+ };
+
+
+ /*! \brief Print an iterator \p v on value set into the output
+ * stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] v An iterator on value set.
+ *
+ * \pre \p v is a valid.
+ *
+ * \return The modified output stream \p ostr.
+ *
+ * \relates mln::Viter
+ */
+ template <typename E>
+ std::ostream& operator<<(std::ostream& ostr, const Viter<E>&
v);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Viter<E>::Viter()
+ {
+ typedef mln_value(E) value;
+ value (E::*m)() const = & E::operator value;
+ m = 0;
+ }
+
+ template <typename E>
+ std::ostream& operator<<(std::ostream& ostr, const Viter<E>&
v)
+ {
+ mln_precondition(exact(v).is_valid());
+ return ostr << mln_value(E)(exact(v));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_VITER_HH
Index: mln/core/concept/doc/value_set.hh
--- mln/core/concept/doc/value_set.hh (revision 0)
+++ mln/core/concept/doc/value_set.hh (revision 0)
@@ -0,0 +1,79 @@
+// 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 mln/core/concept/doc/value_set.hh
+ * \brief This file documents the concept of mln::Value_Set.
+ */
+
+namespace mln
+{
+
+ namespace doc
+ {
+
+ /*! \brief Documentation class for mln::Value_Set.
+ *
+ * \see mln::Value_Set
+ */
+ template <typename E>
+ struct Value_Set : public Object<E>
+ {
+ /*! \brief Value associated type.
+ */
+ typedef void value;
+
+ /*! \brief Viter associated type.
+ */
+ typedef void viter;
+
+ /*! \brief Forward Viter associated type.
+ */
+ typedef void fwd_viter;
+
+ /*! \brief Backward Viter associated type.
+ */
+ typedef void bkd_viter;
+
+ /*! \brief Test if \p v belongs to this set of values.
+ *
+ * \param[in] v A value.
+ * \return True if \p v is an element of the set of values.
+ */
+ bool has(const value& v) const;
+
+ /*! \brief Give the number of values in this set.
+ */
+ std::size_t nvalues() const;
+
+ /*! \brief Give the \p i-th value of this set.
+ */
+ value operator[](std::size_t i) const;
+ };
+
+ } // end of namespace mln::doc
+
+} // end of namespace mln
Index: mln/core/concept/doc/viter.hh
--- mln/core/concept/doc/viter.hh (revision 0)
+++ mln/core/concept/doc/viter.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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 mln/core/concept/doc/viter.hh
+ * \brief This file documents the concept of mln::Viter.
+ */
+
+namespace mln
+{
+
+ namespace doc
+ {
+
+ /*! \brief Documentation class for mln::Viter.
+ *
+ * \see mln::Viter
+ */
+ template <typename E>
+ struct Viter : public Iterator<E>
+ {
+ /*! \brief Value associated type.
+ */
+ typedef void value;
+
+ /*! \brief Convertion into a value.
+ *
+ * \return A value.
+ */
+ operator value() const;
+ };
+
+ } // end of namespace mln::doc
+
+} // end of namespace mln
Index: mln/core/concept/value.hh
--- mln/core/concept/value.hh (revision 0)
+++ mln/core/concept/value.hh (revision 0)
@@ -0,0 +1,73 @@
+// 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_CORE_CONCEPT_VALUE_HH
+# define MLN_CORE_CONCEPT_VALUE_HH
+
+/*! \file mln/core/concept/value.hh
+ * \brief Definition of the concept of mln::Value.
+ */
+
+# include <mln/core/concept/object.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Base class for implementation classes of values.
+ *
+ * \see mln::doc::Value for a complete documentation of this class
+ * contents.
+ */
+ template <typename E>
+ struct Value : public Object<E>
+ {
+ /*
+ typedef enc; // encoding type
+ typedef equiv; // equivalent type
+ */
+
+ protected:
+ Value();
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ Value<E>::Value()
+ {
+ typedef mln_enc(E) enc;
+ typedef mln_equiv(E) equiv;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_CONCEPT_VALUE_HH
Index: mln/value/vset.hh
--- mln/value/vset.hh (revision 0)
+++ mln/value/vset.hh (revision 0)
@@ -0,0 +1,104 @@
+// 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_VSET_HH
+# define MLN_VALUE_VSET_HH
+
+/*! \file mln/value/vset.hh
+ *
+ * \brief Define some basic sets of values from value types.
+ */
+
+# include <mln/core/concept/value_set.hh>
+# include <mln/value/props.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ // Fwd decls.
+ template <typename S> struct fwd_viter_;
+ template <typename S> struct bkd_viter_;
+
+
+ /*! Class that defines the properties of the value type \c T.
+ */
+ template <typename T>
+ struct vset_ : public Value_Set< vset_<T> >
+ {
+ typedef T value;
+
+ typedef fwd_viter_< vset_<T> > fwd_viter;
+ typedef bkd_viter_< vset_<T> > bkd_viter;
+ typedef fwd_viter viter;
+
+ bool has(const T& v) const;
+
+ T operator[](std::size_t i) const;
+
+ std::size_t nvalues() const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ bool
+ vset_<T>::has(const T& v) const
+ {
+ return true;
+ }
+
+ template <typename T>
+ T
+ vset_<T>::operator[](std::size_t i) const
+ {
+ mln_precondition(i < nvalues());
+ return mln_min(T) + i;
+ }
+
+ template <typename T>
+ std::size_t
+ vset_<T>::nvalues() const
+ {
+ return mln_card(T);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+# include <mln/value/viter.hh>
+
+
+#endif // ! MLN_VALUE_VSET_HH
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1001)
+++ mln/value/props.hh (working copy)
@@ -45,6 +45,10 @@
# define mln_max(T) mln::value::props<T>::max()
+/// Get the number of values for value type \c T.
+# define mln_card(T) mln::value::props<T>::card()
+
+
namespace mln
{
@@ -62,6 +66,9 @@
/// Maximum value for type \c T.
static T max();
+
+ /// Number of values for type \c T.
+ static std::size_t card();
};
@@ -72,6 +79,7 @@
{
static bool min() { return false; }
static bool max() { return true; }
+ static std::size_t card() { return 2; }
};
// integers
@@ -81,6 +89,7 @@
{
static unsigned char min() { return 0; }
static unsigned char max() { return 255; }
+ static std::size_t card() { return 256; }
};
template <>
@@ -88,6 +97,7 @@
{
static signed char min() { return -128; }
static signed char max() { return 127; }
+ static std::size_t card() { return 256; }
};
template <>
@@ -95,6 +105,7 @@
{
static unsigned short min() { return 0; }
static unsigned short max() { return 65535; }
+ static std::size_t card() { return 65536; }
};
template <>
@@ -102,6 +113,7 @@
{
static signed short min() { return -32768; }
static signed short max() { return 32767; }
+ static std::size_t card() { return 655356; }
};
template <>
@@ -109,6 +121,7 @@
{
static unsigned int min() { return 0; }
static unsigned int max() { return UINT_MAX; }
+ static std::size_t card() { return std::size_t(UINT_MAX) + 1; }
};
template <>
@@ -116,6 +129,7 @@
{
static signed int min() { return INT_MIN; }
static signed int max() { return INT_MAX; }
+ static std::size_t card() { return std::size_t(UINT_MAX) + 1; }
};
template <>
Index: mln/value/viter.hh
--- mln/value/viter.hh (revision 0)
+++ mln/value/viter.hh (revision 0)
@@ -0,0 +1,224 @@
+// 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_VITER_HH
+# define MLN_VALUE_VITER_HH
+
+/*! \file mln/value/viter.hh
+ *
+ * \brief Definition of iterators on value sets.
+ */
+
+# include <mln/core/concept/viter.hh>
+
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /*! \brief FIXME: Forward iterator on a set of values.
+ *
+ * The parameter \c S is the type of value set.
+ */
+ template <typename S>
+ struct fwd_viter_ : public Viter< fwd_viter_<S> >
+ {
+ /// Value associated type.
+ typedef mln_value(S) value;
+
+ /// Constructor.
+ fwd_viter_(const Value_Set<S>& s);
+
+ /// Convertion into a value.
+ operator value() const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next value.
+ void next_();
+
+ private:
+
+ const S& s_;
+ std::size_t i_;
+ };
+
+
+
+
+ /*! \brief FIXME: Backward iterator on a set of values.
+ *
+ * The parameter \c S is the type of value set.
+ */
+ template <typename S>
+ struct bkd_viter_ : public Viter< bkd_viter_<S> >
+ {
+ /// Value associated type.
+ typedef mln_value(S) value;
+
+ /// Constructor.
+ bkd_viter_(const Value_Set<S>& s);
+
+ /// Convertion into a value.
+ operator value() const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next value.
+ void next_();
+
+ private:
+
+ const S& s_;
+ std::size_t i_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // fwd_viter_<S>
+
+ template <typename S>
+ fwd_viter_<S>::fwd_viter_(const Value_Set<S>& s)
+ : s_(exact(s))
+ {
+ invalidate();
+ }
+
+ template <typename S>
+ fwd_viter_<S>::operator typename fwd_viter_<S>::value () const
+ {
+ mln_precondition(is_valid());
+ return s_[i_];
+ }
+
+ template <typename S>
+ bool
+ fwd_viter_<S>::is_valid() const
+ {
+ return i_ < s_.nvalues();
+ }
+
+ template <typename S>
+ void
+ fwd_viter_<S>::invalidate()
+ {
+ i_ = s_.nvalues();
+ }
+
+ template <typename S>
+ void
+ fwd_viter_<S>::start()
+ {
+ i_ = 0;
+ }
+
+ template <typename S>
+ void
+ fwd_viter_<S>::next_()
+ {
+ ++i_;
+ }
+
+
+ // bkd_viter_<S>
+
+ template <typename S>
+ bkd_viter_<S>::bkd_viter_(const Value_Set<S>& s)
+ : s_(exact(s))
+ {
+ invalidate();
+ }
+
+ template <typename S>
+ bkd_viter_<S>::operator typename bkd_viter_<S>::value () const
+ {
+ mln_precondition(is_valid());
+ return s_[i_];
+ }
+
+ template <typename S>
+ bool
+ bkd_viter_<S>::is_valid() const
+ {
+ return i_ != s_.nvalues();
+ }
+
+ template <typename S>
+ void
+ bkd_viter_<S>::invalidate()
+ {
+ i_ = s_.nvalues();
+ }
+
+ template <typename S>
+ void
+ bkd_viter_<S>::start()
+ {
+ i_ = s_.nvalues() - 1;
+ }
+
+ template <typename S>
+ void
+ bkd_viter_<S>::next_()
+ {
+ if (i_ = 0)
+ {
+ invalidate();
+ return;
+ }
+ --i_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_VITER_HH
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 0)
+++ mln/value/int_u.hh (revision 0)
@@ -0,0 +1,130 @@
+// 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_U_HH
+# define MLN_VALUE_INT_U_HH
+
+/*! \file mln/value/int_u.hh
+ *
+ * \brief Define a generic class for unsigned integers.
+ */
+
+# include <mln/core/concept/value.hh>
+# include <mln/value/internal/value_like.hh>
+# include <mln/value/props.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ 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> >
+ {
+ protected:
+ typedef internal::value_like_< typename internal::encoding_<n>::ret,
+ int_u_<n> > super;
+
+ public:
+
+ /// Encoding associated type.
+ typedef typename super::enc enc;
+
+ /// Constructor without argument.
+ int_u_();
+
+ /// Constructor from an integer.
+ int_u_(int i);
+ };
+
+
+
+
+ template <unsigned n>
+ struct props< int_u_<n> > : public props< typename
internal::encoding_<n>::ret >
+ {
+ };
+
+
+ /// Alias for unsigned 8bit integers.
+ typedef value::int_u_<8> int_u8;
+
+
+ /*! \brief Print an int_u8 \p i into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] i An int_u8.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ std::ostream& operator<<(std::ostream& ostr, const int_u8& i);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n>
+ int_u_<n>::int_u_()
+ {
+ }
+
+ template <unsigned n>
+ 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)
+ {
+ return ostr << unsigned(i);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_U_HH
Index: mln/value/internal/value_like.hh
--- mln/value/internal/value_like.hh (revision 0)
+++ mln/value/internal/value_like.hh (revision 0)
@@ -0,0 +1,135 @@
+// 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_VALUE_LIKE_HH
+# define MLN_VALUE_INTERNAL_VALUE_LIKE_HH
+
+/*! \file mln/value/internal/value_like.hh
+ *
+ * \brief Factor code for value classes defined over another type.
+ *
+ * \internal
+ */
+
+# include <mln/core/concept/value.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ namespace internal
+ {
+
+ /*! \brief Base class for value classes defined over another
+ * type.
+ *
+ * \internal
+ *
+ * Parameters are \c V the equivalent value type and \c E the
+ * exact value type.
+ */
+ template <typename V, typename E>
+ struct value_like_ : public Value<E>
+ {
+ /// Encoding associated type.
+ typedef V enc;
+
+ /// Equivalent associated type.
+ typedef V equiv;
+
+ /// Convertion towards equivalent type.
+ operator V() const;
+
+ /// Assignment from equivalent type.
+ E& operator=(const V& v);
+
+ protected:
+ enc v_; /// The actual value.
+ };
+
+
+ /*! \brief General definition of the "equal to" operator between
+ * value-like types.
+ *
+ * \relates value_like_
+ */
+ template <typename V, typename E>
+ bool operator=(const value_like_<V,E>& lhs, const
value_like_<V,E>& rhs);
+
+
+ /*! \brief General definition of the "less than" operator
+ * between value-like types.
+ *
+ * \relates value_like_
+ */
+ template <typename V, typename E>
+ bool operator<(const value_like_<V,E>& lhs, const
value_like_<V,E>& rhs);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, typename E>
+ value_like_<V, E>::operator V() const
+ {
+ return v_;
+ }
+
+ template <typename V, typename E>
+ E&
+ value_like_<V, E>::operator=(const V& v)
+ {
+ v_ = v;
+ return exact(*this);
+ }
+
+ template <typename V, typename E>
+ bool operator=(const value_like_<V, E>& lhs,
+ const value_like_<V, E>& rhs)
+ {
+ return V(lhs) = V(rhs);
+ }
+
+ template <typename V, typename E>
+ bool operator<(const value_like_<V, E>& lhs,
+ const value_like_<V, E>& rhs)
+ {
+ return V(lhs) < V(rhs);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value::internal
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INTERNAL_VALUE_LIKE_HH