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!");
90 SG_ERROR(
"read_scalar_wrapped(): Implementation error during"
91 " reading JsonFile!");
99 SerializableJsonReader00::read_cont_begin_wrapped(
102 json_object* m = m_file->m_stack_stream.back();
104 if (!json_object_is_type(m, json_type_array))
return false;
106 *len_read_y = json_object_array_length(m);
109 *len_read_x = *len_read_y;
110 for (
index_t i=0; i<*len_read_x; i++) {
111 json_object* buf = json_object_array_get_idx(m, i);
112 if (!json_object_is_type(buf, json_type_array))
115 index_t len = json_object_array_length(buf);
116 if (i == 0) *len_read_y = len;
117 else if (*len_read_y != len)
return false;
125 SerializableJsonReader00::read_cont_end_wrapped(
132 SerializableJsonReader00::read_string_begin_wrapped(
135 json_object* m = m_file->m_stack_stream.back();
137 if (!json_object_is_type(m, json_type_array))
return false;
139 *length = json_object_array_length(m);
145 SerializableJsonReader00::read_string_end_wrapped(
152 SerializableJsonReader00::read_stringentry_begin_wrapped(
155 json_object* m = m_file->m_stack_stream.back();
157 json_object* buf = json_object_array_get_idx(m, y);
158 if (is_error(buf))
return false;
160 m_file->push_object(buf);
165 SerializableJsonReader00::read_stringentry_end_wrapped(
168 m_file->pop_object();
173 SerializableJsonReader00::read_sparse_begin_wrapped(
176 json_object* m = m_file->m_stack_stream.back();
178 if (!json_object_is_type(m, json_type_object))
return false;
181 if (!m_file->get_object(&buf, m, STR_KEY_SPARSE_FEATURES,
182 json_type_array))
return false;
183 *length = json_object_array_length(buf);
184 m_file->push_object(buf);
190 SerializableJsonReader00::read_sparse_end_wrapped(
193 m_file->pop_object();
198 SerializableJsonReader00::read_sparseentry_begin_wrapped(
202 json_object* m = m_file->m_stack_stream.back();
205 = json_object_array_get_idx(m, y);
206 if (is_error(buf_obj))
return false;
207 if (!json_object_is_type(buf_obj, json_type_object))
return false;
210 if (!m_file->get_object(&buf, buf_obj, STR_KEY_SPARSE_FEATINDEX,
211 json_type_int))
return false;
212 *feat_index = json_object_get_int(buf);
214 if (!m_file->get_object_any(&buf, buf_obj, STR_KEY_SPARSE_ENTRY))
216 m_file->push_object(buf);
222 SerializableJsonReader00::read_sparseentry_end_wrapped(
226 m_file->pop_object();
231 SerializableJsonReader00::read_item_begin_wrapped(
234 json_object* m = m_file->m_stack_stream.back();
237 m = json_object_array_get_idx(m, x);
238 m = json_object_array_get_idx(m, y);
240 m_file->push_object(m);
245 SerializableJsonReader00::read_item_end_wrapped(
248 m_file->pop_object();
253 SerializableJsonReader00::read_sgserializable_begin_wrapped(
254 const TSGDataType* type,
char* sgserializable_name,
255 EPrimitiveType*
generic)
257 json_object* m = m_file->m_stack_stream.back();
259 if (m == NULL || json_object_is_type(m, json_type_null)) {
260 *sgserializable_name =
'\0';
return true;
263 if (!json_object_is_type(m, json_type_object))
return false;
266 if (!m_file->get_object(&buf, m, STR_KEY_INSTANCE_NAME,
267 json_type_string))
return false;
268 strncpy(sgserializable_name, json_object_get_string(buf),
271 if (m_file->get_object(&buf, m, STR_KEY_GENERIC_NAME,
274 generic, json_object_get_string(buf)))
return false;
277 if (!m_file->get_object(&buf, m, STR_KEY_INSTANCE,
278 json_type_object))
return false;
279 m_file->push_object(buf);
285 SerializableJsonReader00::read_sgserializable_end_wrapped(
286 const TSGDataType* type,
const char* sgserializable_name,
287 EPrimitiveType
generic)
289 if (*sgserializable_name ==
'\0')
return true;
291 m_file->pop_object();
296 SerializableJsonReader00::read_type_begin_wrapped(
297 const TSGDataType* type,
const char* name,
const char* prefix)
299 json_object* m = m_file->m_stack_stream.back();
301 if (!json_object_is_type(m, json_type_object))
return false;
303 json_object* buf_type;
304 if (!m_file->get_object(&buf_type, m, name, json_type_object))
309 if (!m_file->get_object(&buf, buf_type, STR_KEY_TYPE,
310 json_type_string))
return false;
311 if (strcmp(str_buf, json_object_get_string(buf)) != 0)
315 m_file->get_object_any(&buf, buf_type, STR_KEY_DATA);
316 m_file->push_object(buf);
322 SerializableJsonReader00::read_type_end_wrapped(
323 const TSGDataType* type,
const char* name,
const char* prefix)
325 m_file->pop_object();
static bool string_to_ptype(EPrimitiveType *ptype, const char *str)
Datatypes that shogun supports.
void to_string(char *dest, size_t n) const
all of classes and functions are contained in the shogun namespace
template class SGSparseVectorEntry
char string_t[STRING_LEN]