os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/fadapter.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/fadapter.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,80 @@
     1.4 +#ifndef _fadapter_h_
     1.5 +#define _fadapter_h_
     1.6 +
     1.7 +#include <functional>
     1.8 +
     1.9 +// used as adaptor's return/argument type,
    1.10 +// to allow binders/composers usage
    1.11 +struct __void_tag {};
    1.12 +
    1.13 +#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES)
    1.14 +using std::unary_function;
    1.15 +#endif
    1.16 +
    1.17 +template <class Result>
    1.18 +class pointer_to_void_function {
    1.19 +protected:
    1.20 +  Result (*ptr)();
    1.21 +public:
    1.22 +  explicit pointer_to_void_function(Result (*x)()) : ptr(x) {}
    1.23 +  Result operator()() const { return ptr(); }
    1.24 +  Result operator()(__void_tag) const { return ptr(); }
    1.25 +};
    1.26 +
    1.27 +// to feed composers
    1.28 +template <class Arg1>
    1.29 +struct projectvoid : public unary_function<Arg1,__void_tag> {
    1.30 +  __void_tag operator()(const Arg1& x) const { return __void_tag(); }
    1.31 +};
    1.32 +
    1.33 +#if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)
    1.34 +
    1.35 +template <class Result>
    1.36 +pointer_to_void_function<Result> ptr_fun(Result (*x)()) {
    1.37 +  return pointer_to_void_function<Result>(x);
    1.38 +}
    1.39 +
    1.40 +// alternate name
    1.41 +template <class Result>
    1.42 +pointer_to_void_function<Result> ptr_gen(Result (*x)()) {
    1.43 +  return pointer_to_void_function<Result>(x);
    1.44 +}
    1.45 +
    1.46 +#endif /*  !defined (_STLP_MEMBER_POINTER_PARAM_BUG) */
    1.47 +
    1.48 +template <class Arg>
    1.49 +class pointer_to_unary_procedure /* :public unary_function<Arg, __void_tag> */ {
    1.50 +protected:
    1.51 +  typedef void (*fun_type)(Arg);
    1.52 +  fun_type ptr;
    1.53 +public:
    1.54 +  typedef Arg argument_type;
    1.55 +  pointer_to_unary_procedure() {}
    1.56 +  pointer_to_unary_procedure(fun_type x) : ptr(x) {}
    1.57 +  void operator() (Arg x) const { ptr(x); }
    1.58 +};
    1.59 +
    1.60 +template <class Arg>
    1.61 +inline pointer_to_unary_procedure<Arg> ptr_proc(void (*x)(Arg)) {
    1.62 +  return pointer_to_unary_procedure<Arg>(x);
    1.63 +}
    1.64 +
    1.65 +template <class Arg1, class Arg2>
    1.66 +class pointer_to_binary_procedure /* : public unary_function<Arg1, Arg2, __void_tag> */ {
    1.67 +protected:
    1.68 +  typedef void (*fun_type)(Arg1, Arg2);
    1.69 +  fun_type ptr;
    1.70 +public:
    1.71 +  typedef Arg1 first_argument_type;
    1.72 +  typedef Arg2 second_argument_type;
    1.73 +  pointer_to_binary_procedure() {}
    1.74 +  pointer_to_binary_procedure(fun_type x) : ptr(x) {}
    1.75 +  void operator() (Arg1 x, Arg2 y) const { ptr(x, y); }
    1.76 +};
    1.77 +
    1.78 +template <class Arg1, class Arg2>
    1.79 +inline pointer_to_binary_procedure<Arg1, Arg2> ptr_proc(void (*x)(Arg1, Arg2)) {
    1.80 +  return pointer_to_binary_procedure<Arg1, Arg2>(x);
    1.81 +}
    1.82 +
    1.83 +#endif