diff options
author | Murray Cumming <murrayc@murrayc.com> | 2016-03-04 14:10:01 +0100 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2016-03-04 14:10:03 +0100 |
commit | 7247cbe41268c370a0cf705c73ce5a87a8c8c274 (patch) | |
tree | dd93c9709f23b9643b13728555576c92d91d4374 | |
parent | 638ff0a61820fe98b08d92911a22258fa5187588 (diff) | |
download | sigc++-variadic_mem_fun.tar.gz |
Use retype.h as a normal .h file.variadic_mem_fun
Instead of generating it.
-rw-r--r-- | sigc++/.gitignore | 1 | ||||
-rw-r--r-- | sigc++/adaptors/retype.h | 167 | ||||
-rw-r--r-- | sigc++/filelist.am | 15 |
3 files changed, 171 insertions, 12 deletions
diff --git a/sigc++/.gitignore b/sigc++/.gitignore index d8c2879..e64b803 100644 --- a/sigc++/.gitignore +++ b/sigc++/.gitignore @@ -1,3 +1,2 @@ /limit_reference.h -/adaptors/retype.h /functors/mem_fun.h diff --git a/sigc++/adaptors/retype.h b/sigc++/adaptors/retype.h new file mode 100644 index 0000000..9a36fd7 --- /dev/null +++ b/sigc++/adaptors/retype.h @@ -0,0 +1,167 @@ +// -*- c++ -*- +/* Do not edit! -- generated file */ +#ifndef _SIGC_ADAPTORS_RETYPE_H_ +#define _SIGC_ADAPTORS_RETYPE_H_ +#include <sigc++/adaptors/adaptor_trait.h> +#include <sigc++/functors/ptr_fun.h> +#include <sigc++/functors/mem_fun.h> +#include <sigc++/functors/slot.h> + +namespace sigc { + +/** @defgroup retype retype(), retype_return() + * sigc::retype() alters a sigc::pointer_functor, a sigc::mem_functor or a sigc::slot + * in that it makes C-style casts to the functor's parameter types + * of all parameters passed through operator()(). + * + * Use this adaptor for inline conversion between numeric or other simple types. + * @par Example: + * @code + * void foo(int); + * sigc::retype(sigc::ptr_fun(&foo))(5.7F); // calls foo(5) + * @endcode + * + * The functor that sigc::retype() returns can be passed directly into + * sigc::signal::connect(). + * + * @par Example: + * @code + * sigc::signal<void,float> some_signal; + * void foo(int); + * some_signal.connect(sigc::retype(sigc::ptr_fun(&foo))); + * @endcode + * + * This adaptor builds an exception in that it only works on sig::pointer_functor, + * sigc::mem_functor and sigc::slot because it needs sophisticated information about + * the parameter types that cannot be deduced from arbitrary functor types. + * + * sigc::retype_return() alters the return type of an arbitrary functor. + * Like in sigc::retype() a C-style cast is performed. Usage sigc::retype_return() is + * not restricted to libsigc++ functor types but you need to + * specify the new return type as a template parameter. + * + * @par Example: + * @code + * float foo(); + * std::cout << sigc::retype_return<int>(&foo)(); // converts foo's return value to an integer + * @endcode + * + * @ingroup adaptors + */ + +/** Adaptor that performs C-style casts on the parameters passed on to the functor. + * Use the convenience function sigc::retype() to create an instance of retype_functor. + * + * The following template arguments are used: + * - @e T_functor Type of the functor to wrap. + * - @e T_type Types of @e T_functor's arguments. + * + * @ingroup retype + */ +template <class T_functor, class... T_type> +struct retype_functor + : public adapts<T_functor> +{ + using adaptor_type = typename adapts<T_functor>::adaptor_type; + using result_type = typename adapts<T_functor>::result_type; + + template <class... T_arg> + decltype(auto) + operator()(T_arg... _A_a) + { return this->functor_.template operator()<type_trait_take_t<T_type>...> + (static_cast<T_type>(_A_a)...); + } + + /** Constructs a retype_functor object that performs C-style casts on the parameters passed on to the functor. + * @param _A_functor Functor to invoke from operator()(). + */ + explicit retype_functor(type_trait_take_t<T_functor> _A_functor) + : adapts<T_functor>(_A_functor) + {} +}; + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +//template specialization of visitor<>::do_visit_each<>(action, functor): +/** Performs a functor on each of the targets of a functor. + * The function overload for sigc::retype_functor performs a functor on the + * functor stored in the sigc::retype_functor object. + * + * @ingroup retype + */ +template <class T_functor, class... T_type> +struct visitor<retype_functor<T_functor, T_type...> > +{ + template <typename T_action> + static void do_visit_each(const T_action& _A_action, + const retype_functor<T_functor, T_type...>& _A_target) + { + sigc::visit_each(_A_action, _A_target.functor_); + } +}; +#endif // DOXYGEN_SHOULD_SKIP_THIS + +/** Creates an adaptor of type sigc::retype_functor which performs C-style casts on the parameters passed on to the functor. + * This function template specialization works on sigc::slot. + * + * @param _A_functor Functor that should be wrapped. + * @return Adaptor that executes @e _A_functor performing C-style casts on the paramters passed on. + * + * @ingroup retype + */ +template <class T_return, class... T_arg> +inline decltype(auto) +retype(const slot<T_return, T_arg...>& _A_functor) +{ return retype_functor<slot<T_return, T_arg...>, T_arg...> + (_A_functor); } + + +/** Creates an adaptor of type sigc::retype_functor which performs C-style casts on the parameters passed on to the functor. + * This function template specialization works on sigc::pointer_functor. + * + * @param _A_functor Functor that should be wrapped. + * @return Adaptor that executes @e _A_functor performing C-style casts on the paramters passed on. + * + * @ingroup retype + */ +template <class T_return, class... T_arg> +inline decltype(auto) +retype(const pointer_functor<T_return, T_arg...>& _A_functor) +{ return retype_functor<pointer_functor<T_return, T_arg...>, T_arg... > + (_A_functor); } + + +/** Creates an adaptor of type sigc::retype_functor which performs C-style casts on the parameters passed on to the functor. + * This function template specialization works on sigc::mem_functor_base. + * + * @param _A_functor Functor that should be wrapped. + * @return Adaptor that executes @e _A_functor performing C-style casts on the paramters passed on. + * + * @ingroup retype + */ +template <class T_func, class T_obj_with_modifier, class T_return, class T_obj, class... T_arg> +inline decltype(auto) +retype(const mem_functor_base<T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>& _A_functor) +{ return retype_functor<mem_functor_base<T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>, T_arg...> + (_A_functor); +} + +/** Creates an adaptor of type sigc::retype_functor which performs C-style casts on the parameters passed on to the functor. + * This function template specialization works on sigc::bound_mem_functor_base. + * + * @param _A_functor Functor that should be wrapped. + * @return Adaptor that executes @e _A_functor performing C-style casts on the paramters passed on. + * + * @ingroup retype + */ +template <class T_limit_reference, + class T_func, class T_obj_with_modifier, + class T_return, class T_obj, class... T_arg> +inline decltype(auto) +retype(const bound_mem_functor_base<T_limit_reference, T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>& _A_functor) +{ return retype_functor<bound_mem_functor_base<T_limit_reference, T_func, T_obj_with_modifier, T_return, T_obj, T_arg...>, T_arg...> + (_A_functor); +} + +} /* namespace sigc */ + +#endif /* _SIGC_ADAPTORS_RETYPE_H_ */ diff --git a/sigc++/filelist.am b/sigc++/filelist.am index 31f9916..2aa8707 100644 --- a/sigc++/filelist.am +++ b/sigc++/filelist.am @@ -25,21 +25,13 @@ functors_m4 = mem_fun.h.m4 functors_built_cc = functors_built_h = mem_fun.h -# Adaptors (adaptors/) -adaptors_m4 = retype.h.m4 -adaptors_built_cc = -adaptors_built_h = retype.h - # Combine all the above parts with right directories prefixed sigc_m4 = $(base_m4:%=macros/%) \ - $(functors_m4:%=functors/macros/%) \ - $(adaptors_m4:%=adaptors/macros/%) + $(functors_m4:%=functors/macros/%) sigc_built_cc = $(base_built_cc) \ - $(functors_built_cc:%=functors/%) \ - $(adaptors_built_cc:%=adaptors/%) + $(functors_built_cc:%=functors/%) sigc_built_h = $(base_built_h) \ - $(functors_built_h:%=functors/%) \ - $(adaptors_built_h:%=adaptors/%) + $(functors_built_h:%=functors/%) sigc_public_h = \ bind.h \ @@ -68,6 +60,7 @@ sigc_public_h = \ adaptors/compose.h \ adaptors/exception_catch.h \ adaptors/hide.h \ + adaptors/retype.h \ adaptors/track_obj.h \ adaptors/retype_return.h \ functors/functor_base.h \ |