Index: integre/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* ntg/utils/cast.hh: Fix comparison casts.
Index: olena/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* oln/arith/internal/opdecls.hh: Add missing default functors.
* oln/level/cc.hh: Use default arithmetic functor.
* oln/convert/cast.hh: New.
* oln/convert/basics.hh: Include it.
Index: olena/oln/arith/internal/opdecls.hh
--- olena/oln/arith/internal/opdecls.hh Wed, 08 Oct 2003 23:36:51 +0200 burrus_n (oln/b/22_opdecls.hh 1.14 640)
+++ olena/oln/arith/internal/opdecls.hh Fri, 07 Nov 2003 17:26:19 +0100 burrus_n (oln/b/22_opdecls.hh 1.15 640)
@@ -63,7 +63,12 @@
{ \
return OPCODE; \
} \
- } /* no ; */
+ }; \
+ \
+ template <class T1, class T2 = T1> \
+ struct default_f_##OPNAME \
+ : public f_##OPNAME< T1, T2, ntg_return_type(OPNAME, T1, T2) > \
+ {} /* no ; */
// Functor used by operations between an image and a constant
Index: olena/oln/convert/basics.hh
--- olena/oln/convert/basics.hh Thu, 31 Jul 2003 15:42:27 +0200 reda (oln/23_basics.hh 1.5 640)
+++ olena/oln/convert/basics.hh Fri, 07 Nov 2003 17:26:19 +0100 burrus_n (oln/23_basics.hh 1.6 640)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002 EPITA Research and Development Laboratory
+// Copyright (C) 2001, 2002, 2003 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
@@ -30,6 +30,7 @@
# include <oln/convert/abstract/conversion.hh>
# include <oln/convert/conversion.hh>
+# include <oln/convert/cast.hh>
# include <oln/convert/force.hh>
# include <oln/convert/bound.hh>
# include <oln/convert/stretch.hh>
Index: olena/oln/convert/force.hh
--- olena/oln/convert/force.hh Thu, 07 Aug 2003 02:08:21 +0200 david (oln/20_force.hh 1.11 640)
+++ olena/oln/convert/force.hh Fri, 07 Nov 2003 17:26:19 +0100 burrus_n (oln/20_force.hh 1.12 640)
@@ -35,8 +35,6 @@
namespace oln {
namespace convert {
- // FIXME: is this really useful with new types ?
-
/* Like cast::force, but as a conversion functor. */
template<class Output, class Exact = mlc::final>
struct force : public abstract::conversion_to_type< Output, typename mlc::exact_vt<force<Output, Exact>, Exact>::ret >
Index: olena/oln/level/cc.hh
--- olena/oln/level/cc.hh Thu, 07 Aug 2003 02:37:23 +0200 burrus_n (oln/e/20_cc.hh 1.11.1.8 640)
+++ olena/oln/level/cc.hh Fri, 07 Nov 2003 17:26:19 +0100 burrus_n (oln/e/20_cc.hh 1.11.1.9 640)
@@ -163,7 +163,7 @@
template <class I>
oln_value_type(I) get_n_cc(const abstract::image<I>& input)
{
- return fold(arith::f_max<oln_value_type(I)>(), input);
+ return fold(arith::default_f_max<oln_value_type(I)>(), input);
}
} // end of namespace level
Index: integre/ntg/utils/cast.hh
--- integre/ntg/utils/cast.hh Tue, 05 Aug 2003 21:39:33 +0200 burrus_n (oln/i/26_cast.hh 1.3.1.9 640)
+++ integre/ntg/utils/cast.hh Fri, 07 Nov 2003 17:26:19 +0100 burrus_n (oln/i/26_cast.hh 1.3.1.10 640)
@@ -88,10 +88,10 @@
bound(const Tsrc& val)
{
if (ntg_max_val(Tsrc) > ntg_max_val(Tdest))
- if (val > Tsrc(ntg_max_val(Tdest)))
+ if (val > Tsrc(Tdest(ntg_max_val(Tdest))))
return ntg_max_val(Tdest);
if (ntg_min_val(Tsrc) < ntg_min_val(Tdest))
- if (val < Tsrc(ntg_min_val(Tdest)))
+ if (val < Tsrc(Tdest(ntg_min_val(Tdest))))
return ntg_min_val(Tdest);
return val;
}
@@ -220,9 +220,9 @@
template<class Tdest, class Tsrc> inline
const Tdest rbound(const Tsrc& val)
{
- if (val > ntg_cast(ntg_max_val(Tdest)))
+ if (val > Tsrc(Tdest(ntg_max_val(Tdest))))
return ntg_max_val(Tdest);
- if (val < ntg_cast(ntg_min_val(Tdest)))
+ if (val < Tsrc(Tdest(ntg_min_val(Tdest))))
return ntg_min_val(Tdest);
return cast::round<Tdest>(val);
}
Index: olena/oln/convert/cast.hh
--- olena/oln/convert/cast.hh Fri, 07 Nov 2003 17:38:17 +0100 burrus_n ()
+++ olena/oln/convert/cast.hh Fri, 07 Nov 2003 17:26:19 +0100 burrus_n (oln/v/35_cast.hh 1.1 600)
@@ -0,0 +1,61 @@
+// Copyright (C) 2001, 2002, 2003 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, 59 Temple Place - Suite 330, 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 OLENA_CONVERT_CAST_HH
+# define OLENA_CONVERT_CAST_HH
+
+# include <oln/convert/abstract/conversion.hh>
+# include <ntg/utils/cast.hh>
+
+namespace oln {
+ namespace convert {
+
+ template<class Output, class Exact = mlc::final>
+ struct cast : public abstract::conversion_to_type< Output, typename mlc::exact_vt<cast<Output, Exact>, Exact>::ret >
+ {
+ template< class Input >
+ Output
+ doit(const Input& v) const
+ {
+ return v;
+ }
+
+ static std::string
+ name()
+ {
+ // FIXME: ntg_name(Exact) will not work for mlc::final !
+ return std::string("cast<")
+ + ntg_name(Output) + ", "
+ + "FIXME: ntg_name(Exact)" + ">";
+ }
+
+ };
+
+ } // convert
+} // oln
+
+#endif // OLENA_CONVERT_CAST_HH
Ca marche plutôt bien, on l'enlèvera si ca pose pb ...
Index: metalic/ChangeLog
from Nicolas Burrus <burrus_n(a)lrde.epita.fr>
* mlc/type.hh (any_with_diamond): Use the static offset technique.
Index: metalic/mlc/type.hh
--- metalic/mlc/type.hh Mon, 01 Sep 2003 20:12:38 +0200 burrus_n (oln/c/21_type.hh 1.26 640)
+++ metalic/mlc/type.hh Fri, 07 Nov 2003 17:19:10 +0100 burrus_n (oln/c/21_type.hh 1.27 640)
@@ -34,6 +34,8 @@
# include <string>
# include <cassert>
+// FIXME: make a hierarchy of any with the different implementations
+
// any and any_with_diamond types are not defined in namespace mlc to
// avoid namespace clashes. Indeed, a type inheriting from another in
// a namespace foo will have implicit access to the foo namespace.
@@ -53,12 +55,10 @@
E& exact()
{
- assert(offset_assigned);
return *(E*)((char*)this - exact_offset);
}
const E& exact() const
{
- assert(offset_assigned);
return *(const E*)((const char*)this - exact_offset);
}
@@ -67,25 +67,30 @@
return std::string("any_with_diamond<") + E::name() + ">";
}
- public:
+ private:
// This stores the actual value of the offset between the this
- // pointer and the this pointer of the exact type. This enables
- // diamond hierarchies, as static_cast cannot perform it and
- // reinterpret_cast or (Exact*)(void*) cast are unsafe and
- // compiler dependent. These members should be initialized by
- // every concrete classes, using the mlc_init_static_hierarchy
- // macro.
- static int exact_offset;
- // This Boolean determines if the exact_offset value has already
- // been affected.
- static bool offset_assigned;
+ // pointer and the address of the exact type. This enables diamond
+ // shaped hierarchies (static_cast can't and reinterpret_cast or
+ // (Exact*)(void*) cast are unsafe and compiler dependent).
+ static const int exact_offset;
+
+ // Utility members used to determine the exact_offset
+ static const E exact_obj;
+ static const any_with_diamond<E>& ref_exact_obj;
};
template <class E>
- int any_with_diamond<E>::exact_offset = 0;
+ const E any_with_diamond<E>::exact_obj = E();
+
+ template <class E>
+ const any_with_diamond<E>&
+ any_with_diamond<E>::ref_exact_obj = any_with_diamond<E>::exact_obj;
template <class E>
- bool any_with_diamond<E>::offset_assigned = false;
+ const int any_with_diamond<E>::exact_offset =
+ (const char*)(void*)(&any_with_diamond<E>::ref_exact_obj)
+ - (const char*)(void*)(&any_with_diamond<E>::exact_obj);
+
// Warning, this class does not allow diamond hierarchies, consider
// any_with_diamond if you really need it.
@@ -284,7 +289,14 @@
| mlc_init_static_hierarchy |
`--------------------------*/
-# define mlc_init_static_hierarchy(Exact) \
-mlc::assign_exact_offset<Exact, mlc::final>::doit(this)
+// # define mlc_init_static_hierarchy(Exact)
+// mlc::assign_exact_offset<Exact, mlc::final>::doit(this)
+
+// FIXME: this is for backward compatibility purposes only. This
+// macro is called in every constructor of the classes, so we let them
+// in place for the moment until we are sure that the static offset
+// method works fine.
+
+# define mlc_init_static_hierarchy(Exact)
#endif // ! METALIC_TYPE_HH