SHOGUN
v2.0.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_XML_FILE_H__ 00011 #define __SERIALIZABLE_XML_FILE_H__ 00012 00013 #include <shogun/lib/config.h> 00014 #ifdef HAVE_XML 00015 00016 #include <shogun/io/SerializableFile.h> 00017 #include <shogun/base/DynArray.h> 00018 00019 #include <libxml/parser.h> 00020 #include <libxml/tree.h> 00021 00022 #define STR_TRUE "true" 00023 #define STR_FALSE "false" 00024 00025 #define STR_ITEM "i" 00026 #define STR_STRING "s" 00027 #define STR_SPARSE "r" 00028 00029 #define STR_PROP_TYPE "type" 00030 #define STR_PROP_IS_NULL "is_null" 00031 #define STR_PROP_INSTANCE_NAME "instance_name" 00032 #define STR_PROP_GENERIC_NAME "generic_name" 00033 #define STR_PROP_FEATINDEX "feat_index" 00034 00035 namespace shogun 00036 { 00037 class CSerializableXmlFile 00038 :public CSerializableFile 00039 { 00040 friend class SerializableXmlReader00; 00041 00042 DynArray<xmlNode*> m_stack_stream; 00043 xmlDocPtr m_doc; 00044 bool m_format; 00045 00046 void init(bool format); 00047 bool push_node(const xmlChar* name); 00048 bool join_node(const xmlChar* name); 00049 bool next_node(const xmlChar* name); 00050 void pop_node(); 00051 00052 protected: 00053 virtual TSerializableReader* new_reader( 00054 char* dest_version, size_t n); 00055 00056 virtual bool write_scalar_wrapped( 00057 const TSGDataType* type, const void* param); 00058 00059 virtual bool write_cont_begin_wrapped( 00060 const TSGDataType* type, index_t len_real_y, 00061 index_t len_real_x); 00062 virtual bool write_cont_end_wrapped( 00063 const TSGDataType* type, index_t len_real_y, 00064 index_t len_real_x); 00065 00066 virtual bool write_string_begin_wrapped( 00067 const TSGDataType* type, index_t length); 00068 virtual bool write_string_end_wrapped( 00069 const TSGDataType* type, index_t length); 00070 00071 virtual bool write_stringentry_begin_wrapped( 00072 const TSGDataType* type, index_t y); 00073 virtual bool write_stringentry_end_wrapped( 00074 const TSGDataType* type, index_t y); 00075 00076 virtual bool write_sparse_begin_wrapped( 00077 const TSGDataType* type, index_t length); 00078 virtual bool write_sparse_end_wrapped( 00079 const TSGDataType* type, index_t length); 00080 00081 virtual bool write_sparseentry_begin_wrapped( 00082 const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry, 00083 index_t feat_index, index_t y); 00084 virtual bool write_sparseentry_end_wrapped( 00085 const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry, 00086 index_t feat_index, index_t y); 00087 00088 virtual bool write_item_begin_wrapped( 00089 const TSGDataType* type, index_t y, index_t x); 00090 virtual bool write_item_end_wrapped( 00091 const TSGDataType* type, index_t y, index_t x); 00092 00093 virtual bool write_sgserializable_begin_wrapped( 00094 const TSGDataType* type, const char* sgserializable_name, 00095 EPrimitiveType generic); 00096 virtual bool write_sgserializable_end_wrapped( 00097 const TSGDataType* type, const char* sgserializable_name, 00098 EPrimitiveType generic); 00099 00100 virtual bool write_type_begin_wrapped( 00101 const TSGDataType* type, const char* name, 00102 const char* prefix); 00103 virtual bool write_type_end_wrapped( 00104 const TSGDataType* type, const char* name, 00105 const char* prefix); 00106 00107 public: 00109 explicit CSerializableXmlFile(); 00110 00117 explicit CSerializableXmlFile(const char* fname, char rw='r', 00118 bool format=false); 00119 00121 virtual ~CSerializableXmlFile(); 00122 00124 inline virtual const char* get_name() const { 00125 return "SerializableXmlFile"; 00126 } 00127 00128 virtual void close(); 00129 virtual bool is_opened(); 00130 }; 00131 } 00132 #endif /* HAVE_XML */ 00133 #endif /* __SERIALIZABLE_XML_FILE_H__ */