forked from sfelixwu/ecs36b_s2024_master
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.cpp
169 lines (141 loc) · 3.87 KB
/
Core.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
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
#include "Core.h"
unsigned int Core::core_count { };
Core::Core
(void)
{
core_count++;
host_url = "";
class_name = "Core";
object_id = "";
owner_vsID = "";
}
Core::Core
(std::string arg_host_url, std::string arg_class_name, std::string arg_object_id)
: host_url { arg_host_url }, class_name { arg_class_name },
object_id { arg_object_id }
{
core_count++;
owner_vsID = "";
}
Json::Value *
Core::dump2JSON
(void)
{
Json::Value * result_ptr = new Json::Value();
if (this->host_url != "")
{
(*result_ptr)["host url"] = this->host_url;
}
(*result_ptr)["class name"] = this->class_name;
if (this->object_id != "")
{
(*result_ptr)["object id"] = this->object_id;
}
if (this->owner_vsID != "")
{
(*result_ptr)["owner vsID"] = this->owner_vsID;
}
return result_ptr;
}
void
Core::JSON2Object
(Json::Value * arg_json_ptr)
{
Exception_Info * ei_ptr = NULL;
ecs36b_Exception * lv_exception_ptr = new ecs36b_Exception {};
JSON2Object_precheck(arg_json_ptr, lv_exception_ptr,
ECS36B_ERROR_JSON2OBJECT_CORE);
if (((*arg_json_ptr)["host url"].isNull() == true) ||
((*arg_json_ptr)["host url"].isString() == false))
{
ei_ptr = new Exception_Info {};
ei_ptr->where_code = ECS36B_ERROR_JSON2OBJECT_CORE;
ei_ptr->which_string = "host url";
ei_ptr->how_code = ECS36B_ERROR_NORMAL;
if ((*arg_json_ptr)["host url"].isNull() == true)
{
ei_ptr->what_code = ECS36B_ERROR_JSON_KEY_MISSING;
}
else
{
ei_ptr->what_code = ECS36B_ERROR_JSON_KEY_TYPE_MISMATCHED;
}
ei_ptr->array_index = 0;
(lv_exception_ptr->info_vector).push_back(ei_ptr);
}
else
{
this->host_url = ((*arg_json_ptr)["host url"]).asString();
}
if (((*arg_json_ptr)["class name"].isNull() == true) ||
((*arg_json_ptr)["class name"].isString() == false))
{
ei_ptr = new Exception_Info {};
ei_ptr->where_code = ECS36B_ERROR_JSON2OBJECT_CORE;
ei_ptr->which_string = "class name";
ei_ptr->how_code = ECS36B_ERROR_NORMAL;
if ((*arg_json_ptr)["class name"].isNull() == true)
{
ei_ptr->what_code = ECS36B_ERROR_JSON_KEY_MISSING;
}
else
{
ei_ptr->what_code = ECS36B_ERROR_JSON_KEY_TYPE_MISMATCHED;
}
ei_ptr->array_index = 0;
(lv_exception_ptr->info_vector).push_back(ei_ptr);
}
else
{
this->class_name = ((*arg_json_ptr)["class name"]).asString();
}
if (((*arg_json_ptr)["object id"].isNull() == true) ||
((*arg_json_ptr)["object id"].isString() == false))
{
ei_ptr = new Exception_Info {};
ei_ptr->where_code = ECS36B_ERROR_JSON2OBJECT_CORE;
ei_ptr->which_string = "object id";
ei_ptr->how_code = ECS36B_ERROR_NORMAL;
if ((*arg_json_ptr)["object id"].isNull() == true)
{
ei_ptr->what_code = ECS36B_ERROR_JSON_KEY_MISSING;
}
else
{
ei_ptr->what_code = ECS36B_ERROR_JSON_KEY_TYPE_MISMATCHED;
}
ei_ptr->array_index = 0;
(lv_exception_ptr->info_vector).push_back(ei_ptr);
}
else
{
this->object_id = ((*arg_json_ptr)["object id"]).asString();
}
if (((*arg_json_ptr)["owner vsID"].isNull() == true) ||
((*arg_json_ptr)["owner vsID"].isString() == false))
{
ei_ptr = new Exception_Info {};
ei_ptr->where_code = ECS36B_ERROR_JSON2OBJECT_CORE;
ei_ptr->which_string = "owner vsID";
ei_ptr->how_code = ECS36B_ERROR_NORMAL;
if ((*arg_json_ptr)["owner vsID"].isNull() == true)
{
ei_ptr->what_code = ECS36B_ERROR_JSON_KEY_MISSING;
}
else
{
ei_ptr->what_code = ECS36B_ERROR_JSON_KEY_TYPE_MISMATCHED;
}
ei_ptr->array_index = 0;
(lv_exception_ptr->info_vector).push_back(ei_ptr);
}
else
{
this->owner_vsID = ((*arg_json_ptr)["owner vsID"]).asString();
}
if ((lv_exception_ptr->info_vector).size() != 0)
{
throw (*lv_exception_ptr);
}
return;
}