https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Simplfy header inclusions of oln::image[123]d.
* oln/core/1d/image1d.hh (oln/core/1d/topo1d.hh): Include it.
(oln/core/gen/topo_lbbox.hh, oln/core/1d/aliases.hh): No longer
include them.
* oln/core/2d/image2d.hh (oln/core/2d/topo2d.hh): Include it.
(oln/core/gen/topo_lbbox.hh, oln/core/2d/aliases.hh): No longer
include them.
* oln/core/3d/image3d.hh (oln/core/3d/topo3d.hh): Include it.
(oln/core/gen/topo_lbbox.hh, oln/core/3d/aliases.hh): No longer
include them.
1d/image1d.hh | 5 +----
2d/image2d.hh | 5 +----
3d/image3d.hh | 5 +----
3 files changed, 3 insertions(+), 12 deletions(-)
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 665)
+++ oln/core/1d/image1d.hh (working copy)
@@ -31,14 +31,11 @@
# include <oln/core/image_entry.hh>
# include <oln/core/gen/grid.hh>
-# include <oln/core/gen/topo_lbbox.hh>
# include <oln/core/internal/tracked_ptr.hh>
# include <oln/core/1d/array1d.hh>
# include <oln/core/1d/point1d.hh>
-// For topo1d.
-# include <oln/core/1d/aliases.hh>
+# include <oln/core/1d/topo1d.hh>
// For fwd_piter and bkd_piter virtual types.
-// FIXME: Really necessary?
# include <oln/core/iterator_vtypes.hh>
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 665)
+++ oln/core/2d/image2d.hh (working copy)
@@ -31,14 +31,11 @@
# include <oln/core/image_entry.hh>
# include <oln/core/gen/grid.hh>
-# include <oln/core/gen/topo_lbbox.hh>
# include <oln/core/internal/tracked_ptr.hh>
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/point2d.hh>
-// For topo2d.
-# include <oln/core/2d/aliases.hh>
+# include <oln/core/2d/topo2d.hh>
// For fwd_piter and bkd_piter virtual types.
-// FIXME: Really necessary?
# include <oln/core/iterator_vtypes.hh>
Index: oln/core/3d/image3d.hh
--- oln/core/3d/image3d.hh (revision 665)
+++ oln/core/3d/image3d.hh (working copy)
@@ -31,14 +31,11 @@
# include <oln/core/image_entry.hh>
# include <oln/core/gen/grid.hh>
-# include <oln/core/gen/topo_lbbox.hh>
# include <oln/core/internal/tracked_ptr.hh>
# include <oln/core/3d/array3d.hh>
# include <oln/core/3d/point3d.hh>
-// For topo3d.
-# include <oln/core/3d/aliases.hh>
+# include <oln/core/3d/topo3d.hh>
// For fwd_piter and bkd_piter virtual types.
-// FIXME: Really necessary?
# include <oln/core/iterator_vtypes.hh>
2006-10-20 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add morpher based on mutators.
* tests/value/accessor.cc: New.
* tests/value/Makefile.am: Update.
* oln/morpher/thru_mfun.hh: New.
* oln/value/accessor.hh: New.
* oln/Makefile.am: Update.
* oln/morpher/thru_fun.hh: Use shortcuts.
Index: tests/value/accessor.cc
===================================================================
--- tests/value/accessor.cc (revision 0)
+++ tests/value/accessor.cc (revision 0)
@@ -0,0 +1,51 @@
+// 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, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// Test oln::value::a_*.
+#include <iostream>
+
+#include <oln/color/rgb.hh>
+
+#include <oln/basics2d.hh>
+#include <oln/value/accessor.hh>
+#include <oln/debug/print.hh>
+
+
+int main()
+{
+ using namespace oln;
+
+ typedef color::rgb_<int> rgb_t;
+ rgb_t c;
+
+ image2d<rgb_t> ima(3,3);
+ point2d p(0,0);
+
+ ima(p).red() = 51;
+ assert( a_red(ima)(p) == 51 );
+
+}
Index: tests/value/Makefile.am
===================================================================
--- tests/value/Makefile.am (revision 664)
+++ tests/value/Makefile.am (working copy)
@@ -19,9 +19,11 @@
CXXFLAGS += $(TESTS_CXXFLAGS)
check_PROGRAMS = \
+ accessor \
grey
# Value.
+accessor_SOURCES = accessor.cc
grey_SOURCES = grey.cc
Index: oln/Makefile.am
===================================================================
--- oln/Makefile.am (revision 664)
+++ oln/Makefile.am (working copy)
@@ -168,8 +168,10 @@
morpher/tags.hh \
morpher/slice.hh \
morpher/thru_fun.hh \
+ morpher/thru_mfun.hh \
morpher/value_cast.hh \
\
+ value/accessor.hh \
value/all.hh \
value/default.hh \
value/greylevel.hh \
Index: oln/morpher/thru_mfun.hh
===================================================================
--- oln/morpher/thru_mfun.hh (revision 0)
+++ oln/morpher/thru_mfun.hh (revision 0)
@@ -0,0 +1,185 @@
+// 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, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHER_THRU_MFUN
+# define OLN_MORPHER_THRU_MFUN
+
+# include <xtd/res.hh>
+# include <xtd/abstract/open_nary_fun.hh>
+# include <xtd/mexpr.hh>
+# include <oln/morpher/internal/image_value_morpher.hh>
+
+
+namespace oln
+{
+
+ namespace morpher
+ {
+ // Forward declaration.
+ template <typename Image, typename Fun> struct thru_mfun;
+
+ } // end of namespace oln::morpher
+
+
+ /// Super type.
+ template <typename Image, typename Fun>
+ struct set_super_type< morpher::thru_mfun<Image, Fun> >
+ {
+ typedef morpher::thru_mfun<Image, Fun> self_t;
+ typedef morpher::internal::image_value_morpher<Image, self_t> ret;
+ };
+
+
+ template <typename Image, typename Fun>
+ struct vtypes< morpher::thru_mfun<Image, Fun> >
+ {
+ private:
+ typedef oln_type_of(Image, rvalue) old_value_type;
+ public:
+ typedef mlc::false_ is_computed_type;
+ typedef typename xtd::res_<Fun, old_value_type>::ret value_type;
+ typedef value_type& lvalue_type;
+ };
+
+ template <typename Image, typename Fun>
+ struct single_vtype< morpher::thru_mfun<Image, Fun>, typedef_::rvalue_type >
+ {
+ typedef morpher::thru_mfun<Image, Fun> self_t;
+ typedef oln_value(self_t) ret;
+ };
+
+
+
+ namespace morpher
+ {
+
+ /// 'Image thru Function' morpher.
+ template <typename Image, typename Fun>
+ class thru_mfun : public internal::image_value_morpher< Image,
+ morpher::thru_mfun<Image, Fun> >
+ {
+ private:
+
+ typedef thru_mfun<Image, Fun> self_t;
+ typedef internal::image_value_morpher<Image, self_t> super_t;
+
+ typedef oln_psite(self_t) psite_t;
+ typedef oln_rvalue(self_t) rvalue_t;
+ typedef oln_lvalue(self_t) lvalue_t;
+
+ public:
+
+ thru_mfun(const Image& image, const Fun& fun);
+
+ rvalue_t impl_op_read(const psite_t& p) const;
+ lvalue_t impl_op_readwrite(const psite_t& p);
+
+ protected:
+
+ Fun fun_;
+ };
+
+
+ namespace ERROR
+ {
+
+ struct AN_xtd_mutator_ONLY_WORKS_ON_AN_oln_abstract_mutable_image;
+
+ } // end of namespace oln::morpher::ERROR
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Image, typename Fun>
+ thru_mfun<Image, Fun>::thru_mfun(const Image& image, const Fun& fun) :
+ super_t(image),
+ fun_(fun)
+ {
+ }
+
+ template <typename Image, typename Fun>
+ typename thru_mfun<Image, Fun>::rvalue_t
+ thru_mfun<Image, Fun>::impl_op_read(const typename thru_mfun<Image, Fun>::psite_t& p) const
+ {
+ return fun_(this->image_(p));
+ }
+
+ template <typename Image, typename Fun>
+ typename thru_mfun<Image, Fun>::lvalue_t
+ thru_mfun<Image, Fun>::impl_op_readwrite(const typename thru_mfun<Image, Fun>::psite_t& p)
+ {
+ return fun_(this->image_(p));
+ }
+
+# endif
+
+ } // end of namespace oln::morpher
+
+
+} // end of namespace oln
+
+
+
+namespace xtd
+{
+
+ // open_nary_fun_<1, Fun>::operator()(A& a) const
+ // where A is an oln::abstract::mutable_image<I>
+
+ template <typename Fun, typename A>
+ struct case_ < tag::mutable_fun_operator, mlc::pair_<Fun, A>, 1 >
+ : where_< mlc_is_a(A, oln::abstract::image) >
+ {
+ typedef stc_to_exact(A) I;
+ typedef oln::morpher::thru_mfun<I, Fun> res;
+ typedef oln::morpher::thru_mfun<I, Fun> mutable_res;
+
+ static res impl(const Fun& fun, // target
+ const oln::abstract::image<I>& ima)
+ {
+ mlc::assert_< mlc_is_a(A, oln::abstract::mutable_image),
+ oln::morpher::ERROR::AN_xtd_mutator_ONLY_WORKS_ON_AN_oln_abstract_mutable_image >::check();
+ // FIXME: ima is const... so there may be a problem!
+ res tmp(ima.exact(), fun);
+ return tmp;
+ }
+
+ static res impl(const Fun& fun, // target
+ oln::abstract::image<I>& ima)
+ {
+ mlc::assert_< mlc_is_a(A, oln::abstract::mutable_image),
+ oln::morpher::ERROR::AN_xtd_mutator_ONLY_WORKS_ON_AN_oln_abstract_mutable_image >::check();
+ res tmp(ima.exact(), fun);
+ return tmp;
+ }
+ };
+
+} // end of namespace xtd
+
+
+
+#endif // ! OLN_MORPHER_THRU_MFUN
Index: oln/morpher/thru_fun.hh
===================================================================
--- oln/morpher/thru_fun.hh (revision 664)
+++ oln/morpher/thru_fun.hh (working copy)
@@ -69,7 +69,7 @@
struct single_vtype< morpher::thru_fun<Image, Fun>, typedef_::rvalue_type >
{
typedef morpher::thru_fun<Image, Fun> self_t;
- typedef oln_type_of(self_t, value) ret;
+ typedef oln_value(self_t) ret;
};
@@ -87,8 +87,8 @@
typedef thru_fun<Image, Fun> self_t;
typedef internal::image_value_morpher<Image, self_t> super_t;
- typedef oln_type_of(self_t, psite) psite_t;
- typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_psite(self_t) psite_t;
+ typedef oln_rvalue(self_t) rvalue_t;
public:
@@ -135,7 +135,7 @@
// where A is an oln::abstract::image<I>
template <typename Fun, typename A>
- struct case_ < tag::fun_operator_1, mlc::pair_<Fun, A>, 2 >
+ struct case_ < tag::fun_operator_1, mlc::pair_<Fun, A>, 1 >
: where_< mlc_is_a(A, oln::abstract::image) >
{
typedef stc_to_exact(A) I;
Index: oln/value/accessor.hh
===================================================================
--- oln/value/accessor.hh (revision 0)
+++ oln/value/accessor.hh (revision 0)
@@ -0,0 +1,56 @@
+// 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, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_VALUE_ACCESSOR_HH
+# define OLN_VALUE_ACCESSOR_HH
+
+#include <oln/morpher/thru_fun.hh>
+#include <xtd/accessor.hh>
+
+
+xtd_decl_accessor(value);
+xtd_decl_accessor(vec);
+
+xtd_decl_accessor(red);
+xtd_decl_accessor(green);
+xtd_decl_accessor(blue);
+
+
+namespace oln
+{
+
+ static const xtd::accessor::value_type a_value;
+ static const xtd::accessor::vec_type a_vec;
+
+ static const xtd::accessor::red_type a_red;
+ static const xtd::accessor::green_type a_green;
+ static const xtd::accessor::blue_type a_blue;
+
+} // end of namespace oln
+
+
+#endif // ! OLN_VALUE_ACCESSOR_HH
2006-10-20 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
Add mutators and disable mutable facilities of other functions.
* xtd/mutator.hh: New.
* xtd/abstract/mutable_fun.hh: New.
* tests/accessor.cc: New.
* xtd/res.hh: Add comment.
* xtd/accessor.hh (xtd_decl_accessor): Disable mutable impl_op.
(xtd_decl_accessor): Add static check.
* xtd/abstract/open_nary_fun.hh (fun_operator_1): Disable mutable
impl of default_case_ and add commented mutable_res.
(open_nary_fun_<1,E>): Disable mutable version of operator().
* xtd/abstract/plain_nary_fun.hh
(plain_nary_fun_<1,E>): Disable mutable version of operator().
* xtd/abstract/plain_fun.hh: Add commented code for xtd_mutable_res.
* xtd/mfun.hh (m1fun_): Disable mutable version of impl_calc.
* xtd/Makefile.am: Update.
* tests/Makefile.am: Update.
Index: xtd/res.hh
===================================================================
--- xtd/res.hh (revision 663)
+++ xtd/res.hh (working copy)
@@ -84,6 +84,8 @@
# define xtd_expr_res(F, Args) typename xtd::internal::get_expr_res_< F, Args >::ret
# define xtd_expr_res_(F, Args) xtd::internal::get_expr_res_< F, Args >::ret
+// FIXME: Uncomment below.
+// # define xtd_mutable_res_1(F, A1) typename xtd::internal::get_res_< F, A1 >::ret
// internal so do not use it; prefer xtd_res_0(F)
Index: xtd/mutator.hh
===================================================================
--- xtd/mutator.hh (revision 0)
+++ xtd/mutator.hh (revision 0)
@@ -0,0 +1,97 @@
+// 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, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef XTD_MUTATOR_HH
+# define XTD_MUTATOR_HH
+
+# include <mlc/typedef.hh>
+# include <mlc/cmp.hh>
+
+# include <xtd/abstract/plain_nary_fun.hh>
+# include <xtd/abstract/mutable_fun.hh>
+
+
+# define xtd_decl_mutator(MethodName) \
+ \
+namespace xtd \
+{ \
+ \
+ namespace mutator \
+ { \
+ struct MethodName##_type; \
+ \
+ mlc_decl_typedef(MethodName##_type); \
+ \
+ template <typename T> \
+ struct ERROR__DECLARATION_typedef_OF_##MethodName##_type_NOT_FOUND_IN_; \
+ } \
+ \
+ \
+ template <typename A> \
+ struct res_< mutator::MethodName##_type, A > \
+ \
+ : private mlc::assert_< mlc::neq_< mlc_typedef_in(mutator, A, MethodName##_type), \
+ mlc::not_found >, \
+ mutator::ERROR__DECLARATION_typedef_OF_##MethodName##_type_NOT_FOUND_IN_<A> > \
+ \
+ { \
+ typedef mlc_typedef_in(mutator, A, MethodName##_type) ret; \
+ }; \
+ \
+ namespace mutator \
+ { \
+ \
+ struct MethodName##_type \
+ \
+ : public abstract::mutable_fun_< MethodName##_type > \
+ { \
+ template <typename A> \
+ typename res_<MethodName##_type, A>::ret \
+ impl_op(const A& arg) const \
+ { \
+ return arg.MethodName(); \
+ } \
+ \
+ template <typename A> \
+ typename res_<MethodName##_type, A>::ret & \
+ impl_op(A& arg) const \
+ { \
+ return arg.MethodName(); \
+ } \
+ }; \
+ \
+ static const MethodName##_type MethodName; \
+ \
+ } \
+ \
+} \
+ \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+
+#endif // ! XTD_MUTATOR_HH
Index: xtd/accessor.hh
===================================================================
--- xtd/accessor.hh (revision 663)
+++ xtd/accessor.hh (working copy)
@@ -28,54 +28,75 @@
#ifndef XTD_ACCESSOR_HH
# define XTD_ACCESSOR_HH
+# include <mlc/typedef.hh>
+# include <mlc/cmp.hh>
+
# include <xtd/abstract/plain_nary_fun.hh>
# include <xtd/mfun.hh>
-# define xtd_decl_accessor(MethodName) \
- \
-namespace xtd \
-{ \
- \
- namespace accessor \
- { \
- template <typename T> struct MethodName##_; \
- } \
- \
- template <typename T> \
- struct fun_traits_< accessor::MethodName##_<T> > \
- { \
- typedef T arg_type; \
- typedef typename T::MethodName##_type res_type; \
- }; \
- \
- namespace accessor \
- { \
- \
- template <typename T> \
- struct MethodName##_ \
- : public xtd::abstract::plain_nary_fun_< 1, MethodName##_<T> > \
- { \
- xtd_res(MethodName##_<T>) impl_op(const T& arg) const \
- { \
- return arg.MethodName(); \
- } \
- xtd_res(MethodName##_<T>)& impl_op(T& arg) const \
- { \
- return arg.MethodName(); \
- } \
- }; \
- \
- typedef xtd::m1fun_<MethodName##_> MethodName##_type; \
- \
- static const MethodName##_type MethodName; \
- \
- } \
- \
-} \
- \
+# define xtd_decl_accessor(MethodName) \
+ \
+namespace xtd \
+{ \
+ \
+ namespace accessor \
+ { \
+ template <typename T> struct MethodName##_; \
+ \
+ mlc_decl_typedef(MethodName##_type); \
+ \
+ template <typename T> \
+ struct ERROR__DECLARATION_typedef_OF_##MethodName##_type_NOT_FOUND_IN_; \
+ } \
+ \
+ template <typename T> \
+ struct fun_traits_< accessor::MethodName##_<T> > \
+ : private mlc::assert_< mlc::neq_< mlc_typedef_in(accessor, T, MethodName##_type), \
+ mlc::not_found >, \
+ accessor::ERROR__DECLARATION_typedef_OF_##MethodName##_type_NOT_FOUND_IN_<T> > \
+ { \
+ typedef T arg_type; \
+ typedef mlc_typedef_in(accessor, T, MethodName##_type) res_type; \
+ }; \
+ \
+ namespace accessor \
+ { \
+ \
+ template <typename T> \
+ struct MethodName##_ \
+ : public xtd::abstract::plain_nary_fun_< 1, MethodName##_<T> >, \
+ private mlc::assert_< mlc::neq_< mlc_typedef(T, MethodName##_type), \
+ mlc::not_found >, \
+ ERROR__DECLARATION_typedef_OF_##MethodName##_type_NOT_FOUND_IN_<T> > \
+ { \
+ xtd_res(MethodName##_<T>) impl_op(const T& arg) const \
+ { \
+ return arg.MethodName(); \
+ } \
+ }; \
+ \
+ typedef xtd::m1fun_<MethodName##_> MethodName##_type; \
+ \
+ static const MethodName##_type MethodName; \
+ \
+ } \
+ \
+} \
+ \
struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+// FIXME: To be inserted above.
+// In traits:
+// typedef res_type & mutable_res_type;
+
+// In struct:
+// xtd_mutable_res(MethodName##_<T>) impl_op(T& arg) const
+// {
+// return arg.MethodName();
+// }
+
+
#endif // ! XTD_ACCESSOR_HH
Index: xtd/abstract/mutable_fun.hh
===================================================================
--- xtd/abstract/mutable_fun.hh (revision 0)
+++ xtd/abstract/mutable_fun.hh (revision 0)
@@ -0,0 +1,132 @@
+// 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, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef XTD_ABSTRACT_MUTABLE_FUN_HH
+# define XTD_ABSTRACT_MUTABLE_FUN_HH
+
+# include <xtd/res.hh>
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/abstract/meta_fun.hh>
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+ struct ARG_SHOULD_NOT_BE_A_PLAIN_FUN;
+ struct ARG1_SHOULD_NOT_BE_A_PLAIN_FUN;
+ struct ARG2_SHOULD_NOT_BE_A_PLAIN_FUN;
+ struct ARG3_SHOULD_NOT_BE_A_PLAIN_FUN;
+
+ struct ARG_SHOULD_NOT_BE_A_META_FUN;
+
+ } // end of namespace xtd::ERROR
+
+
+ namespace tag
+ {
+
+ struct mutable_fun_operator;
+
+ } // end of namespace xtd::tag
+
+
+ // mutable_fun_<E>::operator()(const A& a) const
+ // mutable_fun_<E>::operator()(A& a) const
+
+ template <typename E, typename A>
+ struct default_case_ < tag::mutable_fun_operator,
+ mlc::pair_<E, A> >
+ {
+ typedef typename res_<E, A>::ret res;
+ typedef res& mutable_res;
+
+ static res impl(const E& target,
+ const A& a)
+ {
+ return target.impl_op(a);
+ }
+
+ static mutable_res impl(const E& target,
+ A& a)
+ {
+ return target.impl_op(a);
+ }
+ };
+
+
+ namespace abstract
+ {
+
+ template <typename E>
+ class mutable_fun_
+
+ : public open_fun_<E>
+ {
+ public:
+
+ template <typename A>
+ struct lcase_
+
+ : private mlc::assert_< mlc_is_not_a(A, xtd::abstract::plain_fun_),
+ xtd::ERROR::ARG_SHOULD_NOT_BE_A_PLAIN_FUN >,
+
+ private mlc::assert_< mlc_is_not_a(A, xtd::abstract::meta_fun_),
+ xtd::ERROR::ARG_SHOULD_NOT_BE_A_META_FUN >,
+
+ public xtd::case_< xtd::tag::mutable_fun_operator,
+ mlc::pair_<E, A> >::ret
+ {};
+
+ // Const version.
+ template <typename A>
+ typename lcase_<A>::res
+ operator()(const A& a) const
+ {
+ return lcase_<A>::impl(this->exact_(), a);
+ }
+
+ // Mutable version.
+ template <typename A>
+ typename lcase_<A>::mutable_res
+ operator()(A& a) const
+ {
+ return lcase_<A>::impl(this->exact_(), a);
+ }
+
+ protected:
+ mutable_fun_() {}
+ };
+
+ } // end of namespace xtd::abstract
+
+
+} // end of namespace xtd
+
+
+#endif // ! XTD_ABSTRACT_MUTABLE_FUN_HH
Index: xtd/abstract/open_nary_fun.hh
===================================================================
--- xtd/abstract/open_nary_fun.hh (revision 663)
+++ xtd/abstract/open_nary_fun.hh (working copy)
@@ -76,6 +76,7 @@
mlc::pair_<E, A> >
{
typedef xtd_res_1(E, A) res;
+// typedef xtd_mutable_res_1(E, A) mutable_res;
static res impl(const E& target,
const A& a)
@@ -83,12 +84,13 @@
return target.impl_calc(a);
}
- // The "mutable a" version below is dedicated to mutators.
- static res& impl(const E& target,
- A& a)
- {
- return target.impl_calc(a);
- }
+ // FIXME: Uncomment below.
+// // The "mutable a" version below is dedicated to mutators.
+// static mutable_res impl(const E& target,
+// A& a)
+// {
+// return target.impl_calc(a);
+// }
};
@@ -232,13 +234,14 @@
return case_<A>::impl(this->exact_(), a);
}
- // The "mutable a" version below is dedicated to mutators.
- template <typename A>
- typename case_<A>::res &
- operator()(A& a) const
- {
- return case_<A>::impl(this->exact_(), a);
- }
+ // FIXME: Uncomment below.
+// // The "mutable a" version below is dedicated to mutators.
+// template <typename A>
+// typename case_<A>::res &
+// operator()(A& a) const
+// {
+// return case_<A>::impl(this->exact_(), a);
+// }
protected:
open_nary_fun_() {}
Index: xtd/abstract/plain_nary_fun.hh
===================================================================
--- xtd/abstract/plain_nary_fun.hh (revision 663)
+++ xtd/abstract/plain_nary_fun.hh (working copy)
@@ -144,11 +144,12 @@
return this->exact().impl_op(arg);
}
- // The "mutable arg" version below is dedicated to mutators.
- xtd_res(E)& operator()(xtd_arg(E)& arg) const
- {
- return this->exact().impl_op(arg);
- }
+ // FIXME: Uncomment below.
+// // The "mutable arg" version below is dedicated to mutators.
+// xtd_mutable_res(E) operator()(xtd_arg(E)& arg) const
+// {
+// return this->exact().impl_op(arg);
+// }
template <typename A>
xtd_res(E) operator()(const A& arg) const
Index: xtd/abstract/plain_fun.hh
===================================================================
--- xtd/abstract/plain_fun.hh (revision 663)
+++ xtd/abstract/plain_fun.hh (working copy)
@@ -36,6 +36,8 @@
*/
# define xtd_res(F) typename xtd::typedef_::res_type::from_< xtd::fun_traits_< F > >::ret
+// FIXME: Uncomment below.
+// # define xtd_mutable_res(F) typename xtd::typedef_::mutable_res_type::from_< xtd::fun_traits_< F > >::ret
@@ -66,6 +68,8 @@
mlc_decl_typedef(res_type);
+ // FIXME: Uncomment below.
+// mlc_decl_typedef(mutable_res_type);
namespace abstract
{
Index: xtd/mfun.hh
===================================================================
--- xtd/mfun.hh (revision 663)
+++ xtd/mfun.hh (working copy)
@@ -89,18 +89,20 @@
static const F_ f_;
return f_(a);
}
- template <typename A>
- xtd_res(F<A>)& impl_calc(A& a) const
- // ---------
- {
- typedef F<A> F_;
- mlc::assert_< mlc::and_< mlc_is_a(F_, abstract::plain_fun_),
- mlc_is_a(F_, abstract::nary_fun_<1>) >,
- xtd::ERROR::AN_xtd_m1fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_1
- >::check();
- static const F_ f_;
- return f_(a);
- }
+
+ // FIXME: Uncomment below.
+// template <typename A>
+// xtd_mutable_res(F<A>) impl_calc(A& a) const
+// // ---------
+// {
+// typedef F<A> F_;
+// mlc::assert_< mlc::and_< mlc_is_a(F_, abstract::plain_fun_),
+// mlc_is_a(F_, abstract::nary_fun_<1>) >,
+// xtd::ERROR::AN_xtd_m1fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_1
+// >::check();
+// static const F_ f_;
+// return f_(a);
+// }
};
Index: xtd/Makefile.am
===================================================================
--- xtd/Makefile.am (revision 663)
+++ xtd/Makefile.am (working copy)
@@ -8,6 +8,7 @@
abstract/fun_nary_expr.hh \
abstract/meta_fun.hh \
abstract/meta_nary_fun.hh \
+ abstract/mutable_fun.hh \
abstract/nary_fun.hh \
abstract/open_fun.hh \
abstract/open_nary_fun.hh \
@@ -44,6 +45,7 @@
math/tan.hh \
math/tanh.hh \
\
+ accessor.hh \
arg.hh \
args.hh \
bind.hh \
@@ -53,6 +55,7 @@
math.hh \
mexpr.hh \
mfun.hh \
+ mutator.hh \
optraits.hh \
res.hh \
traits.hh \
Index: tests/accessor.cc
===================================================================
--- tests/accessor.cc (revision 0)
+++ tests/accessor.cc (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, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#include <cassert>
+#include <xtd/accessor.hh>
+#include <xtd/mutator.hh>
+
+
+struct test
+{
+ typedef int member_type;
+ int member_;
+ int member() const { return member_; }
+ int& member() { return member_; }
+};
+
+
+xtd_decl_accessor(member);
+xtd_decl_mutator(member);
+
+
+int main()
+{
+ test obj;
+ xtd::mutator::member(obj) = 51;
+ assert( xtd::accessor::member(obj) == 51 );
+ assert( xtd::accessor::member(obj) == xtd::mutator::member(obj) );
+}
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am (revision 663)
+++ tests/Makefile.am (working copy)
@@ -15,6 +15,7 @@
check_PROGRAMS = \
abs \
+ accessor \
bind \
cast \
cfun \
@@ -25,6 +26,7 @@
optraits
abs_SOURCES = abs.cc
+accessor_SOURCES = accessor.cc
bind_SOURCES = bind.cc
cast_SOURCES = cast.cc
cfun_SOURCES = cfun.cc