OSDN Git Service

original
[gb-231r1-is01/GB_2.3_IS01.git] / ndk / tests / device / test-stlport / unit / fadapter.h
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:
19   explicit pointer_to_void_function(Result (*x)()) : ptr(x) {}
20   Result operator()() const { return ptr(); }
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> {
27   __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>
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>
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;
52   pointer_to_unary_procedure() {}
53   pointer_to_unary_procedure(fun_type x) : ptr(x) {}
54   void operator() (Arg x) const { ptr(x); }
55 };
56
57 template <class 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;
70   pointer_to_binary_procedure() {}
71   pointer_to_binary_procedure(fun_type x) : ptr(x) {}
72   void operator() (Arg1 x, Arg2 y) const { ptr(x, y); }
73 };
74
75 template <class Arg1, class 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