16 using namespace shogun;
18 SerializableJsonReader00::SerializableJsonReader00(
19 CSerializableJsonFile* file) { m_file = file; }
21 SerializableJsonReader00::~SerializableJsonReader00()
26 SerializableJsonReader00::read_scalar_wrapped(
29 json_object* m = m_file->m_stack_stream.back();
33 if (!json_object_is_type(m, json_type_boolean))
return false;
34 *(
bool*) param = json_object_get_boolean(m);
37 if (!json_object_is_type(m, json_type_int))
return false;
38 *(
char*) param = json_object_get_int(m);
41 if (!json_object_is_type(m, json_type_int))
return false;
42 *(int8_t*) param = json_object_get_int(m);
45 if (!json_object_is_type(m, json_type_int))
return false;
46 *(uint8_t*) param = json_object_get_int(m);
49 if (!json_object_is_type(m, json_type_int))
return false;
50 *(int16_t*) param = json_object_get_int(m);
53 if (!json_object_is_type(m, json_type_int))
return false;
54 *(uint16_t*) param = json_object_get_int(m);
57 if (!json_object_is_type(m, json_type_int))
return false;
58 *(int32_t*) param = json_object_get_int(m);
61 if (!json_object_is_type(m, json_type_int))
return false;
62 *(uint32_t*) param = json_object_get_int(m);
65 if (!json_object_is_type(m, json_type_int))
return false;
66 *(int64_t*) param = json_object_get_int(m);
69 if (!json_object_is_type(m, json_type_int))
return false;
70 *(uint64_t*) param = json_object_get_int(m);
73 if (!json_object_is_type(m, json_type_double))
return false;
74 *(
float32_t*) param = json_object_get_double(m);
77 if (!json_object_is_type(m, json_type_double))
return false;
78 *(
float64_t*) param = json_object_get_double(m);
81 if (!json_object_is_type(m, json_type_double))
return false;
82 *(
floatmax_t*) param = json_object_get_double(m);
85 SG_ERROR(
"read_scalar_wrapped(): Not supported for complex128_t"
86 " for reading from JsonFile!");
89 SG_ERROR(
"read_scalar_wrapped(): Implementation error during"
90 " reading JsonFile!");
98 SerializableJsonReader00::read_cont_begin_wrapped(
101 json_object* m = m_file->m_stack_stream.back();
103 if (!json_object_is_type(m, json_type_array))
return false;
105 *len_read_y = json_object_array_length(m);
108 *len_read_x = *len_read_y;
109 for (
index_t i=0; i<*len_read_x; i++) {
110 json_object* buf = json_object_array_get_idx(m, i);
111 if (!json_object_is_type(buf, json_type_array))
114 index_t len = json_object_array_length(buf);
115 if (i == 0) *len_read_y = len;
116 else if (*len_read_y != len)
return false;
124 SerializableJsonReader00::read_cont_end_wrapped(
131 SerializableJsonReader00::read_string_begin_wrapped(
134 json_object* m = m_file->m_stack_stream.back();
136 if (!json_object_is_type(m, json_type_array))
return false;
138 *length = json_object_array_length(m);
144 SerializableJsonReader00::read_string_end_wrapped(
151 SerializableJsonReader00::read_stringentry_begin_wrapped(
154 json_object* m = m_file->m_stack_stream.back();
156 json_object* buf = json_object_array_get_idx(m, y);
157 if (is_error(buf))
return false;
159 m_file->push_object(buf);
164 SerializableJsonReader00::read_stringentry_end_wrapped(
167 m_file->pop_object();
172 SerializableJsonReader00::read_sparse_begin_wrapped(
175 json_object* m = m_file->m_stack_stream.back();
177 if (!json_object_is_type(m, json_type_object))
return false;
180 if (!m_file->get_object(&buf, m, STR_KEY_SPARSE_FEATURES,
181 json_type_array))
return false;
182 *length = json_object_array_length(buf);
183 m_file->push_object(buf);
189 SerializableJsonReader00::read_sparse_end_wrapped(
192 m_file->pop_object();
197 SerializableJsonReader00::read_sparseentry_begin_wrapped(
201 json_object* m = m_file->m_stack_stream.back();
204 = json_object_array_get_idx(m, y);
205 if (is_error(buf_obj))
return false;
206 if (!json_object_is_type(buf_obj, json_type_object))
return false;
209 if (!m_file->get_object(&buf, buf_obj, STR_KEY_SPARSE_FEATINDEX,
210 json_type_int))
return false;
211 *feat_index = json_object_get_int(buf);
213 if (!m_file->get_object_any(&buf, buf_obj, STR_KEY_SPARSE_ENTRY))
215 m_file->push_object(buf);
221 SerializableJsonReader00::read_sparseentry_end_wrapped(
225 m_file->pop_object();
230 SerializableJsonReader00::read_item_begin_wrapped(
233 json_object* m = m_file->m_stack_stream.back();
236 m = json_object_array_get_idx(m, x);
237 m = json_object_array_get_idx(m, y);
239 m_file->push_object(m);
244 SerializableJsonReader00::read_item_end_wrapped(
247 m_file->pop_object();
252 SerializableJsonReader00::read_sgserializable_begin_wrapped(
253 const TSGDataType* type,
char* sgserializable_name,
254 EPrimitiveType*
generic)
256 json_object* m = m_file->m_stack_stream.back();
258 if (m == NULL || json_object_is_type(m, json_type_null)) {
259 *sgserializable_name =
'\0';
return true;
262 if (!json_object_is_type(m, json_type_object))
return false;
265 if (!m_file->get_object(&buf, m, STR_KEY_INSTANCE_NAME,
266 json_type_string))
return false;
267 strncpy(sgserializable_name, json_object_get_string(buf),
270 if (m_file->get_object(&buf, m, STR_KEY_GENERIC_NAME,
273 generic, json_object_get_string(buf)))
return false;
276 if (!m_file->get_object(&buf, m, STR_KEY_INSTANCE,
277 json_type_object))
return false;
278 m_file->push_object(buf);
284 SerializableJsonReader00::read_sgserializable_end_wrapped(
285 const TSGDataType* type,
const char* sgserializable_name,
286 EPrimitiveType
generic)
288 if (*sgserializable_name ==
'\0')
return true;
290 m_file->pop_object();
295 SerializableJsonReader00::read_type_begin_wrapped(
296 const TSGDataType* type,
const char* name,
const char* prefix)
298 json_object* m = m_file->m_stack_stream.back();
300 if (!json_object_is_type(m, json_type_object))
return false;
302 json_object* buf_type;
303 if (!m_file->get_object(&buf_type, m, name, json_type_object))
308 if (!m_file->get_object(&buf, buf_type, STR_KEY_TYPE,
309 json_type_string))
return false;
310 if (strcmp(str_buf, json_object_get_string(buf)) != 0)
314 m_file->get_object_any(&buf, buf_type, STR_KEY_DATA);
315 m_file->push_object(buf);
321 SerializableJsonReader00::read_type_end_wrapped(
322 const TSGDataType* type,
const char* name,
const char* prefix)
324 m_file->pop_object();