SerializableXmlFile.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_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_VECINDEX          "vec_index"
00034 #define STR_PROP_FEATINDEX         "feat_index"
00035 
00036 namespace shogun
00037 {
00038 class CSerializableXmlFile
00039     :public CSerializableFile
00040 {
00041     friend class SerializableXmlReader00;
00042 
00043     DynArray<xmlNode*> m_stack_stream;
00044     xmlDocPtr m_doc;
00045     bool m_format;
00046 
00047     void init(bool format);
00048     bool push_node(const xmlChar* name);
00049     bool join_node(const xmlChar* name);
00050     bool next_node(const xmlChar* name);
00051     void pop_node();
00052 
00053 protected:
00054     virtual TSerializableReader* new_reader(
00055         char* dest_version, size_t n);
00056 
00057     virtual bool write_scalar_wrapped(
00058         const TSGDataType* type, const void* param);
00059 
00060     virtual bool write_cont_begin_wrapped(
00061         const TSGDataType* type, index_t len_real_y,
00062         index_t len_real_x);
00063     virtual bool write_cont_end_wrapped(
00064         const TSGDataType* type, index_t len_real_y,
00065         index_t len_real_x);
00066 
00067     virtual bool write_string_begin_wrapped(
00068         const TSGDataType* type, index_t length);
00069     virtual bool write_string_end_wrapped(
00070         const TSGDataType* type, index_t length);
00071 
00072     virtual bool write_stringentry_begin_wrapped(
00073         const TSGDataType* type, index_t y);
00074     virtual bool write_stringentry_end_wrapped(
00075         const TSGDataType* type, index_t y);
00076 
00077     virtual bool write_sparse_begin_wrapped(
00078         const TSGDataType* type, index_t vec_index,
00079         index_t length);
00080     virtual bool write_sparse_end_wrapped(
00081         const TSGDataType* type, index_t vec_index,
00082         index_t length);
00083 
00084     virtual bool write_sparseentry_begin_wrapped(
00085         const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
00086         index_t feat_index, index_t y);
00087     virtual bool write_sparseentry_end_wrapped(
00088         const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
00089         index_t feat_index, index_t y);
00090 
00091     virtual bool write_item_begin_wrapped(
00092         const TSGDataType* type, index_t y, index_t x);
00093     virtual bool write_item_end_wrapped(
00094         const TSGDataType* type, index_t y, index_t x);
00095 
00096     virtual bool write_sgserializable_begin_wrapped(
00097         const TSGDataType* type, const char* sgserializable_name,
00098         EPrimitiveType generic);
00099     virtual bool write_sgserializable_end_wrapped(
00100         const TSGDataType* type, const char* sgserializable_name,
00101         EPrimitiveType generic);
00102 
00103     virtual bool write_type_begin_wrapped(
00104         const TSGDataType* type, const char* name,
00105         const char* prefix);
00106     virtual bool write_type_end_wrapped(
00107         const TSGDataType* type, const char* name,
00108         const char* prefix);
00109 
00110 public:
00112     explicit CSerializableXmlFile();
00113 
00120     explicit CSerializableXmlFile(const char* fname, char rw='r',
00121                                   bool format=false);
00122 
00124     virtual ~CSerializableXmlFile();
00125 
00127     inline virtual const char* get_name() const {
00128         return "SerializableXmlFile";
00129     }
00130 
00131     virtual void close();
00132     virtual bool is_opened();
00133 };
00134 }
00135 #endif /* HAVE_XML  */
00136 #endif /* __SERIALIZABLE_XML_FILE_H__  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation