18 :
CSGObject(), m_fstream(NULL), m_filename(NULL)
20 init(NULL, 0,
"(file)");
24 :
CSGObject(), m_fstream(NULL), m_filename(NULL)
26 REQUIRE(fstream != NULL,
"Provided fstream should be != NULL\n");
27 init(fstream, rw,
"(file)");
31 :
CSGObject(), m_fstream(NULL), m_filename(NULL)
33 const char mode[3] = {rw,
'b',
'\0'};
35 if (fname == NULL || *fname ==
'\0') {
37 SG_ERROR(
"Filename not given for opening file!\n")
40 if (rw !=
'r' && rw !=
'w') {
42 SG_ERROR(
"Unknown mode '%c'!\n", mode[0])
45 FILE* fstream = fopen(fname, mode);
48 SG_ERROR(
"Error opening file '%s'\n", fname)
51 init(fstream, rw, fname);
63 CSerializableFile::init(FILE* fstream,
char task,
const char* filename)
68 m_filename = SG_MALLOC(
char, strlen(filename)+1);
86 CSerializableFile::is_task_warn(
char rw,
const char* name,
89 if (
m_task ==
'r' && m_reader == NULL) {
92 m_reader = new_reader(dest_version,
STRING_LEN);
93 if (m_reader == NULL) {
94 SG_WARNING(
"`%s' has file-version `%s', which is not "
96 close();
return false;
101 SG_WARNING(
"`%s' not opened (for writing) during writing "
106 SG_WARNING(
"`%s' not opened (for reading) during reading "
115 CSerializableFile::false_warn(
const char* prefix,
const char* name)
118 SG_WARNING(
"Could not write `%s%s' to `%s'!\n", prefix,
121 SG_WARNING(
"Could not read `%s%s' from `%s'!\n", prefix,
124 SG_WARNING(
"Could not read/write `%s%s' from `%s'!\n",
131 CSerializableFile::write_scalar(
132 const TSGDataType* type,
const char* name,
const char* prefix,
135 if (!is_task_warn(
'w', name, prefix))
return false;
137 if (!write_scalar_wrapped(type, param))
138 return false_warn(prefix, name);
144 CSerializableFile::read_scalar(
145 const TSGDataType* type,
const char* name,
const char* prefix,
148 if (!is_task_warn(
'r', name, prefix))
return false;
150 if (!m_reader->read_scalar_wrapped(type, param))
151 return false_warn(prefix, name);
157 CSerializableFile::write_cont_begin(
158 const TSGDataType* type,
const char* name,
const char* prefix,
161 if (!is_task_warn(
'w', name, prefix))
return false;
163 if (!write_cont_begin_wrapped(type, len_real_y, len_real_x))
164 return false_warn(prefix, name);
170 CSerializableFile::read_cont_begin(
171 const TSGDataType* type,
const char* name,
const char* prefix,
174 if (!is_task_warn(
'r', name, prefix))
return false;
176 if (!m_reader->read_cont_begin_wrapped(type, len_read_y,
178 return false_warn(prefix, name);
184 CSerializableFile::write_cont_end(
185 const TSGDataType* type,
const char* name,
const char* prefix,
188 if (!is_task_warn(
'w', name, prefix))
return false;
190 if (!write_cont_end_wrapped(type, len_real_y, len_real_x))
191 return false_warn(prefix, name);
197 CSerializableFile::read_cont_end(
198 const TSGDataType* type,
const char* name,
const char* prefix,
201 if (!is_task_warn(
'r', name, prefix))
return false;
203 if (!m_reader->read_cont_end_wrapped(type, len_read_y, len_read_x))
204 return false_warn(prefix, name);
210 CSerializableFile::write_string_begin(
211 const TSGDataType* type,
const char* name,
const char* prefix,
214 if (!is_task_warn(
'w', name, prefix))
return false;
216 if (!write_string_begin_wrapped(type, length))
217 return false_warn(prefix, name);
223 CSerializableFile::read_string_begin(
224 const TSGDataType* type,
const char* name,
const char* prefix,
227 if (!is_task_warn(
'r', name, prefix))
return false;
229 if (!m_reader->read_string_begin_wrapped(type, length))
230 return false_warn(prefix, name);
236 CSerializableFile::write_string_end(
237 const TSGDataType* type,
const char* name,
const char* prefix,
240 if (!is_task_warn(
'w', name, prefix))
return false;
242 if (!write_string_end_wrapped(type, length))
243 return false_warn(prefix, name);
249 CSerializableFile::read_string_end(
250 const TSGDataType* type,
const char* name,
const char* prefix,
253 if (!is_task_warn(
'r', name, prefix))
return false;
255 if (!m_reader->read_string_end_wrapped(type, length))
256 return false_warn(prefix, name);
262 CSerializableFile::write_stringentry_begin(
263 const TSGDataType* type,
const char* name,
const char* prefix,
266 if (!is_task_warn(
'w', name, prefix))
return false;
268 if (!write_stringentry_begin_wrapped(type, y))
269 return false_warn(prefix, name);
275 CSerializableFile::read_stringentry_begin(
276 const TSGDataType* type,
const char* name,
const char* prefix,
279 if (!is_task_warn(
'r', name, prefix))
return false;
281 if (!m_reader->read_stringentry_begin_wrapped(type, y))
282 return false_warn(prefix, name);
288 CSerializableFile::write_stringentry_end(
289 const TSGDataType* type,
const char* name,
const char* prefix,
292 if (!is_task_warn(
'w', name, prefix))
return false;
294 if (!write_stringentry_end_wrapped(type, y))
295 return false_warn(prefix, name);
301 CSerializableFile::read_stringentry_end(
302 const TSGDataType* type,
const char* name,
const char* prefix,
305 if (!is_task_warn(
'r', name, prefix))
return false;
307 if (!m_reader->read_stringentry_end_wrapped(type, y))
308 return false_warn(prefix, name);
314 CSerializableFile::write_sparse_begin(
315 const TSGDataType* type,
const char* name,
const char* prefix,
318 if (!is_task_warn(
'w', name, prefix))
return false;
320 if (!write_sparse_begin_wrapped(type, length))
321 return false_warn(prefix, name);
327 CSerializableFile::read_sparse_begin(
328 const TSGDataType* type,
const char* name,
const char* prefix,
331 if (!is_task_warn(
'r', name, prefix))
return false;
333 if (!m_reader->read_sparse_begin_wrapped(type, length))
334 return false_warn(prefix, name);
340 CSerializableFile::write_sparse_end(
341 const TSGDataType* type,
const char* name,
const char* prefix,
344 if (!is_task_warn(
'w', name, prefix))
return false;
346 if (!write_sparse_end_wrapped(type, length))
347 return false_warn(prefix, name);
353 CSerializableFile::read_sparse_end(
354 const TSGDataType* type,
const char* name,
const char* prefix,
357 if (!is_task_warn(
'r', name, prefix))
return false;
359 if (!m_reader->read_sparse_end_wrapped(type, length))
360 return false_warn(prefix, name);
366 CSerializableFile::write_sparseentry_begin(
367 const TSGDataType* type,
const char* name,
const char* prefix,
371 if (!is_task_warn(
'w', name, prefix))
return false;
373 if (!write_sparseentry_begin_wrapped(type, first_entry,
375 return false_warn(prefix, name);
381 CSerializableFile::read_sparseentry_begin(
382 const TSGDataType* type,
const char* name,
const char* prefix,
385 if (!is_task_warn(
'r', name, prefix))
return false;
387 if (!m_reader->read_sparseentry_begin_wrapped(type, first_entry,
389 return false_warn(prefix, name);
395 CSerializableFile::write_sparseentry_end(
396 const TSGDataType* type,
const char* name,
const char* prefix,
400 if (!is_task_warn(
'w', name, prefix))
return false;
402 if (!write_sparseentry_end_wrapped(type, first_entry, feat_index,
404 return false_warn(prefix, name);
410 CSerializableFile::read_sparseentry_end(
411 const TSGDataType* type,
const char* name,
const char* prefix,
415 if (!is_task_warn(
'r', name, prefix))
return false;
417 if (!m_reader->read_sparseentry_end_wrapped(type, first_entry,
419 return false_warn(prefix, name);
425 CSerializableFile::write_item_begin(
426 const TSGDataType* type,
const char* name,
const char* prefix,
429 if (!is_task_warn(
'w', name, prefix))
return false;
431 if (!write_item_begin_wrapped(type, y, x))
432 return false_warn(prefix, name);
438 CSerializableFile::read_item_begin(
439 const TSGDataType* type,
const char* name,
const char* prefix,
442 if (!is_task_warn(
'r', name, prefix))
return false;
444 if (!m_reader->read_item_begin_wrapped(type, y, x))
445 return false_warn(prefix, name);
451 CSerializableFile::write_item_end(
452 const TSGDataType* type,
const char* name,
const char* prefix,
455 if (!is_task_warn(
'w', name, prefix))
return false;
457 if (!write_item_end_wrapped(type, y, x))
458 return false_warn(prefix, name);
464 CSerializableFile::read_item_end(
465 const TSGDataType* type,
const char* name,
const char* prefix,
468 if (!is_task_warn(
'r', name, prefix))
return false;
470 if (!m_reader->read_item_end_wrapped(type, y, x))
471 return false_warn(prefix, name);
477 CSerializableFile::write_sgserializable_begin(
478 const TSGDataType* type,
const char* name,
const char* prefix,
479 const char* sgserializable_name, EPrimitiveType
generic)
481 if (!is_task_warn(
'w', name, prefix))
return false;
483 if (!write_sgserializable_begin_wrapped(type, sgserializable_name,
485 return false_warn(prefix, name);
491 CSerializableFile::read_sgserializable_begin(
492 const TSGDataType* type,
const char* name,
const char* prefix,
493 char* sgserializable_name, EPrimitiveType*
generic)
495 if (!is_task_warn(
'r', name, prefix))
return false;
497 if (!m_reader->read_sgserializable_begin_wrapped(
498 type, sgserializable_name,
generic))
499 return false_warn(prefix, name);
505 CSerializableFile::write_sgserializable_end(
506 const TSGDataType* type,
const char* name,
const char* prefix,
507 const char* sgserializable_name, EPrimitiveType
generic)
509 if (!is_task_warn(
'w', name, prefix))
return false;
511 if (!write_sgserializable_end_wrapped(type, sgserializable_name,
513 return false_warn(prefix, name);
519 CSerializableFile::read_sgserializable_end(
520 const TSGDataType* type,
const char* name,
const char* prefix,
521 const char* sgserializable_name, EPrimitiveType
generic)
523 if (!is_task_warn(
'r', name, prefix))
return false;
525 if (!m_reader->read_sgserializable_end_wrapped(
526 type, sgserializable_name,
generic))
527 return false_warn(prefix, name);
533 CSerializableFile::write_type_begin(
534 const TSGDataType* type,
const char* name,
const char* prefix)
536 if (!is_task_warn(
'w', name, prefix))
return false;
538 if (!write_type_begin_wrapped(type, name, prefix))
539 return false_warn(prefix, name);
545 CSerializableFile::read_type_begin(
546 const TSGDataType* type,
const char* name,
const char* prefix)
548 if (!is_task_warn(
'r', name, prefix))
return false;
550 if (!m_reader->read_type_begin_wrapped(type, name, prefix))
551 return false_warn(prefix, name);
557 CSerializableFile::write_type_end(
558 const TSGDataType* type,
const char* name,
const char* prefix)
560 if (!is_task_warn(
'w', name, prefix))
return false;
562 if (!write_type_end_wrapped(type, name, prefix))
563 return false_warn(prefix, name);
569 CSerializableFile::read_type_end(
570 const TSGDataType* type,
const char* name,
const char* prefix)
572 if (!is_task_warn(
'r', name, prefix))
return false;
574 if (!m_reader->read_type_end_wrapped(type, name, prefix))
575 return false_warn(prefix, name);
virtual ~CSerializableFile()
Datatypes that shogun supports.
Class SGObject is the base class of all shogun objects.
all of classes and functions are contained in the shogun namespace
template class SGSparseVectorEntry
char string_t[STRING_LEN]
void init(FILE *fstream, char task, const char *filename)