16 using namespace shogun;
18 SerializableJsonReader00::SerializableJsonReader00(
19 CSerializableJsonFile* file) { m_file = file; }
21 SerializableJsonReader00::~SerializableJsonReader00() {}
24 SerializableJsonReader00::read_scalar_wrapped(
27 json_object* m = m_file->m_stack_stream.back();
31 if (!json_object_is_type(m, json_type_boolean))
return false;
32 *(
bool*) param = json_object_get_boolean(m);
35 if (!json_object_is_type(m, json_type_int))
return false;
36 *(
char*) param = json_object_get_int(m);
39 if (!json_object_is_type(m, json_type_int))
return false;
40 *(int8_t*) param = json_object_get_int(m);
43 if (!json_object_is_type(m, json_type_int))
return false;
44 *(uint8_t*) param = json_object_get_int(m);
47 if (!json_object_is_type(m, json_type_int))
return false;
48 *(int16_t*) param = json_object_get_int(m);
51 if (!json_object_is_type(m, json_type_int))
return false;
52 *(uint16_t*) param = json_object_get_int(m);
55 if (!json_object_is_type(m, json_type_int))
return false;
56 *(int32_t*) param = json_object_get_int(m);
59 if (!json_object_is_type(m, json_type_int))
return false;
60 *(uint32_t*) param = json_object_get_int(m);
63 if (!json_object_is_type(m, json_type_int))
return false;
64 *(int64_t*) param = json_object_get_int(m);
67 if (!json_object_is_type(m, json_type_int))
return false;
68 *(uint64_t*) param = json_object_get_int(m);
71 if (!json_object_is_type(m, json_type_double))
return false;
72 *(
float32_t*) param = json_object_get_double(m);
75 if (!json_object_is_type(m, json_type_double))
return false;
76 *(
float64_t*) param = json_object_get_double(m);
79 if (!json_object_is_type(m, json_type_double))
return false;
80 *(
floatmax_t*) param = json_object_get_double(m);
83 SG_ERROR(
"write_scalar_wrapped(): Implementation error during"
84 " writing JsonFile!");
92 SerializableJsonReader00::read_cont_begin_wrapped(
95 json_object* m = m_file->m_stack_stream.back();
97 if (!json_object_is_type(m, json_type_array))
return false;
99 *len_read_y = json_object_array_length(m);
102 *len_read_x = *len_read_y;
103 for (
index_t i=0; i<*len_read_x; i++) {
104 json_object* buf = json_object_array_get_idx(m, i);
105 if (!json_object_is_type(buf, json_type_array))
108 index_t len = json_object_array_length(buf);
109 if (i == 0) *len_read_y = len;
110 else if (*len_read_y != len)
return false;
118 SerializableJsonReader00::read_cont_end_wrapped(
125 SerializableJsonReader00::read_string_begin_wrapped(
128 json_object* m = m_file->m_stack_stream.back();
130 if (!json_object_is_type(m, json_type_array))
return false;
132 *length = json_object_array_length(m);
138 SerializableJsonReader00::read_string_end_wrapped(
145 SerializableJsonReader00::read_stringentry_begin_wrapped(
148 json_object* m = m_file->m_stack_stream.back();
150 json_object* buf = json_object_array_get_idx(m, y);
151 if (is_error(buf))
return false;
153 m_file->push_object(buf);
158 SerializableJsonReader00::read_stringentry_end_wrapped(
161 m_file->pop_object();
166 SerializableJsonReader00::read_sparse_begin_wrapped(
169 json_object* m = m_file->m_stack_stream.back();
171 if (!json_object_is_type(m, json_type_object))
return false;
174 if (!m_file->get_object(&buf, m, STR_KEY_SPARSE_FEATURES,
175 json_type_array))
return false;
176 *length = json_object_array_length(buf);
177 m_file->push_object(buf);
183 SerializableJsonReader00::read_sparse_end_wrapped(
186 m_file->pop_object();
191 SerializableJsonReader00::read_sparseentry_begin_wrapped(
195 json_object* m = m_file->m_stack_stream.back();
198 = json_object_array_get_idx(m, y);
199 if (is_error(buf_obj))
return false;
200 if (!json_object_is_type(buf_obj, json_type_object))
return false;
203 if (!m_file->get_object(&buf, buf_obj, STR_KEY_SPARSE_FEATINDEX,
204 json_type_int))
return false;
205 *feat_index = json_object_get_int(buf);
207 if (!m_file->get_object_any(&buf, buf_obj, STR_KEY_SPARSE_ENTRY))
209 m_file->push_object(buf);
215 SerializableJsonReader00::read_sparseentry_end_wrapped(
219 m_file->pop_object();
224 SerializableJsonReader00::read_item_begin_wrapped(
227 json_object* m = m_file->m_stack_stream.back();
230 m = json_object_array_get_idx(m, x);
231 m = json_object_array_get_idx(m, y);
233 m_file->push_object(m);
238 SerializableJsonReader00::read_item_end_wrapped(
241 m_file->pop_object();
246 SerializableJsonReader00::read_sgserializable_begin_wrapped(
247 const TSGDataType* type,
char* sgserializable_name,
248 EPrimitiveType*
generic)
250 json_object* m = m_file->m_stack_stream.back();
252 if (m == NULL || json_object_is_type(m, json_type_null)) {
253 *sgserializable_name =
'\0';
return true;
256 if (!json_object_is_type(m, json_type_object))
return false;
259 if (!m_file->get_object(&buf, m, STR_KEY_INSTANCE_NAME,
260 json_type_string))
return false;
261 strncpy(sgserializable_name, json_object_get_string(buf),
264 if (m_file->get_object(&buf, m, STR_KEY_GENERIC_NAME,
267 generic, json_object_get_string(buf)))
return false;
270 if (!m_file->get_object(&buf, m, STR_KEY_INSTANCE,
271 json_type_object))
return false;
272 m_file->push_object(buf);
278 SerializableJsonReader00::read_sgserializable_end_wrapped(
279 const TSGDataType* type,
const char* sgserializable_name,
280 EPrimitiveType
generic)
282 if (*sgserializable_name ==
'\0')
return true;
284 m_file->pop_object();
289 SerializableJsonReader00::read_type_begin_wrapped(
290 const TSGDataType* type,
const char* name,
const char* prefix)
292 json_object* m = m_file->m_stack_stream.back();
294 if (!json_object_is_type(m, json_type_object))
return false;
296 json_object* buf_type;
297 if (!m_file->get_object(&buf_type, m, name, json_type_object))
302 if (!m_file->get_object(&buf, buf_type, STR_KEY_TYPE,
303 json_type_string))
return false;
304 if (strcmp(str_buf, json_object_get_string(buf)) != 0)
307 if (!m_file->get_object_any(&buf, buf_type, STR_KEY_DATA))
309 m_file->push_object(buf);
315 SerializableJsonReader00::read_type_end_wrapped(
316 const TSGDataType* type,
const char* name,
const char* prefix)
318 m_file->pop_object();