-
Notifications
You must be signed in to change notification settings - Fork 0
/
value.cpp
101 lines (100 loc) · 2.35 KB
/
value.cpp
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
#include "value.hpp"
using namespace Asago;
Value::~Value()
{
if (dispose == true)
{
delete result;
delete array_values;
delete mapped_values;
}
};
Value::Value(bool tf)
{
this->value_type = ValueType::BOOL;
this->result = new char[1];
this->result_sz = 1;
this->result[0] = (int)tf;
}
Value::Value(std::string value)
{
this->value_type = ValueType::STRING;
this->result = new char[value.size() + 1];
this->result_sz = value.size() + 1; // include "\0"
memcpy(this->result, value.c_str(), value.size() + 1);
}
Value::Value(double value)
{
this->value_type = ValueType::DOUBLE;
this->result = new char[sizeof(value)];
this->result_sz = sizeof(value);
memcpy(this->result, &value, sizeof(value));
}
Value::Value(int32_t value)
{
this->value_type = ValueType::NUMBER;
this->result = new char[sizeof(value)];
this->result_sz = sizeof(value);
memcpy(this->result, &value, sizeof(value));
}
Value::Value(char *arr, size_t sz, ValueType val_type, bool copy)
{
this->value_type = val_type;
this->result_sz = sz;
if (copy)
{
this->result = new char[sz];
memcpy(arr, this->result, sz);
}
else
{
this->result = arr;
}
this->result = arr;
}
Value::Value(Value *val, bool copy)
{
this->value_type = val->value_type;
this->result_sz = val->result_sz;
if (val->value_type == ValueType::ARRAY)
{
if (copy)
{
this->array_values = new std::vector<Value *>();
auto &values = *val->array_values;
for (size_t i = 0; i < values.size(); i++)
{
this->array_values->push_back(new Value(values[i], copy));
}
}
else
{
this->array_values = val->array_values;
}
}
else if (val->value_type == ValueType::OBJ)
{
if (copy)
{
// implement this!
this->mapped_values = val->mapped_values;
}
else
{
this->mapped_values = val->mapped_values;
}
}
else
{
if (copy)
{
this->result = new char[result_sz];
memcpy(this->result, val->result, result_sz);
}
else
{
this->result = val->result;
}
this->array_values = val->array_values;
}
}