https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Fix value concepts and related file inclusions.
* tests/value_scalar.cc: New.
* tests/value_gray.cc: Rename as...
* tests/value_graylevel.cc: ...this.
(assert): Change to...
(mln_assertion): ...this!
* tests/trait_op_plus.cc,
* mln/metal/mat.hh,
* mln/metal/vec.hh: Include value concepts.
* mln/trait/image/print.hh: (print). New overload.
* mln/trait/op: New directory; to be populated.
* mln/core/ops.hh: Remove dead code.
* mln/value/graylevel.hh: Layout.
* mln/value/scalar.hh: New.
* mln/value/builtin.hh: Replace includes by decls.
* mln/value/concept/symbolic.hh,
* mln/value/concept/floating.hh,
* mln/value/concept/integer.hh,
* mln/value/concept/structured.hh,
* mln/value/concept/scalar.hh,
* mln/value/concept/vectorial.hh: Fix.
* mln/value/concept/all.hh: New.
mln/core/ops.hh | 13 +++
mln/metal/mat.hh | 1
mln/metal/vec.hh | 1
mln/trait/image/print.hh | 9 ++
mln/value/builtin.hh | 14 +--
mln/value/concept/all.hh | 43 +++++++++++
mln/value/concept/floating.hh | 21 +++--
mln/value/concept/integer.hh | 22 ++++--
mln/value/concept/scalar.hh | 18 +++--
mln/value/concept/structured.hh | 23 ++++--
mln/value/concept/symbolic.hh | 21 ++++-
mln/value/concept/vectorial.hh | 21 ++++-
mln/value/graylevel.hh | 3
mln/value/scalar.hh | 144 ++++++++++++++++++++++++++++++++++++++++
tests/trait_op_plus.cc | 1
tests/value_graylevel.cc | 16 +++-
tests/value_scalar.cc | 51 ++++++++++++++
17 files changed, 372 insertions(+), 50 deletions(-)
Index: tests/value_scalar.cc
--- tests/value_scalar.cc (revision 0)
+++ tests/value_scalar.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/value_scalar.cc
+ *
+ * \brief Tests on mln::value::scalar.
+ */
+
+#include <iostream>
+#include <mln/value/scalar.hh>
+
+
+template <typename T>
+void foo(const T& t)
+{
+ std::cout << mln::value::scalar(t) << std::endl;
+}
+
+
+int main()
+{
+ using namespace mln;
+
+ int i = 51;
+ foo(i);
+ foo( value::scalar(i) );
+}
Index: tests/trait_op_plus.cc
--- tests/trait_op_plus.cc (revision 1267)
+++ tests/trait_op_plus.cc (working copy)
@@ -31,6 +31,7 @@
*/
#include <mln/core/concept/image.hh>
+#include <mln/value/concept/all.hh>
#include <mln/trait/op_plus.hh>
Index: tests/value_graylevel.cc
--- tests/value_graylevel.cc (revision 1264)
+++ tests/value_graylevel.cc (working copy)
@@ -25,22 +25,30 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+/*! \file tests/value_graylevel.cc
+ *
+ * \brief Tests on mln::value::graylevel.
+ */
+
#include <mln/value/graylevel.hh>
+
int main()
{
using namespace mln::value;
gl8 a = white;
gl16 b = white;
- assert((a = b) = true);
+ mln_assertion(a = b);
+
gl8 c = (a + b) / 2;
- assert(c = white);
+ mln_assertion(c = white);
+
c = a;
- assert(c = white);
+ mln_assertion(c = white);
c = (a * 2) / 2;
- assert(c = white);
+ mln_assertion(c = white);
c = c / 6;
}
Index: mln/trait/image/print.hh
--- mln/trait/image/print.hh (revision 1267)
+++ mln/trait/image/print.hh (working copy)
@@ -55,6 +55,9 @@
template <typename I>
void print(std::ostream& ostr);
+ template <typename I>
+ void print(const Image<I>& ima, std::ostream& ostr);
+
# ifndef MLN_INCLUDE_ONLY
@@ -78,6 +81,12 @@
<< typename the::speed() .name() << " }" <<
std::endl;
}
+ template <typename I>
+ void print(const Image<I>&, std::ostream& ostr)
+ {
+ print<I>(ostr);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::trait::image
Index: mln/core/ops.hh
--- mln/core/ops.hh (revision 1267)
+++ mln/core/ops.hh (working copy)
@@ -99,6 +99,18 @@
// Operator +.
+ // FIXME HERE
+
+// namespace trait {
+
+// template < typename L, typename R >
+// struct set_binary_< op_plus, Built_In, L, Object, R >
+// {
+// typedef mln_trait_op_plus(R, L)
+// };
+
+// }
+
// FIXME: Doc!
template <typename O>
mln_trait_op_plus(O, int)
@@ -123,6 +135,7 @@
return exact(rhs) + lhs;
}
+
// Operator *.
// FIXME: Doc!
Index: mln/metal/mat.hh
--- mln/metal/mat.hh (revision 1267)
+++ mln/metal/mat.hh (working copy)
@@ -34,6 +34,7 @@
# include <mln/core/contract.hh>
# include <mln/trait/all.hh>
# include <mln/value/props.hh>
+# include <mln/value/concept/all.hh>
// FIXME: Document.
Index: mln/metal/vec.hh
--- mln/metal/vec.hh (revision 1267)
+++ mln/metal/vec.hh (working copy)
@@ -36,6 +36,7 @@
# include <mln/value/props.hh>
# include <mln/fun/i2v/all.hh>
# include <mln/literal/zero.hh>
+# include <mln/value/concept/all.hh>
// FIXME: Document.
Index: mln/value/graylevel.hh
--- mln/value/graylevel.hh (revision 1267)
+++ mln/value/graylevel.hh (working copy)
@@ -29,15 +29,18 @@
# define MLN_CORE_VALUE_GRAYLEVEL_HH
# include <iostream>
+
# include <mln/core/contract.hh>
# include <mln/metal/math.hh>
# include <mln/metal/bexpr.hh>
+
# include <mln/value/internal/value_like.hh>
# include <mln/value/concept/integer.hh>
# include <mln/value/internal/encoding.hh>
# include <mln/value/gray.hh>
# include <mln/value/props.hh>
+
namespace mln
{
Index: mln/value/scalar.hh
--- mln/value/scalar.hh (revision 0)
+++ mln/value/scalar.hh (revision 0)
@@ -0,0 +1,144 @@
+// Copyright (C) 2006, 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_SCALAR_HH
+# define MLN_VALUE_SCALAR_HH
+
+# include <mln/value/concept/scalar.hh>
+# include <mln/metal/is_a.hh>
+# include <mln/metal/if.hh>
+
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+ template <typename T>
+ class scalar_ : public Scalar< scalar_<T> >
+ {
+ public:
+
+ /// Encoding associated type.
+ typedef T enc; // FIXME
+
+ /// Equivalent associated type.
+ typedef T equiv; // FIXME
+
+
+ /// Ctor.
+ scalar_();
+
+ /// Ctor.
+ scalar_(const T& val);
+
+ /// Conversion.
+ operator T() const;
+
+ protected:
+ T val_; // FIXME: const&?
+ };
+
+
+ template <typename T>
+ class scalar_< scalar_<T> >; // Safety.
+
+
+
+ template <typename T>
+ std::ostream& operator<<(std::ostream& ostr, const
scalar_<T>& s);
+
+
+
+ namespace internal
+ {
+
+ template <typename T>
+ struct helper_scalar_
+ {
+ typedef mlc_is_a(T, Scalar) is_scalar_;
+ typedef mlc_if(is_scalar_, T, scalar_<T>) ret;
+ };
+
+ } // end of namespace mln::value::internal
+
+
+ // Routine.
+ template <typename T>
+ typename internal::helper_scalar_<T>::ret
+ scalar(const T& s); // FIXME: if T already is a scalar_...
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // scalar_<T>.
+
+ template <typename T>
+ scalar_<T>::scalar_()
+ {
+ }
+
+ template <typename T>
+ scalar_<T>::scalar_(const T& val)
+ : val_(val)
+ {
+ }
+
+ template <typename T>
+ scalar_<T>::operator T() const
+ {
+ return val_;
+ }
+
+ // Operator.
+
+ template <typename T>
+ std::ostream& operator<<(std::ostream& ostr, const
scalar_<T>& s)
+ {
+ return ostr << T(s);
+ }
+
+ // Routine.
+
+ template <typename T>
+ typename internal::helper_scalar_<T>::ret
+ scalar(const T& s)
+ {
+ return s;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_SCALAR_HH
Index: mln/value/builtin.hh
--- mln/value/builtin.hh (revision 1267)
+++ mln/value/builtin.hh (working copy)
@@ -32,16 +32,19 @@
* \brief Some definitions about builtins.
*/
-# include <mln/value/concept/symbolic.hh>
-# include <mln/value/concept/integer.hh>
-# include <mln/value/concept/floating.hh>
+# include <mln/core/category.hh>
+
namespace mln
{
// Fwd decl.
template <typename E> struct Value;
-
+ namespace value {
+ template <typename E> struct Symbolic;
+ template <typename E> struct Integer;
+ template <typename E> struct Floating;
+ }
// The case of built-in types.
@@ -68,7 +71,4 @@
} // end of namespace mln
-# include <mln/core/concept/value.hh>
-
-
#endif // ! MLN_VALUE_BUILTIN_HH
Index: mln/value/concept/symbolic.hh
--- mln/value/concept/symbolic.hh (revision 1267)
+++ mln/value/concept/symbolic.hh (working copy)
@@ -25,19 +25,26 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_VALUE_CONCEPT_VALUE_SYMBOLIC_HH
-# define MLN_VALUE_CONCEPT_VALUE_SYMBOLIC_HH
+#ifndef MLN_VALUE_CONCEPT_SYMBOLIC_HH
+# define MLN_VALUE_CONCEPT_SYMBOLIC_HH
-/*! \file mln/value/symbolic.hh
+/*! \file mln/value/concept/symbolic.hh
*
* \brief Define a generic class for symbolic values.
*/
+# include <mln/core/concept/value.hh>
+
+
namespace mln
{
- // Fwd decl.
+ // Fwd decls.
template <typename E> struct Value;
+ namespace value
+ {
+ template <typename E> struct Symbolic;
+ }
namespace trait
{
@@ -68,6 +75,8 @@
} // end of namespace mln
-# include <mln/core/concept/value.hh>
-#endif // ! MLN_VALUE_CONCEPT_VALUE_SYMBOLIC_HH
+# include <mln/value/concept/all.hh>
+
+
+#endif // ! MLN_VALUE_CONCEPT_SYMBOLIC_HH
Index: mln/value/concept/floating.hh
--- mln/value/concept/floating.hh (revision 1267)
+++ mln/value/concept/floating.hh (working copy)
@@ -25,19 +25,26 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_VALUE_CONCEPT_VALUE_FLOATING_HH
-# define MLN_VALUE_CONCEPT_VALUE_FLOATING_HH
+#ifndef MLN_VALUE_CONCEPT_FLOATING_HH
+# define MLN_VALUE_CONCEPT_FLOATING_HH
-/*! \file mln/value/floating.hh
+/*! \file mln/value/concept/floating.hh
*
* \brief Define a generic class for float values.
*/
# include <mln/value/concept/scalar.hh>
+
namespace mln
{
+ // Fwd decl.
+ namespace value
+ {
+ template <typename E> struct Floating;
+ }
+
namespace trait
{
// FIXME
@@ -46,9 +53,6 @@
namespace value
{
- // Fwd decl.
- template <typename E> struct Floating;
-
// Category flag type.
template <>
struct Floating<void>
@@ -66,4 +70,7 @@
} // end of namespace mln
-#endif // ! MLN_VALUE_CONCEPT_VALUE_FLOATING_HH
+# include <mln/value/concept/all.hh>
+
+
+#endif // ! MLN_VALUE_CONCEPT_FLOATING_HH
Index: mln/value/concept/structured.hh
--- mln/value/concept/structured.hh (revision 1267)
+++ mln/value/concept/structured.hh (working copy)
@@ -25,29 +25,36 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_VALUE_CONCEPT_VALUE_STRUCTURED_HH
-# define MLN_VALUE_CONCEPT_VALUE_STRUCTURED_HH
+#ifndef MLN_VALUE_CONCEPT_STRUCTURED_HH
+# define MLN_VALUE_CONCEPT_STRUCTURED_HH
-/*! \file mln/value/structured.hh
+/*! \file mln/value/concept/structured.hh
*
* \brief Define a generic class for structured values.
*/
+# include <mln/core/concept/value.hh>
+
+
namespace mln
{
// Fwd decl.
- template <typename E> struct Value;
+ namespace value
+ {
+ template <typename E> struct Structured;
+ }
+
namespace trait
{
// FIXME
} // end of namespace mln::trait
+
namespace value
{
-
// Fwd decl.
template <typename E> struct Structured;
@@ -67,6 +74,8 @@
} // end of namespace mln
-# include <mln/core/concept/value.hh>
-#endif // ! MLN_VALUE_CONCEPT_VALUE_STRUCTURED_HH
+# include <mln/value/concept/all.hh>
+
+
+#endif // ! MLN_VALUE_CONCEPT_STRUCTURED_HH
Index: mln/value/concept/scalar.hh
--- mln/value/concept/scalar.hh (revision 1267)
+++ mln/value/concept/scalar.hh (working copy)
@@ -25,19 +25,26 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_VALUE_CONCEPT_VALUE_SCALAR_HH
-# define MLN_VALUE_CONCEPT_VALUE_SCALAR_HH
+#ifndef MLN_VALUE_CONCEPT_SCALAR_HH
+# define MLN_VALUE_CONCEPT_SCALAR_HH
-/*! \file mln/value/scalar.hh
+/*! \file mln/value/concept/scalar.hh
*
* \brief Define a generic class for scalar values.
*/
+# include <mln/core/concept/value.hh>
+
+
namespace mln
{
- // Fwd decl.
+ // Fwd decls.
template <typename E> struct Value;
+ namespace value
+ {
+ template <typename E> struct Scalar;
+ }
namespace trait
{
@@ -66,6 +73,5 @@
} // end of namespace mln
-# include <mln/core/concept/value.hh>
-#endif // ! MLN_VALUE_CONCEPT_VALUE_SCALAR_HH
+#endif // ! MLN_VALUE_CONCEPT_SCALAR_HH
Index: mln/value/concept/vectorial.hh
--- mln/value/concept/vectorial.hh (revision 1267)
+++ mln/value/concept/vectorial.hh (working copy)
@@ -25,19 +25,25 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_VALUE_CONCEPT_VALUE_VECTORIEL_HH
-# define MLN_VALUE_CONCEPT_VALUE_VECTORIEL_HH
+#ifndef MLN_VALUE_CONCEPT_VECTORIAL_HH
+# define MLN_VALUE_CONCEPT_VECTORIAL_HH
-/*! \file mln/value/vectorial.hh
+/*! \file mln/value/concept/vectorial.hh
*
* \brief Define a generic class for vectorial values.
*/
+# include <mln/core/concept/value.hh>
+
+
namespace mln
{
// Fwd decl.
- template <typename E> struct Value;
+ namespace value
+ {
+ template <typename E> struct Vectorial;
+ }
namespace trait
{
@@ -46,6 +52,7 @@
} // end of namespace mln::trait
+
namespace value
{
@@ -68,6 +75,8 @@
} // end of namespace mln
-# include <mln/core/concept/value.hh>
-#endif // ! MLN_VALUE_CONCEPT_VALUE_VECTORIEL_HH
+# include <mln/value/concept/all.hh>
+
+
+#endif // ! MLN_VALUE_CONCEPT_VECTORIAL_HH
Index: mln/value/concept/all.hh
--- mln/value/concept/all.hh (revision 0)
+++ mln/value/concept/all.hh (revision 0)
@@ -0,0 +1,43 @@
+// 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_CONCEPT_ALL_HH
+# define MLN_VALUE_CONCEPT_ALL_HH
+
+/*! \file mln/value/concept/all.hh
+ *
+ * \brief FIXME
+ */
+
+# include <mln/value/concept/integer.hh>
+# include <mln/value/concept/floating.hh>
+# include <mln/value/concept/vectorial.hh>
+# include <mln/value/concept/structured.hh>
+# include <mln/value/concept/symbolic.hh>
+
+
+#endif // ! MLN_VALUE_CONCEPT_ALL_HH
Index: mln/value/concept/integer.hh
--- mln/value/concept/integer.hh (revision 1267)
+++ mln/value/concept/integer.hh (working copy)
@@ -25,18 +25,26 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_VALUE_CONCEPT_VALUE_INTEGER_HH
-# define MLN_VALUE_CONCEPT_VALUE_INTEGER_HH
+#ifndef MLN_VALUE_CONCEPT_INTEGER_HH
+# define MLN_VALUE_CONCEPT_INTEGER_HH
-/*! \file mln/value/integer.hh
+/*! \file mln/value/concept/integer.hh
*
* \brief Define a generic class for integer values.
*/
# include <mln/value/concept/scalar.hh>
+
namespace mln
{
+
+ // Fwd decl.
+ namespace value
+ {
+ template <typename E> struct Integer;
+ }
+
namespace trait
{
// FIXME
@@ -45,9 +53,6 @@
namespace value
{
- // Fwd decl.
- template <typename E> struct Integer;
-
// Category flag type.
template <>
struct Integer<void>
@@ -65,4 +70,7 @@
} // end of namespace mln
-#endif // ! MLN_VALUE_CONCEPT_VALUE_INTEGER_HH
+# include <mln/value/concept/all.hh>
+
+
+#endif // ! MLN_VALUE_CONCEPT_INTEGER_HH