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