-
Notifications
You must be signed in to change notification settings - Fork 9
/
value.h
355 lines (294 loc) · 10.2 KB
/
value.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
//
// AYA version 5
//
// 値を扱うクラス CValue/CValueSub
// written by umeici. 2004
//
// CValueは型フラグと型別の情報を持っています。その中にvector<CValueSub>という可変長配列があり、
// これが汎用配列となります。CValueSubクラスは配列を持たないほかはCValueと類似しています(汎用
// 配列を多次元化出来ない、というAYA5の制限はこの構造に由来しています)。
//
#ifndef VALUEH
#define VALUEH
//----
#if defined(WIN32) || defined(_WIN32_WCE)
# include "stdafx.h"
#endif
#include <vector>
#include <memory>
//modified by Neo 2015.oct
#include <climits>
//modified by Neo 2015.oct
#include "manifest.h"
#include "globaldef.h"
class CValue;
class CValueSub;
typedef std::vector<CValueSub> CValueArray;
class CValueSub
{
friend class CValue;
protected:
int type; // 型
public:
yaya::string_t s_value; // 文字列値
double d_value; // 実数値
yaya::int_t i_value; // 整数値
private:
int CalcEscalationTypeNum(const int rhs) const;
int CalcEscalationTypeStr(const int rhs) const;
public:
CValueSub(void) :
type(F_TAG_VOID) , s_value(), d_value(0.0), i_value(0) { }
CValueSub(int value) :
type(F_TAG_INT) , d_value(0.0) , i_value(value) { }
CValueSub(yaya::int_t value) :
type(F_TAG_INT) , d_value(0.0) , i_value(value) { }
CValueSub(double value) :
type(F_TAG_DOUBLE) , d_value(value), i_value(0) { }
CValueSub(const yaya::string_t &value) :
type(F_TAG_STRING) , s_value(value), d_value(0.0), i_value(0) { }
CValueSub(const yaya::char_t *value) :
type(F_TAG_STRING) , s_value(value), d_value(0.0), i_value(0) { }
CValueSub(const CValue &v);
~CValueSub(void) {}
inline int GetType(void) const { return type; }
inline void SetType(int tp) { type = tp; }
inline bool IsVoid(void) const { return type == F_TAG_VOID; }
inline bool IsString(void) const { return type == F_TAG_STRING || type == F_TAG_VOID; }
inline bool IsStringReal(void) const { return type == F_TAG_STRING; }
inline bool IsInt(void) const { return type == F_TAG_INT || type == F_TAG_VOID; }
inline bool IsIntReal(void) const { return type == F_TAG_INT; }
inline bool IsDouble(void) const { return type == F_TAG_DOUBLE || type == F_TAG_VOID; }
inline bool IsDoubleReal(void) const { return type == F_TAG_DOUBLE; }
inline bool IsNum(void) const { return type == F_TAG_INT || type == F_TAG_DOUBLE || type == F_TAG_VOID; }
yaya::int_t GetValueInt(void) const;
double GetValueDouble(void) const;
yaya::string_t GetValueString(void) const;
CValueSub &operator =(yaya::int_t value) LVALUE_MODIFIER;
CValueSub &operator =(double value) LVALUE_MODIFIER;
CValueSub &operator =(const yaya::string_t &value) LVALUE_MODIFIER;
#if CPP_STD_VER > 2011
CValueSub &operator =(yaya::string_t&& value) LVALUE_MODIFIER;
#endif
CValueSub &operator =(const yaya::char_t *value) LVALUE_MODIFIER;
CValueSub &operator =(const CValue &v) LVALUE_MODIFIER;
CValueSub operator +(const CValueSub &value) const;
CValueSub operator -(const CValueSub &value) const;
CValueSub operator *(const CValueSub &value) const;
CValueSub operator /(const CValueSub &value) const;
CValueSub operator %(const CValueSub &value) const;
void operator +=(const CValueSub &value) LVALUE_MODIFIER;
void operator -=(const CValueSub &value) LVALUE_MODIFIER;
void operator *=(const CValueSub &value) LVALUE_MODIFIER;
void operator /=(const CValueSub &value) LVALUE_MODIFIER;
void operator %=(const CValueSub &value) LVALUE_MODIFIER;
inline bool operator ==(const CValueSub &value) const {
return Compare(value);
}
inline bool operator !=(const CValueSub &value) const {
return !operator==(value);
}
inline bool operator <(const CValueSub &value) const {
return Less(value);
}
bool Less(const CValueSub &value) const;
bool Compare(const CValueSub &value) const;
};
class CValue
{
friend class CValueSub;
protected:
int type; // 型
public:
yaya::string_t s_value; // 文字列値
double d_value; // 実数値
yaya::int_t i_value; // 整数値
private:
mutable std_shared_ptr<CValueArray> m_array; // 汎用配列
private:
int CalcEscalationTypeNum(const int rhs) const;
int CalcEscalationTypeStr(const int rhs) const;
int Compare(const CValue &value) const;
int Great(const CValue &value) const;
int Less(const CValue &value) const;
public:
CValue(const CValue &rhs)
{
type = rhs.type;
//i,dはサイズが小さいのでコピーしたほうが手っ取り早い
i_value = rhs.i_value;
d_value = rhs.d_value;
if ( type == F_TAG_ARRAY ) {
m_array = rhs.m_array;
}
else if ( type == F_TAG_STRING ) {
s_value = rhs.s_value;
}
}
CValue& operator =(const CValue &rhs)
{
type = rhs.type;
//i,dはサイズが小さいのでコピーしたほうが手っ取り早い
i_value = rhs.i_value;
d_value = rhs.d_value;
if ( type == F_TAG_ARRAY ) {
m_array = rhs.m_array;
}
else {
m_array.reset();
if ( type == F_TAG_STRING ) {
s_value = rhs.s_value;
}
}
return *this;
}
CValue(int value) :
type(F_TAG_INT) , d_value(0.0) , i_value(value) { }
CValue(yaya::int_t value) :
type(F_TAG_INT) , d_value(0.0) , i_value(value) { }
CValue(double value) :
type(F_TAG_DOUBLE) , d_value(value), i_value(0) { }
CValue(const yaya::string_t &value) :
type(F_TAG_STRING) , s_value(value), d_value(0.0), i_value(0) { }
CValue(const yaya::char_t *value) :
type(F_TAG_STRING) , s_value(value), d_value(0.0), i_value(0) { }
CValue(const CValueSub &value) : d_value(0.0), i_value(0)
{
switch(value.GetType()) {
case F_TAG_INT:
type = F_TAG_INT;
i_value = value.i_value;
break;
case F_TAG_DOUBLE:
type = F_TAG_DOUBLE;
d_value = value.d_value;
break;
case F_TAG_STRING:
type = F_TAG_STRING;
s_value = value.s_value;
break;
default:
type = F_TAG_VOID;
break;
};
}
CValue(int tp, int) : type(tp), d_value(0.0), i_value(0) { } // 型指定して初期化
CValue(void) : type(F_TAG_VOID), d_value(0.0), i_value(0) { }
~CValue(void) {}
inline void SetType(int tp) { type = tp; }
inline int GetType(void) const { return type; }
inline bool IsVoid(void) const { return type == F_TAG_VOID; }
inline bool IsString(void) const { return type == F_TAG_STRING || type == F_TAG_VOID; }
inline bool IsStringReal(void) const { return type == F_TAG_STRING; }
inline bool IsInt(void) const { return type == F_TAG_INT || type == F_TAG_VOID; }
inline bool IsIntReal(void) const { return type == F_TAG_INT; }
inline bool IsDouble(void) const { return type == F_TAG_DOUBLE || type == F_TAG_VOID; }
inline bool IsDoubleReal(void) const { return type == F_TAG_DOUBLE; }
inline bool IsArray(void) const { return type == F_TAG_ARRAY; }
inline bool IsNum(void) const { return type == F_TAG_INT || type == F_TAG_DOUBLE || type == F_TAG_VOID; }
bool GetTruth(void) const
{
switch(type) {
case F_TAG_VOID: return false;
case F_TAG_INT: return i_value != 0;
case F_TAG_DOUBLE: return d_value != 0.0;
case F_TAG_STRING: return s_value.size() != 0;
case F_TAG_ARRAY:
if( m_array.get() ) {
return m_array->size() != 0;
}
else {
return false;
}
default:
break;
};
return false;
}
yaya::int_t GetValueInt(void) const;
double GetValueDouble(void) const;
yaya::string_t GetValueString(void) const;
yaya::string_t GetValueStringForLogging(void) const;
void SetArrayValue(const CValue &oval, const CValue &value);
bool DecodeArrayOrder(size_t& order, size_t& order1, yaya::string_t& delimiter) const;
CValue &operator =(yaya::int_t value) LVALUE_MODIFIER;
CValue &operator =(double value) LVALUE_MODIFIER;
CValue &operator =(const yaya::string_t &value) LVALUE_MODIFIER;
#if CPP_STD_VER > 2011
CValue &operator =(yaya::string_t&& value) LVALUE_MODIFIER;
#endif
CValue &operator =(const yaya::char_t *value) LVALUE_MODIFIER;
CValue &operator =(const CValueArray &value) LVALUE_MODIFIER;
CValue &operator =(const CValueSub &value) LVALUE_MODIFIER;
void SubstToArray(CValueArray &value) LVALUE_MODIFIER;
CValue operator +(const CValue &value) const;
CValue operator -(const CValue &value) const;
CValue operator *(const CValue &value) const;
CValue operator /(const CValue &value) const;
CValue operator %(const CValue &value) const;
void operator +=(const CValue &value) LVALUE_MODIFIER;
void operator -=(const CValue &value) LVALUE_MODIFIER;
void operator *=(const CValue &value) LVALUE_MODIFIER;
void operator /=(const CValue &value) LVALUE_MODIFIER;
void operator %=(const CValue &value) LVALUE_MODIFIER;
CValue operator [](const CValue &value) const;
inline CValue operator ==(const CValue &value) const {
return CValue(Compare(value));
}
inline CValue operator !=(const CValue &value) const {
return CValue(1 - Compare(value));
}
inline CValue operator >(const CValue &value) const {
return CValue(Great(value));
}
inline CValue operator <=(const CValue &value) const {
return CValue(1 - Great(value));
}
inline CValue operator <(const CValue &value) const {
return CValue(Less(value));
}
inline CValue operator >=(const CValue &value) const {
return CValue(1 - Less(value));
}
inline CValue operator ||(const CValue &value) const {
return CValue(GetTruth() || value.GetTruth());
}
inline CValue operator && (const CValue &value) const {
return CValue(GetTruth() && value.GetTruth());
}
//////////////////////////////////////////////
CValueArray::size_type array_size(void) const {
if ( ! m_array.get() ) {
return 0;
}
else {
return m_array->size();
}
}
std_shared_ptr<CValueArray> &array_shared(void) const {
return m_array;
}
const CValueArray& array(void) const {
if( ! m_array.get() ) {
m_array=std_make_shared<CValueArray>();
}
return *m_array;
}
CValueArray& array(void) {
if( ! m_array.get() ) {
m_array=std_make_shared<CValueArray>();
}
else if ( m_array.use_count() >= 2 ) {
CValueArray *pV = m_array.get();
m_array=std_make_shared<CValueArray>(*pV);
}
return *m_array;
}
inline void array_clear(void) {
m_array.reset();
}
};
//----
//からっぽ変数(ダミー用)
extern const CValue emptyvalue;
#endif