SHOGUN  6.0.0
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 
15 #ifdef HAVE_JSON
16 
17 #include <json.h>
18 #include <bits.h>
19 
21 #include <shogun/base/DynArray.h>
22 
23 #define STR_KEY_TYPE "type"
24 #define STR_KEY_DATA "data"
25 #define STR_KEY_INSTANCE_NAME "instance_name"
26 #define STR_KEY_INSTANCE "instance"
27 #define STR_KEY_GENERIC_NAME "generic_name"
28 #define STR_KEY_SPARSE_FEATURES "features"
29 #define STR_KEY_SPARSE_FEATINDEX "feat_index"
30 #define STR_KEY_SPARSE_ENTRY "entry"
31 
32 namespace shogun
33 {
34 #define IGNORE_IN_CLASSLIST
35 IGNORE_IN_CLASSLIST class CSerializableJsonFile
36  :public CSerializableFile
37 {
38  friend class SerializableJsonReader00;
39 
40  DynArray<json_object*> m_stack_stream;
41 
42  void init(const char* fname);
43  void push_object(json_object* o);
44  void pop_object();
45 
46  static bool get_object_any(json_object** dest, json_object* src,
47  const char* key);
48  static bool get_object(json_object** dest, json_object* src,
49  const char* key, json_type t);
50 
51 protected:
52  virtual TSerializableReader* new_reader(
53  char* dest_version, size_t n);
54 
55  virtual bool write_scalar_wrapped(
56  const TSGDataType* type, const void* param);
57 
58  virtual bool write_cont_begin_wrapped(
59  const TSGDataType* type, index_t len_real_y,
60  index_t len_real_x);
61  virtual bool write_cont_end_wrapped(
62  const TSGDataType* type, index_t len_real_y,
63  index_t len_real_x);
64 
65  virtual bool write_string_begin_wrapped(
66  const TSGDataType* type, index_t length);
67  virtual bool write_string_end_wrapped(
68  const TSGDataType* type, index_t length);
69 
70  virtual bool write_stringentry_begin_wrapped(
71  const TSGDataType* type, index_t y);
72  virtual bool write_stringentry_end_wrapped(
73  const TSGDataType* type, index_t y);
74 
75  virtual bool write_sparse_begin_wrapped(
76  const TSGDataType* type, index_t length);
77  virtual bool write_sparse_end_wrapped(
78  const TSGDataType* type, index_t length);
79 
80  virtual bool write_sparseentry_begin_wrapped(
81  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
82  index_t feat_index, index_t y);
83  virtual bool write_sparseentry_end_wrapped(
84  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
85  index_t feat_index, index_t y);
86 
87  virtual bool write_item_begin_wrapped(
88  const TSGDataType* type, index_t y, index_t x);
89  virtual bool write_item_end_wrapped(
90  const TSGDataType* type, index_t y, index_t x);
91 
92  virtual bool write_sgserializable_begin_wrapped(
93  const TSGDataType* type, const char* sgserializable_name,
94  EPrimitiveType generic);
95  virtual bool write_sgserializable_end_wrapped(
96  const TSGDataType* type, const char* sgserializable_name,
97  EPrimitiveType generic);
98 
99  virtual bool write_type_begin_wrapped(
100  const TSGDataType* type, const char* name,
101  const char* prefix);
102  virtual bool write_type_end_wrapped(
103  const TSGDataType* type, const char* name,
104  const char* prefix);
105 
106 public:
108  explicit CSerializableJsonFile();
109 
115  explicit CSerializableJsonFile(const char* fname, char rw='r');
116 
118  virtual ~CSerializableJsonFile();
119 
121  virtual const char* get_name() const {
122  return "SerializableJsonFile";
123  }
124 
125  virtual void close();
126  virtual bool is_opened();
127 };
128 }
129 #endif /* HAVE_JSON */
130 #endif /* __SERIALIZABLE_JSON_FILE_H__ */
int32_t index_t
Definition: common.h:72
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
#define IGNORE_IN_CLASSLIST
Definition: CPLEXSVM.h:24

SHOGUN Machine Learning Toolbox - Documentation