SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SerializableXmlFile.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2010 Soeren Sonnenburg
8  * Copyright (C) 2010 Berlin Institute of Technology
9  */
10 #ifndef __SERIALIZABLE_XML_FILE_H__
11 #define __SERIALIZABLE_XML_FILE_H__
12 
13 #include <shogun/lib/config.h>
14 #ifdef HAVE_XML
15 
17 #include <shogun/base/DynArray.h>
18 
19 #include <libxml/parser.h>
20 #include <libxml/tree.h>
21 
22 #define STR_TRUE "true"
23 #define STR_FALSE "false"
24 
25 #define STR_ITEM "i"
26 #define STR_STRING "s"
27 #define STR_SPARSE "r"
28 
29 #define STR_PROP_TYPE "type"
30 #define STR_PROP_IS_NULL "is_null"
31 #define STR_PROP_INSTANCE_NAME "instance_name"
32 #define STR_PROP_GENERIC_NAME "generic_name"
33 #define STR_PROP_VECINDEX "vec_index"
34 #define STR_PROP_FEATINDEX "feat_index"
35 
36 namespace shogun
37 {
38 class CSerializableXmlFile
39  :public CSerializableFile
40 {
41  friend class SerializableXmlReader00;
42 
43  DynArray<xmlNode*> m_stack_stream;
44  xmlDocPtr m_doc;
45  bool m_format;
46 
47  void init(bool format);
48  bool push_node(const xmlChar* name);
49  bool join_node(const xmlChar* name);
50  bool next_node(const xmlChar* name);
51  void pop_node();
52 
53 protected:
54  virtual TSerializableReader* new_reader(
55  char* dest_version, size_t n);
56 
57  virtual bool write_scalar_wrapped(
58  const TSGDataType* type, const void* param);
59 
60  virtual bool write_cont_begin_wrapped(
61  const TSGDataType* type, index_t len_real_y,
62  index_t len_real_x);
63  virtual bool write_cont_end_wrapped(
64  const TSGDataType* type, index_t len_real_y,
65  index_t len_real_x);
66 
67  virtual bool write_string_begin_wrapped(
68  const TSGDataType* type, index_t length);
69  virtual bool write_string_end_wrapped(
70  const TSGDataType* type, index_t length);
71 
72  virtual bool write_stringentry_begin_wrapped(
73  const TSGDataType* type, index_t y);
74  virtual bool write_stringentry_end_wrapped(
75  const TSGDataType* type, index_t y);
76 
77  virtual bool write_sparse_begin_wrapped(
78  const TSGDataType* type, index_t vec_index,
79  index_t length);
80  virtual bool write_sparse_end_wrapped(
81  const TSGDataType* type, index_t vec_index,
82  index_t length);
83 
84  virtual bool write_sparseentry_begin_wrapped(
85  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
86  index_t feat_index, index_t y);
87  virtual bool write_sparseentry_end_wrapped(
88  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
89  index_t feat_index, index_t y);
90 
91  virtual bool write_item_begin_wrapped(
92  const TSGDataType* type, index_t y, index_t x);
93  virtual bool write_item_end_wrapped(
94  const TSGDataType* type, index_t y, index_t x);
95 
96  virtual bool write_sgserializable_begin_wrapped(
97  const TSGDataType* type, const char* sgserializable_name,
98  EPrimitiveType generic);
99  virtual bool write_sgserializable_end_wrapped(
100  const TSGDataType* type, const char* sgserializable_name,
101  EPrimitiveType generic);
102 
103  virtual bool write_type_begin_wrapped(
104  const TSGDataType* type, const char* name,
105  const char* prefix);
106  virtual bool write_type_end_wrapped(
107  const TSGDataType* type, const char* name,
108  const char* prefix);
109 
110 public:
112  explicit CSerializableXmlFile();
113 
120  explicit CSerializableXmlFile(const char* fname, char rw='r',
121  bool format=false);
122 
124  virtual ~CSerializableXmlFile();
125 
127  inline virtual const char* get_name() const {
128  return "SerializableXmlFile";
129  }
130 
131  virtual void close();
132  virtual bool is_opened();
133 };
134 }
135 #endif /* HAVE_XML */
136 #endif /* __SERIALIZABLE_XML_FILE_H__ */

SHOGUN Machine Learning Toolbox - Documentation