"Fossies" - the Fresh Open Source Software Archive

Member "libsigc++-2.10.2/sigc++/adaptors/macros/bind_return.h.m4" (5 May 2019, 4833 Bytes) of package /linux/misc/libsigc++-2.10.2.tar.xz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 dnl Copyright 2002, The libsigc++ Development Team
    2 dnl
    3 dnl This library is free software; you can redistribute it and/or
    4 dnl modify it under the terms of the GNU Lesser General Public
    5 dnl License as published by the Free Software Foundation; either
    6 dnl version 2.1 of the License, or (at your option) any later version.
    7 dnl
    8 dnl This library is distributed in the hope that it will be useful,
    9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
   10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   11 dnl Lesser General Public License for more details.
   12 dnl
   13 dnl You should have received a copy of the GNU Lesser General Public
   14 dnl License along with this library; if not, write to the Free Software
   15 dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
   16 dnl
   17 divert(-1)
   18 
   19 include(template.macros.m4)
   20 
   21 define([BIND_RETURN_OPERATOR],[dnl
   22   /** Invokes the wrapped functor passing on the arguments.dnl
   23 FOR(1, $1,[
   24    * @param _A_a%1 Argument to be passed on to the functor.])
   25    * @return The fixed return value.
   26    */
   27   template <LOOP(class T_arg%1, $1)>
   28   inline typename unwrap_reference<T_return>::type operator()(LOOP(T_arg%1 _A_a%1, $1))
   29     { this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(T_arg%1), $1)>
   30         (LOOP(_A_a%1, $1)); return ret_value_.invoke();
   31     }
   32 
   33   #ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
   34   template <LOOP(class T_arg%1, $1)>
   35   inline typename unwrap_reference<T_return>::type sun_forte_workaround(LOOP(T_arg%1 _A_a%1, $1))
   36     { this->functor_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP(_P_(T_arg%1), $1)>
   37         (LOOP(_A_a%1, $1)); return ret_value_.invoke();
   38     }
   39   #endif
   40 
   41 ])
   42 
   43 divert(0)dnl
   44 _FIREWALL([ADAPTORS_BIND_RETURN])
   45 #include <sigc++/adaptors/adaptor_trait.h>
   46 #include <sigc++/adaptors/bound_argument.h>
   47 
   48 namespace sigc {
   49 
   50 /** Adaptor that fixes the return value of the wrapped functor.
   51  * Use the convenience function sigc::bind_return() to create an instance of sigc::bind_return_functor.
   52  *
   53  * The following template arguments are used:
   54  * - @e T_return Type of the fixed return value.
   55  * - @e T_functor Type of the functor to wrap.
   56  *
   57  * @ingroup bind
   58  */
   59 template <class T_return, class T_functor>
   60 struct bind_return_functor : public adapts<T_functor>
   61 {
   62 #ifndef DOXYGEN_SHOULD_SKIP_THIS
   63   template <LOOP(class T_arg%1=void, CALL_SIZE)>
   64   struct deduce_result_type
   65     { typedef typename unwrap_reference<T_return>::type type; };
   66 #endif
   67   typedef typename unwrap_reference<T_return>::type result_type;
   68 
   69   /** Invokes the wrapped functor dropping its return value.
   70    * @return The fixed return value.
   71    */
   72   typename unwrap_reference<T_return>::type operator()();
   73 
   74 FOR(1,CALL_SIZE,[[BIND_RETURN_OPERATOR(%1)]])dnl
   75 
   76   /** Constructs a bind_return_functor object that fixes the return value to @p _A_ret_value.
   77    * @param _A_functor Functor to invoke from operator()().
   78    * @param _A_ret_value Value to return from operator()().
   79    */
   80   bind_return_functor(_R_(T_functor) _A_functor, _R_(T_return) _A_ret_value)
   81     : adapts<T_functor>(_A_functor), ret_value_(_A_ret_value)
   82     {}
   83 
   84   /// The fixed return value.
   85   bound_argument<T_return> ret_value_; // public, so that visit_each() can access it
   86 };
   87 
   88 template <class T_return, class T_functor>
   89 typename unwrap_reference<T_return>::type bind_return_functor<T_return, T_functor>::operator()()
   90   { this->functor_(); return ret_value_.invoke(); }
   91 
   92 #ifndef DOXYGEN_SHOULD_SKIP_THIS
   93 //template specialization of visitor<>::do_visit_each<>(action, functor):
   94 /** Performs a functor on each of the targets of a functor.
   95  * The function overload for sigc::bind_return_functor performs a functor on the
   96  * functor and on the object instance stored in the sigc::bind_return_functor object.
   97  *
   98  * @ingroup bind
   99  */
  100 template <class T_return, class T_functor>
  101 struct visitor<bind_return_functor<T_return, T_functor> >
  102 {
  103   template <class T_action>
  104   static void do_visit_each(const T_action& _A_action,
  105                             const bind_return_functor<T_return, T_functor>& _A_target)
  106   {
  107     sigc::visit_each(_A_action, _A_target.ret_value_);
  108     sigc::visit_each(_A_action, _A_target.functor_);
  109   }
  110 };
  111 #endif // DOXYGEN_SHOULD_SKIP_THIS
  112 
  113 /** Creates an adaptor of type sigc::bind_return_functor which fixes the return value of the passed functor to the passed argument.
  114  *
  115  * @param _A_functor Functor that should be wrapped.
  116  * @param _A_ret_value Argument to fix the return value of @e _A_functor to.
  117  * @return Adaptor that executes @e _A_functor on invokation and returns @e _A_ret_value.
  118  *
  119  * @ingroup bind
  120  */
  121 template <class T_return, class T_functor>
  122 inline bind_return_functor<T_return, T_functor>
  123 bind_return(const T_functor& _A_functor, T_return _A_ret_value)
  124 { return bind_return_functor<T_return, T_functor>(_A_functor, _A_ret_value); }
  125 
  126 } /* namespace sigc */