summaryrefslogtreecommitdiff
path: root/include/argument.h
blob: 862b677d61ee47dabe2a1b24feb2491025baff98 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
 *  Argument.h
 *
 *  Class holds information about an argument that is passed to a function.
 *  You'll need this class when you're defining your own functions.
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2013 Copernica BV
 */

/**
 *  Set up namespace
 */
namespace PhpCpp {

/**
 *  Forward definitions
 */
class ArgInfo;

/**
 *  Class definition
 */
class Argument
{
public:
    /**
     *  Constructor if this argument should be an instance of a certain class
     *  @param  name        Name of the argument
     *  @param  classname   If a specific class is required, the class type
     *  @param  null        Are NULL values allowed in stead of an instance?
     *  @param  ref         Is this a pass-by-reference argument?
     */
    Argument(const std::string &name, const std::string &classname, bool null = true, bool ref = false);

    /**
     *  Constructor if the argument can be anything
     *  @param  name        Name of the argument
     *  @param  type        Type hint
     *  @param  ref         Is this a pass-by-reference argument?
     */
    Argument(const std::string &name, Type type = nullType, bool ref = false);
    
    /**
     *  Copy constructor
     *  @param  argument    The argument to copy
     */
    Argument(const Argument &argument)
    {
        // copy members
        _refcount = argument._refcount;
        _info = argument._info;
        
        // increase references
        (*_refcount)++;
    }
    
    /**
     *  Destructor
     */
    virtual ~Argument()
    {
        // cleanup current object
        cleanup();
    }

    /**
     *  Copy operator
     *  @param  argument    The argument to copy
     *  @return Argument
     */
    Argument &operator=(const Argument &argument)
    {
        // skip self assignment
        if (this == &argument) return *this;
        
        // clean up current object
        cleanup();
        
        // copy members
        _refcount = argument._refcount;
        _info = argument._info;
        
        // increase references
        (*_refcount)++;
        
        // done
        return *this;
    }
    
    /**
     *  Retrieve argument info
     *  @return ArgInfo
     *  @internal
     */
    ArgInfo *internal() const
    {
        return _info;
    }

private:
    /**
     *  Number of references
     *  @var int
     */
    int *_refcount;
    
    /**
     *  Pointer to the implementation
     *  @var ArgInfo
     */
    ArgInfo *_info;
    
    /**
     *  Remove one reference from the object
     */
    void cleanup();
    
};
    
/**
 *  End of namespace
 */
}