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
|
/**
* Object.h
*
* Extended Value that can be used to instantiate new objects, and to turn
* Php::Base objects into regular Php::Value instances
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2014 Copernica BV
*/
/**
* Set up namespace
*/
namespace Php {
/**
* Class definition
*/
class Object : public Value
{
public:
/**
* Constructor for an empty stdClass object
*/
Object() : Value() { setType(Type::Object); }
/**
* Move constructor is passed to the parent
* @param value
*/
Object(Value &&value) : Value(std::move(value))
{
// throw exception in case of problems
if (value.type() != Type::Object) throw Php::Exception("Constructing an object variable by moving a non object");
}
/**
* Copy constructor is valid if the passed in object is also an object,
* or when it is a string holding a classname
* @param that An other object
*/
Object(const Value &value) : Value()
{
// string types are instantiated
if (value.isString()) instantiate(value);
// otherwise copy the other object
else operator=(value);
}
/**
* Constructor to create a new instance
*
* This constructor comes in many different forms, to support all possible
* number of parameters that are passed to the constructor
*
* @param name Name of the class to instantiate
* @param arg0 Optional argument 1
* @param arg1 Optional argument 2
* @param arg2 Optional argument 3
* @param arg3 Optional argument 4
* @param arg4 Optional argument 5
* @param arg5 Optional argument 6
* @param arg6 Optional argument 7
* @param arg7 Optional argument 8
* @param arg8 Optional argument 9
* @param arg9 Optional argument 10
*/
Object(const char *name) { instantiate(name); call("__construct"); }
Object(const char *name, Value p0) { instantiate(name); call("__construct", p0); }
Object(const char *name, Value p0, Value p1) { instantiate(name); call("__construct", p0, p1); }
Object(const char *name, Value p0, Value p1, Value p2) { instantiate(name); call("__construct", p0, p1, p2); }
Object(const char *name, Value p0, Value p1, Value p2, Value p3) { instantiate(name); call("__construct", p0, p1, p2, p3); }
Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4) { instantiate(name); call("__construct", p0, p1, p2, p3, p4); }
Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5); }
Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5, p6); }
Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5, p6, p7); }
Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5, p6, p7, p8); }
Object(const char *name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9) { instantiate(name); call("__construct", p0, p1, p2, p3, p4, p5, p6, p7, p8, p9); }
/**
* Destructor
*/
virtual ~Object() {}
/**
* Change the internal type of the variable
* @param Type
*/
virtual Value &setType(Type type) override
{
// throw exception if things are going wrong
if (type != Type::Object) throw Php::Exception("Changing type of a fixed object variable");
// call base
return Value::setType(type);
}
/**
* Assignment operator
* @param value
* @return ForcedValue
*/
Object &operator=(const Value &value)
{
// skip self assignment
if (this == &value) return *this;
// type must be valid
if (value.type() != Type::Object) throw Php::Exception("Assiging a non-object to an object variable");
// call base
Value::operator=(value);
// done
return *this;
}
/**
* Move assignment operator
* @param value
* @return ForcedValue
*/
Object &operator=(Value &&value)
{
// skip self assignment
if (this == &value) return *this;
// type must be valid
if (value.type() != Type::Object) throw Php::Exception("Moving a non-object to an object variable");
// call base
Value::operator=(std::move(value));
// done
return *this;
}
private:
/**
* Helper method to instantiate an object
* @param name Class name
*/
void instantiate(const char *name);
};
/**
* End namespace
*/
}
|