* mln/util/level.hh,
* tests/util/level.cc: New.
* tests/util/Makefile.am: New target.
---
milena/ChangeLog | 9 ++
milena/mln/util/level.hh | 128 ++++++++++++++++++++
milena/tests/util/Makefile.am | 4 +-
.../tests/{world/k1/is_1_face.cc => util/level.cc} | 21 ++--
4 files changed, 152 insertions(+), 10 deletions(-)
create mode 100644 milena/mln/util/level.hh
copy milena/tests/{world/k1/is_1_face.cc => util/level.cc} (80%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index d86373c..b223262 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,14 @@
2012-10-18 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Introduce level tag.
+
+ * mln/util/level.hh,
+ * tests/util/level.cc: New.
+
+ * tests/util/Makefile.am: New target.
+
+2012-10-18 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Fix accu::stat::median_interval.
* mln/accu/stat/median_interval.hh: Fix bugs and add support for
diff --git a/milena/mln/util/level.hh b/milena/mln/util/level.hh
new file mode 100644
index 0000000..ea7f3f3
--- /dev/null
+++ b/milena/mln/util/level.hh
@@ -0,0 +1,128 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_UTIL_LEVEL_HH
+# define MLN_UTIL_LEVEL_HH
+
+# include <mln/core/concept/value.hh>
+# include <mln/value/scalar.hh>
+
+/// \file
+///
+/// Definition of a level tag.
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ /// \brief Level tag structure.
+ template <typename T>
+ struct level_t
+ : public Object<level_t<T> >
+ {
+ const T& value;
+ explicit level_t(const T& value);
+ };
+
+ /// \brief construct a level tag.
+ template <typename T>
+ level_t<T> level(const T& value);
+
+
+ // Comparison Operators
+
+ template <typename T, typename U>
+ bool
+ operator<(const Object<T>& i, const level_t<U>& v);
+
+ template <typename T, typename U>
+ bool
+ operator<(const level_t<U>& v, const Object<T>& i);
+
+ template <typename T, typename U>
+ bool
+ operator==(const Object<T>& i, const level_t<U>& v);
+
+ template <typename T, typename U>
+ bool
+ operator==(const level_t<U>& v, const Object<T>& i);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ level_t<T>::level_t(const T& value)
+ : value(value)
+ {
+ }
+
+ template <typename T>
+ inline
+ level_t<T> level(const T& value)
+ {
+ return level_t<T>(value);
+ }
+
+ template <typename T, typename U>
+ inline
+ bool
+ operator<(const Object<T>& i, const level_t<U>& v)
+ {
+ return exact(i) < v.value;
+ }
+
+ template <typename T, typename U>
+ inline
+ bool
+ operator<(const level_t<U>& v, const Object<T>& i)
+ {
+ return v.value < exact(i);
+ }
+
+ template <typename T, typename U>
+ inline
+ bool
+ operator==(const Object<T>& i, const level_t<U>& v)
+ {
+ return exact(i) == v.value;
+ }
+
+ template <typename T, typename U>
+ inline
+ bool
+ operator==(const level_t<U>& v, const Object<T>& i)
+ {
+ return v.value == exact(i);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::util
+
+} // end of namespace mln
+
+#endif // ! MLN_UTIL_LEVEL_HH
diff --git a/milena/tests/util/Makefile.am b/milena/tests/util/Makefile.am
index 0a1119e..5bf503f 100644
--- a/milena/tests/util/Makefile.am
+++ b/milena/tests/util/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+# Copyright (C) 2007, 2008, 2009, 2012 EPITA Research and Development
# Laboratory (LRDE).
#
# This file is part of Olena.
@@ -27,6 +27,7 @@ check_PROGRAMS = \
graph \
lazy_set \
lemmings \
+ level \
line_graph \
ord \
ord_pair \
@@ -44,6 +45,7 @@ fibonacci_heap_SOURCES = fibonacci_heap.cc
graph_SOURCES = graph.cc
lazy_set_SOURCES = lazy_set.cc
lemmings_SOURCES = lemmings.cc
+level_SOURCES = level.cc
line_graph_SOURCES = line_graph.cc
ord_SOURCES = ord.cc
ord_pair_SOURCES = ord_pair.cc
diff --git a/milena/tests/world/k1/is_1_face.cc b/milena/tests/util/level.cc
similarity index 80%
copy from milena/tests/world/k1/is_1_face.cc
copy to milena/tests/util/level.cc
index bd50f84..3f0c8bf 100644
--- a/milena/tests/world/k1/is_1_face.cc
+++ b/milena/tests/util/level.cc
@@ -23,17 +23,20 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-/// \file
+#include <mln/util/level.hh>
+#include <mln/value/int_u8.hh>
-#include <mln/core/alias/point2d.hh>
-#include <mln/world/k1/is_1_face.hh>
-
-int main()
+int main ()
{
using namespace mln;
- mln_assertion(!world::k1::is_1_face(point2d(-1, -1)));
- mln_assertion(world::k1::is_1_face(point2d(-1, 0)));
- mln_assertion(world::k1::is_1_face(point2d(0, -1)));
- mln_assertion(!world::k1::is_1_face(point2d(0, 0)));
+ util::level_t<int> l(3);
+ mln_assertion(2 < l);
+ mln_assertion(l > 2);
+ mln_assertion(l == 3);
+
+ value::int_u8 v = 4;
+ mln_assertion(!(v < l));
+ mln_assertion(v > l);
+ mln_assertion(!(v == l));
}
--
1.7.2.5