00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __SERIALIZABLE_FILE_H__
00013 #define __SERIALIZABLE_FILE_H__
00014
00015 #include <stdio.h>
00016 #include <shogun/base/SGObject.h>
00017 #include <shogun/lib/DataType.h>
00018 #include <shogun/lib/SGSparseVector.h>
00019
00020 namespace shogun
00021 {
00022 class CSGObject;
00023
00025 class CSerializableFile :public CSGObject
00026 {
00027 public:
00029 struct TSerializableReader :public CSGObject {
00030
00031
00032
00033
00034 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00035 virtual bool read_scalar_wrapped(
00036 const TSGDataType* type, void* param) = 0;
00037
00038 virtual bool read_cont_begin_wrapped(
00039 const TSGDataType* type, index_t* len_read_y,
00040 index_t* len_read_x) = 0;
00041 virtual bool read_cont_end_wrapped(
00042 const TSGDataType* type, index_t len_read_y,
00043 index_t len_read_x) = 0;
00044
00045 virtual bool read_string_begin_wrapped(
00046 const TSGDataType* type, index_t* length) = 0;
00047 virtual bool read_string_end_wrapped(
00048 const TSGDataType* type, index_t length) = 0;
00049
00050 virtual bool read_stringentry_begin_wrapped(
00051 const TSGDataType* type, index_t y) = 0;
00052 virtual bool read_stringentry_end_wrapped(
00053 const TSGDataType* type, index_t y) = 0;
00054
00055 virtual bool read_sparse_begin_wrapped(
00056 const TSGDataType* type, index_t* length) = 0;
00057 virtual bool read_sparse_end_wrapped(
00058 const TSGDataType* type, index_t length) = 0;
00059
00060 virtual bool read_sparseentry_begin_wrapped(
00061 const TSGDataType* type, SGSparseVectorEntry<char>* first_entry,
00062 index_t* feat_index, index_t y) = 0;
00063 virtual bool read_sparseentry_end_wrapped(
00064 const TSGDataType* type, SGSparseVectorEntry<char>* first_entry,
00065 index_t* feat_index, index_t y) = 0;
00066
00067 virtual bool read_item_begin_wrapped(
00068 const TSGDataType* type, index_t y, index_t x) = 0;
00069 virtual bool read_item_end_wrapped(
00070 const TSGDataType* type, index_t y, index_t x) = 0;
00071
00072 virtual bool read_sgserializable_begin_wrapped(
00073 const TSGDataType* type, char* sgserializable_name,
00074 EPrimitiveType* generic) = 0;
00075 virtual bool read_sgserializable_end_wrapped(
00076 const TSGDataType* type, const char* sgserializable_name,
00077 EPrimitiveType generic) = 0;
00078
00079 virtual bool read_type_begin_wrapped(
00080 const TSGDataType* type, const char* name,
00081 const char* prefix) = 0;
00082 virtual bool read_type_end_wrapped(
00083 const TSGDataType* type, const char* name,
00084 const char* prefix) = 0;
00085
00086 #endif
00087
00088
00089
00090 };
00091
00092 private:
00094 TSerializableReader* m_reader;
00095
00096 bool is_task_warn(char rw, const char* name, const char* prefix);
00097 bool false_warn(const char* prefix, const char* name);
00098
00099 protected:
00101 FILE* m_fstream;
00103 char m_task;
00105 char* m_filename;
00106
00112 virtual void init(FILE* fstream, char task, const char* filename);
00113
00114
00115
00116
00117 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00118 virtual TSerializableReader* new_reader(
00119 char* dest_version, size_t n) = 0;
00120
00121 virtual bool write_scalar_wrapped(
00122 const TSGDataType* type, const void* param) = 0;
00123
00124 virtual bool write_cont_begin_wrapped(
00125 const TSGDataType* type, index_t len_real_y,
00126 index_t len_real_x) = 0;
00127 virtual bool write_cont_end_wrapped(
00128 const TSGDataType* type, index_t len_real_y,
00129 index_t len_real_x) = 0;
00130
00131 virtual bool write_string_begin_wrapped(
00132 const TSGDataType* type, index_t length) = 0;
00133 virtual bool write_string_end_wrapped(
00134 const TSGDataType* type, index_t length) = 0;
00135
00136 virtual bool write_stringentry_begin_wrapped(
00137 const TSGDataType* type, index_t y) = 0;
00138 virtual bool write_stringentry_end_wrapped(
00139 const TSGDataType* type, index_t y) = 0;
00140
00141 virtual bool write_sparse_begin_wrapped(
00142 const TSGDataType* type, index_t length) = 0;
00143 virtual bool write_sparse_end_wrapped(
00144 const TSGDataType* type, index_t length) = 0;
00145
00146 virtual bool write_sparseentry_begin_wrapped(
00147 const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
00148 index_t feat_index, index_t y) = 0;
00149 virtual bool write_sparseentry_end_wrapped(
00150 const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
00151 index_t feat_index, index_t y) = 0;
00152
00153 virtual bool write_item_begin_wrapped(
00154 const TSGDataType* type, index_t y, index_t x) = 0;
00155 virtual bool write_item_end_wrapped(
00156 const TSGDataType* type, index_t y, index_t x) = 0;
00157
00158 virtual bool write_sgserializable_begin_wrapped(
00159 const TSGDataType* type, const char* sgserializable_name,
00160 EPrimitiveType generic) = 0;
00161 virtual bool write_sgserializable_end_wrapped(
00162 const TSGDataType* type, const char* sgserializable_name,
00163 EPrimitiveType generic) = 0;
00164
00165 virtual bool write_type_begin_wrapped(
00166 const TSGDataType* type, const char* name,
00167 const char* prefix) = 0;
00168 virtual bool write_type_end_wrapped(
00169 const TSGDataType* type, const char* name,
00170 const char* prefix) = 0;
00171 #endif
00172
00173
00174
00175
00176 public:
00178 explicit CSerializableFile();
00179
00185 explicit CSerializableFile(FILE* fstream, char rw);
00186
00192 explicit CSerializableFile(const char* fname, char rw='r');
00193
00195 virtual ~CSerializableFile();
00196
00198 virtual void close();
00199
00201 virtual bool is_opened();
00202
00203
00204
00205
00206 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00207 virtual bool write_scalar(
00208 const TSGDataType* type, const char* name, const char* prefix,
00209 const void* param);
00210 virtual bool read_scalar(
00211 const TSGDataType* type, const char* name, const char* prefix,
00212 void* param);
00213
00214 virtual bool write_cont_begin(
00215 const TSGDataType* type, const char* name, const char* prefix,
00216 index_t len_real_y, index_t len_real_x);
00217 virtual bool read_cont_begin(
00218 const TSGDataType* type, const char* name, const char* prefix,
00219 index_t* len_read_y, index_t* len_read_x);
00220
00221 virtual bool write_cont_end(
00222 const TSGDataType* type, const char* name, const char* prefix,
00223 index_t len_real_y, index_t len_real_x);
00224 virtual bool read_cont_end(
00225 const TSGDataType* type, const char* name, const char* prefix,
00226 index_t len_read_y, index_t len_read_x);
00227
00228 virtual bool write_string_begin(
00229 const TSGDataType* type, const char* name, const char* prefix,
00230 index_t length);
00231 virtual bool read_string_begin(
00232 const TSGDataType* type, const char* name, const char* prefix,
00233 index_t* length);
00234
00235 virtual bool write_string_end(
00236 const TSGDataType* type, const char* name, const char* prefix,
00237 index_t length);
00238 virtual bool read_string_end(
00239 const TSGDataType* type, const char* name, const char* prefix,
00240 index_t length);
00241
00242 virtual bool write_stringentry_begin(
00243 const TSGDataType* type, const char* name, const char* prefix,
00244 index_t y);
00245 virtual bool read_stringentry_begin(
00246 const TSGDataType* type, const char* name, const char* prefix,
00247 index_t y);
00248
00249 virtual bool write_stringentry_end(
00250 const TSGDataType* type, const char* name, const char* prefix,
00251 index_t y);
00252 virtual bool read_stringentry_end(
00253 const TSGDataType* type, const char* name, const char* prefix,
00254 index_t y);
00255
00256 virtual bool write_sparse_begin(
00257 const TSGDataType* type, const char* name, const char* prefix,
00258 index_t length);
00259 virtual bool read_sparse_begin(
00260 const TSGDataType* type, const char* name, const char* prefix,
00261 index_t* length);
00262
00263 virtual bool write_sparse_end(
00264 const TSGDataType* type, const char* name, const char* prefix,
00265 index_t length);
00266 virtual bool read_sparse_end(
00267 const TSGDataType* type, const char* name, const char* prefix,
00268 index_t length);
00269
00270 virtual bool write_sparseentry_begin(
00271 const TSGDataType* type, const char* name, const char* prefix,
00272 const SGSparseVectorEntry<char>* first_entry, index_t feat_index,
00273 index_t y);
00274 virtual bool read_sparseentry_begin(
00275 const TSGDataType* type, const char* name, const char* prefix,
00276 SGSparseVectorEntry<char>* first_entry, index_t* feat_index,
00277 index_t y);
00278
00279 virtual bool write_sparseentry_end(
00280 const TSGDataType* type, const char* name, const char* prefix,
00281 const SGSparseVectorEntry<char>* first_entry, index_t feat_index,
00282 index_t y);
00283 virtual bool read_sparseentry_end(
00284 const TSGDataType* type, const char* name, const char* prefix,
00285 SGSparseVectorEntry<char>* first_entry, index_t* feat_index,
00286 index_t y);
00287
00288 virtual bool write_item_begin(
00289 const TSGDataType* type, const char* name, const char* prefix,
00290 index_t y, index_t x);
00291 virtual bool read_item_begin(
00292 const TSGDataType* type, const char* name, const char* prefix,
00293 index_t y, index_t x);
00294
00295 virtual bool write_item_end(
00296 const TSGDataType* type, const char* name, const char* prefix,
00297 index_t y, index_t x);
00298 virtual bool read_item_end(
00299 const TSGDataType* type, const char* name, const char* prefix,
00300 index_t y, index_t x);
00301
00302 virtual bool write_sgserializable_begin(
00303 const TSGDataType* type, const char* name, const char* prefix,
00304 const char* sgserializable_name, EPrimitiveType generic);
00305 virtual bool read_sgserializable_begin(
00306 const TSGDataType* type, const char* name, const char* prefix,
00307 char* sgserializable_name, EPrimitiveType* generic);
00308
00309 virtual bool write_sgserializable_end(
00310 const TSGDataType* type, const char* name, const char* prefix,
00311 const char* sgserializable_name, EPrimitiveType generic);
00312 virtual bool read_sgserializable_end(
00313 const TSGDataType* type, const char* name, const char* prefix,
00314 const char* sgserializable_name, EPrimitiveType generic);
00315
00316 virtual bool write_type_begin(
00317 const TSGDataType* type, const char* name, const char* prefix);
00318 virtual bool read_type_begin(
00319 const TSGDataType* type, const char* name, const char* prefix);
00320
00321 virtual bool write_type_end(
00322 const TSGDataType* type, const char* name, const char* prefix);
00323 virtual bool read_type_end(
00324 const TSGDataType* type, const char* name, const char* prefix);
00325 #endif
00326
00327
00328 };
00329 }
00330 #endif // __SERIALIZABLE_FILE_H__