SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
15 #ifdef HAVE_XML
16 
18 #include <shogun/base/DynArray.h>
19 
20 #include <libxml/parser.h>
21 #include <libxml/tree.h>
22 
23 #define STR_TRUE "true"
24 #define STR_FALSE "false"
25 
26 #define STR_ITEM "i"
27 #define STR_STRING "s"
28 #define STR_SPARSE "r"
29 
30 #define STR_PROP_TYPE "type"
31 #define STR_PROP_IS_NULL "is_null"
32 #define STR_PROP_INSTANCE_NAME "instance_name"
33 #define STR_PROP_GENERIC_NAME "generic_name"
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 length);
79  virtual bool write_sparse_end_wrapped(
80  const TSGDataType* type, index_t length);
81 
82  virtual bool write_sparseentry_begin_wrapped(
83  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
84  index_t feat_index, index_t y);
85  virtual bool write_sparseentry_end_wrapped(
86  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
87  index_t feat_index, index_t y);
88 
89  virtual bool write_item_begin_wrapped(
90  const TSGDataType* type, index_t y, index_t x);
91  virtual bool write_item_end_wrapped(
92  const TSGDataType* type, index_t y, index_t x);
93 
94  virtual bool write_sgserializable_begin_wrapped(
95  const TSGDataType* type, const char* sgserializable_name,
96  EPrimitiveType generic);
97  virtual bool write_sgserializable_end_wrapped(
98  const TSGDataType* type, const char* sgserializable_name,
99  EPrimitiveType generic);
100 
101  virtual bool write_type_begin_wrapped(
102  const TSGDataType* type, const char* name,
103  const char* prefix);
104  virtual bool write_type_end_wrapped(
105  const TSGDataType* type, const char* name,
106  const char* prefix);
107 
108 public:
110  explicit CSerializableXmlFile();
111 
118  explicit CSerializableXmlFile(const char* fname, char rw='r',
119  bool format=false);
120 
122  virtual ~CSerializableXmlFile();
123 
125  virtual const char* get_name() const {
126  return "SerializableXmlFile";
127  }
128 
129  virtual void close();
130  virtual bool is_opened();
131 };
132 }
133 #endif /* HAVE_XML */
134 #endif /* __SERIALIZABLE_XML_FILE_H__ */
int32_t index_t
Definition: common.h:62
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18

SHOGUN Machine Learning Toolbox - Documentation