SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SerializableJsonFile.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_JSON_FILE_H__
11 #define __SERIALIZABLE_JSON_FILE_H__
12 
13 #include <shogun/lib/config.h>
14 #ifdef HAVE_JSON
15 
16 #include <json.h>
17 
19 #include <shogun/base/DynArray.h>
20 
21 #define STR_KEY_TYPE "type"
22 #define STR_KEY_DATA "data"
23 #define STR_KEY_INSTANCE_NAME "instance_name"
24 #define STR_KEY_INSTANCE "instance"
25 #define STR_KEY_GENERIC_NAME "generic_name"
26 #define STR_KEY_SPARSE_VECINDEX "vec_index"
27 #define STR_KEY_SPARSE_FEATURES "features"
28 #define STR_KEY_SPARSE_FEATINDEX "feat_index"
29 #define STR_KEY_SPARSE_ENTRY "entry"
30 
31 namespace shogun
32 {
33 #define IGNORE_IN_CLASSLIST
34 IGNORE_IN_CLASSLIST class CSerializableJsonFile
35  :public CSerializableFile
36 {
37  friend class SerializableJsonReader00;
38 
39  DynArray<json_object*> m_stack_stream;
40 
41  void init(const char* fname);
42  void push_object(json_object* o);
43  void pop_object();
44 
45  static bool get_object_any(json_object** dest, json_object* src,
46  const char* key);
47  static bool get_object(json_object** dest, json_object* src,
48  const char* key, json_type t);
49 
50 protected:
51  virtual TSerializableReader* new_reader(
52  char* dest_version, size_t n);
53 
54  virtual bool write_scalar_wrapped(
55  const TSGDataType* type, const void* param);
56 
57  virtual bool write_cont_begin_wrapped(
58  const TSGDataType* type, index_t len_real_y,
59  index_t len_real_x);
60  virtual bool write_cont_end_wrapped(
61  const TSGDataType* type, index_t len_real_y,
62  index_t len_real_x);
63 
64  virtual bool write_string_begin_wrapped(
65  const TSGDataType* type, index_t length);
66  virtual bool write_string_end_wrapped(
67  const TSGDataType* type, index_t length);
68 
69  virtual bool write_stringentry_begin_wrapped(
70  const TSGDataType* type, index_t y);
71  virtual bool write_stringentry_end_wrapped(
72  const TSGDataType* type, index_t y);
73 
74  virtual bool write_sparse_begin_wrapped(
75  const TSGDataType* type, index_t vec_index,
76  index_t length);
77  virtual bool write_sparse_end_wrapped(
78  const TSGDataType* type, index_t vec_index,
79  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 CSerializableJsonFile();
110 
116  explicit CSerializableJsonFile(const char* fname, char rw='r');
117 
119  virtual ~CSerializableJsonFile();
120 
122  inline virtual const char* get_name() const {
123  return "SerializableJsonFile";
124  }
125 
126  virtual void close();
127  virtual bool is_opened();
128 };
129 }
130 #endif /* HAVE_JSON */
131 #endif /* __SERIALIZABLE_JSON_FILE_H__ */

SHOGUN Machine Learning Toolbox - Documentation