summaryrefslogtreecommitdiff
path: root/include/function.h
blob: ef185ce0cb5134454bc19b142df2c21af14b0ce1 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/**
 *  Function.h
 *
 *  Object represents a callable function that is defined with the CPP API.
 *  After you've instantiated the extension, you can add function objects to
 *  it.
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2013 Copernica BV
 */
 
/**
 *  Set up namespace
 */
namespace PhpCpp {

/**
 *  Forward definitions
 */
class Callable;

/** 
 *  Class definition
 */
class Function
{
public:
    /**
     *  Constructor
     *  @param  name        Name of the function
     *  @param  arguments   The arguments that can be passed to the function
     */
    Function(const std::string &name, const std::initializer_list<Argument> &arguments);

    /**
     *  Constructor
     *  @param  name        Name of the function
     */
    Function(const char *name) : Function(name, {}) {}
    
    /**
     *  No copy constructor
     *  @param  function    The other function
     */
    Function(const Function &function) = delete;

    /**
     *  Move constructor
     *  @param  function    The other function
     */
    Function(Function &&function)
    {
        _callable = function._callable;
        function._callable = nullptr;
    }
    
    /**
     *  Destructor
     */
    virtual ~Function();
    
    /**
     *  No assignment operator
     *  @param  function    The other function
     *  @return Function
     */
    Function &operator=(const Function &function) {}

    /**
     *  Method that gets called every time the function is executed
     *  @param  request     The request during which the call was made
     *  @param  arguments   The actual arguments that were passed
     *  @return Variable    Return value
     */
    virtual Value invoke(const Request *request, const std::initializer_list<Value> &arguments);
    
    /**
     *  Get access to the internal object
     *  @return Callable
     *  @internal
     */
    Callable *internal() const
    {
        return _callable;
    }

protected:
    /**
     *  Pointer to the callable object
     *  @var smart_ptr
     */
    Callable *_callable;
};

/**
 *  End of namespace
 */
}