summaryrefslogtreecommitdiff
path: root/include/argument.h
blob: f7fb78229bd76f6e502191ee37db0f0d39e84ad9 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
 *  @file 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.
 *
 *  The constructor of the argument is protected. Use the ByVal or ByRef
 *  classes instead.
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2013, 2014 Copernica BV
 */

/**
 *  Set up namespace
 */
namespace Php {

/**
 *  Class definition
 */
class PHPCPP_EXPORT Argument
{
public:
    /**
     *  Destructor
     */
    virtual ~Argument() = default;

protected:
    /**
     *  Constructor
     *  @param  name        Name of the argument
     *  @param  type        Argument type
     *  @param  required    Is this argument required?
     *  @param  byref       Is this a reference argument
     */
    Argument(const char *name, Type type, bool required = true, bool byref = false) :
        _name(name), _type(type), _required(required), _byReference(byref) {}

    /**
     *  Constructor
     *  @param  name        Name of the argument
     *  @param  classname   Name of the class
     *  @param  nullable    Can it be null?
     *  @param  required    Is this argument required?
     *  @param  byref       Is this a reference argument?
     */
    Argument(const char *name, const char *classname, bool nullable = true, bool required = true, bool byref = false) :
        _name(name), _type(Type::Object), _classname(classname), _nullable(nullable), _required(required), _byReference(byref) {}

public:
    /**
     *  Is this a required argument?
     *  @return bool
     *  @internal
     */
    bool required() const
    {
        return _required;
    }

    /**
     *  Name of the argument
     *  @return const char *
     */
    const char *name() const
    {
        return _name;
    }

    /**
     *  Type-hint for the argument
     *  @return Type
     */
    Type type() const
    {
        return _type;
    }

    /**
     *  If the type is a class, the name of the class
     *  @return const char *
     */
    const char *classname() const
    {
        return _classname;
    }

    /**
     *  Is it allowed to pass parameter with a null value?
     *  @return bool
     */
    bool allowNull() const
    {
        return _nullable;
    }

    /**
     *  Is this a parameter-by-reference?
     *  @return bool
     */
    bool byReference() const
    {
        return _byReference;
    }

private:
    /**
     *  Name of the argument
     *  @var const char *
     */
    const char *_name = nullptr;

    /**
     *  Type of argument
     *  @var Type
     */
    Type _type = Type::Null;

    /**
     *  Classname, if this is a parameter that is supposed to be an instance of a class
     *  @var std::string
     */
    const char *_classname = nullptr;

    /**
     *  May the parameter be null?
     *  @var bool
     */
    bool _nullable = false;

    /**
     *  Is this a required argument
     *  @var    bool
     */
    bool _required = true;

    /**
     *  Is this a 'by-reference' parameter?
     *  @var    bool
     */
    bool _byReference = false;
};

/**
 *  Old Visual C++ environments do not support initializer lists
 */
#if defined(_MSC_VER) && _MSC_VER < 1800

/**
 *  For old visual c++ compilers, arguments should be passed as vectors
 */
using Arguments = std::vector<Argument>;

/**
 *  Other compilers, and visual C++ 2013 do support initializer lists
 */
#else

/**
 *  A list of arguments can be supplied to methods
 *  @type   Arguments
 */
using Arguments = std::initializer_list<Argument>;

/**
 *  End of visual C++ check
 */
#endif


/**
 *  End of namespace
 */
}