SerializableAsciiFile.h

Go to the documentation of this file.
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 "lib/SerializableFile.h"
00014 #include "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 {
00033 class CSerializableAsciiFile :public CSerializableFile
00034 {
00035     friend class SerializableAsciiReader00;
00036 
00037     DynArray<long> m_stack_fpos;
00038 
00039     void init(void);
00040     bool ignore(void);
00041 
00042 protected:
00043     virtual TSerializableReader* new_reader(
00044         char* dest_version, size_t n);
00045 
00046     virtual bool write_scalar_wrapped(
00047         const TSGDataType* type, const void* param);
00048 
00049     virtual bool write_cont_begin_wrapped(
00050         const TSGDataType* type, index_t len_real_y,
00051         index_t len_real_x);
00052     virtual bool write_cont_end_wrapped(
00053         const TSGDataType* type, index_t len_real_y,
00054         index_t len_real_x);
00055 
00056     virtual bool write_string_begin_wrapped(
00057         const TSGDataType* type, index_t length);
00058     virtual bool write_string_end_wrapped(
00059         const TSGDataType* type, index_t length);
00060 
00061     virtual bool write_stringentry_begin_wrapped(
00062         const TSGDataType* type, index_t y);
00063     virtual bool write_stringentry_end_wrapped(
00064         const TSGDataType* type, index_t y);
00065 
00066     virtual bool write_sparse_begin_wrapped(
00067         const TSGDataType* type, index_t vec_index,
00068         index_t length);
00069     virtual bool write_sparse_end_wrapped(
00070         const TSGDataType* type, index_t vec_index,
00071         index_t length);
00072 
00073     virtual bool write_sparseentry_begin_wrapped(
00074         const TSGDataType* type, const TSparseEntry<char>* first_entry,
00075         index_t feat_index, index_t y);
00076     virtual bool write_sparseentry_end_wrapped(
00077         const TSGDataType* type, const TSparseEntry<char>* first_entry,
00078         index_t feat_index, index_t y);
00079 
00080     virtual bool write_item_begin_wrapped(
00081         const TSGDataType* type, index_t y, index_t x);
00082     virtual bool write_item_end_wrapped(
00083         const TSGDataType* type, index_t y, index_t x);
00084 
00085     virtual bool write_sgserializable_begin_wrapped(
00086         const TSGDataType* type, const char* sgserializable_name,
00087         EPrimitiveType generic);
00088     virtual bool write_sgserializable_end_wrapped(
00089         const TSGDataType* type, const char* sgserializable_name,
00090         EPrimitiveType generic);
00091 
00092     virtual bool write_type_begin_wrapped(
00093         const TSGDataType* type, const char* name,
00094         const char* prefix);
00095     virtual bool write_type_end_wrapped(
00096         const TSGDataType* type, const char* name,
00097         const char* prefix);
00098 
00099 public:
00101     explicit CSerializableAsciiFile(void);
00102 
00107     explicit CSerializableAsciiFile(FILE* fstream, char rw);
00108 
00114     explicit CSerializableAsciiFile(const char* fname, char rw='r');
00115 
00117     virtual ~CSerializableAsciiFile();
00118 
00120     inline virtual const char* get_name(void) const {
00121         return "SerializableAsciiFile";
00122     }
00123 };
00124 }
00125 
00126 #endif /* __SERIALIZABLE_ASCII_FILE_H__  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation