summaryrefslogtreecommitdiff
path: root/src/argument.cpp
blob: fc9d720deb2246472937407cab42b6b7ba0eb0c7 (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
/**
 *  Argument.cpp
 *
 *  Implementation for the Argument class
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2013 Copernica BV
 */
#include "includes.h"

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

/**
 *  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::Argument(const std::string &name, const std::string &classname, bool null, bool ref)
{
    _refcount = new int[1];
    _info = new ArgInfo(name, classname, null, ref);
}

/**
 *  Constructor if the argument can be anything
 *  Note that only arrayType and callableType are supported type-hints
 *  @param  name        Name of the argument
 *  @param  type        Type hint (arrayType or callableType)
 *  @param  ref         Is this a pass-by-reference argument?
 */
Argument::Argument(const std::string &name, Type type, bool ref)
{
    _refcount = new int[1];
    _info = new ArgInfo(name, type, ref);
}

/**
 *  Constructor if the argument can be anything
 *  @param  name        Name of the argument
 *  @param  ref         Is this a pass-by-reference argument?
 */
Argument::Argument(const std::string &name, bool ref)
{
    _refcount = new int[1];
    _info = new ArgInfo(name, ref);
}

/**
 *  Clean up the object
 */
void Argument::cleanup()
{
    // one reference less
    (*_refcount)--;
    
    // leap out if still in use
    if (*_refcount > 0) return;
    
    // release memory
    delete _refcount;
    delete _info;
}

/**
 *  End of namespace
 */
}