blob: cc8ad02adbe18e7e450ee983352d8633bc890117 (
plain)
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
|
/**
* Function.h
*
* Small extension to the Value class that allows a value to be
* constructed with a std::function.
*
* If you want to assign a std::function to a value, the following
* piece of code won't work:
*
* Php::Value value([]() { .... });
*
* Because the passed in function would match with many of the possible
* Value constructors. For that reason we have created a small and
* simple Function class that can be used instead:
*
* Php::Function valu([]() { .... });
*
* A Php::Function is an extended Php::Value object, so can be used
* in place of Php::Values all the time. The only difference is that
* it has a different constructor
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2015 Copernica BV
*/
/**
* Set up namespace
*/
namespace Php {
/**
* Class definition
*/
class PHPCPP_EXPORT Function : public Value
{
public:
/**
* Constructor to wrap a function that takes parameters
* @param function The C++ function to be wrapped
*/
Function(const std::function<Value(Parameters&)> &function);
/**
* Constructor to wrap a function that does not accept parameters
*
* Old C++ compilers do not see a difference between std::function
* objects based on the function signature, so these old compilers
* do not see this method.
*
* @param function The C++ function to be wrapped
*/
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7) || __clang__
Function(const std::function<Value()> &function) : Function([function](Parameters ¶ms) -> Value {
// call original function, forget about the parameters
return function();
}) {}
#endif
/**
* Destructor
*/
virtual ~Function() {}
private:
/**
* Retrieve the class entry of the _functor class
* @return _zend_class_entry
*/
static struct _zend_class_entry *entry();
};
/**
* End namespace
*/
}
|