SHOGUN  4.1.0
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
SerializableJsonFile.h
浏览该文件的文档.
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 
20 #include <shogun/base/DynArray.h>
21 
22 #define STR_KEY_TYPE "type"
23 #define STR_KEY_DATA "data"
24 #define STR_KEY_INSTANCE_NAME "instance_name"
25 #define STR_KEY_INSTANCE "instance"
26 #define STR_KEY_GENERIC_NAME "generic_name"
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 length);
76  virtual bool write_sparse_end_wrapped(
77  const TSGDataType* type, index_t length);
78 
79  virtual bool write_sparseentry_begin_wrapped(
80  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
81  index_t feat_index, index_t y);
82  virtual bool write_sparseentry_end_wrapped(
83  const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
84  index_t feat_index, index_t y);
85 
86  virtual bool write_item_begin_wrapped(
87  const TSGDataType* type, index_t y, index_t x);
88  virtual bool write_item_end_wrapped(
89  const TSGDataType* type, index_t y, index_t x);
90 
91  virtual bool write_sgserializable_begin_wrapped(
92  const TSGDataType* type, const char* sgserializable_name,
93  EPrimitiveType generic);
94  virtual bool write_sgserializable_end_wrapped(
95  const TSGDataType* type, const char* sgserializable_name,
96  EPrimitiveType generic);
97 
98  virtual bool write_type_begin_wrapped(
99  const TSGDataType* type, const char* name,
100  const char* prefix);
101  virtual bool write_type_end_wrapped(
102  const TSGDataType* type, const char* name,
103  const char* prefix);
104 
105 public:
107  explicit CSerializableJsonFile();
108 
114  explicit CSerializableJsonFile(const char* fname, char rw='r');
115 
117  virtual ~CSerializableJsonFile();
118 
120  virtual const char* get_name() const {
121  return "SerializableJsonFile";
122  }
123 
124  virtual void close();
125  virtual bool is_opened();
126 };
127 }
128 #endif /* HAVE_JSON */
129 #endif /* __SERIALIZABLE_JSON_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
#define IGNORE_IN_CLASSLIST
Definition: CPLEXSVM.h:24

SHOGUN 机器学习工具包 - 项目文档