File: fadapter.h

package info (click to toggle)
stlport4.6 4.6.2-7
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 7,056 kB
  • ctags: 16,390
  • sloc: ansic: 46,190; cpp: 18,805; sh: 266; asm: 93; perl: 58; makefile: 10
file content (81 lines) | stat: -rw-r--r-- 2,230 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef	_fadapter_h_
#define	_fadapter_h_

#include <functional>

// used as adaptor's return/argument type, 
// to allow binders/composers usage
struct __void_tag {};

# if !defined (STLPORT) || defined (__STL_USE_NAMESPACES)
using std::unary_function;
# endif

template <class Result>
class pointer_to_void_function {
protected:
    Result (*ptr)();
public:
    explicit pointer_to_void_function(Result (*x)()) : ptr(x) {}
    Result operator()() const { return ptr(); }
    Result operator()(__void_tag) const { return ptr(); }
};

// to feed composers
template <class Arg1>
struct projectvoid :
  public unary_function<Arg1,__void_tag> {
  __void_tag operator()(const Arg1& x) const { return __void_tag(); }
};

# if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)

template <class Result>
pointer_to_void_function<Result> ptr_fun(Result (*x)()) {
    return pointer_to_void_function<Result>(x);
}

// alternate name
template <class Result>
pointer_to_void_function<Result> ptr_gen(Result (*x)()) {
    return pointer_to_void_function<Result>(x);
}

# endif /*  !defined (__STL_MEMBER_POINTER_PARAM_BUG) */


template <class Arg>
class	pointer_to_unary_procedure /* :public unary_function<Arg, __void_tag> */ {
protected:
	typedef void	(*fun_type)(Arg);
        fun_type ptr;
public:
    typedef Arg argument_type;
	pointer_to_unary_procedure()	{}
	pointer_to_unary_procedure(fun_type x) : ptr(x)	{}
	void	operator() (Arg x) const	{ ptr(x); }
};
template <class Arg>
inline pointer_to_unary_procedure<Arg> ptr_proc(void (*x)(Arg)) {
	return pointer_to_unary_procedure<Arg>(x);
}

template <class Arg1, class Arg2>
class   pointer_to_binary_procedure /* : public unary_function<Arg1, Arg2, __void_tag> */ {
protected:
    typedef void    (*fun_type)(Arg1, Arg2);
    fun_type ptr;
public:
    typedef Arg1 first_argument_type;
    typedef Arg2 second_argument_type;
        pointer_to_binary_procedure()    {}
        pointer_to_binary_procedure(fun_type x) : ptr(x)    {}
        void    operator() (Arg1 x, Arg2 y) const        { ptr(x, y); }
};
template <class Arg1, class Arg2>
inline pointer_to_binary_procedure<Arg1, Arg2> ptr_proc(void (*x)(Arg1, Arg2)) {
        return pointer_to_binary_procedure<Arg1, Arg2>(x);
}

#endif