SHOGUN
v1.1.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2010 Soeren Sonnenburg 00008 * Copyright (C) 2010 Berlin Institute of Technology 00009 */ 00010 #ifndef __SERIALIZABLE_ASCII_FILE_H__ 00011 #define __SERIALIZABLE_ASCII_FILE_H__ 00012 00013 #include <shogun/io/SerializableFile.h> 00014 #include <shogun/base/DynArray.h> 00015 00016 #define CHAR_CONT_BEGIN '(' 00017 #define CHAR_CONT_END ')' 00018 #define CHAR_ITEM_BEGIN '{' 00019 #define CHAR_ITEM_END '}' 00020 #define CHAR_SGSERIAL_BEGIN '[' 00021 #define CHAR_SGSERIAL_END ']' 00022 #define CHAR_STRING_BEGIN CHAR_SGSERIAL_BEGIN 00023 #define CHAR_STRING_END CHAR_SGSERIAL_END 00024 #define CHAR_SPARSE_BEGIN CHAR_CONT_BEGIN 00025 #define CHAR_SPARSE_END CHAR_CONT_END 00026 00027 #define CHAR_TYPE_END '\n' 00028 00029 #define STR_SGSERIAL_NULL "null" 00030 00031 namespace shogun 00032 { 00034 class CSerializableAsciiFile :public CSerializableFile 00035 { 00036 friend class SerializableAsciiReader00; 00037 00038 DynArray<long> m_stack_fpos; 00039 00040 void init(); 00041 bool ignore(); 00042 00043 protected: 00044 00049 virtual TSerializableReader* new_reader( 00050 char* dest_version, size_t n); 00051 00052 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00053 virtual bool write_scalar_wrapped( 00054 const TSGDataType* type, const void* param); 00055 00056 virtual bool write_cont_begin_wrapped( 00057 const TSGDataType* type, index_t len_real_y, 00058 index_t len_real_x); 00059 virtual bool write_cont_end_wrapped( 00060 const TSGDataType* type, index_t len_real_y, 00061 index_t len_real_x); 00062 00063 virtual bool write_string_begin_wrapped( 00064 const TSGDataType* type, index_t length); 00065 virtual bool write_string_end_wrapped( 00066 const TSGDataType* type, index_t length); 00067 00068 virtual bool write_stringentry_begin_wrapped( 00069 const TSGDataType* type, index_t y); 00070 virtual bool write_stringentry_end_wrapped( 00071 const TSGDataType* type, index_t y); 00072 00073 virtual bool write_sparse_begin_wrapped( 00074 const TSGDataType* type, index_t vec_index, 00075 index_t length); 00076 virtual bool write_sparse_end_wrapped( 00077 const TSGDataType* type, index_t vec_index, 00078 index_t length); 00079 00080 virtual bool write_sparseentry_begin_wrapped( 00081 const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry, 00082 index_t feat_index, index_t y); 00083 virtual bool write_sparseentry_end_wrapped( 00084 const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry, 00085 index_t feat_index, index_t y); 00086 00087 virtual bool write_item_begin_wrapped( 00088 const TSGDataType* type, index_t y, index_t x); 00089 virtual bool write_item_end_wrapped( 00090 const TSGDataType* type, index_t y, index_t x); 00091 00092 virtual bool write_sgserializable_begin_wrapped( 00093 const TSGDataType* type, const char* sgserializable_name, 00094 EPrimitiveType generic); 00095 virtual bool write_sgserializable_end_wrapped( 00096 const TSGDataType* type, const char* sgserializable_name, 00097 EPrimitiveType generic); 00098 00099 virtual bool write_type_begin_wrapped( 00100 const TSGDataType* type, const char* name, 00101 const char* prefix); 00102 virtual bool write_type_end_wrapped( 00103 const TSGDataType* type, const char* name, 00104 const char* prefix); 00105 #endif 00106 public: 00108 explicit CSerializableAsciiFile(); 00109 00115 explicit CSerializableAsciiFile(FILE* fstream, char rw); 00116 00122 explicit CSerializableAsciiFile(const char* fname, char rw='r'); 00123 00125 virtual ~CSerializableAsciiFile(); 00126 00128 inline virtual const char* get_name() const { 00129 return "SerializableAsciiFile"; 00130 } 00131 }; 00132 } 00133 00134 #endif /* __SERIALIZABLE_ASCII_FILE_H__ */