
https://svn.lrde.epita.fr/svn/oln/trunk/metalic Index: ChangeLog from Thierry Geraud <theo@lrde.epita.fr> First step towards explicit bexpr. * mlc/bool.hh: Fix doc typo. * mlc/TODO: Update. * mlc/wrap.hh (unwrap): Remove cause useless. (value_wrap_, boolean_wrap_): New dedicated wrappers. * mlc/bexpr.hh: New file. It provides an explicit wrapper for Boolean expression types; it is a first step towards the disambiguation between the Boolean value type and the many Boolean expression types. * mlc/is_a.hh (mlc_is_a): Update; now use bexpr_ instead of wrap_. * mlc/value.hh (mlc_value): Suggest this macro. TODO | 34 +++++++++++++++++++++++++++++++++- bexpr.hh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ bool.hh | 2 +- is_a.hh | 4 ++-- value.hh | 17 +++++++++++++++++ wrap.hh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 166 insertions(+), 5 deletions(-) Index: mlc/bool.hh --- mlc/bool.hh (revision 427) +++ mlc/bool.hh (working copy) @@ -32,7 +32,7 @@ # include <mlc/flags.hh> -/*! \def 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. Index: mlc/TODO --- mlc/TODO (revision 427) +++ mlc/TODO (working copy) @@ -2,4 +2,36 @@ * files -create assert.hh from bool.hh +** bool.hh + +create assert.hh from parts of bool.hh + +** boolean and bexpr + +there is a confusion between mlc::abstract::boolean and the notion of +bexpr (Boolean expression type)! + +** value.hh + +This file mixes bool_, int_, etc. so I should be split into several +parts and all value-related files should be re-organized. The current +situation is weird: internal::value is not in value.hh; uint.hh does +not define mlc::uint_; etc. + + +* renaming + +** cmp.hh + +eq_ -> equal_ etc. + +** comma.hh + +mlc_comma_N -> mlc_cmN (the shorter the better) + + +* design + +** mlc_is_a + +It uses wrap_; though, is it really useful? Index: mlc/wrap.hh --- mlc/wrap.hh (revision 427) +++ mlc/wrap.hh (working copy) @@ -28,9 +28,23 @@ #ifndef METALIC_WRAP_HH # define METALIC_WRAP_HH +# include <mlc/is_a.hh> + namespace mlc { + + /// Forward declarations of types used in specific version of wrap_. + /// \{ + namespace abstract + { + struct value; + struct boolean; + } + /// \} + + + /*! \class mlc::wrap_<T> ** ** This class is a workaround to the problem of implicit typename @@ -47,14 +61,60 @@ ** ** Design note: a detailed example can be read at the end of ** the file mlc/wrap.hh + ** + ** + ** \see mlc::value_wrap_<T>, mlc::bexpr_wrap_<T> */ template <class T> struct wrap_ : public T { - typedef T unwrap; + // FIXME: there's no use to unwrap so disabled(?) + // typedef T unwrap; + }; + + + + /*! \class mlc::value_wrap_<T> + ** + ** This class acts like mlc::wrap_<T> but is dedicated to + ** value types. The parameter \a T should be a value type. + ** + ** \see mlc::wrap_<T> + */ + + template <class T> + struct value_wrap_ : private assert_< mlc_is_a(T, mlc::abstract::value) >, + public T + { + typedef typename T::type type; + static const T value = T::value; + }; + + + + /*! \class mlc::boolean_wrap_<T> + ** + ** This class acts like mlc::wrap_<T> but is dedicated to Boolean. + ** The parameter \a T should be a Boolean expression type. FIXME: + ** there is a confusion between the Boolean value type and Boolean + ** expression types!!! + ** + ** \see mlc::wrap_<T> + */ + + template <class T> + struct boolean_wrap_ : private assert_< mlc_is_a(T, mlc::abstract::boolean) >, + public T + { + typedef typename T::type type; + static const T value = T::value; + + typedef typename T::eval eval; }; + + } // end of namespace mlc Index: mlc/is_a.hh --- mlc/is_a.hh (revision 427) +++ mlc/is_a.hh (working copy) @@ -29,7 +29,7 @@ # define METALIC_IS_A_HH # include <mlc/bool.hh> -# include <mlc/wrap.hh> +# include <mlc/bexpr.hh> // private macro so do _not_ use it @@ -238,7 +238,7 @@ */ # define mlc_is_a(T, U) \ -mlc::wrap_< typename mlc::is_a_<sizeof(mlc::form::of<U >())>::ret<T,U > > +mlc::bexpr_< typename mlc::is_a_< sizeof(mlc::form::of< U >()) >::ret< T, U > > # define mlc_is_a_(T, U) \ mlc::is_a_< sizeof(mlc::form::of<U >())>::ret<T,U > Index: mlc/value.hh --- mlc/value.hh (revision 427) +++ mlc/value.hh (working copy) @@ -29,6 +29,23 @@ # define METALIC_VALUE_HH # include <mlc/type.hh> +// # include <mlc/wrap.hh> + + + +/** \def mlc_value(T) + ** \brief Returns the value of a value type. + ** + ** Only works when \a T is a value type such as mlc::bool_<b> or + ** mlc::int_<i>. The result is respectively a bool value and an int + ** value. Please prefer using this macro to a direct call to + ** T::value because such a direct call may not compile (read the + ** design notes below for details). + ** + ** Design notes: FIXME: doc + */ + +// # define mlc_value(T) mlc::wrap_<T>::value Index: mlc/bexpr.hh --- mlc/bexpr.hh (revision 0) +++ mlc/bexpr.hh (revision 0) @@ -0,0 +1,52 @@ +// 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_BEXPR_HH +# define METALIC_BEXPR_HH + + +namespace mlc +{ + + /*! \class mlc::bexpr_<T> + ** + ** This class is a wrapper for Boolean expression types. FIXME: doc + ** + ** \see mlc::wrap_<T> + */ + + template <class T> + struct bexpr_ : public T + { + typedef typename T::eval eval; + }; + + +} // end of namespace mlc + + +#endif // ! METALIC_BEXPR_HH