os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/fadapter.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#ifndef _fadapter_h_
sl@0
     2
#define _fadapter_h_
sl@0
     3
sl@0
     4
#include <functional>
sl@0
     5
sl@0
     6
// used as adaptor's return/argument type,
sl@0
     7
// to allow binders/composers usage
sl@0
     8
struct __void_tag {};
sl@0
     9
sl@0
    10
#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES)
sl@0
    11
using std::unary_function;
sl@0
    12
#endif
sl@0
    13
sl@0
    14
template <class Result>
sl@0
    15
class pointer_to_void_function {
sl@0
    16
protected:
sl@0
    17
  Result (*ptr)();
sl@0
    18
public:
sl@0
    19
  explicit pointer_to_void_function(Result (*x)()) : ptr(x) {}
sl@0
    20
  Result operator()() const { return ptr(); }
sl@0
    21
  Result operator()(__void_tag) const { return ptr(); }
sl@0
    22
};
sl@0
    23
sl@0
    24
// to feed composers
sl@0
    25
template <class Arg1>
sl@0
    26
struct projectvoid : public unary_function<Arg1,__void_tag> {
sl@0
    27
  __void_tag operator()(const Arg1& x) const { return __void_tag(); }
sl@0
    28
};
sl@0
    29
sl@0
    30
#if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)
sl@0
    31
sl@0
    32
template <class Result>
sl@0
    33
pointer_to_void_function<Result> ptr_fun(Result (*x)()) {
sl@0
    34
  return pointer_to_void_function<Result>(x);
sl@0
    35
}
sl@0
    36
sl@0
    37
// alternate name
sl@0
    38
template <class Result>
sl@0
    39
pointer_to_void_function<Result> ptr_gen(Result (*x)()) {
sl@0
    40
  return pointer_to_void_function<Result>(x);
sl@0
    41
}
sl@0
    42
sl@0
    43
#endif /*  !defined (_STLP_MEMBER_POINTER_PARAM_BUG) */
sl@0
    44
sl@0
    45
template <class Arg>
sl@0
    46
class pointer_to_unary_procedure /* :public unary_function<Arg, __void_tag> */ {
sl@0
    47
protected:
sl@0
    48
  typedef void (*fun_type)(Arg);
sl@0
    49
  fun_type ptr;
sl@0
    50
public:
sl@0
    51
  typedef Arg argument_type;
sl@0
    52
  pointer_to_unary_procedure() {}
sl@0
    53
  pointer_to_unary_procedure(fun_type x) : ptr(x) {}
sl@0
    54
  void operator() (Arg x) const { ptr(x); }
sl@0
    55
};
sl@0
    56
sl@0
    57
template <class Arg>
sl@0
    58
inline pointer_to_unary_procedure<Arg> ptr_proc(void (*x)(Arg)) {
sl@0
    59
  return pointer_to_unary_procedure<Arg>(x);
sl@0
    60
}
sl@0
    61
sl@0
    62
template <class Arg1, class Arg2>
sl@0
    63
class pointer_to_binary_procedure /* : public unary_function<Arg1, Arg2, __void_tag> */ {
sl@0
    64
protected:
sl@0
    65
  typedef void (*fun_type)(Arg1, Arg2);
sl@0
    66
  fun_type ptr;
sl@0
    67
public:
sl@0
    68
  typedef Arg1 first_argument_type;
sl@0
    69
  typedef Arg2 second_argument_type;
sl@0
    70
  pointer_to_binary_procedure() {}
sl@0
    71
  pointer_to_binary_procedure(fun_type x) : ptr(x) {}
sl@0
    72
  void operator() (Arg1 x, Arg2 y) const { ptr(x, y); }
sl@0
    73
};
sl@0
    74
sl@0
    75
template <class Arg1, class Arg2>
sl@0
    76
inline pointer_to_binary_procedure<Arg1, Arg2> ptr_proc(void (*x)(Arg1, Arg2)) {
sl@0
    77
  return pointer_to_binary_procedure<Arg1, Arg2>(x);
sl@0
    78
}
sl@0
    79
sl@0
    80
#endif