• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _fadapter_h_
2 #define _fadapter_h_
3 
4 #include <functional>
5 
6 // used as adaptor's return/argument type,
7 // to allow binders/composers usage
8 struct __void_tag {};
9 
10 #if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES)
11 using std::unary_function;
12 #endif
13 
14 template <class Result>
15 class pointer_to_void_function {
16 protected:
17   Result (*ptr)();
18 public:
pointer_to_void_function(Result (* x)())19   explicit pointer_to_void_function(Result (*x)()) : ptr(x) {}
operator()20   Result operator()() const { return ptr(); }
operator()21   Result operator()(__void_tag) const { return ptr(); }
22 };
23 
24 // to feed composers
25 template <class Arg1>
26 struct projectvoid : public unary_function<Arg1,__void_tag> {
operatorprojectvoid27   __void_tag operator()(const Arg1& x) const { return __void_tag(); }
28 };
29 
30 #if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)
31 
32 template <class Result>
ptr_fun(Result (* x)())33 pointer_to_void_function<Result> ptr_fun(Result (*x)()) {
34   return pointer_to_void_function<Result>(x);
35 }
36 
37 // alternate name
38 template <class Result>
ptr_gen(Result (* x)())39 pointer_to_void_function<Result> ptr_gen(Result (*x)()) {
40   return pointer_to_void_function<Result>(x);
41 }
42 
43 #endif /*  !defined (_STLP_MEMBER_POINTER_PARAM_BUG) */
44 
45 template <class Arg>
46 class pointer_to_unary_procedure /* :public unary_function<Arg, __void_tag> */ {
47 protected:
48   typedef void (*fun_type)(Arg);
49   fun_type ptr;
50 public:
51   typedef Arg argument_type;
pointer_to_unary_procedure()52   pointer_to_unary_procedure() {}
pointer_to_unary_procedure(fun_type x)53   pointer_to_unary_procedure(fun_type x) : ptr(x) {}
operator()54   void operator() (Arg x) const { ptr(x); }
55 };
56 
57 template <class Arg>
ptr_proc(void (* x)(Arg))58 inline pointer_to_unary_procedure<Arg> ptr_proc(void (*x)(Arg)) {
59   return pointer_to_unary_procedure<Arg>(x);
60 }
61 
62 template <class Arg1, class Arg2>
63 class pointer_to_binary_procedure /* : public unary_function<Arg1, Arg2, __void_tag> */ {
64 protected:
65   typedef void (*fun_type)(Arg1, Arg2);
66   fun_type ptr;
67 public:
68   typedef Arg1 first_argument_type;
69   typedef Arg2 second_argument_type;
pointer_to_binary_procedure()70   pointer_to_binary_procedure() {}
pointer_to_binary_procedure(fun_type x)71   pointer_to_binary_procedure(fun_type x) : ptr(x) {}
operator()72   void operator() (Arg1 x, Arg2 y) const { ptr(x, y); }
73 };
74 
75 template <class Arg1, class Arg2>
ptr_proc(void (* x)(Arg1,Arg2))76 inline pointer_to_binary_procedure<Arg1, Arg2> ptr_proc(void (*x)(Arg1, Arg2)) {
77   return pointer_to_binary_procedure<Arg1, Arg2>(x);
78 }
79 
80 #endif
81