summaryrefslogtreecommitdiff
path: root/src/variable.cpp
blob: 47352674bed01ca1829fabdd940cd9501aa07bde (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/**
 *  Variable.cpp
 *
 *  Implementation for the Variable class, which wraps a PHP userspace 
 *  variable (a 'zval' in Zend's terminology) into a C++ object
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2013 Copernica BV
 */
#include "includes.h"

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

/**
 *  Constructor (value = NULL)
 */
Variable::Variable()
{
    // create a null zval
    MAKE_STD_ZVAL(_val);
    ZVAL_NULL(_val);
}

/**
 *  Constructor based on integer value
 *  @param  value
 */
Variable::Variable(int value)
{
    // create an integer zval
    MAKE_STD_ZVAL(_val);
    ZVAL_LONG(_val, value);
}

/**
 *  Constructor based on boolean value
 *  @param  value
 */
Variable::Variable(bool value)
{
    // create a boolean zval
    MAKE_STD_ZVAL(_val);
    ZVAL_BOOL(_val, value);
}

/**
 *  Constructor based on string value
 *  @param  value
 */
Variable::Variable(const std::string &value)
{
    // create a string zval
    MAKE_STD_ZVAL(_val);
    ZVAL_STRINGL(_val, value.c_str(), value.size(), 1);
}

/**
 *  Constructor based on decimal value
 *  @param  value
 */
Variable::Variable(double value)
{
    // create a double zval
    MAKE_STD_ZVAL(_val);
    ZVAL_DOUBLE(_val, value);
}

/**
 *  Wrap object around zval
 *  @param  zval
 */
Variable::Variable(struct _zval_struct *zval)
{
    // just copy the zval into this object
    _val = zval;
}

/**
 *  Copy constructor
 *  @param  value
 */
Variable::Variable(const Variable &that)
{
    // @todo implementation, what should we do 
    
    
}

/**
 *  Destructor
 */
Variable::~Variable()
{
    // @todo implementation
    
}

/**
 *  Assignment operator
 *  @param  value
 *  @return Variable
 */
Variable &Variable::operator=(const Variable &value)
{
    // skip self assignment
    if (this == &value) return *this;
    
    // @todo implementation
    

    // done
    return *this;
}

/**
 *  Assignment operator
 *  @param  value
 *  @return Variable
 */
Variable &Variable::operator=(int value)
{
    // @todo implementation
    
    // done
    return *this;
}

/**
 *  Assignment operator
 *  @param  value
 *  @return Variable
 */
Variable &Variable::operator=(bool value)
{
    // @todo implementation
    
    
    // done
    return *this;
}

/**
 *  Assignment operator
 *  @param  value
 *  @return Variable
 */
Variable &Variable::operator=(const std::string &value)
{
    // @todo implementation
    
    
    // done
    return *this;
}

/**
 *  Assignment operator
 *  @param  value
 *  @return Variable
 */
Variable &Variable::operator=(double value)
{
    // @todo implementation
    
    
    // done
    return *this;
}

/**
 *  The type of object
 *  @return Type
 */
Type Variable::type()
{
    return (Type)Z_TYPE_P(_val);
}

/**
 *  Change the internal type
 *  @param  type
 */
void Variable::setType(Type type)
{
    // @todo implementation
    
}

/**
 *  Is this a NULL value?
 *  @return bool
 */
bool Variable::isNull()
{
    return Z_TYPE_P(_val) == IS_NULL;
}

/**
 *  Is this an integer value?
 *  @return bool
 */
bool Variable::isInt()
{
    return Z_TYPE_P(_val) == IS_LONG;
}

/**
 *  Is this a boolean value?
 *  @return bool
 */
bool Variable::isBool()
{
    return Z_TYPE_P(_val) == IS_BOOL;
}

/**
 *  Is this a string value?
 *  @return bool
 */
bool Variable::isString()
{
    return Z_TYPE_P(_val) == IS_STRING;
}

/**
 *  Is this a decimal value?
 *  @return bool
 */
bool Variable::isDecimal()
{
    return Z_TYPE_P(_val) == IS_DOUBLE;
}

/**
 *  Is this an object value?
 *  @return bool
 */
bool Variable::isObject()
{
    return Z_TYPE_P(_val) == IS_OBJECT;
}

/**
 *  Is this an array value?
 *  @return bool
 */
bool Variable::isArray()
{
    return Z_TYPE_P(_val) == IS_ARRAY;
}

/**
 *  Retrieve the value as integer
 *  @return int
 */
int Variable::intValue()
{
    // @todo implementation
}

/**
 *  Retrieve the value as boolean
 *  @return bool
 */
bool Variable::boolValue()
{
    // @todo implementation
}

/**
 *  Retrieve the value as string
 *  @return string
 */
std::string Variable::stringValue()
{
    // @todo implementation
}

/**
 *  End of namespace
 */
}