SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SerializableJsonFile.h
Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2010 Soeren Sonnenburg
00008  * Copyright (C) 2010 Berlin Institute of Technology
00009  */
00010 #ifndef __SERIALIZABLE_JSON_FILE_H__
00011 #define __SERIALIZABLE_JSON_FILE_H__
00012 
00013 #include <shogun/lib/config.h>
00014 #ifdef HAVE_JSON
00015 
00016 #include <stdint.h>
00017 #include <json.h>
00018 
00019 #include <shogun/io/SerializableFile.h>
00020 #include <shogun/base/DynArray.h>
00021 
00022 #define STR_KEY_TYPE               "type"
00023 #define STR_KEY_DATA               "data"
00024 #define STR_KEY_INSTANCE_NAME      "instance_name"
00025 #define STR_KEY_INSTANCE           "instance"
00026 #define STR_KEY_GENERIC_NAME       "generic_name"
00027 #define STR_KEY_SPARSE_FEATURES    "features"
00028 #define STR_KEY_SPARSE_FEATINDEX   "feat_index"
00029 #define STR_KEY_SPARSE_ENTRY       "entry"
00030 
00031 namespace shogun
00032 {
00033 #define IGNORE_IN_CLASSLIST
00034 IGNORE_IN_CLASSLIST class CSerializableJsonFile
00035     :public CSerializableFile
00036 {
00037     friend class SerializableJsonReader00;
00038 
00039     DynArray<json_object*> m_stack_stream;
00040 
00041     void init(const char* fname);
00042     void push_object(json_object* o);
00043     void pop_object();
00044 
00045     static bool get_object_any(json_object** dest, json_object* src,
00046                                const char* key);
00047     static bool get_object(json_object** dest, json_object* src,
00048                            const char* key, json_type t);
00049 
00050 protected:
00051     virtual TSerializableReader* new_reader(
00052         char* dest_version, size_t n);
00053 
00054     virtual bool write_scalar_wrapped(
00055         const TSGDataType* type, const void* param);
00056 
00057     virtual bool write_cont_begin_wrapped(
00058         const TSGDataType* type, index_t len_real_y,
00059         index_t len_real_x);
00060     virtual bool write_cont_end_wrapped(
00061         const TSGDataType* type, index_t len_real_y,
00062         index_t len_real_x);
00063 
00064     virtual bool write_string_begin_wrapped(
00065         const TSGDataType* type, index_t length);
00066     virtual bool write_string_end_wrapped(
00067         const TSGDataType* type, index_t length);
00068 
00069     virtual bool write_stringentry_begin_wrapped(
00070         const TSGDataType* type, index_t y);
00071     virtual bool write_stringentry_end_wrapped(
00072         const TSGDataType* type, index_t y);
00073 
00074     virtual bool write_sparse_begin_wrapped(
00075         const TSGDataType* type, index_t length);
00076     virtual bool write_sparse_end_wrapped(
00077         const TSGDataType* type, index_t length);
00078 
00079     virtual bool write_sparseentry_begin_wrapped(
00080         const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
00081         index_t feat_index, index_t y);
00082     virtual bool write_sparseentry_end_wrapped(
00083         const TSGDataType* type, const SGSparseVectorEntry<char>* first_entry,
00084         index_t feat_index, index_t y);
00085 
00086     virtual bool write_item_begin_wrapped(
00087         const TSGDataType* type, index_t y, index_t x);
00088     virtual bool write_item_end_wrapped(
00089         const TSGDataType* type, index_t y, index_t x);
00090 
00091     virtual bool write_sgserializable_begin_wrapped(
00092         const TSGDataType* type, const char* sgserializable_name,
00093         EPrimitiveType generic);
00094     virtual bool write_sgserializable_end_wrapped(
00095         const TSGDataType* type, const char* sgserializable_name,
00096         EPrimitiveType generic);
00097 
00098     virtual bool write_type_begin_wrapped(
00099         const TSGDataType* type, const char* name,
00100         const char* prefix);
00101     virtual bool write_type_end_wrapped(
00102         const TSGDataType* type, const char* name,
00103         const char* prefix);
00104 
00105 public:
00107     explicit CSerializableJsonFile();
00108 
00114     explicit CSerializableJsonFile(const char* fname, char rw='r');
00115 
00117     virtual ~CSerializableJsonFile();
00118 
00120     virtual const char* get_name() const {
00121         return "SerializableJsonFile";
00122     }
00123 
00124     virtual void close();
00125     virtual bool is_opened();
00126 };
00127 }
00128 #endif /* HAVE_JSON  */
00129 #endif /* __SERIALIZABLE_JSON_FILE_H__  */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation