SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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_FEATINDEX "feat_index"
34 
35 namespace shogun
36 {
37 class CSerializableXmlFile
38  :public CSerializableFile
39 {
40  friend class SerializableXmlReader00;
41 
42  DynArray<xmlNode*> m_stack_stream;
43  xmlDocPtr m_doc;
44  bool m_format;
45 
46  void init(bool format);
47  bool push_node(const xmlChar* name);
48  bool join_node(const xmlChar* name);
49  bool next_node(const xmlChar* name);
50  void pop_node();
51 
52 protected:
53  virtual TSerializableReader* new_reader(
54  char* dest_version, size_t n);
55 
56  virtual bool write_scalar_wrapped(
57  const TSGDataType* type, const void* param);
58 
59  virtual bool write_cont_begin_wrapped(
60  const TSGDataType* type, index_t len_real_y,
61  index_t len_real_x);
62  virtual bool write_cont_end_wrapped(
63  const TSGDataType* type, index_t len_real_y,
64  index_t len_real_x);
65 
66  virtual bool write_string_begin_wrapped(
67  const TSGDataType* type, index_t length);
68  virtual bool write_string_end_wrapped(
69  const TSGDataType* type, index_t length);
70 
71  virtual bool write_stringentry_begin_wrapped(
72  const TSGDataType* type, index_t y);
73  virtual bool write_stringentry_end_wrapped(
74  const TSGDataType* type, index_t y);
75 
76  virtual bool write_sparse_begin_wrapped(
77  const TSGDataType* type, index_t length);
78  virtual bool write_sparse_end_wrapped(
79  const TSGDataType* type, index_t length);
80 
81  virtual bool write_sparseentry_begin_wrapped(
82  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
83  index_t feat_index, index_t y);
84  virtual bool write_sparseentry_end_wrapped(
85  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
86  index_t feat_index, index_t y);
87 
88  virtual bool write_item_begin_wrapped(
89  const TSGDataType* type, index_t y, index_t x);
90  virtual bool write_item_end_wrapped(
91  const TSGDataType* type, index_t y, index_t x);
92 
93  virtual bool write_sgserializable_begin_wrapped(
94  const TSGDataType* type, const char* sgserializable_name,
95  EPrimitiveType generic);
96  virtual bool write_sgserializable_end_wrapped(
97  const TSGDataType* type, const char* sgserializable_name,
98  EPrimitiveType generic);
99 
100  virtual bool write_type_begin_wrapped(
101  const TSGDataType* type, const char* name,
102  const char* prefix);
103  virtual bool write_type_end_wrapped(
104  const TSGDataType* type, const char* name,
105  const char* prefix);
106 
107 public:
109  explicit CSerializableXmlFile();
110 
117  explicit CSerializableXmlFile(const char* fname, char rw='r',
118  bool format=false);
119 
121  virtual ~CSerializableXmlFile();
122 
124  inline virtual const char* get_name() const {
125  return "SerializableXmlFile";
126  }
127 
128  virtual void close();
129  virtual bool is_opened();
130 };
131 }
132 #endif /* HAVE_XML */
133 #endif /* __SERIALIZABLE_XML_FILE_H__ */

SHOGUN Machine Learning Toolbox - Documentation