SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SerializableAsciiFile.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2010 Soeren Sonnenburg
8  * Copyright (C) 2010 Berlin Institute of Technology
9  */
10 #ifndef __SERIALIZABLE_ASCII_FILE_H__
11 #define __SERIALIZABLE_ASCII_FILE_H__
12 
13 #include <shogun/lib/config.h>
14 
16 #include <shogun/base/DynArray.h>
17 #include <shogun/lib/DataType.h>
18 #include <shogun/lib/common.h>
19 
20 #define CHAR_CONT_BEGIN '('
21 #define CHAR_CONT_END ')'
22 #define CHAR_ITEM_BEGIN '{'
23 #define CHAR_ITEM_END '}'
24 #define CHAR_SGSERIAL_BEGIN '['
25 #define CHAR_SGSERIAL_END ']'
26 #define CHAR_STRING_BEGIN CHAR_SGSERIAL_BEGIN
27 #define CHAR_STRING_END CHAR_SGSERIAL_END
28 #define CHAR_SPARSE_BEGIN CHAR_CONT_BEGIN
29 #define CHAR_SPARSE_END CHAR_CONT_END
30 
31 #define CHAR_TYPE_END '\n'
32 
33 #define STR_SGSERIAL_NULL "null"
34 
35 namespace shogun
36 {
37 template <class T> struct SGSparseVectorEntry;
38 
41 {
43 
44  DynArray<long> m_stack_fpos;
45 
46  void init();
47  bool ignore();
48 
49 protected:
50 
56  char* dest_version, size_t n);
57 
58 #ifndef DOXYGEN_SHOULD_SKIP_THIS
59  virtual bool write_scalar_wrapped(
60  const TSGDataType* type, const void* param);
61 
62  virtual bool write_cont_begin_wrapped(
63  const TSGDataType* type, index_t len_real_y,
64  index_t len_real_x);
65  virtual bool write_cont_end_wrapped(
66  const TSGDataType* type, index_t len_real_y,
67  index_t len_real_x);
68 
69  virtual bool write_string_begin_wrapped(
70  const TSGDataType* type, index_t length);
71  virtual bool write_string_end_wrapped(
72  const TSGDataType* type, index_t length);
73 
74  virtual bool write_stringentry_begin_wrapped(
75  const TSGDataType* type, index_t y);
76  virtual bool write_stringentry_end_wrapped(
77  const TSGDataType* type, index_t y);
78 
79  virtual bool write_sparse_begin_wrapped(
80  const TSGDataType* type, index_t length);
81  virtual bool write_sparse_end_wrapped(
82  const TSGDataType* type, index_t length);
83 
84  virtual bool write_sparseentry_begin_wrapped(
85  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
86  index_t feat_index, index_t y);
87  virtual bool write_sparseentry_end_wrapped(
88  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
89  index_t feat_index, index_t y);
90 
91  virtual bool write_item_begin_wrapped(
92  const TSGDataType* type, index_t y, index_t x);
93  virtual bool write_item_end_wrapped(
94  const TSGDataType* type, index_t y, index_t x);
95 
96  virtual bool write_sgserializable_begin_wrapped(
97  const TSGDataType* type, const char* sgserializable_name,
98  EPrimitiveType generic);
99  virtual bool write_sgserializable_end_wrapped(
100  const TSGDataType* type, const char* sgserializable_name,
101  EPrimitiveType generic);
102 
103  virtual bool write_type_begin_wrapped(
104  const TSGDataType* type, const char* name,
105  const char* prefix);
106  virtual bool write_type_end_wrapped(
107  const TSGDataType* type, const char* name,
108  const char* prefix);
109 #endif
110 public:
112  explicit CSerializableAsciiFile();
113 
119  explicit CSerializableAsciiFile(FILE* fstream, char rw);
120 
126  explicit CSerializableAsciiFile(const char* fname, char rw='r');
127 
129  virtual ~CSerializableAsciiFile();
130 
132  virtual const char* get_name() const {
133  return "SerializableAsciiFile";
134  }
135 };
136 }
137 
138 #endif /* __SERIALIZABLE_ASCII_FILE_H__ */
int32_t index_t
Definition: common.h:62
Datatypes that shogun supports.
Definition: DataType.h:68
virtual const char * get_name() const
virtual TSerializableReader * new_reader(char *dest_version, size_t n)
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
template class SGSparseVectorEntry
Definition: File.h:23

SHOGUN Machine Learning Toolbox - Documentation