-
Notifications
You must be signed in to change notification settings - Fork 0
/
construct.h
128 lines (110 loc) · 1.98 KB
/
construct.h
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
constructor var () {
type = varNull; ref = 0;
tmp_charp = 0;
}
~var () {
unref();
}
constructor var (const var& a) {
type = varNull; ref = 0;
copy(a);
}
constructor var (const varSyntax syntax) {
//type = varNull; //not needed because ref=0 means no unref()
ref = 0;
self = syntax;
}
void operator = (const varSyntax syntax) {
if (ref) unref();
if (syntax == Array) {
type = varArr;
ref = new Ref;
ref->data = newLst();
} else if (syntax == Object) {
type = varObj;
ref = new Ref;
ref->data = newObj();
} else if (syntax == argIgnore) {
type = varIgnore;
} else {
type = varNull;
}
//TODO: other types (and wrong values like NaN, undefined)
}
void operator = (const var &a) {
unref();
copy(a);
}
constructor var (int a) {
self = (double) a;
}
constructor var (long a) {
self = (double) a;
}
constructor var (bool a) {
type = varBool;
ref = 0;
num = (double)a;
}
void operator = (int a) { self = (var)a;}
void operator = (bool a) { self = (var)a;}
void operator = (double a) {
num = a;
type = varNum;
}
constructor var (char* a) {
ref = 0;
self = a;
}
constructor var (const char* a) {
ref = 0;
self = (char*)a;
}
constructor var (jschar* a) {
ref = 0;
self = a;
}
constructor var (double a) {
self = a;
}
void operator = (char* a) {
if (ref) unref();
makeStringToSet();
_chr().setUtf(a);
// printf("SET '%s'\n", a);
//_chr().setAscii(a);
}
void setUtf (char* a, int size = -1) {
if (ref) unref();
makeStringToSet();
_chr().setUtf(a, size);
}
void operator = (jschar* a) {
if (ref) unref();
makeStringToSet();
_chr().set(a);
}
void copy(const var &a);
void unref() {
if (type == varNum || type == varNull || type == varBool) return;
else if (type == varStr) {
ref->uses--;
if (ref->uses == 0) {
delete (chr*)ref->data, delete ref;
}
}
else if (type == varArr) {
ref->uses--;
if (ref->uses == 0) {
deleteLst();
}
}
else if (type == varObj) {
ref->uses--;
if (ref->uses == 0) {
deleteObj();
}
}
type = varNull;
ref = 0;
}