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);
161 m_file->push_object(buf);
166 SerializableJsonReader00::read_stringentry_end_wrapped(
169 m_file->pop_object();
174 SerializableJsonReader00::read_sparse_begin_wrapped(
177 json_object* m = m_file->m_stack_stream.back();
179 if (!json_object_is_type(m, json_type_object))
return false;
182 if (!m_file->get_object(&buf, m, STR_KEY_SPARSE_FEATURES,
183 json_type_array))
return false;
184 *length = json_object_array_length(buf);
185 m_file->push_object(buf);
191 SerializableJsonReader00::read_sparse_end_wrapped(
194 m_file->pop_object();
199 SerializableJsonReader00::read_sparseentry_begin_wrapped(
203 json_object* m = m_file->m_stack_stream.back();
206 = json_object_array_get_idx(m, y);
207 if (buf_obj ==
nullptr)
209 if (!json_object_is_type(buf_obj, json_type_object))
return false;
212 if (!m_file->get_object(&buf, buf_obj, STR_KEY_SPARSE_FEATINDEX,
213 json_type_int))
return false;
214 *feat_index = json_object_get_int(buf);
216 if (!m_file->get_object_any(&buf, buf_obj, STR_KEY_SPARSE_ENTRY))
218 m_file->push_object(buf);
224 SerializableJsonReader00::read_sparseentry_end_wrapped(
228 m_file->pop_object();
233 SerializableJsonReader00::read_item_begin_wrapped(
236 json_object* m = m_file->m_stack_stream.back();
239 m = json_object_array_get_idx(m, x);
240 m = json_object_array_get_idx(m, y);
242 m_file->push_object(m);
247 SerializableJsonReader00::read_item_end_wrapped(
250 m_file->pop_object();
255 SerializableJsonReader00::read_sgserializable_begin_wrapped(
256 const TSGDataType* type,
char* sgserializable_name,
257 EPrimitiveType*
generic)
259 json_object* m = m_file->m_stack_stream.back();
261 if (m == NULL || json_object_is_type(m, json_type_null)) {
262 *sgserializable_name =
'\0';
return true;
265 if (!json_object_is_type(m, json_type_object))
return false;
268 if (!m_file->get_object(&buf, m, STR_KEY_INSTANCE_NAME,
269 json_type_string))
return false;
270 strncpy(sgserializable_name, json_object_get_string(buf),
273 if (m_file->get_object(&buf, m, STR_KEY_GENERIC_NAME,
276 generic, json_object_get_string(buf)))
return false;
279 if (!m_file->get_object(&buf, m, STR_KEY_INSTANCE,
280 json_type_object))
return false;
281 m_file->push_object(buf);
287 SerializableJsonReader00::read_sgserializable_end_wrapped(
288 const TSGDataType* type,
const char* sgserializable_name,
289 EPrimitiveType
generic)
291 if (*sgserializable_name ==
'\0')
return true;
293 m_file->pop_object();
298 SerializableJsonReader00::read_type_begin_wrapped(
299 const TSGDataType* type,
const char* name,
const char* prefix)
301 json_object* m = m_file->m_stack_stream.back();
303 if (!json_object_is_type(m, json_type_object))
return false;
305 json_object* buf_type;
306 if (!m_file->get_object(&buf_type, m, name, json_type_object))
311 if (!m_file->get_object(&buf, buf_type, STR_KEY_TYPE,
312 json_type_string))
return false;
313 if (strcmp(str_buf, json_object_get_string(buf)) != 0)
317 m_file->get_object_any(&buf, buf_type, STR_KEY_DATA);
318 m_file->push_object(buf);
324 SerializableJsonReader00::read_type_end_wrapped(
325 const TSGDataType* type,
const char* name,
const char* prefix)
327 m_file->pop_object();
static bool string_to_ptype(EPrimitiveType *ptype, const char *str)
Datatypes that shogun supports.
all of classes and functions are contained in the shogun namespace
template class SGSparseVectorEntry
char string_t[STRING_LEN]
void to_string(char *dest, size_t n) const