Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
(This message was sent to the olena-patches list but did not appear in
the lrde.olena.patches newsgroup, so I'm posting it again. Sorry for
the duplicate message in olena-patches.)
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add tests for mlc_is_a, mlc_if and mlc_typedef.
* tests/is_a.cc, tests/if.cc, tests/typedef.cc: New tests.
if.cc | 17 +++++++++++++++++
is_a.cc | 14 ++++++++++++++
typedef.cc | 17 +++++++++++++++++
3 files changed, 48 insertions(+)
Index: tests/is_a.cc
--- tests/is_a.cc (revision 0)
+++ tests/is_a.cc (revision 0)
@@ -0,0 +1,14 @@
+#include <mlc/is_a.hh>
+
+struct A {};
+struct B : public A {};
+
+template <class T> struct C {};
+template <class T> struct D : public C<T> {};
+
+int
+main ()
+{
+ mlc_is_a_(B, A)::ensure();
+ mlc_is_a_(D<int>, C<int>)::ensure();
+}
Index: tests/if.cc
--- tests/if.cc (revision 0)
+++ tests/if.cc (revision 0)
@@ -0,0 +1,17 @@
+#include <mlc/if.hh>
+#include <mlc/cmp.hh>
+
+struct alpha;
+struct beta;
+struct gamma;
+struct delta;
+
+int
+main()
+{
+ typedef mlc_if_(mlc::true_, alpha, beta) x;
+ mlc_eq(x, alpha)::ensure();
+
+ typedef mlc_if_(mlc::false_, gamma, delta) y;
+ mlc_eq(y, delta)::ensure();
+}
Index: tests/typedef.cc
--- tests/typedef.cc (revision 0)
+++ tests/typedef.cc (revision 0)
@@ -0,0 +1,17 @@
+#include <mlc/typedef.hh>
+#include <mlc/cmp.hh>
+
+struct foo
+{
+ typedef int good_type;
+};
+
+mlc_decl_typedef(good_type);
+mlc_decl_typedef(bad_type);
+
+int
+main ()
+{
+ mlc_eq(mlc_typedef_(foo, good_type), foo::good_type)::ensure();
+ mlc_eq(mlc_typedef_(foo, bad_type), mlc::not_found)::ensure();
+}
1
0
(This message was sent to the olena-patches list but did not appear in
the lrde.olena.patches newsgroup, so I'm posting it again. Sorry for
the duplicate message in olena-patches.)
https://svn.lrde.epita.fr/svn/oln/trunk
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add TODO.
* TODO: New.
TODO | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
Index: TODO
--- TODO (revision 0)
+++ TODO (revision 0)
@@ -0,0 +1,27 @@
+See also the TODO in oln-proto-1.0 and oln-proto-stl-style
+
+* Metalic
+
+** Modules
+Split Metalic into several modules:
+
+ mlc : core Metalic tools
+ stc : static inheritance
+ xtd : meta-functions and operator traits (for built-in types)
+ dyn : static-dynamic bridge (work of Damien Thivolle and Nicolas
+ Pouillard)
+
+** Static inheritance
+
+*** mlc/properties -- Roland
+
+
+* Olena
+
+
+* Integre
+
+
+Local Variables:
+mode: outline
+End:
1
0
(This message was sent to the olena-patches list but did not appear in
the lrde.olena.patches newsgroup, so I'm posting it again. Sorry for
the duplicate message in olena-patches.)
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add some documentation and types to Metalic.
* mlc/cmp.hh: More documentation.
(is_found, is_not_found, is_ok): New.
* mlc/implies.hh, mlc/is_a.hh: Fix Doxygen comment.
* mlc/flags.hh: More documentation.
(dummy, locked): New.
From Thierry Géraud.
* mlc/value.hh: Remove dead code.
cmp.hh | 35 ++++++++++++--
flags.hh | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++----------
implies.hh | 4 -
is_a.hh | 4 -
value.hh | 19 -------
5 files changed, 162 insertions(+), 49 deletions(-)
Index: mlc/implies.hh
--- mlc/implies.hh (revision 398)
+++ mlc/implies.hh (working copy)
@@ -31,9 +31,9 @@
# include <mlc/bool.hh>
-/*! \macro mlc_implies(Left_BExpr, Right_BExpr)
+/*! \def mlc_implies(Left_BExpr, Right_BExpr)
**
-** Macro correponding to mlc::implies_<L, R>, for use in a template
+** Macro corresponding to mlc::implies_<L, R>, for use in a template
** context.
**
** \see mlc::implies_<L, R>
Index: mlc/is_a.hh
--- mlc/is_a.hh (revision 398)
+++ mlc/is_a.hh (working copy)
@@ -205,7 +205,7 @@
-/*! \macro mlc_is_a(T, U)
+/*! \def mlc_is_a(T, U)
**
** Macro that answers if T is an U. T should be a type and U can have
** different forms: class, template class, etc. The result is a
@@ -240,7 +240,7 @@
mlc::wrap_<typename mlc::internal::is_a<sizeof(mlc::form::of<U >())>::ret<T,U > >
-/*! \macro mlc_is_a_(T, U)
+/*! \def mlc_is_a_(T, U)
**
** Macro equivalent as mlc_is_a(T, U) for use in a non templated
** context. The result is a Boolean expression type.
Index: mlc/flags.hh
--- mlc/flags.hh (revision 398)
+++ mlc/flags.hh (working copy)
@@ -38,9 +38,15 @@
/*! \class mlc::abstract::flag
**
- ** Abstract base class for types that are only flags.
+ ** Abstract base class for types that are flags. A flag type
+ ** expresses a particular property translated by the name of the
+ ** type. For instance, mlc::undefined is a flag type which
+ ** means "declared but not defined".
**
- ** Example: mlc::undefined is a mlc::abstract::flag.
+ ** Flag types have no interface; they only serve as types.
+ **
+ ** The flags provided in mlc are: dummy, locked, none, not_found,
+ ** undefined, and unknown.
*/
struct flag : public type {};
@@ -48,37 +54,91 @@
} // end of namespace mlc::abstract
- /*! \class mlc::undefined
+ /*! \class mlc::dummy
**
- ** Flag class to state that a type is undefined, that is, declared
- ** but not defined.
+ ** Flag class to value a type when one knows that this value does
+ ** not matter and will not be used.
**
- ** Sample use: you want to define a trait to get the signed version
- ** of a type T. For that, you write:
+ ** The dummy type appears typically in some part of meta-program
+ ** that are ignored. In mlc_typedef_onlyif, for instance, dummy is
+ ** returned when the guard value is false. When defining a
+ ** pattern matching meta-program, if a clause is not a match, the
+ ** returned type for this clause is evaluated into dummy.
+ */
+ struct dummy : public abstract::flag {};
+
+
+ /*! \class mlc::locked
+ **
+ ** Flag class whose purpose is to state and ensure that a type
+ ** should not be re-defined (or specialized) by the client.
+ **
+ ** Let us consider a type that should not be re-defined or
+ ** specialized by the client. Such a type is defined having
+ ** mlc::locked as base class. Inserting the static check
+ ** mlc_is_a(type, locked) then ensures that this type is untouched.
+ **
+ ** Sample use: First a type (set_foo) is declared for the user to
+ ** specialize it:
+ **
+ ** template <typename T> struct set_foo;
+ **
+ ** and the access to this specialization (handled by the type
+ ** get_foo), for use in a meta-program, is written once for all.
+ ** The access code should not be re-defined by the client so it is
+ ** tagged as locked:
**
** template <typename T>
- ** struct signed_type_of
- ** {
- ** typedef mlc::undefined ret;
+ ** struct get_foo : public mlc::locked,
+ ** public set_foo<T> {
+ ** using set_foo<T>::ret;
** };
**
- ** which means that the return type (ret) is not defined by default.
- ** Put differently, this trait is just declared. So far, the
- ** type "signed_type_of<unsigned short>::ret" is "mlc::undefined".
- **
- ** Other flags are mlc::unknown, mlc::none, and mlc::not_found.
+ ** The meta-program that reads the value of get_foo<T>::ret also
+ ** checks that get_foo<T> derives from mlc::locked. That thus
+ ** ensures that the client has not confuse set_foo with get_foo.
*/
- struct undefined : public abstract::flag {};
+ struct locked : public abstract::flag {};
- struct unknown : public abstract::flag {};
+ /*! \class mlc::none
+ **
+ ** Flag class to state that there is no type corresponding to a
+ ** request.
+ **
+ ** Sample use 1: In the context of a variadic parameter list, none
+ ** is the default value for every parameter after the first one.
+ **
+ ** With:
+ ** template <typename P1,
+ ** typename P2 = none,
+ ** typename P3 = none>
+ ** struct foo {
+ ** typedef P1 param1;
+ ** typedef P2 param2;
+ ** typedef P3 param3;
+ ** };
+ **
+ ** instantiated into foo<int, float>, we thus have param3 set to
+ ** none.
+ **
+ ** Sample use 2: The type none can be used as a trait value. For
+ ** instance:
+ **
+ ** template<>
+ ** struct super_type_of <int> {
+ ** typedef none ret;
+ ** };
+ */
struct none : public abstract::flag {};
/*! \class mlc::not_found
**
- ** Flag class to state that a type is not found (for use in the
- ** context of trying to retrieve a type).
+ ** Flag class to state that a type is not found. This class is for
+ ** use in the context of trying to retrieve a type. More precisely,
+ ** this flag type should only appear as a return of a piece of
+ ** meta-program.
**
** Design issue: this flag is used in some meta-code to handle the
** case of an "absent" typedef. For instance it is used in the
@@ -86,14 +146,59 @@
** mlc_typedef(std::vector<int>, value_type) is int, whereas
** mlc_typedef(std::vector<int>, walue_type) is mlc::not_found.
**
- ** Other flags are mlc::undefined, mlc::unknown, and mlc::none.
- **
** \see mlc_typedef
*/
struct not_found : public abstract::flag {};
- // FIXME: add corresponding is_* types
+ /*! \class mlc::undefined
+ **
+ ** Flag class to state that a type is undefined, that is, declared
+ ** but not defined.
+ **
+ ** Sample use: When you want to define a trait to get the signed
+ ** version of a type T, you write:
+ **
+ ** template <typename T>
+ ** struct signed_type_of
+ ** {
+ ** typedef mlc::undefined ret;
+ ** };
+ **
+ ** meaning that the return type (ret) is not defined by default.
+ ** Put differently, this trait is just declared. So far, the trait
+ ** value signed_type_of<unsigned short>::ret is mlc::undefined. If
+ ** it happens that this trait value is not specialized in some
+ ** following code, this value thus remains mlc::undefined, which
+ ** clearly denotes an error.
+ **
+ ** \see mlc::abstract::flag.
+ */
+ struct undefined : public abstract::flag {};
+
+
+ /*! \class mlc::unknown
+ **
+ ** Flag class to state that a result is yet unknown.
+ **
+ ** Sample use: This flag can be used in a meta-program to express
+ ** that a sub-program fails to give the expected result. For
+ ** instance in:
+ **
+ ** template <class T>
+ ** struct foo {
+ ** typedef sub_program_1 ret1;
+ ** typedef sub_program_2 ret2;
+ ** typedef typename if_< neq_<ret1, unknown>,
+ ** ret1,
+ ** ret2 >::ret ret;
+ ** };
+ */
+ struct unknown : public abstract::flag {};
+
+
+ // FIXME: Doc.
+ struct not_ok : public abstract::flag {};
} // end of namespace mlc
Index: mlc/value.hh
--- mlc/value.hh (revision 398)
+++ mlc/value.hh (working copy)
@@ -164,23 +164,4 @@
# include <mlc/bool.hh>
-// FIXME: the following code causes inclusion recursion...
-
-// # include <mlc/is_a.hh>
-
-// namespace mlc {
-
-// template <typename T>
-// struct is_value : public mlc_is_a(T, mlc::abstract::value)
-// {
-// };
-
-// template <typename T>
-// struct is_not_value : public not_<mlc_is_a(T, mlc::abstract::value)>
-// {
-// };
-
-// } // end of namespace mlc
-
-
#endif // ! METALIC_VALUE_HH
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 398)
+++ mlc/cmp.hh (working copy)
@@ -39,13 +39,14 @@
namespace mlc
{
- // FIXME: code moved from the end of value.hh
+ /// Check whether \a T is a mlc::abstract::value.
template <typename T>
struct is_value : public mlc_is_a(T, mlc::abstract::value)
{
};
+ /// Check whether \a T is not a mlc::abstract::value.
template <typename T>
struct is_not_value : public not_<mlc_is_a(T, mlc::abstract::value)>
{
@@ -54,7 +55,7 @@
/// Equality test between a couple of types.
-
+ /// \{
template <typename T1, typename T2>
struct eq_ : private ensure_list_< is_not_value<T1>,
is_not_value<T2> >,
@@ -67,10 +68,10 @@
public true_
{
};
-
+ /// \}
/// Inequality test between a couple of types.
-
+ /// \{
template <typename T1, typename T2>
struct neq_ : private ensure_list_< is_not_value<T1>,
is_not_value<T2> >,
@@ -83,7 +84,33 @@
public false_
{
};
+ /// \}
+
+
+ /*--------------------------------------.
+ | Syntactic sugar for flag comparison. |
+ `--------------------------------------*/
+
+ /// Shortcuts for comparison with mlc::not_found.
+ /// \{
+ template <typename T>
+ struct is_found : public neq_<T, not_found>
+ {
+ };
+
+ template <typename T>
+ struct is_not_found : public neq_<T, not_found>
+ {
+ };
+ /// \}
+
+ /// Check whether a type is a sound (supposedly before using it).
+ struct is_ok : public ands_< neq_<T, not_found>,
+ neq_<T, not_ok>,
+ neq_<T, undefined > >
+ {
+ };
} // end of namespace mlc
1
0
This is just a simple packaging, mainly to automate the tests. I know
that previous Olena release/prototypes came with a much more complex
equipment (w.r.t configuration and tests); but don't worry, we'll add
this later.
https://svn.lrde.epita.fr/svn/oln/trunk
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Autoconfiscate the project and automate the tests.
* configure.ac: New file.
* Makefile.am, build-aux/Makefile.am, metalic/Makefile.am,
* metalic/mlc/Makefile.am, metalic/tests/Makefile.am: New file.
Makefile.am | 3 ++
build-aux/Makefile.am | 1
configure.ac | 60 ++++++++++++++++++++++++++++++++++++++++++++++
metalic/Makefile.am | 3 ++
metalic/mlc/Makefile.am | 22 ++++++++++++++++
metalic/tests/Makefile.am | 21 ++++++++++++++++
6 files changed, 110 insertions(+)
Index: configure.ac
--- configure.ac (revision 0)
+++ configure.ac (revision 0)
@@ -0,0 +1,60 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ([2.59])
+
+
+## ---------------- ##
+## Package set up. ##
+## ---------------- ##
+
+AC_INIT([Olena], [1.0], [olena(a)lrde.epita.fr] [olena])
+
+# Auxiliary files.
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_FILES([build-aux/Makefile])
+
+# Automake.
+# 1.9.4 because of changelog vs. ChangeLog on Darwin.
+AM_INIT_AUTOMAKE([1.9.4 foreign check-news dist-bzip2 -Wall])
+
+
+## --------------------- ##
+## C++ Compiler Set up. ##
+## --------------------- ##
+
+# Look for a C++ compiler.
+AC_LANG([C++])
+AC_PROG_CXX
+
+# Speed the compilation up.
+if test "$GXX" = yes; then
+ CXXFLAGS="$CXXFLAGS -pipe"
+fi
+
+
+## ------- ##
+## Tests. ##
+## ------- ##
+
+# Students should create their test suite in tests/. Add the needed
+# configure options here.
+AC_CONFIG_FILES([metalic/tests/Makefile])
+
+
+## --------------- ##
+## Configuration. ##
+## --------------- ##
+
+# Ask for config.h.
+AM_CONFIG_HEADER([config.h])
+
+# Ask for the Makefile creations.
+AC_CONFIG_FILES([
+ Makefile
+ metalic/Makefile
+ metalic/mlc/Makefile
+])
+
+# Checks for library functions.
+AC_OUTPUT
Index: Makefile.am
--- Makefile.am (revision 0)
+++ Makefile.am (revision 0)
@@ -0,0 +1,3 @@
+## Process this file through Automake to produce Makefile.in -*- Makefile -*-
+
+SUBDIRS = build-aux metalic
Index: build-aux/Makefile.am
--- build-aux/Makefile.am (revision 0)
+++ build-aux/Makefile.am (revision 0)
@@ -0,0 +1 @@
+## Process this file through Automake to produce Makefile.in -*- Makefile -*-
Index: metalic/tests/Makefile.am
--- metalic/tests/Makefile.am (revision 0)
+++ metalic/tests/Makefile.am (revision 0)
@@ -0,0 +1,21 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+AM_CPPFLAGS = -I$(top_srcdir)/metalic
+# FIXME: Add
+#
+# AM_CXXFLAGS = $(CXXFLAGS_STRICT) $(CXXFLAGS_OPTIMIZE) -ggdb
+#
+# when oln.m4 is available in the distribution.
+
+check_PROGRAMS = \
+ if \
+ is_a \
+ properties \
+ typedef
+
+if_SOURCES = if.cc
+is_a_SOURCES = is_a.cc
+properties_SOURCES = properties.cc
+typedef_SOURCES = typedef.cc
+
+TESTS = $(check_PROGRAMS)
Index: metalic/Makefile.am
--- metalic/Makefile.am (revision 0)
+++ metalic/Makefile.am (revision 0)
@@ -0,0 +1,3 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+SUBDIRS = mlc tests
Index: metalic/mlc/Makefile.am
--- metalic/mlc/Makefile.am (revision 0)
+++ metalic/mlc/Makefile.am (revision 0)
@@ -0,0 +1,22 @@
+## Process this file through Automake to create Makefile.in -*- Makefile -*-
+
+mlcdir = $(includedir)/mlc
+nobase_mlc_HEADERS = \
+ bool.hh \
+ cmp.hh \
+ comma.hh \
+ elt.hh \
+ flags.hh \
+ if.hh \
+ implies.hh \
+ is_a.hh \
+ logic.hh \
+ pair.hh \
+ properties.hh \
+ to_string.hh \
+ type.hh \
+ typedef.hh \
+ uint.hh \
+ valist.hh \
+ value.hh \
+ wrap.hh
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Switch to the new properties system.
* mlc/properties.hh: Switch to the new properties system.
* tests/properties.cc: Adjust test.
mlc/properties.hh | 307 ++++++++++++++++++++++++++++------------------------
tests/properties.cc | 72 +++---------
2 files changed, 189 insertions(+), 190 deletions(-)
Index: tests/properties.cc
--- tests/properties.cc (revision 409)
+++ tests/properties.cc (working copy)
@@ -1,7 +1,4 @@
-#include <ostream>
-
#include <mlc/properties.hh>
-#include <mlc/to_string.hh>
#include <mlc/cmp.hh>
@@ -11,6 +8,9 @@
// browse mlc/properties.hh so as to make a list of the features to be
// checked.
+// Helper macro.
+#define my_type_of_(FromType, Typedef) \
+ mlc_typeof_(my::category::my_cat, FromType, Typedef)
namespace my
{
@@ -42,46 +42,8 @@
struct my_cat;
}
- template <>
- struct set_default_props < category::my_cat >
- {
- typedef mlc::undefined ptr_type;
- };
-
- /* FIXME: In the current version of SCOOP 2, this ``packing'' is no
- longer done at this stage, but thanks to the `get_types'
- mechanism. */
- /// Retrieval of any image type properties (FIXME: say 'packing').
- template <typename T>
- struct get_props < category::my_cat, T >
- {
- typedef char ptr_type;
-
- // FIXME: Same remark as in the above FIXME: this echo() method
- // should be place lower in the prop/type hierarchy.
- static void echo(std::ostream& ostr)
- {
- ostr << "props_of( oln::category::point, "
- << mlc_to_string(T) << " ) =" << std::endl
- << "{" << std::endl
- << "\t ptr_type = " << mlc_to_string(ptr_type) << std::endl
- << "}" << std::endl;
- }
-
- static void ensure()
- {
- mlc::is_ok< ptr_type >::ensure();
- }
- };
-
-}
-// Helper macro.
-#define my_type_of_(FromType, Alias) \
- mlc_type_of_(my, my::category::my_cat, FromType, Alias)
-namespace my
-{
/*----.
| A. |
`----*/
@@ -92,7 +54,7 @@
// FIXME: Rename as set_types<> when mlc/properties.hh is updated.
// Associated types.
template<>
- struct set_props<category::my_cat, my::A>
+ struct set_types<category::my_cat, my::A>
{
typedef int foo_type;
typedef float bar_type;
@@ -115,28 +77,32 @@
// Forward declaration.
struct B;
- // FIXME: Is there any `set_super_type(T)'' sugar available?
- template<>
- struct set_super_type<my::B>
- {
- typedef A ret;
- };
+ // Warning, this sugar might me remove from properties.hh.
+ mlc_set_super(B, A);
+ /// \brief Redefined types associated to \a B.
+ ///
+ /// Keeping the inheritance is absolutely capital here (i.e., when
+ /// you redefine an associated type with redefine_types).
template<>
- struct set_props<category::my_cat, B>
+ struct redefine_types<category::my_cat, B> :
+ mlc_super_types_(category::my_cat, B)
{
- // Note: foo_type is untouched here.
-
// A type redefined here.
typedef double bar_type;
// A type defined here (but declared abstract in the super class).
typedef char baz_type;
+ };
+
+ /// \brief New types associated to \a B.
+ template<>
+ struct set_types<category::my_cat, B>
+ {
// A type defined only here (and not in the super class).
typedef long quux_type;
};
- // FIXME: Is there any `set_super_type(T)'' sugar available?
- struct B : public internal::get_super_type<B>
+ struct B : public mlc_super(B)
{
// Aliases.
typedef my_type_of_(B, foo) foo_type;
Index: mlc/properties.hh
--- mlc/properties.hh (revision 409)
+++ mlc/properties.hh (working copy)
@@ -25,6 +25,11 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+// \file mlc/properties.hh
+// \brief Property mechanism.
+//
+// From Theo's presentation (olena-06-jan.pdf).
+
#ifndef METALIC_PROPERTIES_HH
# define METALIC_PROPERTIES_HH
@@ -34,209 +39,237 @@
# include <mlc/cmp.hh>
# include <mlc/if.hh>
# include <mlc/is_a.hh>
-# include <mlc/implies.hh>
-// Note: TypedefName must be of the form `typedef_::foo'.
-# define mlc_internal_get_typedef_(Type, TypedefName) \
- typename TypedefName::template from_< Type >::ret
+/*------------.
+| Equipment. |
+`------------*/
+
+// Note: TypedefName *must* be of the form `typedef_::foo'.
+# define mlc_internal_get_typedef(Type, TypedefName) \
+ typename TypedefName::template from_< Type >::ret
+// FIXME: Add support for hierarchies with several super classes.
# define mlc_equip_namespace_with_properties() \
\
- template <template <typename> class abstraction> \
- struct is_a \
- { \
- template <typename E> \
- struct instantiated_with \
- { \
- typedef abstraction<E> ret; \
- }; \
- }; \
+ /* ------------------------- */ \
+ /* Inheritance declaration. */ \
+ /* ------------------------- */ \
\
- template <typename type, unsigned i = 0> \
+ template <typename type> \
struct set_super_type \
{ \
typedef mlc::none ret; \
}; \
\
- template <typename type, unsigned i = 0> \
- struct set_category \
- { \
- typedef mlc::none ret; \
- }; \
\
- template <typename category> \
- struct set_default_props \
+ /* ---------------------------------------- */ \
+ /* ``Internal'' associated types facility. */ \
+ /* ---------------------------------------- */ \
+ \
+ /** Fwd decl. */ \
+ namespace internal { \
+ template <typename category, typename from_type> struct get_types; \
+ } \
+ \
+ /** Specialize this class to set ``internal'' associated types. */ \
+ template <typename category, typename from_type> \
+ struct set_types \
{ \
}; \
\
- template <typename category, typename type> \
- struct set_props \
+ /** \brief Specialize this class to redefine ``internal'' */ \
+ /** associated types. */ \
+ /** */ \
+ /** Notice the inheritance relation, which enable the automatic */ \
+ /** retrieval of the types associated to the super class of \a */ \
+ /** from_type. */ \
+ template <typename category, typename from_type> \
+ struct redefine_types : public mlc_super_types(category, from_type) \
{ \
}; \
\
- template <typename category, typename type> \
- struct get_props \
+ \
+ /* ----------------------------------------- */ \
+ /* ``External'' associated types machinery. */ \
+ /* ----------------------------------------- */ \
+ \
+ /** Fwd decl. */ \
+ namespace internal { \
+ template <typename category, typename from_type, typename typedef_type> \
+ struct get_ext_type; \
+ } \
+ \
+ /** Specialize this class to set an ``external'' associated type. */ \
+ template <typename category, typename from_type, typename typedef_type> \
+ struct set_ext_type \
{ \
}; \
\
+ /** \brief Specialize this class to redefine an ``external'' */ \
+ /** associated type. */ \
+ /** */ \
+ /** Notice the inheritance relation, which enable the automatic */ \
+ /** retrieval of the types associated to the super class of \a */ \
+ /** from_type. */ \
template <typename category, typename from_type, typename typedef_type> \
- struct set_type \
+ struct redefine_ext_type : \
+ public mlc_super_ext_type(category, from_type, typedef_type) \
{ \
}; \
\
- namespace internal \
- { \
\
- template <typename type, unsigned i = 0> \
- struct get_super_type : public set_super_type <type, i> \
- { \
- }; \
+ /* -------------------- */ \
+ /* Internal machinery. */ \
+ /* -------------------- */ \
\
- template <typename type, unsigned i = 0> \
- struct get_category : public set_category <type, i> \
+ /** The classes enclosed in this namespace must not be specialized */ \
+ /** by the user (they are part of the automatic associated types */ \
+ /** retrieval mechanism). */ \
+ namespace internal \
+ { \
+ template <typename category, typename from_type> \
+ struct get_types : \
+ public set_types<category, from_type>, \
+ public redefine_types<category, from_type> \
{ \
}; \
\
+ /** End of the recursive construction of any get_types<> hierarchy. */ \
template <typename category> \
- struct get_default_props : public set_default_props <category> \
+ struct get_types<category, mlc::none> \
{ \
}; \
\
- template <typename category, typename type> \
- struct get_props : public set_props <category, type> \
+ template <typename category, typename from_type, typename typedef_type> \
+ struct get_ext_type : \
+ public set_ext_type<category, from_type, typedef_type>, \
+ public redefine_ext_type<category, from_type, typedef_type> \
{ \
}; \
\
- template <typename category, typename from_type, typename typedef_type> \
- struct get_type : public set_type <category, from_type, typedef_type> \
- { \
- ~get_type() \
+ /** End of the recursive construction of any get_ext_type<> */ \
+ /** hierarchy. */ \
+ template <typename category, typename typedef_type> \
+ struct get_ext_type<category, mlc::none, typedef_type> \
{ \
- typedef set_type <category, from_type, typedef_type> super_type; \
- typedef mlc_internal_get_typedef_(get_default_props<category>, \
- typedef_type) prop_type; \
- \
- mlc::implies_< mlc::neq_< mlc_ret(super_type), \
- mlc::not_found >, \
- mlc::eq_< prop_type, \
- mlc::not_found > >::ensure(); \
- } \
}; \
\
+ /** Typedef selector. */ \
+ /** \{ */ \
+ /** Fwd decl. */ \
+ template <bool external_typedef_p, bool internal_typedef_p, \
+ typename external_typedef, typename internal_typedef> \
+ struct select_typedef; \
\
- template <typename category, typename from_type, typename typedef_type> \
- struct f_rec_get_prop \
+ /** The typedef is found in both an external and an internal */ \
+ /** type definitions: error. */ \
+ template <typename external_typedef, typename internal_typedef> \
+ struct select_typedef<true, true, external_typedef, internal_typedef> \
{ \
- typedef get_props<category, from_type> props; \
- typedef mlc_internal_get_typedef_(props, typedef_type) prop; \
- \
- typedef typename \
- mlc::if_< mlc::neq_< prop, mlc::not_found >, \
- prop, \
- typename f_rec_get_prop< category, \
- typename get_super_type<from_type, 0>::ret, \
- typedef_type >::ret \
- >::ret ret; \
+ /* No ret member. */ \
}; \
\
- template <typename category, typename typedef_type> \
- struct f_rec_get_prop <category, mlc::none, typedef_type> \
- { \
- typedef mlc_internal_get_typedef_(get_default_props<category>, \
- typedef_type) ret; \
- ~f_rec_get_prop() \
+ /** The typedef is found neither in an external nor in an */ \
+ /** internal type definition: error. */ \
+ template <typename external_typedef, typename internal_typedef> \
+ struct select_typedef<false, false, external_typedef, internal_typedef> \
{ \
- mlc::and_< mlc::neq_< ret, mlc::not_found >, \
- mlc::neq_< ret, mlc::undefined > >::ensure(); \
- } \
+ /* No ret member. */ \
}; \
\
- \
- template <typename category, typename from_type, typename typedef_type> \
- struct f_rec_get_type \
+ /** The typedef is found in an extternal definition only: good. */ \
+ template <typename external_typedef, typename internal_typedef> \
+ struct select_typedef<true, false, external_typedef, internal_typedef> \
{ \
- typedef get_type<category, from_type, typedef_type> client_type; \
- typedef mlc_ret(client_type) type; \
- \
- typedef typename \
- mlc::if_< mlc::neq_< type, mlc::not_found >, \
- type, \
- typename f_rec_get_type< category, \
- typename get_super_type<from_type, 0>::ret, \
- typedef_type >::ret \
- >::ret ret; \
+ typedef external_typedef ret; \
}; \
\
- template <typename category, typename typedef_type> \
- struct f_rec_get_type <category, mlc::none, typedef_type> \
+ /** The typedef is found in an internal definition only: good. */ \
+ template <typename external_typedef, typename internal_typedef> \
+ struct select_typedef<false, true, external_typedef, internal_typedef> \
{ \
- typedef mlc::not_found ret; \
+ typedef internal_typedef ret; \
}; \
+ /** \} */ \
\
+ } /** End of namespace internal. */ \
+ \
+ \
+ /** FIXME: Don't query from_type directly, but */ \
+ /** exact_type(from_type) instead */ \
template <typename category, typename from_type, typename typedef_type> \
- struct f_get_type \
+ struct typeof_ \
{ \
+ typedef internal::get_types<category, from_type> types; \
+ /* FIXME: Add a check in typeof_ to ensure that get_ext_type */ \
+ /* derives from get_ext_type<none> */ \
typedef \
- mlc_internal_get_typedef_(get_default_props<category>, typedef_type) \
- default_prop; \
+ internal::get_ext_type<category, from_type, typedef_type> ext_type; \
+ /* FIXME: Add a check in typeof_ to ensure that get_ext_type */ \
+ /* derives from get_ext_type<none> */ \
\
+ /** Look for the typedef as an external type. */ \
typedef \
- typename f_rec_get_prop<category, from_type, typedef_type>::ret \
- prop; \
- \
+ mlc_internal_get_typedef(ext_type, typedef_::ret) external_typedef; \
+ /** Look for the typedef in internal types. */ \
typedef \
- typename f_rec_get_type<category, from_type, typedef_type>::ret \
- type; \
+ mlc_internal_get_typedef(types, typedef_type) internal_typedef; \
\
- ~f_get_type() \
- { \
- mlc::implies_< mlc::is_found<default_prop>, \
- mlc::is_not_found<type> >::ensure(); \
- mlc::xor_< mlc::is_found<prop>, \
- mlc::is_found<type> >::ensure(); \
- } \
+ static const bool found_external_p = \
+ mlc::is_found<external_typedef>::value; \
+ static const bool found_internal_p = \
+ mlc::is_found<internal_typedef>::value; \
\
- typedef typename mlc::if_< mlc::is_ok<prop>, \
- prop, \
- typename mlc::if_< mlc::is_ok<type>, \
- type, \
- mlc::not_ok \
- > ::ret \
- > ::ret ret; \
+ typedef typename \
+ internal::select_typedef<found_external_p, found_internal_p, \
+ external_typedef, internal_typedef>::ret ret; \
}; \
\
- } \
- \
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
-
-# define mlc_type_of_(Namespace, Category, FromType, Alias) \
- Namespace::internal::f_get_type<Category, \
- FromType, \
- Namespace::typedef_::Alias##_type>::ret
-
-# define mlc_type_2_of_(Namespace, Category, FromType,_2, Alias) \
- Namespace::internal::f_get_type<Category, \
- FromType,_2, \
- Namespace::typedef_::Alias##_type>::ret
-
-
-# define mlc_type_of(Namespace, Category, FromType, Alias) \
- typename mlc_type_of_(Namespace, Category, FromType, Alias)
-
-# define mlc_type_2_of(Namespace, Category, FromType,_2, Alias) \
- typename mlc_type_2_of_(Namespace, Category, FromType,_2, Alias)
-
-
-
-// FIXME: TODO-list
-//
-// f_get_type lance d'une part f_rec_get_prop et d'autre part f_rec_get_type
-// fusion des r�sultats: si 2 not_found err, si 1 ok + 1 not_found -> ok
-//
-// f_rec_get_prop et f_rec_get_type examine plusieurs super (i=0,1,2)
+/*---------.
+| Macros. |
+`---------*/
+
+/* FIXME: I don't know this macro will be really usable; what if T is
+ a template class? */
+// mlc_set_super_type(T, S) to declare the immediate base class S of T
+# define mlc_set_super(Type, Super) \
+ template <> \
+ struct set_super_type<Type> \
+ { \
+ typedef Super ret; \
+ }
+
+/// \def Get the immediate base class of T
+# define mlc_super(T) \
+ set_super_type<T>::ret
+
+// FIXME: Doc.
+# define mlc_super_types(Category, FromType) \
+ internal::get_types<Category, typename mlc_super(FromType)>
+
+// FIXME: Doc.
+# define mlc_super_types_(Category, FromType) \
+ internal::get_types<Category, mlc_super(FromType)>
+
+// FIXME: Doc.
+# define mlc_super_ext_type(Category, FromType, Typedef) \
+ internal::get_ext_type<Category, typename mlc_super(FromType), Typedef>
+
+// FIXME: Doc.
+# define mlc_super_ext_type_(Category, FromType, Typedef) \
+ internal::get_ext_type<Category, mlc_super(FromType), Typedef>
+
+/// Get the property \a Typedef from \a FromType (version with typename).
+#define mlc_typeof(Category, FromType, Typedef) \
+ typename typeof_<Category, FromType, typedef_:: Typedef##_type >::ret
+
+/// Get the property \a Typedef from \a FromType (version without typename).
+#define mlc_typeof_(Category, FromType, Typedef) \
+ typeof_<Category, FromType, typedef_:: Typedef##_type >::ret
#endif // ! METALIC_PROPERTIES_HH
1
0
16 Feb '06
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
Replace ensure_ (ensure_list_) with assert_ (multiple_assert_).
* tests/properties.cc: Fix bug to get compatibility with g++-3.3.
* mlc/bool.hh (ensure_item_<i, expr, check>): Rename as...
(check_item_<i, bexpr, result>): ...this.
(check_<bexpr, result>): New class dedicated to assert_.
(retrieve_ensure_): Remove.
(ASSERTION_FAILED_, AN_ASSERTION_FAILED_): New internal classes
mimicking respectively the old ensure_ and ensure_list_.
(no_error_message, no_bexpr): New classes.
(ensure_, ensure_list_): Rename as...
(assert_, multiple_assert_): ...these.
* mlc/pair.hh: Update.
* mlc/logic.hh: Update.
* mlc/valist.hh: Update.
* mlc/implies.hh: Update.
* mlc/is_a.hh: Update.
* mlc/cmp.hh: Update.
mlc/bool.hh | 209 +++++++++++++++++++++++++++++++---------------------
mlc/cmp.hh | 8 -
mlc/implies.hh | 2
mlc/is_a.hh | 2
mlc/logic.hh | 4
mlc/pair.hh | 2
mlc/valist.hh | 4
tests/properties.cc | 4
8 files changed, 138 insertions(+), 97 deletions(-)
Index: tests/properties.cc
--- tests/properties.cc (revision 408)
+++ tests/properties.cc (working copy)
@@ -99,7 +99,7 @@
typedef mlc::undefined baz_type;
};
- class A
+ struct A
{
// Aliases.
typedef my_type_of_(A, foo) foo_type;
@@ -136,7 +136,7 @@
};
// FIXME: Is there any `set_super_type(T)'' sugar available?
- class B : public internal::get_super_type<B>
+ struct B : public internal::get_super_type<B>
{
// Aliases.
typedef my_type_of_(B, foo) foo_type;
Index: mlc/pair.hh
--- mlc/pair.hh (revision 408)
+++ mlc/pair.hh (working copy)
@@ -59,7 +59,7 @@
typedef E2 second_elt;
template <unsigned i>
- struct elt : private ensure_< or_< uint_equal_<i, 1>,
+ struct elt : private assert_< or_< uint_equal_<i, 1>,
uint_equal_<i, 2> > >,
public internal::pair_elt_<E1, E2, i>
{
Index: mlc/bool.hh
--- mlc/bool.hh (revision 408)
+++ mlc/bool.hh (working copy)
@@ -141,11 +141,11 @@
** Please note that, however, we usually do not need expression
** evaluation. The most common use of a Boolean expression is
** to check that it is verified (true) and, for that, we provide
- ** "expr::ensure();" and "ensure_<expr..>". For instance:
+ ** "expr::ensure();" and "assert_<expr..>". For instance:
** or_<mlc_is_a(T, int), mlc_is_a(T, unsigned)>::ensure();
** ensures that T is int or unsigned without using ::eval.
**
- ** \see mlc::true_, mlc::false_, mlc::ensure_<expr..>.
+ ** \see mlc::true_, mlc::false_, mlc::assert_<expr..>.
*/
typedef bool_<b> eval;
@@ -163,47 +163,71 @@
};
- /*! \class mlc::internal::ensure_item_<i, expr, check>
+ /*! \class mlc::internal::check_<bexpr, result>
**
** Internal so do not use it. This class is for use in the
- ** definition of mlc::ensure_<..>.
+ ** definition of mlc::assert_<bexpr, err>.
**
** Design note: this class does not derive from abstract::type
** because it is used in inheritance so a ctor should exist.
**
- ** \see mlc::ensure_<..>
+ ** \see mlc::assert_<bexpr, err>
*/
- template <unsigned i, typename expr, typename check>
- struct ensure_item_
+ template <typename bexpr, typename result>
+ struct check_
{
};
- /*! \class mlc::internal::retrieve_ensure_
+ /*! \class mlc::internal::check_item_<i, bexpr, result>
**
** Internal so do not use it. This class is for use in the
- ** definition of mlc::ensure_<..>.
+ ** definition of mlc::multiple_assert_<..>.
**
- ** Design notes: 1) This class does not derive from abstract::type
- ** because it is used in inheritance so a ctor should exist. 2)
- ** This class provides internal_ensure_ so that it acts like the
- ** value 'true' in a sequence of 'and'; it thus has no effect when
- ** appearing in an ensure_item_.
+ ** Design note: this class does not derive from abstract::type
+ ** because it is used in inheritance so a ctor should exist.
**
- ** \see mlc::ensure_<..>
+ ** \see mlc::multiple_assert_<..>
*/
- template <typename bexpr>
- struct retrieve_ensure_
+ template <unsigned i, typename bexpr, typename result>
+ struct check_item_
{
- typedef typename bexpr::internal_ensure_ ret; // provided such as in classes inheriting from true_
};
- template <>
- struct retrieve_ensure_ < mlc::none >
+
+ // FIXME: doc
+
+ template <typename bexpr, typename err>
+ struct ASSERTION_FAILED_ :
+ private virtual check_<bexpr, typename bexpr::is_true>
+ {
+ };
+
+
+ // FIXME: doc
+
+ template <typename bexpr1,
+ typename bexpr2,
+ typename bexpr3,
+ typename bexpr4,
+ typename bexpr5,
+ typename bexpr6,
+ typename bexpr7,
+ typename bexpr8,
+ typename bexpr9>
+ struct AN_ASSERTION_FAILED_ :
+ private virtual check_item_<1, bexpr1, typename bexpr1::is_true>,
+ private virtual check_item_<2, bexpr2, typename bexpr2::is_true>,
+ private virtual check_item_<3, bexpr3, typename bexpr3::is_true>,
+ private virtual check_item_<4, bexpr4, typename bexpr4::is_true>,
+ private virtual check_item_<5, bexpr5, typename bexpr5::is_true>,
+ private virtual check_item_<6, bexpr6, typename bexpr6::is_true>,
+ private virtual check_item_<7, bexpr7, typename bexpr7::is_true>,
+ private virtual check_item_<8, bexpr8, typename bexpr8::is_true>,
+ private virtual check_item_<9, bexpr9, typename bexpr9::is_true>
{
- typedef mlc::dummy ret;
};
@@ -211,21 +235,42 @@
- /*! \class mlc::ensure_<expr>
+ /*! \class mlc::no_error_message
+ **
+ ** FIXME: doc
+ */
+
+ struct no_error_message;
+
+
+ /*! \class mlc::no_bexpr
+ **
+ ** Internal class for use in mlc::multiple_assert_<..>.
+ */
+
+ struct no_bexpr
+ {
+ typedef dummy is_true;
+ };
+
+
+ /*! \class mlc::assert_<bexpr, err>
+ **
+ ** FIXME: this doc is partially obsolete!
**
** This class is a replacement for the instruction "expr::ensure();"
** when there is no room for having instruction. The typical use
** is to express a constraint (or several constraints) upon a
** parameter (or several parameters) of a templated class.
**
- ** ensure_<expr> only accepts one parameter, which has to be a
+ ** assert_<expr> only accepts one parameter, which has to be a
** Boolean expression type. An equivalent version for a variadic
- ** list of parameters is ensure_list_<expr1,..>
+ ** list of parameters is multiple_assert_<expr1,..>
**
** Sample use:
**
** template <class T>
- ** struct foo : private virtual ensure_< neq_<T, int> >
+ ** struct foo : private virtual assert_< neq_<T, int> >
** { ...
** };
** means that T can be any type but int.
@@ -233,42 +278,43 @@
**
** Please avoid the following code:
** template <class T1, class T2>
- ** struct bar : private virtual ensure_< neq_<T1, int> >,
- ** private virtual ensure_< neq_<T2, int> >
+ ** struct bar : private virtual assert_< neq_<T1, int> >,
+ ** private virtual assert_< neq_<T2, int> >
** { ...
** };
** a better replacement is:
** template <class T1, class T2>
- ** struct bar : private virtual ensure_list_< neq_<T1, int>,
+ ** struct bar : private virtual multiple_assert_< neq_<T1, int>,
** neq_<T2, int> >
** { ...
** };
** see the design notes below for details.
**
- ** Also prefer the use of ensure_list_<expr1, expr2> than the
- ** equivalent ensure_< and_<expr1, expr2> >. Actually, the former
+ ** Also prefer the use of multiple_assert_<expr1, expr2> than the
+ ** equivalent assert_< and_<expr1, expr2> >. Actually, the former
** provides better error messages since the compiler is able to
** say which expr is not verified, whereas the latter cannot.
**
**
** Design notes: 1) This class does not derive from abstract::type
** because it is used in inheritance so a ctor should exist. 2)
- ** This class relies on mlc::internal::ensure_item_ to check that
+ ** This class relies on mlc::internal::assert_item_ to check that
** the expression is true. 3) When several contrains such as
- ** "private ensure_<..>" appear through a hierarchy of classes or
+ ** "private assert_<..>" appear through a hierarchy of classes or
** for a given class, the program may not compile because of
** multiple inheritance of the same base class; the solution is to
- ** systematically write "private virtual ensure_<..>".
+ ** systematically write "private virtual assert_<..>".
**
- ** \see ensure_list_<bexpr1,..>
+ ** \see multiple_assert_<bexpr1,..>
**
*/
- template <typename bexpr>
- struct ensure_ :
- private virtual internal::ensure_item_<0, bexpr,
- typename internal::retrieve_ensure_<bexpr>::ret>
+ template <typename bexpr, typename err = no_error_message>
+ struct assert_ : public internal::ASSERTION_FAILED_<bexpr, err>
{
+ static void run() {}
+ protected:
+ assert_() {}
};
@@ -279,14 +325,15 @@
*/
template <typename T, typename bexpr>
struct iff_ :
- private ensure_<bexpr>
+ private assert_<bexpr>
{
typedef T ret;
};
-
- /*! \class mlc::ensure_list_<expr1..>
+ /*! \class mlc::multiple_assert_<bexpr1..>
+ **
+ ** FIXME: this doc is partially obsolete!
**
** This class is a replacement for a sequence of instructions:
** "expr1::ensure(); .." when there is no room for having
@@ -294,63 +341,55 @@
** several constraints) upon a parameter (or several parameters)
** of a templated class.
**
- ** ensure_list_<..> has a variadic list of parameters. It expects
+ ** multiple_assert_<..> has a variadic list of parameters. It expects
** at least 2 parameters and handles up to 9 parameters. Each
** parameter has to be a Boolean expression type. To check only a
- ** single expression, the appropriate tool is ensure_<expr>.
+ ** single expression, the appropriate tool is assert_<expr>.
**
**
** Sample use:
**
** template <class T1, class T2>
- ** struct foo : private virtual ensure_list_< neq_<T1, int>,
+ ** struct foo : private virtual multiple_assert_< neq_<T1, int>,
** neq_<T2, int> >
** { ...
** };
**
** Design notes: 1) This class does not derive from abstract::type
** because it is used in inheritance so a ctor should exist. 2)
- ** This class relies on mlc::internal::ensure_item_ to check that
+ ** This class relies on mlc::internal::assert_item_ to check that
** each expression is true. 3) using "virtual" allow to encompass
** the multiple base class problem.
**
- ** \see ensure_<expr>
+ ** \see assert_<bexpr, err>
*/
template <typename bexpr1,
typename bexpr2,
- typename bexpr3 = none,
- typename bexpr4 = none,
- typename bexpr5 = none,
- typename bexpr6 = none,
- typename bexpr7 = none,
- typename bexpr8 = none,
- typename bexpr9 = none>
- struct ensure_list_ :
- private virtual internal::ensure_item_<1, bexpr1,
- typename internal::retrieve_ensure_<bexpr1>::ret>,
- private virtual internal::ensure_item_<2, bexpr2,
- typename internal::retrieve_ensure_<bexpr2>::ret>,
- private virtual internal::ensure_item_<3, bexpr3,
- typename internal::retrieve_ensure_<bexpr3>::ret>,
- private virtual internal::ensure_item_<4, bexpr4,
- typename internal::retrieve_ensure_<bexpr4>::ret>,
- private virtual internal::ensure_item_<5, bexpr5,
- typename internal::retrieve_ensure_<bexpr5>::ret>,
- private virtual internal::ensure_item_<6, bexpr6,
- typename internal::retrieve_ensure_<bexpr6>::ret>,
- private virtual internal::ensure_item_<7, bexpr7,
- typename internal::retrieve_ensure_<bexpr7>::ret>,
- private virtual internal::ensure_item_<8, bexpr8,
- typename internal::retrieve_ensure_<bexpr8>::ret>,
- private virtual internal::ensure_item_<9, bexpr9,
- typename internal::retrieve_ensure_<bexpr9>::ret>
+ typename bexpr3 = no_bexpr,
+ typename bexpr4 = no_bexpr,
+ typename bexpr5 = no_bexpr,
+ typename bexpr6 = no_bexpr,
+ typename bexpr7 = no_bexpr,
+ typename bexpr8 = no_bexpr,
+ typename bexpr9 = no_bexpr>
+ struct multiple_assert_ : public internal::AN_ASSERTION_FAILED_<bexpr1,
+ bexpr2,
+ bexpr3,
+ bexpr4,
+ bexpr5,
+ bexpr6,
+ bexpr7,
+ bexpr8,
+ bexpr9>
{
+ static void run() {}
+ protected:
+ multiple_assert_() {}
};
-
/*! \class mlc::bool_<true>
**
** Specialization of mlc::bool_<b> for b set to true. This type
@@ -379,28 +418,29 @@
** "Expr::ensure();"
**
** When there is no room in code for an instruction, use
- ** mlc::ensure_<expr1..> instead.
+ ** mlc::assert_<bexpr> instead.
**
** Design note: This member is a no-op (it has no cost at
** run-time).
**
- ** \see: mlc::ensure<expr1..>
+ ** \see: mlc::assert_<expr>
*/
static void ensure() {}
- /*! \typedef internal_ensure_
+ /*! \typedef is_true
**
- ** This is internal stuff so do not use it.
+ ** You should not use this typedef.
**
** This typedef is inherited in every Boolean expression types
** that derive from mlc::true_. This typedef is not provided in
** mlc::false_. The type returned by this typedef has no meaning
- ** (and thus no significant value). A static check via
- ** "mlc::ensure_<..>" uses this typedef.
+ ** (and thus no significant value). Static checks via
+ ** "mlc::assert_<bexpr, err>" rely on the presence or absence of
+ ** this typedef.
**
- ** \see mlc::internal::ensure_item_<i, expr>
+ ** \see mlc::assert_<bexpr, err>
*/
- typedef dummy internal_ensure_;
+ typedef dummy is_true;
};
@@ -414,14 +454,15 @@
** derive either from this type or from mlc::true_.
**
** Conversely to mlc::true_, this class does not feature ensure()
- ** nor ensure_. So, when a Boolean expression type, say Expr,
+ ** nor assert_. So, when a Boolean expression type, say Expr,
** is evaluated to false, the static checks "Expr::ensure();" and
- ** "Expr::ensure_" do not compile.
+ ** "Expr::assert_" do not compile.
**
** Design notes: 1) This specialization is defined so that mlc
** Booleans derive from mlc::abstract::boolean. 2) This
** specialization conforms to the interface of the generic version
- ** of mlc::internal::value_.
+ ** of mlc::internal::value_. 3) Conversely to "mlc::bool_<true>"
+ ** no typedef "is_true" is provided.
**
** \see mlc::bool_<true>
*/
Index: mlc/logic.hh
--- mlc/logic.hh (revision 408)
+++ mlc/logic.hh (working copy)
@@ -259,7 +259,7 @@
typename A6 = none,
typename A7 = none,
typename A8 = none>
- struct or_list_ : private ensure_list_< internal::is_bexpr_or_none_<A1>,
+ struct or_list_ : private multiple_assert_< internal::is_bexpr_or_none_<A1>,
internal::is_bexpr_or_none_<A2>,
internal::is_bexpr_or_none_<A3>,
internal::is_bexpr_or_none_<A4>,
@@ -297,7 +297,7 @@
typename A6 = none,
typename A7 = none,
typename A8 = none>
- struct and_list_ : private ensure_list_< internal::is_bexpr_or_none_<A1>,
+ struct and_list_ : private multiple_assert_< internal::is_bexpr_or_none_<A1>,
internal::is_bexpr_or_none_<A2>,
internal::is_bexpr_or_none_<A3>,
internal::is_bexpr_or_none_<A4>,
Index: mlc/valist.hh
--- mlc/valist.hh (revision 408)
+++ mlc/valist.hh (working copy)
@@ -46,7 +46,7 @@
# define mlc_internal_valist_elt_spe(I) \
template < mlc_internal_valist_decl_params_ > \
struct valist_elt_ < mlc_internal_valist_params_, I > \
- : private ensure_< neq_<E##I, internal::valist_none> > \
+ : private assert_< neq_<E##I, internal::valist_none> > \
{ \
typedef E##I ret; \
}
@@ -89,7 +89,7 @@
valist_<mlc_internal_valist_params_> >::value;
template <unsigned i>
- struct elt : private ensure_list_< uint_greater_or_equal_<i, 1>,
+ struct elt : private multiple_assert_< uint_greater_or_equal_<i, 1>,
uint_less_or_equal_<i, size_value> >,
public internal::valist_elt_<mlc_internal_valist_params_, i>
{
Index: mlc/implies.hh
--- mlc/implies.hh (revision 408)
+++ mlc/implies.hh (working copy)
@@ -55,7 +55,7 @@
** expression types. This class is also a Boolean expression type.
**
** Sample use:
- ** mlc::implies_< mlc_is_builtin(T), mlc_eq(T, int) >::ensure();
+ ** mlc::implies_< mlc_is_builtin(T), mlc_eq(T, int) >::assert();
** which means "if T is a buit-in type, it has to be int".
*/
Index: mlc/is_a.hh
--- mlc/is_a.hh (revision 408)
+++ mlc/is_a.hh (working copy)
@@ -218,7 +218,7 @@
** A constraint on the parameter of a class, which should be any
** subclass of base<B>, whatever B, can then be easily written:
** template <class T>
-** struct foo : private mlc::ensure_< mlc_is_a(T, base) > {
+** struct foo : private mlc::assert_< mlc_is_a(T, base) > {
** // ...
** };
**
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 408)
+++ mlc/cmp.hh (working copy)
@@ -57,14 +57,14 @@
/// Equality test between a couple of types.
/// \{
template <typename T1, typename T2>
- struct eq_ : private ensure_list_< is_not_value<T1>,
+ struct eq_ : private multiple_assert_< is_not_value<T1>,
is_not_value<T2> >,
public false_
{
};
template <typename T>
- struct eq_ <T, T> : private ensure_< is_not_value<T> >,
+ struct eq_ <T, T> : private assert_< is_not_value<T> >,
public true_
{
};
@@ -73,14 +73,14 @@
/// Inequality test between a couple of types.
/// \{
template <typename T1, typename T2>
- struct neq_ : private ensure_list_< is_not_value<T1>,
+ struct neq_ : private multiple_assert_< is_not_value<T1>,
is_not_value<T2> >,
public true_
{
};
template <typename T>
- struct neq_ <T, T> : private ensure_< is_not_value<T> >,
+ struct neq_ <T, T> : private assert_< is_not_value<T> >,
public false_
{
};
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
Add new features such as variadic type list.
* mlc/elt.hh: New file.
* mlc/bool.hh (iff_): New class.
* mlc/pair.hh: New file.
* mlc/valist.hh: New file.
* mlc/cmp.hh: Update.
* mlc/uint.hh: New file.
bool.hh | 22 +++++--
cmp.hh | 2
elt.hh | 38 +++++++++++++
pair.hh | 99 +++++++++++++++++++++++++++++++++++
uint.hh | 68 ++++++++++++++++++++++++
valist.hh | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 396 insertions(+), 7 deletions(-)
Index: mlc/elt.hh
--- mlc/elt.hh (revision 0)
+++ mlc/elt.hh (revision 0)
@@ -0,0 +1,38 @@
+// Copyright (C) 2006 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 METALIC_ELT_HH
+# define METALIC_ELT_HH
+
+
+# define mlc_elt(Type, Ith) typename Type::template elt<I>::ret
+
+# define mlc_elt_(Type, Ith) Type::template elt<I>::ret
+
+
+
+#endif // ! METALIC_ELT_HH
Index: mlc/bool.hh
--- mlc/bool.hh (revision 407)
+++ mlc/bool.hh (working copy)
@@ -30,9 +30,10 @@
# include <mlc/value.hh>
# include <mlc/flags.hh>
+# include <mlc/wrap.hh>
-/*! \macro mlc_bool(BExpr)
+/*! \def mlc_bool(BExpr)
**
** Macro that retrieves a Boolean value from a Boolean expression type.
** Its result is either true or false.
@@ -41,9 +42,14 @@
-// FIXME: keep it or not?
-# define mlc_type_when(T, BExpr) \
- typename type_when_<T, BExpr>::ret
+/*! \def mlc_iff(Type, BExpr)
+**
+** FIXME: doc
+*/
+# define mlc_iff(Type, BExpr) typename mlc::iff_<Type, BExpr>::ret
+# define mlc_iff_(Type, BExpr) mlc::iff_<Type, BExpr>::ret
+
+
@@ -266,9 +272,13 @@
};
- // FIXME: keep it or not?
+ /*! \class mlc::iff_<T, bexpr>
+ **
+ ** FIXME: doc
+ ** T iff bexpr
+ */
template <typename T, typename bexpr>
- struct type_when_ :
+ struct iff_ :
private ensure_<bexpr>
{
typedef T ret;
Index: mlc/pair.hh
--- mlc/pair.hh (revision 0)
+++ mlc/pair.hh (revision 0)
@@ -0,0 +1,99 @@
+// Copyright (C) 2006 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 METALIC_PAIR_HH
+# define METALIC_PAIR_HH
+
+# include <mlc/bool.hh>
+# include <mlc/uint.hh>
+
+
+
+
+namespace mlc
+{
+
+ namespace internal
+ {
+
+ template <typename E1, typename E2, unsigned i>
+ struct pair_elt_;
+
+ } // end of namespace mlc::internal
+
+
+ /*! \class mlc::pair_<E1, E2>
+ **
+ ** This class is FIXME */
+
+ template <typename E1, typename E2>
+ struct pair_ : public mlc::abstract::type
+ {
+ static const unsigned size_value = 2;
+
+ typedef E1 first_elt;
+ typedef E2 second_elt;
+
+ template <unsigned i>
+ struct elt : private ensure_< or_< uint_equal_<i, 1>,
+ uint_equal_<i, 2> > >,
+ public internal::pair_elt_<E1, E2, i>
+ {
+ };
+ };
+
+
+
+ namespace internal
+ {
+
+ template <typename E1, typename E2>
+ struct pair_elt_ <E1, E2, 1>
+ {
+ typedef E1 ret;
+ };
+
+ template <typename E1, typename E2>
+ struct pair_elt_ <E1, E2, 2>
+ {
+ typedef E2 ret;
+ };
+
+ } // end of namespace mlc::internal
+
+
+
+} // end of namespace mlc
+
+
+
+# include <mlc/elt.hh>
+
+
+
+
+#endif // ! METALIC_PAIR_HH
Index: mlc/valist.hh
--- mlc/valist.hh (revision 0)
+++ mlc/valist.hh (revision 0)
@@ -0,0 +1,174 @@
+// Copyright (C) 2006 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 METALIC_VALIST_HH
+# define METALIC_VALIST_HH
+
+# include <mlc/bool.hh>
+# include <mlc/cmp.hh>
+# include <mlc/uint.hh>
+
+
+# define mlc_internal_valist_decl_params_ \
+ typename E1, typename E2, typename E3, \
+ typename E4, typename E5, typename E6, typename E7, \
+ typename E8, typename E9
+
+
+# define mlc_internal_valist_params_ \
+ E1, E2, E3, E4, E5, E6, E7, E8, E9
+
+
+# define mlc_internal_valist_elt_spe(I) \
+ template < mlc_internal_valist_decl_params_ > \
+ struct valist_elt_ < mlc_internal_valist_params_, I > \
+ : private ensure_< neq_<E##I, internal::valist_none> > \
+ { \
+ typedef E##I ret; \
+ }
+
+
+
+namespace mlc
+{
+
+ namespace internal
+ {
+
+ struct valist_none;
+
+ template < mlc_internal_valist_decl_params_,
+ unsigned i >
+ struct valist_elt_;
+
+ template <typename list> struct valist_size_;
+
+ } // end of namespace mlc::internal
+
+
+ /*! \class mlc::valist_<E1,..>
+ **
+ ** This class is FIXME */
+
+ template < typename E1 = internal::valist_none,
+ typename E2 = internal::valist_none,
+ typename E3 = internal::valist_none,
+ typename E4 = internal::valist_none,
+ typename E5 = internal::valist_none,
+ typename E6 = internal::valist_none,
+ typename E7 = internal::valist_none,
+ typename E8 = internal::valist_none,
+ typename E9 = internal::valist_none >
+ struct valist_ : public mlc::abstract::type
+ {
+ static const unsigned size_value = internal::valist_size_<
+ valist_<mlc_internal_valist_params_> >::value;
+
+ template <unsigned i>
+ struct elt : private ensure_list_< uint_greater_or_equal_<i, 1>,
+ uint_less_or_equal_<i, size_value> >,
+ public internal::valist_elt_<mlc_internal_valist_params_, i>
+ {
+ };
+ };
+
+
+
+ namespace internal
+ {
+
+ mlc_internal_valist_elt_spe(1);
+ mlc_internal_valist_elt_spe(2);
+ mlc_internal_valist_elt_spe(3);
+ mlc_internal_valist_elt_spe(4);
+ mlc_internal_valist_elt_spe(5);
+ mlc_internal_valist_elt_spe(6);
+ mlc_internal_valist_elt_spe(7);
+ mlc_internal_valist_elt_spe(8);
+ mlc_internal_valist_elt_spe(9);
+
+
+ template <>
+ struct valist_size_ < valist_<> >
+ { enum { value = 0 }; };
+
+ template <class E1>
+ struct valist_size_ < valist_<E1> >
+ { enum { value = 1 }; };
+
+ template <class E1, class E2>
+ struct valist_size_ < valist_<E1,E2> >
+ { enum { value = 2 }; };
+
+ template <class E1, class E2, class E3>
+ struct valist_size_ < valist_<E1,E2,E3> >
+ { enum { value = 3 }; };
+
+ template <class E1, class E2, class E3, class E4>
+ struct valist_size_ < valist_<E1,E2,E3,E4> >
+ { enum { value = 4 }; };
+
+ template <class E1, class E2, class E3, class E4,
+ class E5>
+ struct valist_size_ < valist_<E1,E2,E3,E4,E5> >
+ { enum { value = 5 }; };
+
+ template <class E1, class E2, class E3, class E4,
+ class E5, class E6>
+ struct valist_size_ < valist_<E1,E2,E3,E4,E5,E6> >
+ { enum { value = 6 }; };
+
+ template <class E1, class E2, class E3, class E4,
+ class E5, class E6, class E7>
+ struct valist_size_ < valist_<E1,E2,E3,E4,E5,E6,E7> >
+ { enum { value = 7 }; };
+
+ template <class E1, class E2, class E3, class E4,
+ class E5, class E6, class E7, class E8>
+ struct valist_size_ < valist_<E1,E2,E3,E4,E5,E6,E7,E8> >
+ { enum { value = 8 }; };
+
+ template <class E1, class E2, class E3, class E4,
+ class E5, class E6, class E7, class E8,
+ class E9>
+ struct valist_size_ < valist_<E1,E2,E3,E4,E5,E6,E7,E8,E9> >
+ { enum { value = 9 }; };
+
+
+
+ } // end of namespace mlc::internal
+
+
+
+} // end of namespace mlc
+
+
+# include <mlc/elt.hh>
+
+
+
+#endif // ! METALIC_VALIST_HH
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 407)
+++ mlc/cmp.hh (working copy)
@@ -107,7 +107,7 @@
/// Check whether a type is a sound (supposedly before using it).
template <typename T>
- struct is_ok : public ands_< neq_<T, not_found>,
+ struct is_ok : public and_list_< neq_<T, not_found>,
neq_<T, not_ok>,
neq_<T, undefined > >
{
Index: mlc/uint.hh
--- mlc/uint.hh (revision 0)
+++ mlc/uint.hh (revision 0)
@@ -0,0 +1,68 @@
+// Copyright (C) 2006 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 METALIC_UINT_HH
+# define METALIC_UINT_HH
+
+# include <mlc/bool.hh>
+
+
+namespace mlc
+{
+
+ // FIXME: doc and complete code...
+
+ template <unsigned lvalue, unsigned rvalue>
+ struct uint_equal_ : public bool_<( lvalue == rvalue )>
+ {};
+
+ template <unsigned lvalue, unsigned rvalue>
+ struct uint_not_equal_ : public bool_<( lvalue != rvalue )>
+ {};
+
+ template <unsigned lvalue, unsigned rvalue>
+ struct uint_greater_ : public bool_<( lvalue > rvalue )>
+ {};
+
+ template <unsigned lvalue, unsigned rvalue>
+ struct uint_greater_or_equal_ : public bool_<( lvalue >= rvalue )>
+ {};
+
+ template <unsigned lvalue, unsigned rvalue>
+ struct uint_less_ : public bool_<( lvalue < rvalue )>
+ {};
+
+ template <unsigned lvalue, unsigned rvalue>
+ struct uint_less_or_equal_ : public bool_<( lvalue <= rvalue )>
+ {};
+
+
+} // end of namespace mlc
+
+
+
+#endif // ! METALIC_UINT_HH
1
0
proto-1.0 407: Implementation of Image Inpainting algorithm in Olena 0.10.
by Nicolas Widynski 15 Feb '06
by Nicolas Widynski 15 Feb '06
15 Feb '06
https://svn/svn/oln/prototypes/proto-1.0/olena
Index: ChangeLog
from Nicolas Widynski <nicolas.widynski(a)lrde.epita.fr>
Implementation of Image Inpainting algorithm in Olena 0.10.
* oln/convolution/laplacian_olena_0_10.hh: New. Laplacian 2d.
* oln/level/anisotropic_diffusion_olena_0_10.hh: New. Anisotropic diffusion
from Perona Malik.
* oln/morpho/gradient_morpho_olena_0_10.hh: New. Morphological gradient.
* oln/appli/inpainting/image_inpainting_olena_0_10.hh: New. Image inpainting
algorithm from Bertalmio.
appli/inpainting/image_inpainting_olena_0_10.hh | 48 ------------------------
level/anisotropic_diffusion_olena_0_10.hh | 2 -
2 files changed, 1 insertion(+), 49 deletions(-)
Index: oln/convolution/laplacian_olena_0_10.hh
Index: oln/level/anisotropic_diffusion_olena_0_10.hh
--- oln/level/anisotropic_diffusion_olena_0_10.hh (revision 406)
+++ oln/level/anisotropic_diffusion_olena_0_10.hh (working copy)
@@ -75,7 +75,7 @@
template <typename T>
double compute_capa(const image2d<T>& input)
{
- // static version of cappa (near the variance)
+ // static version of cappa (near the variance).
return 20;
}
Index: oln/morpho/gradient_morpho_olena_0_10.hh
Index: oln/appli/inpainting/image_inpainting_olena_0_10.hh
--- oln/appli/inpainting/image_inpainting_olena_0_10.hh (revision 406)
+++ oln/appli/inpainting/image_inpainting_olena_0_10.hh (working copy)
@@ -210,54 +210,6 @@
return g;
}
- template <typename T>
- std::ostream& operator<<(std::ostream& ostr, const image2d<std::vector<T> >& ima)
- {
- for (int i = 0; i < 9; i++)
- {
- for (int j = 0; j < 9; j++)
- {
- ostr << "(" << ima(i,j)[0] << "," << ima(i,j)[1] << ") " << "\t";
- if ((ima(i,j)[0] == 0 or ima(i,j)[0] == 1) and
- (ima(i,j)[1] == 0 or ima(i,j)[1] == 1))
- ostr << "\t";
- }
-
- ostr << std::endl;
- }
- return ostr;
- }
-
-
- template <typename T>
- std::ostream& operator<<(std::ostream& ostr, const image2d<T>& ima)
- {
- for (int i = 0; i < 9; i++)
- {
- for (int j = 0; j < 9; j++)
- ostr << ima(i,j) << "\t";
- ostr << std::endl;
- }
- return ostr;
- }
-
-
- template <typename T>
- void clean_ima(image2d<T>& ima)
- {
- for (int j = 0; j < ima.size().ncols(); j++)
- {
- ima(-1, j) = ima(0, j);
- ima(ima.size().nrows(), j) = ima(ima.size().nrows() - 1, j);
- }
-
- for (int j = 0; j < ima.size().nrows(); j++)
- {
- ima(j, -1) = ima(j, 0);
- ima(j, ima.size().ncols()) = ima(j, ima.size().ncols() - 1);
- }
- }
-
template <typename T, typename T2>
image2d<ntg::int_u8>
1
0
15 Feb '06
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
Split bool.hh to move logical ops in an independant file.
* mlc/bool.hh: Move logical ops in...
* mlc/logic.hh: this new file.
(ors_, ands_): Rename as...
(or_list_, and_list_): ...these.
bool.hh | 244 ++++++++++++-----------------------------------
logic.hh | 323 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 388 insertions(+), 179 deletions(-)
Index: mlc/bool.hh
--- mlc/bool.hh (revision 403)
+++ mlc/bool.hh (working copy)
@@ -29,14 +29,22 @@
# define METALIC_BOOL_HH
# include <mlc/value.hh>
+# include <mlc/flags.hh>
-/*! \macro mlc_bool(T)
+/*! \macro mlc_bool(BExpr)
**
-** Macro that retrieves a Boolean value from a Boolean expression type
-** T. Its result is either true or false.
+** Macro that retrieves a Boolean value from a Boolean expression type.
+** Its result is either true or false.
*/
-# define mlc_bool(Type) mlc::internal::get_bool<Type>::value
+# define mlc_bool(BExpr) mlc::internal::get_bool<BExpr>::value
+
+
+
+// FIXME: keep it or not?
+# define mlc_type_when(T, BExpr) \
+ typename type_when_<T, BExpr>::ret
+
namespace mlc
@@ -166,7 +174,7 @@
};
- /*! \class mlc::internal::none_
+ /*! \class mlc::internal::retrieve_ensure_
**
** Internal so do not use it. This class is for use in the
** definition of mlc::ensure_<..>.
@@ -180,9 +188,16 @@
** \see mlc::ensure_<..>
*/
- struct none_
+ template <typename bexpr>
+ struct retrieve_ensure_
+ {
+ typedef typename bexpr::internal_ensure_ ret; // provided such as in classes inheriting from true_
+ };
+
+ template <>
+ struct retrieve_ensure_ < mlc::none >
{
- typedef none_ internal_ensure_; // provided such as in classes inheriting from true_
+ typedef mlc::dummy ret;
};
@@ -239,17 +254,27 @@
** multiple inheritance of the same base class; the solution is to
** systematically write "private virtual ensure_<..>".
**
- ** \see ensure_list_<expr1,..>
+ ** \see ensure_list_<bexpr1,..>
**
*/
- template <typename expr>
+ template <typename bexpr>
struct ensure_ :
- private virtual internal::ensure_item_<0, expr, typename expr::internal_ensure_>
+ private virtual internal::ensure_item_<0, bexpr,
+ typename internal::retrieve_ensure_<bexpr>::ret>
{
};
+ // FIXME: keep it or not?
+ template <typename T, typename bexpr>
+ struct type_when_ :
+ private ensure_<bexpr>
+ {
+ typedef T ret;
+ };
+
+
/*! \class mlc::ensure_list_<expr1..>
**
@@ -282,25 +307,34 @@
** \see ensure_<expr>
*/
- template <typename expr_1,
- typename expr_2,
- typename expr_3 = internal::none_,
- typename expr_4 = internal::none_,
- typename expr_5 = internal::none_,
- typename expr_6 = internal::none_,
- typename expr_7 = internal::none_,
- typename expr_8 = internal::none_,
- typename expr_9 = internal::none_>
+ template <typename bexpr1,
+ typename bexpr2,
+ typename bexpr3 = none,
+ typename bexpr4 = none,
+ typename bexpr5 = none,
+ typename bexpr6 = none,
+ typename bexpr7 = none,
+ typename bexpr8 = none,
+ typename bexpr9 = none>
struct ensure_list_ :
- private virtual internal::ensure_item_<1, expr_1, typename expr_1::internal_ensure_>,
- private virtual internal::ensure_item_<2, expr_2, typename expr_2::internal_ensure_>,
- private virtual internal::ensure_item_<3, expr_3, typename expr_3::internal_ensure_>,
- private virtual internal::ensure_item_<4, expr_4, typename expr_4::internal_ensure_>,
- private virtual internal::ensure_item_<5, expr_5, typename expr_5::internal_ensure_>,
- private virtual internal::ensure_item_<6, expr_6, typename expr_6::internal_ensure_>,
- private virtual internal::ensure_item_<7, expr_7, typename expr_7::internal_ensure_>,
- private virtual internal::ensure_item_<8, expr_8, typename expr_8::internal_ensure_>,
- private virtual internal::ensure_item_<9, expr_9, typename expr_9::internal_ensure_>
+ private virtual internal::ensure_item_<1, bexpr1,
+ typename internal::retrieve_ensure_<bexpr1>::ret>,
+ private virtual internal::ensure_item_<2, bexpr2,
+ typename internal::retrieve_ensure_<bexpr2>::ret>,
+ private virtual internal::ensure_item_<3, bexpr3,
+ typename internal::retrieve_ensure_<bexpr3>::ret>,
+ private virtual internal::ensure_item_<4, bexpr4,
+ typename internal::retrieve_ensure_<bexpr4>::ret>,
+ private virtual internal::ensure_item_<5, bexpr5,
+ typename internal::retrieve_ensure_<bexpr5>::ret>,
+ private virtual internal::ensure_item_<6, bexpr6,
+ typename internal::retrieve_ensure_<bexpr6>::ret>,
+ private virtual internal::ensure_item_<7, bexpr7,
+ typename internal::retrieve_ensure_<bexpr7>::ret>,
+ private virtual internal::ensure_item_<8, bexpr8,
+ typename internal::retrieve_ensure_<bexpr8>::ret>,
+ private virtual internal::ensure_item_<9, bexpr9,
+ typename internal::retrieve_ensure_<bexpr9>::ret>
{
};
@@ -356,7 +390,7 @@
**
** \see mlc::internal::ensure_item_<i, expr>
*/
- typedef internal::none_ internal_ensure_;
+ typedef dummy internal_ensure_;
};
@@ -390,158 +424,10 @@
typedef bool_<false> false_;
- /*! \class mlc::not_<T>
- **
- ** Logical unary 'not' operator on a Boolean expression type. This
- ** class is also a Boolean expression type.
- */
- template <typename T> struct not_ : public bool_<(!mlc_bool(T))> {};
-
-
- /*! \class mlc::and_<L,R>
- **
- ** Logical binary 'and' operator on a couple of Boolean expression
- ** types. This class is also a Boolean expression type.
- **
- ** \see mlc::ands_<..>
- */
- template <typename L, typename R> struct and_ : public bool_< (mlc_bool(L) && mlc_bool(R)) > {};
-
- /*! \class mlc::nand_<L,R>
- **
- ** Logical binary 'not and' operator on a couple of Boolean
- ** expression types. This class is also a Boolean expression type.
- **
- ** Design note: an equivalent is mlc::not_< mlc::and_<L,R> >.
- */
- template <typename L, typename R> struct nand_ : public bool_<(!(mlc_bool(L) && mlc_bool(R)))> {};
-
- /*! \class mlc::or_<L,R>
- **
- ** Logical binary 'or' operator on a couple of Boolean expression
- ** types. This class is also a Boolean expression type.
- **
- ** \see mlc::ors_<..>
- */
- template <typename L, typename R> struct or_ : public bool_< (mlc_bool(L) || mlc_bool(R)) > {};
-
- /*! \class mlc::nor_<L,R>
- **
- ** Logical binary 'not or' operator on a couple of Boolean
- ** expression types. This class is also a Boolean expression type.
- **
- ** Design note: an equivalent is mlc::not_< mlc::or_<L,R> >.
- */
- template <typename L, typename R> struct nor_ : public bool_<(!(mlc_bool(L) || mlc_bool(R)))> {};
-
- /*! \class mlc::xor_<L,R>
- **
- ** Logical binary 'exclusive or' operator on a couple of Boolean
- ** expression types. This class is also a Boolean expression type.
- */
- template <typename L, typename R> struct xor_ : public bool_< (mlc_bool(L) != mlc_bool(R)) > {};
-
- /*! \class mlc::xnor_<L,R>
- **
- ** Logical binary 'exclusive not or' operator on a couple of Boolean
- ** expression types. This class is also a Boolean expression type.
- */
- template <typename L, typename R> struct xnor_ : public bool_<(!(mlc_bool(L) != mlc_bool(R)))> {};
-
-
- /// Internal helpers for logical operators between several Boolean types
-
- namespace internal
- {
-
- // ors_2_
- template <typename A1, typename A2> struct ors_2_ : public or_<A1, A2> {};
- template <> struct ors_2_ <none_, none_> : public true_ {};
- template <typename A1> struct ors_2_ <A1, none_> : public A1 {};
- template <typename A2> struct ors_2_ <none_, A2>;
- // ors_4_
- template <typename A1, typename A2,
- typename A3, typename A4>
- struct ors_4_ : public ors_2_< ors_2_<A1, A2>,
- ors_2_<A3, A4> > {};
- template <>
- struct ors_4_ <none_, none_, none_, none_> : public true_ {};
- // ors_8_
- template <typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8>
- struct ors_8_ : public ors_2_< ors_4_<A1, A2, A3, A4>,
- ors_4_<A5, A6, A7, A8> > {};
- // ands_2_
- template <typename A1, typename A2> struct ands_2_ : public and_<A1, A2> {};
- template <> struct ands_2_ <none_, none_> : public true_ {};
- template <typename A1> struct ands_2_ <A1, none_> : public A1 {};
- template <typename A2> struct ands_2_ <none_, A2>;
- // ands_4_
- template <typename A1, typename A2,
- typename A3, typename A4>
- struct ands_4_ : public ands_2_< ands_2_<A1, A2>,
- ands_2_<A3, A4> > {};
- template <>
- struct ands_4_ <none_, none_, none_, none_> : public true_ {};
- // ands_8_
- template <typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8>
- struct ands_8_ : public ands_2_< ands_4_<A1, A2, A3, A4>,
- ands_4_<A5, A6, A7, A8> > {};
-
- } // end of mlc::internal
-
-
- /*! \class mlc::ors_<..>
- **
- ** Logical n-ary 'or' operator on a set of Boolean expression types.
- ** The number of arguments (parameters) should be at least 3 and at
- ** most 8. This class is also a Boolean expression type.
- **
- ** Sample use:
- ** mlc::ors_< mlc::eq_<T, int>,
- ** mlc_is_a(T, mlc::int_),
- ** mlc_is_a(T, my::integer) >
- **
- ** \see mlc::or_<L,R> mlc::ands_<..>
- */
-
- template <typename A1,
- typename A2,
- typename A3,
- typename A4 = internal::none_,
- typename A5 = internal::none_,
- typename A6 = internal::none_,
- typename A7 = internal::none_,
- typename A8 = internal::none_>
- struct ors_ : public internal::ors_8_< A1, A2, A3, A4, A5, A6, A7, A8 >
- {
- };
-
-
- /*! \class mlc::ands_<..>
- **
- ** Logical n-ary 'and' operator on a set of Boolean expression types.
- ** The number of arguments (parameters) should be at least 3 and at
- ** most 8. This class is also a Boolean expression type.
- **
- ** \see mlc::and_<L,R> mlc::ors_<..>
- */
-
- template <typename A1,
- typename A2,
- typename A3,
- typename A4 = internal::none_,
- typename A5 = internal::none_,
- typename A6 = internal::none_,
- typename A7 = internal::none_,
- typename A8 = internal::none_>
- struct ands_ : public internal::ands_8_< A1, A2, A3, A4, A5, A6, A7, A8 >
- {
- };
+} // end of namespace mlc
-} // end of namespace mlc
+# include <mlc/logic.hh>
#endif // ! METALIC_BOOL_HH
Index: mlc/logic.hh
--- mlc/logic.hh (revision 0)
+++ mlc/logic.hh (revision 0)
@@ -0,0 +1,323 @@
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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 METALIC_LOGIC_HH
+# define METALIC_LOGIC_HH
+
+# include <mlc/bool.hh>
+# include <mlc/flags.hh>
+
+
+
+namespace mlc
+{
+
+ /*! \class mlc::not_<T>
+ **
+ ** Logical unary 'not' operator on a Boolean expression type. This
+ ** class is also a Boolean expression type.
+ */
+ template <typename T>
+ struct not_
+ : public bool_<( !mlc_bool(T) )>
+ {};
+
+
+ /*! \class mlc::and_<L,R>
+ **
+ ** Logical binary 'and' operator on a couple of Boolean expression
+ ** types. This class is also a Boolean expression type.
+ **
+ ** \see mlc::and_list_<..>
+ */
+ template <typename L, typename R>
+ struct and_
+ : public bool_<( mlc_bool(L) && mlc_bool(R) )>
+ {};
+
+
+ /*! \class mlc::nand_<L,R>
+ **
+ ** Logical binary 'not and' operator on a couple of Boolean
+ ** expression types. This class is also a Boolean expression type.
+ **
+ ** Design note: an equivalent is mlc::not_< mlc::and_<L,R> >.
+ */
+ template <typename L, typename R>
+ struct nand_
+ : public bool_<( !(mlc_bool(L) && mlc_bool(R)) )>
+ {};
+
+
+ /*! \class mlc::or_<L,R>
+ **
+ ** Logical binary 'or' operator on a couple of Boolean expression
+ ** types. This class is also a Boolean expression type.
+ **
+ ** \see mlc::or_list_<..>
+ */
+ template <typename L, typename R>
+ struct or_
+ : public bool_<( mlc_bool(L) || mlc_bool(R) )>
+ {};
+
+
+ /*! \class mlc::nor_<L,R>
+ **
+ ** Logical binary 'not or' operator on a couple of Boolean
+ ** expression types. This class is also a Boolean expression type.
+ **
+ ** Design note: an equivalent is mlc::not_< mlc::or_<L,R> >.
+ */
+ template <typename L, typename R>
+ struct nor_
+ : public bool_<( !(mlc_bool(L) || mlc_bool(R)) )>
+ {};
+
+
+ /*! \class mlc::xor_<L,R>
+ **
+ ** Logical binary 'exclusive or' operator on a couple of Boolean
+ ** expression types. This class is also a Boolean expression type.
+ */
+ template <typename L, typename R>
+ struct xor_
+ : public bool_<( mlc_bool(L) != mlc_bool(R) )>
+ {};
+
+
+ /*! \class mlc::xnor_<L,R>
+ **
+ ** Logical binary 'exclusive not or' operator on a couple of Boolean
+ ** expression types. This class is also a Boolean expression type.
+ */
+ template <typename L, typename R>
+ struct xnor_
+ : public bool_<( !(mlc_bool(L) != mlc_bool(R)) )>
+ {};
+
+
+ /// Internal helpers for logical operators between several Boolean types
+
+ namespace internal
+ {
+ // FIXME: doc
+
+ template <typename A>
+ struct is_bexpr_or_none_ : public true_ // FIXME: pb using mlc_is_a because of circular deps
+ {
+ };
+
+
+ // va_eval_
+
+ template <typename A>
+ struct va_eval_
+ {
+ typedef typename A::eval ret;
+ };
+
+ template <>
+ struct va_eval_ <none>
+ {
+ typedef none ret;
+ };
+
+
+ // or_list_2_
+
+ template <typename A1, typename A2>
+ struct or_list_2_
+ : public or_<A1, A2>::eval
+ {};
+
+ template <>
+ struct or_list_2_ <none, none>
+ : public true_
+ {};
+
+ template <typename A1>
+ struct or_list_2_ <A1, none>
+ : public A1
+ {};
+
+ template <typename A2>
+ struct or_list_2_ <none, A2>; // forbidden
+
+ // or_list_4_
+
+ template <typename A1, typename A2, typename A3, typename A4>
+ struct or_list_4_
+ : public or_list_2_< typename or_list_2_<A1, A2>::eval,
+ typename or_list_2_<A3, A4>::eval >::eval
+ {};
+
+ template <>
+ struct or_list_4_ <none, none, none, none>
+ : public true_
+ {};
+
+ // or_list_
+
+ template <typename A1, typename A2, typename A3, typename A4,
+ typename A5, typename A6, typename A7, typename A8>
+ struct or_list_
+ : public or_list_2_< typename or_list_4_<A1, A2, A3, A4>::eval,
+ typename or_list_4_<A5, A6, A7, A8>::eval >::eval
+ {};
+
+
+ // and_list_2_
+
+ template <typename A1, typename A2>
+ struct and_list_2_
+ : public and_<A1, A2>::eval
+ {};
+
+ template <>
+ struct and_list_2_ <none, none>
+ : public true_
+ {};
+
+ template <typename A1>
+ struct and_list_2_ <A1, none>
+ : public A1
+ {};
+
+ template <typename A2>
+ struct and_list_2_ <none, A2>; // forbidden
+
+ // and_list_4_
+
+ template <typename A1, typename A2, typename A3, typename A4>
+ struct and_list_4_
+ : public and_list_2_< typename and_list_2_<A1, A2>::eval,
+ typename and_list_2_<A3, A4>::eval >::eval
+ {};
+
+ template <>
+ struct and_list_4_ <none, none, none, none>
+ : public true_
+ {};
+
+ // and_list_
+
+ template <typename A1, typename A2, typename A3, typename A4,
+ typename A5, typename A6, typename A7, typename A8>
+ struct and_list_
+ : public and_list_2_< typename and_list_4_<A1, A2, A3, A4>::eval,
+ typename and_list_4_<A5, A6, A7, A8>::eval >::eval
+ {};
+
+ } // end of mlc::internal
+
+
+
+ /*! \class mlc::or_list_<..>
+ **
+ ** Logical n-ary 'or' operator on a set of Boolean expression types.
+ ** The number of arguments (parameters) should be at least 3 and at
+ ** most 8. This class is also a Boolean expression type.
+ **
+ ** Sample use:
+ ** mlc::or_list_< mlc::eq_<T, int>,
+ ** mlc_is_a(T, mlc::int_),
+ ** mlc_is_a(T, my::integer) >
+ **
+ ** \see mlc::or_<L,R> mlc::and_list_<..>
+ */
+
+ template <typename A1,
+ typename A2,
+ typename A3,
+ typename A4 = none,
+ typename A5 = none,
+ typename A6 = none,
+ typename A7 = none,
+ typename A8 = none>
+ struct or_list_ : private ensure_list_< internal::is_bexpr_or_none_<A1>,
+ internal::is_bexpr_or_none_<A2>,
+ internal::is_bexpr_or_none_<A3>,
+ internal::is_bexpr_or_none_<A4>,
+ internal::is_bexpr_or_none_<A5>,
+ internal::is_bexpr_or_none_<A6>,
+ internal::is_bexpr_or_none_<A7>,
+ internal::is_bexpr_or_none_<A8> >,
+ public internal::or_list_< typename internal::va_eval_<A1>::ret,
+ typename internal::va_eval_<A2>::ret,
+ typename internal::va_eval_<A3>::ret,
+ typename internal::va_eval_<A4>::ret,
+ typename internal::va_eval_<A5>::ret,
+ typename internal::va_eval_<A6>::ret,
+ typename internal::va_eval_<A7>::ret,
+ typename internal::va_eval_<A8>::ret >
+ {
+ };
+
+
+
+ /*! \class mlc::and_list_<..>
+ **
+ ** Logical n-ary 'and' operator on a set of Boolean expression types.
+ ** The number of arguments (parameters) should be at least 3 and at
+ ** most 8. This class is also a Boolean expression type.
+ **
+ ** \see mlc::and_<L,R> mlc::or_list_<..>
+ */
+
+ template <typename A1,
+ typename A2,
+ typename A3,
+ typename A4 = none,
+ typename A5 = none,
+ typename A6 = none,
+ typename A7 = none,
+ typename A8 = none>
+ struct and_list_ : private ensure_list_< internal::is_bexpr_or_none_<A1>,
+ internal::is_bexpr_or_none_<A2>,
+ internal::is_bexpr_or_none_<A3>,
+ internal::is_bexpr_or_none_<A4>,
+ internal::is_bexpr_or_none_<A5>,
+ internal::is_bexpr_or_none_<A6>,
+ internal::is_bexpr_or_none_<A7>,
+ internal::is_bexpr_or_none_<A8> >,
+ public internal::and_list_< typename internal::va_eval_<A1>::ret,
+ typename internal::va_eval_<A2>::ret,
+ typename internal::va_eval_<A3>::ret,
+ typename internal::va_eval_<A4>::ret,
+ typename internal::va_eval_<A5>::ret,
+ typename internal::va_eval_<A6>::ret,
+ typename internal::va_eval_<A7>::ret,
+ typename internal::va_eval_<A8>::ret >
+ {
+ };
+
+
+} // end of namespace mlc
+
+
+#endif // ! METALIC_LOGIC_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
This is just for testing purpose (namely, to see if the new typedef
facility works with the old properties). I'm currently working on the
new implementation of mlc/properties.hh, described in Th�o's
presentation from January 2006.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Add the old properties system.
* tests/properties.cc, mlc/to_string.hh: New files.
* mlc/properties.hh: New test.
mlc/properties.hh | 53 +++++++----------
tests/properties.cc | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 184 insertions(+), 29 deletions(-)
Index: tests/properties.cc
--- tests/properties.cc (revision 0)
+++ tests/properties.cc (revision 0)
@@ -0,0 +1,160 @@
+#include <ostream>
+
+#include <mlc/properties.hh>
+#include <mlc/to_string.hh>
+#include <mlc/cmp.hh>
+
+
+// FIXME: Split this test into several smaller tests? For instance,
+// we have to test inheritance, properties/associated types,
+// ``external properties'', etc. The best approach is probably to
+// browse mlc/properties.hh so as to make a list of the features to be
+// checked.
+
+
+namespace my
+{
+ /*----------------------.
+ | Namespace equipment. |
+ `----------------------*/
+
+ mlc_equip_namespace_with_properties();
+
+
+ /*-----------.
+ | Typedefs. |
+ `-----------*/
+
+ mlc_decl_typedef(ptr_type);
+ mlc_decl_typedef(foo_type);
+ mlc_decl_typedef(bar_type);
+ mlc_decl_typedef(baz_type);
+ mlc_decl_typedef(quux_type);
+
+
+ /*-----------.
+ | Category. |
+ `-----------*/
+
+ // We only use one category here.
+ namespace category
+ {
+ struct my_cat;
+ }
+
+ template <>
+ struct set_default_props < category::my_cat >
+ {
+ typedef mlc::undefined ptr_type;
+ };
+
+ /* FIXME: In the current version of SCOOP 2, this ``packing'' is no
+ longer done at this stage, but thanks to the `get_types'
+ mechanism. */
+ /// Retrieval of any image type properties (FIXME: say 'packing').
+ template <typename T>
+ struct get_props < category::my_cat, T >
+ {
+ typedef char ptr_type;
+
+ // FIXME: Same remark as in the above FIXME: this echo() method
+ // should be place lower in the prop/type hierarchy.
+ static void echo(std::ostream& ostr)
+ {
+ ostr << "props_of( oln::category::point, "
+ << mlc_to_string(T) << " ) =" << std::endl
+ << "{" << std::endl
+ << "\t ptr_type = " << mlc_to_string(ptr_type) << std::endl
+ << "}" << std::endl;
+ }
+
+ static void ensure()
+ {
+ mlc::is_ok< ptr_type >::ensure();
+ }
+ };
+
+}
+
+// Helper macro.
+#define my_type_of_(FromType, Alias) \
+ mlc_type_of_(my, my::category::my_cat, FromType, Alias)
+
+namespace my
+{
+ /*----.
+ | A. |
+ `----*/
+
+ // Forward declaration.
+ struct A;
+
+ // FIXME: Rename as set_types<> when mlc/properties.hh is updated.
+ // Associated types.
+ template<>
+ struct set_props<category::my_cat, my::A>
+ {
+ typedef int foo_type;
+ typedef float bar_type;
+ typedef mlc::undefined baz_type;
+ };
+
+ class A
+ {
+ // Aliases.
+ typedef my_type_of_(A, foo) foo_type;
+ typedef my_type_of_(A, bar) bar_type;
+ typedef my_type_of_(A, baz) baz_type;
+ };
+
+
+ /*------------.
+ | B ---|> A. |
+ `------------*/
+
+ // Forward declaration.
+ struct B;
+
+ // FIXME: Is there any `set_super_type(T)'' sugar available?
+ template<>
+ struct set_super_type<my::B>
+ {
+ typedef A ret;
+ };
+
+ template<>
+ struct set_props<category::my_cat, B>
+ {
+ // Note: foo_type is untouched here.
+
+ // A type redefined here.
+ typedef double bar_type;
+ // A type defined here (but declared abstract in the super class).
+ typedef char baz_type;
+ // A type defined only here (and not in the super class).
+ typedef long quux_type;
+ };
+
+ // FIXME: Is there any `set_super_type(T)'' sugar available?
+ class B : public internal::get_super_type<B>
+ {
+ // Aliases.
+ typedef my_type_of_(B, foo) foo_type;
+ typedef my_type_of_(B, bar) bar_type;
+ typedef my_type_of_(B, baz) baz_type;
+ typedef my_type_of_(B, quux) quux_type;
+ };
+}
+
+int
+main()
+{
+ // Check associated types.
+ mlc_eq(my::A::foo_type, int)::ensure ();
+ mlc_eq(my::A::bar_type, float)::ensure ();
+
+ // Check associated types.
+ mlc_neq(my::B::bar_type, my::A::bar_type)::ensure ();
+ mlc_eq(my::B::baz_type, char)::ensure ();
+ mlc_eq(my::B::quux_type, long)::ensure ();
+}
Index: mlc/properties.hh
--- mlc/properties.hh (revision 0)
+++ mlc/properties.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2005 EPITA Research and Development Laboratory
+// Copyright (C) 2005, 2006 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
@@ -28,26 +28,21 @@
#ifndef METALIC_PROPERTIES_HH
# define METALIC_PROPERTIES_HH
-# include <mlc/types.hh>
+# include <mlc/flags.hh>
# include <mlc/typedef.hh>
# include <mlc/bool.hh>
-# include <mlc/implies.hh>
# include <mlc/cmp.hh>
# include <mlc/if.hh>
# include <mlc/is_a.hh>
+# include <mlc/implies.hh>
-
-// this is an internal macro
-# define mlc_internal_get_typedef_(FromType, TypedefType) \
- typename internal::get_typedef <FromType, TypedefType> ::ret
-
+// Note: TypedefName must be of the form `typedef_::foo'.
+# define mlc_internal_get_typedef_(Type, TypedefName) \
+ typename TypedefName::template from_< Type >::ret
# define mlc_equip_namespace_with_properties() \
\
- mlc_equip_namespace_with_typedef(); \
- mlc_decl_typedef(ret); \
- \
template <template <typename> class abstraction> \
struct is_a \
{ \
@@ -61,13 +56,13 @@
template <typename type, unsigned i = 0> \
struct set_super_type \
{ \
- typedef mlc::no_type ret; \
+ typedef mlc::none ret; \
}; \
\
template <typename type, unsigned i = 0> \
struct set_category \
{ \
- typedef mlc::no_type ret; \
+ typedef mlc::none ret; \
}; \
\
template <typename category> \
@@ -122,10 +117,10 @@
typedef mlc_internal_get_typedef_(get_default_props<category>, \
typedef_type) prop_type; \
\
- mlc::implies< mlc::neq< mlc_typedef_of(super_type, ret), \
- mlc::internal::not_found >, \
- mlc::eq< prop_type, \
- mlc::internal::not_found > >::ensure(); \
+ mlc::implies_< mlc::neq_< mlc_ret(super_type), \
+ mlc::not_found >, \
+ mlc::eq_< prop_type, \
+ mlc::not_found > >::ensure(); \
} \
}; \
\
@@ -137,7 +132,7 @@
typedef mlc_internal_get_typedef_(props, typedef_type) prop; \
\
typedef typename \
- mlc::if_< mlc::neq< prop, mlc::internal::not_found >, \
+ mlc::if_< mlc::neq_< prop, mlc::not_found >, \
prop, \
typename f_rec_get_prop< category, \
typename get_super_type<from_type, 0>::ret, \
@@ -146,14 +141,14 @@
}; \
\
template <typename category, typename typedef_type> \
- struct f_rec_get_prop <category, mlc::no_type, typedef_type> \
+ struct f_rec_get_prop <category, mlc::none, typedef_type> \
{ \
typedef mlc_internal_get_typedef_(get_default_props<category>, \
typedef_type) ret; \
~f_rec_get_prop() \
{ \
- mlc::and_< mlc::neq< ret, mlc::internal::not_found >, \
- mlc::neq< ret, mlc::undefined_type > >::ensure(); \
+ mlc::and_< mlc::neq_< ret, mlc::not_found >, \
+ mlc::neq_< ret, mlc::undefined > >::ensure(); \
} \
}; \
\
@@ -162,10 +157,10 @@
struct f_rec_get_type \
{ \
typedef get_type<category, from_type, typedef_type> client_type; \
- typedef mlc_typedef_of(client_type, ret) type; \
+ typedef mlc_ret(client_type) type; \
\
typedef typename \
- mlc::if_< mlc::neq< type, mlc::internal::not_found >, \
+ mlc::if_< mlc::neq_< type, mlc::not_found >, \
type, \
typename f_rec_get_type< category, \
typename get_super_type<from_type, 0>::ret, \
@@ -174,9 +169,9 @@
}; \
\
template <typename category, typename typedef_type> \
- struct f_rec_get_type <category, mlc::no_type, typedef_type> \
+ struct f_rec_get_type <category, mlc::none, typedef_type> \
{ \
- typedef mlc::internal::not_found ret; \
+ typedef mlc::not_found ret; \
}; \
\
template <typename category, typename from_type, typename typedef_type> \
@@ -196,7 +191,7 @@
\
~f_get_type() \
{ \
- mlc::implies< mlc::is_found<default_prop>, \
+ mlc::implies_< mlc::is_found<default_prop>, \
mlc::is_not_found<type> >::ensure(); \
mlc::xor_< mlc::is_found<prop>, \
mlc::is_found<type> >::ensure(); \
@@ -206,7 +201,7 @@
prop, \
typename mlc::if_< mlc::is_ok<type>, \
type, \
- mlc::internal::not_ok \
+ mlc::not_ok \
> ::ret \
> ::ret ret; \
}; \
@@ -220,12 +215,12 @@
# define mlc_type_of_(Namespace, Category, FromType, Alias) \
Namespace::internal::f_get_type<Category, \
FromType, \
- Namespace::internal::typedef_::Alias##_type>::ret
+ Namespace::typedef_::Alias##_type>::ret
# define mlc_type_2_of_(Namespace, Category, FromType,_2, Alias) \
Namespace::internal::f_get_type<Category, \
FromType,_2, \
- Namespace::internal::typedef_::Alias##_type>::ret
+ Namespace::typedef_::Alias##_type>::ret
# define mlc_type_of(Namespace, Category, FromType, Alias) \
1
0