SHOGUN  v3.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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_FEATURES "features"
27 #define STR_KEY_SPARSE_FEATINDEX "feat_index"
28 #define STR_KEY_SPARSE_ENTRY "entry"
29 
30 namespace shogun
31 {
32 #define IGNORE_IN_CLASSLIST
33 IGNORE_IN_CLASSLIST class CSerializableJsonFile
34  :public CSerializableFile
35 {
36  friend class SerializableJsonReader00;
37 
38  DynArray<json_object*> m_stack_stream;
39 
40  void init(const char* fname);
41  void push_object(json_object* o);
42  void pop_object();
43 
44  static bool get_object_any(json_object** dest, json_object* src,
45  const char* key);
46  static bool get_object(json_object** dest, json_object* src,
47  const char* key, json_type t);
48 
49 protected:
50  virtual TSerializableReader* new_reader(
51  char* dest_version, size_t n);
52 
53  virtual bool write_scalar_wrapped(
54  const TSGDataType* type, const void* param);
55 
56  virtual bool write_cont_begin_wrapped(
57  const TSGDataType* type, index_t len_real_y,
58  index_t len_real_x);
59  virtual bool write_cont_end_wrapped(
60  const TSGDataType* type, index_t len_real_y,
61  index_t len_real_x);
62 
63  virtual bool write_string_begin_wrapped(
64  const TSGDataType* type, index_t length);
65  virtual bool write_string_end_wrapped(
66  const TSGDataType* type, index_t length);
67 
68  virtual bool write_stringentry_begin_wrapped(
69  const TSGDataType* type, index_t y);
70  virtual bool write_stringentry_end_wrapped(
71  const TSGDataType* type, index_t y);
72 
73  virtual bool write_sparse_begin_wrapped(
74  const TSGDataType* type, index_t length);
75  virtual bool write_sparse_end_wrapped(
76  const TSGDataType* type, index_t length);
77 
78  virtual bool write_sparseentry_begin_wrapped(
79  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
80  index_t feat_index, index_t y);
81  virtual bool write_sparseentry_end_wrapped(
82  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
83  index_t feat_index, index_t y);
84 
85  virtual bool write_item_begin_wrapped(
86  const TSGDataType* type, index_t y, index_t x);
87  virtual bool write_item_end_wrapped(
88  const TSGDataType* type, index_t y, index_t x);
89 
90  virtual bool write_sgserializable_begin_wrapped(
91  const TSGDataType* type, const char* sgserializable_name,
92  EPrimitiveType generic);
93  virtual bool write_sgserializable_end_wrapped(
94  const TSGDataType* type, const char* sgserializable_name,
95  EPrimitiveType generic);
96 
97  virtual bool write_type_begin_wrapped(
98  const TSGDataType* type, const char* name,
99  const char* prefix);
100  virtual bool write_type_end_wrapped(
101  const TSGDataType* type, const char* name,
102  const char* prefix);
103 
104 public:
106  explicit CSerializableJsonFile();
107 
113  explicit CSerializableJsonFile(const char* fname, char rw='r');
114 
116  virtual ~CSerializableJsonFile();
117 
119  virtual const char* get_name() const {
120  return "SerializableJsonFile";
121  }
122 
123  virtual void close();
124  virtual bool is_opened();
125 };
126 }
127 #endif /* HAVE_JSON */
128 #endif /* __SERIALIZABLE_JSON_FILE_H__ */

SHOGUN Machine Learning Toolbox - Documentation