Loading...
Searching...
No Matches
gx_json.h
Go to the documentation of this file.
/*
* Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
* Copyright (C) 2011 Pete Shorthose
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* --------------------------------------------------------------------------
*/
/* ------- This is the System namespace ------- */
#pragma once
#ifndef SRC_HEADERS_GX_JSON_H_
#define SRC_HEADERS_GX_JSON_H_
namespace gx_engine {
class GxMachine;
class GxMachineRemote;
}
namespace gx_system {
/****************************************************************
** class JsonParser, class JsonWriter, class JsonException
** classes for reading and writing JSON files
*/
class JsonException: public exception {
protected:
Glib::ustring what_str;
public:
JsonException(const Glib::ustring& desc);
~JsonException() throw() { }
virtual const char* what() const throw() { return what_str.c_str(); }
};
class JsonExceptionEOF: public JsonException {
public:
JsonExceptionEOF(const char* desc): JsonException(desc) {}
~JsonExceptionEOF() throw() { }
};
class JsonWriter {
private:
ostream *os;
bool first;
int deferred_nl;
string indent;
void snl(bool v) { if (deferred_nl >= 0) deferred_nl = (v ? 1 : 0); }
void komma();
void space();
void iplus();
void iminus();
public:
JsonWriter(ostream* o = 0, bool enable_newlines = true);
virtual ~JsonWriter();
void reset();
void set_stream(ostream* o) { os = o; }
bool good() { return os->good(); }
void flush();
virtual void close();
bool is_closed() { return !os; }
void write(float v, bool nl = false);
void write(double v, bool nl = false);
void write(int i, bool nl = false);
void write(unsigned int i, bool nl = false);
void write(const char* p, bool nl = false);
void write(const string& s, bool nl = false) { write(s.c_str(), nl); }
void write_kv(const char *key, float v) { write_key(key); write(v, true); }
void write_kv(const char *key, double v) { write_key(key); write(v, true); }
void write_kv(const char *key, int i) { write_key(key); write(i, true); }
void write_kv(const char *key, unsigned int i) { write_key(key); write(i, true); }
void write_kv(const char *key, const char* p) { write_key(key); write(p, true); }
void write_kv(const char *key, const std::string& s) { write_key(key); write(s, true); }
void write_lit(const string& s, bool nl = false);
void begin_object(bool nl = false);
void end_object(bool nl = false);
void begin_array(bool nl = false);
void end_array(bool nl = false);
void write_key(const char* p, bool nl = false);
void write_key(const string& p, bool nl = false);
void write_null(bool nl = false) { write_lit("null", nl); }
void newline() { snl(true); }
};
class JsonStringWriter: public JsonWriter {
private:
ostringstream stream;
public:
JsonStringWriter(): JsonWriter(0, false) { set_stream(&stream); }
void send_notify_begin(const char *method);
void send_notify_end();
void reset() { stream.str(""); }
void finish() { stream << endl; }
std::string get_string() { return stream.str(); }
};
class JsonParser {
public:
JsonParser(istream* i = 0);
virtual ~JsonParser();
virtual void close();
void reset();
bool is_closed() { return !is; }
void set_stream(istream* i) { is = i; }
istream *get_stream() { return is; }
enum token {
no_token = 0x0000,
end_token = 0x0001,
begin_object = 0x002,
end_object = 0x0004,
begin_array = 0x0008,
end_array = 0x0010,
value_string = 0x0020,
value_number = 0x0040,
value_key = 0x0080,
value_null = 0x0100,
value_false = 0x0200,
value_true = 0x0400,
value_bool = 0x0600, // value_false | value_true
};
const char* get_token_name(token tok);
bool good() { return is->good(); }
token next(token expect = no_token);
token peek() { return next_tok; }
streampos get_streampos() { return next_pos + streamoff(-1); }
void set_streampos(streampos pos);
void check_expect(token expect) { if ((cur_tok & expect) == 0) throw_unexpected(expect); }
inline string current_value() const { return str; }
int current_value_int() { return atoi(str.c_str()); }
unsigned int current_value_uint() { return atoi(str.c_str()); }
float current_value_float() {
istringstream b(str);
float f;
b >> f;
return f;
}
double current_value_double() {
istringstream b(str);
double d;
b >> d;
return d;
}
bool read_kv(const char *key, float& v);
bool read_kv(const char *key, double& v);
bool read_kv(const char *key, int& i);
bool read_kv(const char *key, unsigned int& i);
bool read_kv(const char *key, std::string& s);
bool read_kv(const char *key, Glib::ustring& s);
template<class T> inline bool read_kv(const char *key, T& v) {
int i;
if (read_kv(key, i)) {
v = static_cast<T>(i);
return true;
}
return false;
}
void copy_object(JsonWriter& jw);
void skip_object();
void throw_unexpected(token expect);
private:
istream* is;
int depth;
token cur_tok;
string str;
bool nl;
int next_depth;
token next_tok;
string next_str;
string log_tok;
streampos next_pos;
const char* readcode();
string readstring();
token read_value_token(char c);
string readnumber(char c);
void read_next();
};
class JsonSubParser: public JsonParser {
private:
std::streampos position;
public:
JsonSubParser(JsonParser& jp, streampos pos);
~JsonSubParser();
};
class JsonStringParser: public JsonParser {
private:
std::stringstream stream;
public:
JsonStringParser() {}
void put(char c) { stream.put(c); }
std::ostream& get_ostream() { return stream; }
void start_parser() { stream.seekg(0); set_stream(&stream); }
std::string get_string() { return stream.str(); }
void reset() { stream.str(""); JsonParser::reset(); }
char peek_first_char() { stream >> ws; return stream.peek(); }
};
/****************************************************************
** Setting file handling
** class SettingsFileHeader, class StateFile, class PresetFile,
** class AbstractStateIO, class AbstractPresetIO
** class PresetBanks
** class GxSettingsBase
*/
class SettingsFileHeader {
int file_major;
int file_minor;
string file_gx_version;
public:
enum {
major = 1,
minor = 2
};
static const string gx_version; // = GX_VERSION
SettingsFileHeader()
: file_major(), file_minor(), file_gx_version() {}
void read(JsonParser&);
static void write(JsonWriter&);
void set_to_current() { file_major = major; file_minor = minor; file_gx_version = gx_version; }
int get_major() const { return file_major; }
int get_minor() const { return file_minor; }
string get_revision() const { return file_gx_version; }
bool is_major_diff() const { return major != file_major; }
bool is_minor_diff() const { return minor != file_minor; }
bool is_current() const { return !is_major_diff() && !is_minor_diff(); }
bool is_equal() const { return is_current() && gx_version == file_gx_version; }
string display() const { ostringstream s; s << file_major << "." << file_minor << "." << file_gx_version; return s.str(); }
Glib::ustring version_string() const { return Glib::ustring::compose("%1.%2", file_major, file_minor); }
inline Glib::ustring current_version_string() const { return Glib::ustring::compose("%1.%2", int(major), int(minor)); }
static bool make_empty_settingsfile(const string& name);
static void write_current_major_minor(JsonWriter& jw);
void write_major_minor(JsonWriter& jw);
void read_major_minor(JsonParser& jp);
};
class StateFile {
private:
string filename;
istream *is;
time_t mtime;
SettingsFileHeader header;
void open();
public:
StateFile()
: filename(), is(0), mtime(), header() {}
~StateFile() { delete is; }
void set_filename(const string& fn);
const SettingsFileHeader& get_header() const { return header; }
string get_filename() const { return filename; }
JsonParser *create_reader();
JsonWriter *create_writer(bool *preserve_preset);
void ensure_is_current();
};
class PresetTransformer: public JsonWriter {
private:
string filename;
string tmpfile;
ofstream os;
protected:
istream *is;
public:
JsonParser jp;
SettingsFileHeader header;
void close();
void close_nocheck();
void abort();
PresetTransformer(string filename, istream* is);
~PresetTransformer();
};
enum {
PRESET_FLAG_VERSIONDIFF = 1,
PRESET_FLAG_READONLY = 2,
PRESET_FLAG_INVALID = 4,
};
class PresetFileGui;
class PresetFile : boost::noncopyable {
public:
enum { PRESET_SEP = -1, PRESET_SCRATCH = 0, PRESET_FILE = 1, PRESET_FACTORY = 2 };
protected:
class Position {
public:
Glib::ustring name;
streampos pos;
Position(Glib::ustring n, streampos p): name(n), pos(p) {}
};
std::string filename;
ifstream *is;
time_t mtime;
SettingsFileHeader header;
std::vector<Position> entries;
Glib::ustring name;
int tp;
int flags;
friend class gx_engine::GxMachineRemote;
protected:
void open();
public:
typedef std::vector<Position>::iterator iterator;
PresetFile();
~PresetFile() { delete is; }
void readJSON_remote(JsonParser& jp);
void writeJSON_remote(JsonWriter& jw);
bool open_file(const Glib::ustring& name, const std::string& path, int tp, int flags);
bool create_file(const Glib::ustring& name, const std::string& path, int tp, int flags);
bool set_factory(const Glib::ustring& name_, const std::string& path);
bool readJSON(const std::string& dirpath, JsonParser &jp, bool *mtime_diff);
void writeJSON(JsonWriter& jw);
void reopen() { if (!is && !filename.empty()) open(); }
void open(const std::string& fname);
void close() { delete is; is = 0; }
bool fail();
bool ensure_is_current();
void check_flags();
const std::string& get_filename() const { return filename; }
const SettingsFileHeader& get_header();
int size();
void fill_names(vector<Glib::ustring>&);
const Glib::ustring& get_name(int n);
int get_index(const Glib::ustring& name);
JsonParser *create_reader(int n);
JsonParser *create_reader(const Glib::ustring& name) {
return create_reader(get_index(name)); }
JsonWriter *create_writer(int n) {
return create_writer(get_name(n)); }
JsonWriter *create_writer(const Glib::ustring& name);
JsonWriter *create_writer_at(const Glib::ustring& pos, const Glib::ustring& name);
PresetTransformer *create_transformer();
bool clear();
bool erase(const Glib::ustring& name);
bool rename(const Glib::ustring& name, Glib::ustring newname);
bool has_entry(const Glib::ustring& name) { return get_index(name) >= 0; }
void append(const Glib::ustring& name);
void insert_before(const Glib::ustring& nm, const Glib::ustring& newentry);
void insert_after(const Glib::ustring& nm, const Glib::ustring& newentry);
int get_flags() const { return flags; }
void set_flags(int f) { flags = f; }
void set_flag(int flag, bool v) { flags = (flags & ~flag) | (v ? flag : 0); }
int get_type() const { return tp; }
const Glib::ustring& get_name() const { return name; }
bool set_name(const Glib::ustring& n, const std::string& newfile);
bool remove_file();
iterator begin();
iterator end() { return entries.end(); }
bool is_moveable() const { return tp == PRESET_SCRATCH || tp == PRESET_FILE; }
bool is_mutable() const { return is_moveable() && !flags; }
PresetFileGui *get_guiwrapper();
bool is_newer(time_t m);
};
class PresetFileGui: private PresetFile {
private:
PresetFileGui();
~PresetFileGui();
friend class PresetFile;
friend class gx_engine::GxMachine;
friend class gx_engine::GxMachineRemote;
public:
using PresetFile::get_header;
using PresetFile::size;
using PresetFile::fill_names;
using PresetFile::get_name;
using PresetFile::get_index;
using PresetFile::has_entry;
using PresetFile::get_flags;
using PresetFile::get_type;
using PresetFile::begin;
using PresetFile::end;
using PresetFile::is_moveable;
using PresetFile::is_mutable;
operator PresetFile*() { return this; }
};
inline PresetFileGui *PresetFile::get_guiwrapper() { return static_cast<PresetFileGui*>(this); }
class AbstractStateIO {
public:
virtual ~AbstractStateIO();
virtual void read_state(JsonParser&,const SettingsFileHeader&) = 0;
virtual void commit_state() = 0;
virtual void write_state(JsonWriter&, bool) = 0;
};
class AbstractPresetIO {
public:
virtual ~AbstractPresetIO();
virtual void read_preset(JsonParser&,const SettingsFileHeader&) = 0;
virtual void commit_preset() = 0;
virtual void write_preset(JsonWriter&) = 0;
virtual void copy_preset(JsonParser&,const SettingsFileHeader&,JsonWriter&) = 0;
};
class PresetBanks {
private:
typedef std::list<PresetFile*> bl_type;
bl_type banklist;
std::string filepath;
time_t mtime;
std::string preset_dir;
void parse_factory_list(const std::string& path);
void parse_bank_list(bl_type::iterator pos);
void collect_lost_banks(const char* scratchpad_name, const char* scratchpad_file);
friend class gx_engine::GxMachineRemote;
public:
class iterator {
private:
bl_type::iterator it;
public:
iterator(bl_type::iterator i): it(i) {}
bool operator!=(const iterator& i) const { return it != i.it; }
iterator& operator++() { ++it; return *this; }
PresetFile* operator->() { return *it; }
PresetFile* operator*() { return *it; }
};
PresetBanks();
~PresetBanks();
void readJSON_remote(gx_system::JsonParser& jp);
bool check_reparse();
void parse(const std::string& bank_path, const std::string& preset_dir,
const std::string& factory_path, const char* scratchpad_name, const char* scratchpad_file);
PresetFile* get_file(const Glib::ustring& bank) const;
int get_index(const Glib::ustring& bank) const;
iterator begin() { return iterator(banklist.begin()); }
iterator end() { return iterator(banklist.end()); }
bool remove(const Glib::ustring& bank);
void check_save();
void save();
int size() { return banklist.size(); }
Glib::ustring get_name(int n);
void insert(PresetFile* f, int position = 0);
bool has_entry(const Glib::ustring& bank) const { return get_file(bank) != 0; }
bool has_file(const std::string& file) const;
bool rename(const Glib::ustring& oldname, const Glib::ustring& newname, const std::string& newfile);
void reorder(const std::vector<Glib::ustring>& neworder);
static void make_valid_utf8(Glib::ustring& s);
static std::string add_preset_postfix(const std::string& filename);
static bool strip_preset_postfix(std::string& name);
void make_bank_unique(Glib::ustring& name, std::string *file = 0);
};
class GxSettingsBase {
protected:
AbstractStateIO* state_io;
AbstractPresetIO* preset_io;
StateFile statefile;
PresetBanks banks;
Glib::ustring current_bank;
Glib::ustring current_name;
gx_engine::EngineControl& seq;
sigc::signal<void> selection_changed;
sigc::signal<void> presetlist_changed;
bool loadsetting(PresetFile *p, const Glib::ustring& name);
protected:
void loadstate();
void set_io(AbstractStateIO* st, AbstractPresetIO* pr) { state_io = st; preset_io = pr; }
public:
inline sigc::signal<void>& signal_selection_changed() {
return selection_changed; }
inline sigc::signal<void>& signal_presetlist_changed() {
return presetlist_changed; }
GxSettingsBase(gx_engine::EngineControl& seq_);
~GxSettingsBase();
const Glib::ustring& get_current_bank() { return current_bank; }
PresetFile *get_current_bank_file() { return setting_is_preset() ? banks.get_file(current_bank) : 0; }
const Glib::ustring& get_current_name() { return current_name; }
void set_statefilename(const std::string& fn) { statefile.set_filename(fn); }
void save_to_state(bool preserve_preset=false);
void set_source_to_state();
void erase_preset(const Glib::ustring& name);
bool setting_is_preset() { return !current_bank.empty(); }
bool convert_preset(PresetFile& pf);
void reorder_preset(PresetFile& pf, const std::vector<Glib::ustring>& neworder);
void erase_preset(PresetFile& pf, const Glib::ustring& name);
void save(PresetFile& pf, const Glib::ustring& name);
void append(PresetFile& pf, const Glib::ustring& src, PresetFile& pftgt, const Glib::ustring& name);
void insert_before(PresetFile& pf, const Glib::ustring& src, PresetFile& pftgt, const Glib::ustring& pos, const Glib::ustring& name);
void insert_after(PresetFile& pf, const Glib::ustring& src, PresetFile& pftgt, const Glib::ustring& pos, const Glib::ustring& name);
void load_preset(PresetFile *pf, const Glib::ustring& name);
bool rename_bank(const Glib::ustring& oldname, const Glib::ustring& newname, const std::string& newfile);
bool remove_bank(const Glib::ustring& bank);
bool rename_preset(PresetFile& pf, const Glib::ustring& oldname, const Glib::ustring& newname);
#ifdef GUITARIX_AS_PLUGIN
AbstractStateIO * get_state_io() { return state_io; }
#endif
};
} /* end of gx_system namespace */
#endif // SRC_HEADERS_GX_JSON_H_
gx_engine::EngineControl
Definition gx_modulesequencer.h:245
gx_engine::GxMachine
Definition machine.h:239
gx_engine::GxMachineRemote
Definition machine.h:407
gx_system::AbstractPresetIO
Definition gx_json.h:406
gx_system::AbstractPresetIO::write_preset
virtual void write_preset(JsonWriter &)=0
gx_system::AbstractPresetIO::~AbstractPresetIO
virtual ~AbstractPresetIO()
gx_system::AbstractPresetIO::commit_preset
virtual void commit_preset()=0
gx_system::AbstractPresetIO::read_preset
virtual void read_preset(JsonParser &, const SettingsFileHeader &)=0
gx_system::AbstractPresetIO::copy_preset
virtual void copy_preset(JsonParser &, const SettingsFileHeader &, JsonWriter &)=0
gx_system::AbstractStateIO
Definition gx_json.h:398
gx_system::AbstractStateIO::~AbstractStateIO
virtual ~AbstractStateIO()
gx_system::AbstractStateIO::read_state
virtual void read_state(JsonParser &, const SettingsFileHeader &)=0
gx_system::AbstractStateIO::write_state
virtual void write_state(JsonWriter &, bool)=0
gx_system::AbstractStateIO::commit_state
virtual void commit_state()=0
gx_system::GxSettingsBase::erase_preset
void erase_preset(const Glib::ustring &name)
gx_system::GxSettingsBase::GxSettingsBase
GxSettingsBase(gx_engine::EngineControl &seq_)
gx_system::GxSettingsBase::selection_changed
sigc::signal< void > selection_changed
Definition gx_json.h:472
gx_system::GxSettingsBase::state_io
AbstractStateIO * state_io
Definition gx_json.h:465
gx_system::GxSettingsBase::rename_bank
bool rename_bank(const Glib::ustring &oldname, const Glib::ustring &newname, const std::string &newfile)
gx_system::GxSettingsBase::set_source_to_state
void set_source_to_state()
gx_system::GxSettingsBase::convert_preset
bool convert_preset(PresetFile &pf)
gx_system::GxSettingsBase::loadstate
void loadstate()
gx_system::GxSettingsBase::setting_is_preset
bool setting_is_preset()
Definition gx_json.h:492
gx_system::GxSettingsBase::presetlist_changed
sigc::signal< void > presetlist_changed
Definition gx_json.h:473
gx_system::GxSettingsBase::banks
PresetBanks banks
Definition gx_json.h:468
gx_system::GxSettingsBase::current_bank
Glib::ustring current_bank
Definition gx_json.h:469
gx_system::GxSettingsBase::signal_selection_changed
sigc::signal< void > & signal_selection_changed()
Definition gx_json.h:479
gx_system::GxSettingsBase::reorder_preset
void reorder_preset(PresetFile &pf, const std::vector< Glib::ustring > &neworder)
gx_system::GxSettingsBase::set_io
void set_io(AbstractStateIO *st, AbstractPresetIO *pr)
Definition gx_json.h:477
gx_system::GxSettingsBase::save_to_state
void save_to_state(bool preserve_preset=false)
gx_system::GxSettingsBase::get_current_name
const Glib::ustring & get_current_name()
Definition gx_json.h:487
gx_system::GxSettingsBase::remove_bank
bool remove_bank(const Glib::ustring &bank)
gx_system::GxSettingsBase::~GxSettingsBase
~GxSettingsBase()
gx_system::GxSettingsBase::current_name
Glib::ustring current_name
Definition gx_json.h:470
gx_system::GxSettingsBase::save
void save(PresetFile &pf, const Glib::ustring &name)
gx_system::GxSettingsBase::loadsetting
bool loadsetting(PresetFile *p, const Glib::ustring &name)
gx_system::GxSettingsBase::seq
gx_engine::EngineControl & seq
Definition gx_json.h:471
gx_system::GxSettingsBase::get_current_bank
const Glib::ustring & get_current_bank()
Definition gx_json.h:485
gx_system::GxSettingsBase::append
void append(PresetFile &pf, const Glib::ustring &src, PresetFile &pftgt, const Glib::ustring &name)
gx_system::GxSettingsBase::rename_preset
bool rename_preset(PresetFile &pf, const Glib::ustring &oldname, const Glib::ustring &newname)
gx_system::GxSettingsBase::signal_presetlist_changed
sigc::signal< void > & signal_presetlist_changed()
Definition gx_json.h:481
gx_system::GxSettingsBase::set_statefilename
void set_statefilename(const std::string &fn)
Definition gx_json.h:488
gx_system::GxSettingsBase::load_preset
void load_preset(PresetFile *pf, const Glib::ustring &name)
gx_system::GxSettingsBase::insert_before
void insert_before(PresetFile &pf, const Glib::ustring &src, PresetFile &pftgt, const Glib::ustring &pos, const Glib::ustring &name)
gx_system::GxSettingsBase::insert_after
void insert_after(PresetFile &pf, const Glib::ustring &src, PresetFile &pftgt, const Glib::ustring &pos, const Glib::ustring &name)
gx_system::GxSettingsBase::get_current_bank_file
PresetFile * get_current_bank_file()
Definition gx_json.h:486
gx_system::GxSettingsBase::statefile
StateFile statefile
Definition gx_json.h:467
gx_system::GxSettingsBase::preset_io
AbstractPresetIO * preset_io
Definition gx_json.h:466
gx_system::GxSettingsBase::erase_preset
void erase_preset(PresetFile &pf, const Glib::ustring &name)
gx_system::JsonExceptionEOF::~JsonExceptionEOF
~JsonExceptionEOF()
Definition gx_json.h:52
gx_system::JsonExceptionEOF::JsonExceptionEOF
JsonExceptionEOF(const char *desc)
Definition gx_json.h:51
gx_system::JsonException::what_str
Glib::ustring what_str
Definition gx_json.h:42
gx_system::JsonException::~JsonException
~JsonException()
Definition gx_json.h:45
gx_system::JsonException::what
virtual const char * what() const
Definition gx_json.h:46
gx_system::JsonException::JsonException
JsonException(const Glib::ustring &desc)
gx_system::JsonParser
Definition gx_json.h:112
gx_system::JsonParser::skip_object
void skip_object()
gx_system::JsonParser::next_tok
token next_tok
Definition gx_json.h:182
gx_system::JsonParser::token
token
Definition gx_json.h:121
gx_system::JsonParser::end_array
@ end_array
Definition gx_json.h:127
gx_system::JsonParser::begin_object
@ begin_object
Definition gx_json.h:124
gx_system::JsonParser::value_string
@ value_string
Definition gx_json.h:128
gx_system::JsonParser::no_token
@ no_token
Definition gx_json.h:122
gx_system::JsonParser::end_object
@ end_object
Definition gx_json.h:125
gx_system::JsonParser::value_null
@ value_null
Definition gx_json.h:131
gx_system::JsonParser::value_true
@ value_true
Definition gx_json.h:133
gx_system::JsonParser::value_false
@ value_false
Definition gx_json.h:132
gx_system::JsonParser::value_key
@ value_key
Definition gx_json.h:130
gx_system::JsonParser::end_token
@ end_token
Definition gx_json.h:123
gx_system::JsonParser::value_bool
@ value_bool
Definition gx_json.h:134
gx_system::JsonParser::value_number
@ value_number
Definition gx_json.h:129
gx_system::JsonParser::begin_array
@ begin_array
Definition gx_json.h:126
gx_system::JsonParser::get_token_name
const char * get_token_name(token tok)
gx_system::JsonParser::read_kv
bool read_kv(const char *key, double &v)
gx_system::JsonParser::peek
token peek()
Definition gx_json.h:139
gx_system::JsonParser::next_depth
int next_depth
Definition gx_json.h:181
gx_system::JsonParser::good
bool good()
Definition gx_json.h:137
gx_system::JsonParser::current_value_int
int current_value_int()
Definition gx_json.h:144
gx_system::JsonParser::current_value_float
float current_value_float()
Definition gx_json.h:146
gx_system::JsonParser::is
istream * is
Definition gx_json.h:176
gx_system::JsonParser::current_value_double
double current_value_double()
Definition gx_json.h:152
gx_system::JsonParser::str
string str
Definition gx_json.h:179
gx_system::JsonParser::read_kv
bool read_kv(const char *key, Glib::ustring &s)
gx_system::JsonParser::read_next
void read_next()
gx_system::JsonParser::read_kv
bool read_kv(const char *key, std::string &s)
gx_system::JsonParser::set_streampos
void set_streampos(streampos pos)
gx_system::JsonParser::next_str
string next_str
Definition gx_json.h:183
gx_system::JsonParser::is_closed
bool is_closed()
Definition gx_json.h:118
gx_system::JsonParser::readstring
string readstring()
gx_system::JsonParser::cur_tok
token cur_tok
Definition gx_json.h:178
gx_system::JsonParser::next_pos
streampos next_pos
Definition gx_json.h:185
gx_system::JsonParser::set_stream
void set_stream(istream *i)
Definition gx_json.h:119
gx_system::JsonParser::nl
bool nl
Definition gx_json.h:180
gx_system::JsonParser::throw_unexpected
void throw_unexpected(token expect)
gx_system::JsonParser::depth
int depth
Definition gx_json.h:177
gx_system::JsonParser::get_stream
istream * get_stream()
Definition gx_json.h:120
gx_system::JsonParser::read_kv
bool read_kv(const char *key, float &v)
gx_system::JsonParser::current_value_uint
unsigned int current_value_uint()
Definition gx_json.h:145
gx_system::JsonParser::~JsonParser
virtual ~JsonParser()
gx_system::JsonParser::read_kv
bool read_kv(const char *key, int &i)
gx_system::JsonParser::readcode
const char * readcode()
gx_system::JsonParser::read_value_token
token read_value_token(char c)
gx_system::JsonParser::get_streampos
streampos get_streampos()
Definition gx_json.h:140
gx_system::JsonParser::read_kv
bool read_kv(const char *key, T &v)
Definition gx_json.h:164
gx_system::JsonParser::next
token next(token expect=no_token)
gx_system::JsonParser::close
virtual void close()
gx_system::JsonParser::copy_object
void copy_object(JsonWriter &jw)
gx_system::JsonParser::JsonParser
JsonParser(istream *i=0)
gx_system::JsonParser::log_tok
string log_tok
Definition gx_json.h:184
gx_system::JsonParser::reset
void reset()
gx_system::JsonParser::check_expect
void check_expect(token expect)
Definition gx_json.h:142
gx_system::JsonParser::read_kv
bool read_kv(const char *key, unsigned int &i)
gx_system::JsonParser::current_value
string current_value() const
Definition gx_json.h:143
gx_system::JsonParser::readnumber
string readnumber(char c)
gx_system::JsonStringParser::get_ostream
std::ostream & get_ostream()
Definition gx_json.h:208
gx_system::JsonStringParser::get_string
std::string get_string()
Definition gx_json.h:210
gx_system::JsonStringParser::start_parser
void start_parser()
Definition gx_json.h:209
gx_system::JsonStringParser::JsonStringParser
JsonStringParser()
Definition gx_json.h:206
gx_system::JsonStringParser::reset
void reset()
Definition gx_json.h:211
gx_system::JsonStringParser::put
void put(char c)
Definition gx_json.h:207
gx_system::JsonStringParser::peek_first_char
char peek_first_char()
Definition gx_json.h:212
gx_system::JsonStringParser::stream
std::stringstream stream
Definition gx_json.h:204
gx_system::JsonStringWriter::send_notify_begin
void send_notify_begin(const char *method)
gx_system::JsonStringWriter::JsonStringWriter
JsonStringWriter()
Definition gx_json.h:103
gx_system::JsonStringWriter::finish
void finish()
Definition gx_json.h:107
gx_system::JsonStringWriter::reset
void reset()
Definition gx_json.h:106
gx_system::JsonStringWriter::get_string
std::string get_string()
Definition gx_json.h:108
gx_system::JsonStringWriter::stream
ostringstream stream
Definition gx_json.h:101
gx_system::JsonStringWriter::send_notify_end
void send_notify_end()
gx_system::JsonSubParser::position
std::streampos position
Definition gx_json.h:196
gx_system::JsonSubParser::JsonSubParser
JsonSubParser(JsonParser &jp, streampos pos)
gx_system::JsonSubParser::~JsonSubParser
~JsonSubParser()
gx_system::JsonWriter
Definition gx_json.h:55
gx_system::JsonWriter::first
bool first
Definition gx_json.h:58
gx_system::JsonWriter::good
bool good()
Definition gx_json.h:71
gx_system::JsonWriter::write_key
void write_key(const string &p, bool nl=false)
gx_system::JsonWriter::write_kv
void write_kv(const char *key, float v)
Definition gx_json.h:81
gx_system::JsonWriter::write
void write(const string &s, bool nl=false)
Definition gx_json.h:80
gx_system::JsonWriter::write
void write(const char *p, bool nl=false)
gx_system::JsonWriter::snl
void snl(bool v)
Definition gx_json.h:61
gx_system::JsonWriter::space
void space()
gx_system::JsonWriter::write
void write(double v, bool nl=false)
gx_system::JsonWriter::write_kv
void write_kv(const char *key, int i)
Definition gx_json.h:83
gx_system::JsonWriter::begin_object
void begin_object(bool nl=false)
gx_system::JsonWriter::write
void write(int i, bool nl=false)
gx_system::JsonWriter::write_kv
void write_kv(const char *key, unsigned int i)
Definition gx_json.h:84
gx_system::JsonWriter::JsonWriter
JsonWriter(ostream *o=0, bool enable_newlines=true)
gx_system::JsonWriter::komma
void komma()
gx_system::JsonWriter::write
void write(float v, bool nl=false)
gx_system::JsonWriter::os
ostream * os
Definition gx_json.h:57
gx_system::JsonWriter::set_stream
void set_stream(ostream *o)
Definition gx_json.h:70
gx_system::JsonWriter::write_kv
void write_kv(const char *key, const char *p)
Definition gx_json.h:85
gx_system::JsonWriter::newline
void newline()
Definition gx_json.h:95
gx_system::JsonWriter::deferred_nl
int deferred_nl
Definition gx_json.h:59
gx_system::JsonWriter::close
virtual void close()
gx_system::JsonWriter::begin_array
void begin_array(bool nl=false)
gx_system::JsonWriter::is_closed
bool is_closed()
Definition gx_json.h:74
gx_system::JsonWriter::~JsonWriter
virtual ~JsonWriter()
gx_system::JsonWriter::end_object
void end_object(bool nl=false)
gx_system::JsonWriter::iplus
void iplus()
gx_system::JsonWriter::write_kv
void write_kv(const char *key, const std::string &s)
Definition gx_json.h:86
gx_system::JsonWriter::write_kv
void write_kv(const char *key, double v)
Definition gx_json.h:82
gx_system::JsonWriter::iminus
void iminus()
gx_system::JsonWriter::write_key
void write_key(const char *p, bool nl=false)
gx_system::JsonWriter::write_null
void write_null(bool nl=false)
Definition gx_json.h:94
gx_system::JsonWriter::reset
void reset()
gx_system::JsonWriter::write_lit
void write_lit(const string &s, bool nl=false)
gx_system::JsonWriter::end_array
void end_array(bool nl=false)
gx_system::JsonWriter::write
void write(unsigned int i, bool nl=false)
gx_system::JsonWriter::indent
string indent
Definition gx_json.h:60
gx_system::JsonWriter::flush
void flush()
gx_system::PresetBanks::iterator
Definition gx_json.h:427
gx_system::PresetBanks::iterator::iterator
iterator(bl_type::iterator i)
Definition gx_json.h:431
gx_system::PresetBanks::iterator::operator!=
bool operator!=(const iterator &i) const
Definition gx_json.h:432
gx_system::PresetBanks::iterator::it
bl_type::iterator it
Definition gx_json.h:429
gx_system::PresetBanks::iterator::operator->
PresetFile * operator->()
Definition gx_json.h:434
gx_system::PresetBanks::iterator::operator*
PresetFile * operator*()
Definition gx_json.h:435
gx_system::PresetBanks::iterator::operator++
iterator & operator++()
Definition gx_json.h:433
gx_system::PresetBanks
Definition gx_json.h:415
gx_system::PresetBanks::parse_bank_list
void parse_bank_list(bl_type::iterator pos)
gx_system::PresetBanks::readJSON_remote
void readJSON_remote(gx_system::JsonParser &jp)
gx_system::PresetBanks::add_preset_postfix
static std::string add_preset_postfix(const std::string &filename)
gx_system::PresetBanks::filepath
std::string filepath
Definition gx_json.h:419
gx_system::PresetBanks::banklist
bl_type banklist
Definition gx_json.h:418
gx_system::PresetBanks::~PresetBanks
~PresetBanks()
gx_system::PresetBanks::parse
void parse(const std::string &bank_path, const std::string &preset_dir, const std::string &factory_path, const char *scratchpad_name, const char *scratchpad_file)
gx_system::PresetBanks::has_entry
bool has_entry(const Glib::ustring &bank) const
Definition gx_json.h:453
gx_system::PresetBanks::reorder
void reorder(const std::vector< Glib::ustring > &neworder)
gx_system::PresetBanks::end
iterator end()
Definition gx_json.h:446
gx_system::PresetBanks::remove
bool remove(const Glib::ustring &bank)
gx_system::PresetBanks::check_save
void check_save()
gx_system::PresetBanks::get_file
PresetFile * get_file(const Glib::ustring &bank) const
gx_system::PresetBanks::begin
iterator begin()
Definition gx_json.h:445
gx_system::PresetBanks::PresetBanks
PresetBanks()
gx_system::PresetBanks::save
void save()
gx_system::PresetBanks::parse_factory_list
void parse_factory_list(const std::string &path)
gx_system::PresetBanks::rename
bool rename(const Glib::ustring &oldname, const Glib::ustring &newname, const std::string &newfile)
gx_system::PresetBanks::insert
void insert(PresetFile *f, int position=0)
gx_system::PresetBanks::make_valid_utf8
static void make_valid_utf8(Glib::ustring &s)
gx_system::PresetBanks::preset_dir
std::string preset_dir
Definition gx_json.h:421
gx_system::PresetBanks::mtime
time_t mtime
Definition gx_json.h:420
gx_system::PresetBanks::bl_type
std::list< PresetFile * > bl_type
Definition gx_json.h:417
gx_system::PresetBanks::get_name
Glib::ustring get_name(int n)
gx_system::PresetBanks::make_bank_unique
void make_bank_unique(Glib::ustring &name, std::string *file=0)
gx_system::PresetBanks::get_index
int get_index(const Glib::ustring &bank) const
gx_system::PresetBanks::has_file
bool has_file(const std::string &file) const
gx_system::PresetBanks::collect_lost_banks
void collect_lost_banks(const char *scratchpad_name, const char *scratchpad_file)
gx_system::PresetBanks::check_reparse
bool check_reparse()
gx_system::PresetBanks::strip_preset_postfix
static bool strip_preset_postfix(std::string &name)
gx_system::PresetBanks::size
int size()
Definition gx_json.h:450
gx_system::PresetFile::Position::Position
Position(Glib::ustring n, streampos p)
Definition gx_json.h:307
gx_system::PresetFile::Position::name
Glib::ustring name
Definition gx_json.h:305
gx_system::PresetFile::Position::pos
streampos pos
Definition gx_json.h:306
gx_system::PresetFileGui
Definition gx_json.h:373
gx_system::PresetFileGui::~PresetFileGui
~PresetFileGui()
gx_system::PresetFileGui::PresetFile
friend class PresetFile
Definition gx_json.h:377
gx_system::PresetFileGui::PresetFileGui
PresetFileGui()
gx_system::PresetFile
Definition gx_json.h:299
gx_system::PresetFile::get_type
int get_type() const
Definition gx_json.h:361
gx_system::PresetFile::PRESET_FILE
@ PRESET_FILE
Definition gx_json.h:301
gx_system::PresetFile::PRESET_SCRATCH
@ PRESET_SCRATCH
Definition gx_json.h:301
gx_system::PresetFile::PRESET_FACTORY
@ PRESET_FACTORY
Definition gx_json.h:301
gx_system::PresetFile::PRESET_SEP
@ PRESET_SEP
Definition gx_json.h:301
gx_system::PresetFile::begin
iterator begin()
gx_system::PresetFile::insert_before
void insert_before(const Glib::ustring &nm, const Glib::ustring &newentry)
gx_system::PresetFile::fill_names
void fill_names(vector< Glib::ustring > &)
gx_system::PresetFile::end
iterator end()
Definition gx_json.h:366
gx_system::PresetFile::readJSON_remote
void readJSON_remote(JsonParser &jp)
gx_system::PresetFile::filename
std::string filename
Definition gx_json.h:309
gx_system::PresetFile::iterator
std::vector< Position >::iterator iterator
Definition gx_json.h:321
gx_system::PresetFile::close
void close()
Definition gx_json.h:333
gx_system::PresetFile::~PresetFile
~PresetFile()
Definition gx_json.h:323
gx_system::PresetFile::create_transformer
PresetTransformer * create_transformer()
gx_system::PresetFile::entries
std::vector< Position > entries
Definition gx_json.h:313
gx_system::PresetFile::check_flags
void check_flags()
gx_system::PresetFile::get_guiwrapper
PresetFileGui * get_guiwrapper()
Definition gx_json.h:396
gx_system::PresetFile::reopen
void reopen()
Definition gx_json.h:331
gx_system::PresetFile::flags
int flags
Definition gx_json.h:316
gx_system::PresetFile::get_name
const Glib::ustring & get_name() const
Definition gx_json.h:362
gx_system::PresetFile::get_index
int get_index(const Glib::ustring &name)
gx_system::PresetFile::has_entry
bool has_entry(const Glib::ustring &name)
Definition gx_json.h:354
gx_system::PresetFile::get_header
const SettingsFileHeader & get_header()
gx_system::PresetFile::tp
int tp
Definition gx_json.h:315
gx_system::PresetFile::set_factory
bool set_factory(const Glib::ustring &name_, const std::string &path)
gx_system::PresetFile::mtime
time_t mtime
Definition gx_json.h:311
gx_system::PresetFile::create_writer
JsonWriter * create_writer(int n)
Definition gx_json.h:346
gx_system::PresetFile::writeJSON
void writeJSON(JsonWriter &jw)
gx_system::PresetFile::create_writer
JsonWriter * create_writer(const Glib::ustring &name)
gx_system::PresetFile::set_flag
void set_flag(int flag, bool v)
Definition gx_json.h:360
gx_system::PresetFile::get_flags
int get_flags() const
Definition gx_json.h:358
gx_system::PresetFile::is_newer
bool is_newer(time_t m)
gx_system::PresetFile::is
ifstream * is
Definition gx_json.h:310
gx_system::PresetFile::create_reader
JsonParser * create_reader(const Glib::ustring &name)
Definition gx_json.h:344
gx_system::PresetFile::set_flags
void set_flags(int f)
Definition gx_json.h:359
gx_system::PresetFile::open
void open(const std::string &fname)
gx_system::PresetFile::erase
bool erase(const Glib::ustring &name)
gx_system::PresetFile::create_file
bool create_file(const Glib::ustring &name, const std::string &path, int tp, int flags)
gx_system::PresetFile::PresetFile
PresetFile()
gx_system::PresetFile::open_file
bool open_file(const Glib::ustring &name, const std::string &path, int tp, int flags)
gx_system::PresetFile::is_moveable
bool is_moveable() const
Definition gx_json.h:367
gx_system::PresetFile::rename
bool rename(const Glib::ustring &name, Glib::ustring newname)
gx_system::PresetFile::fail
bool fail()
gx_system::PresetFile::header
SettingsFileHeader header
Definition gx_json.h:312
gx_system::PresetFile::is_mutable
bool is_mutable() const
Definition gx_json.h:368
gx_system::PresetFile::get_name
const Glib::ustring & get_name(int n)
gx_system::PresetFile::create_writer_at
JsonWriter * create_writer_at(const Glib::ustring &pos, const Glib::ustring &name)
gx_system::PresetFile::open
void open()
gx_system::PresetFile::append
void append(const Glib::ustring &name)
gx_system::PresetFile::set_name
bool set_name(const Glib::ustring &n, const std::string &newfile)
gx_system::PresetFile::clear
bool clear()
gx_system::PresetFile::readJSON
bool readJSON(const std::string &dirpath, JsonParser &jp, bool *mtime_diff)
gx_system::PresetFile::name
Glib::ustring name
Definition gx_json.h:314
gx_system::PresetFile::size
int size()
gx_system::PresetFile::writeJSON_remote
void writeJSON_remote(JsonWriter &jw)
gx_system::PresetFile::create_reader
JsonParser * create_reader(int n)
gx_system::PresetFile::ensure_is_current
bool ensure_is_current()
gx_system::PresetFile::insert_after
void insert_after(const Glib::ustring &nm, const Glib::ustring &newentry)
gx_system::PresetFile::get_filename
const std::string & get_filename() const
Definition gx_json.h:337
gx_system::PresetFile::remove_file
bool remove_file()
gx_system::PresetTransformer
Definition gx_json.h:274
gx_system::PresetTransformer::is
istream * is
Definition gx_json.h:280
gx_system::PresetTransformer::close
void close()
gx_system::PresetTransformer::header
SettingsFileHeader header
Definition gx_json.h:283
gx_system::PresetTransformer::tmpfile
string tmpfile
Definition gx_json.h:277
gx_system::PresetTransformer::filename
string filename
Definition gx_json.h:276
gx_system::PresetTransformer::~PresetTransformer
~PresetTransformer()
gx_system::PresetTransformer::close_nocheck
void close_nocheck()
gx_system::PresetTransformer::abort
void abort()
gx_system::PresetTransformer::os
ofstream os
Definition gx_json.h:278
gx_system::PresetTransformer::PresetTransformer
PresetTransformer(string filename, istream *is)
gx_system::PresetTransformer::jp
JsonParser jp
Definition gx_json.h:282
gx_system::SettingsFileHeader
Definition gx_json.h:224
gx_system::SettingsFileHeader::file_minor
int file_minor
Definition gx_json.h:226
gx_system::SettingsFileHeader::write
static void write(JsonWriter &)
gx_system::SettingsFileHeader::set_to_current
void set_to_current()
Definition gx_json.h:238
gx_system::SettingsFileHeader::read_major_minor
void read_major_minor(JsonParser &jp)
gx_system::SettingsFileHeader::is_major_diff
bool is_major_diff() const
Definition gx_json.h:242
gx_system::SettingsFileHeader::file_major
int file_major
Definition gx_json.h:225
gx_system::SettingsFileHeader::file_gx_version
string file_gx_version
Definition gx_json.h:227
gx_system::SettingsFileHeader::is_equal
bool is_equal() const
Definition gx_json.h:245
gx_system::SettingsFileHeader::write_current_major_minor
static void write_current_major_minor(JsonWriter &jw)
gx_system::SettingsFileHeader::get_minor
int get_minor() const
Definition gx_json.h:240
gx_system::SettingsFileHeader::minor
@ minor
Definition gx_json.h:231
gx_system::SettingsFileHeader::major
@ major
Definition gx_json.h:230
gx_system::SettingsFileHeader::gx_version
static const string gx_version
Definition gx_json.h:233
gx_system::SettingsFileHeader::current_version_string
Glib::ustring current_version_string() const
Definition gx_json.h:248
gx_system::SettingsFileHeader::get_major
int get_major() const
Definition gx_json.h:239
gx_system::SettingsFileHeader::make_empty_settingsfile
static bool make_empty_settingsfile(const string &name)
gx_system::SettingsFileHeader::display
string display() const
Definition gx_json.h:246
gx_system::SettingsFileHeader::write_major_minor
void write_major_minor(JsonWriter &jw)
gx_system::SettingsFileHeader::version_string
Glib::ustring version_string() const
Definition gx_json.h:247
gx_system::SettingsFileHeader::get_revision
string get_revision() const
Definition gx_json.h:241
gx_system::SettingsFileHeader::SettingsFileHeader
SettingsFileHeader()
Definition gx_json.h:234
gx_system::SettingsFileHeader::is_current
bool is_current() const
Definition gx_json.h:244
gx_system::SettingsFileHeader::read
void read(JsonParser &)
gx_system::SettingsFileHeader::is_minor_diff
bool is_minor_diff() const
Definition gx_json.h:243
gx_system::StateFile
Definition gx_json.h:255
gx_system::StateFile::is
istream * is
Definition gx_json.h:258
gx_system::StateFile::mtime
time_t mtime
Definition gx_json.h:259
gx_system::StateFile::filename
string filename
Definition gx_json.h:257
gx_system::StateFile::~StateFile
~StateFile()
Definition gx_json.h:265
gx_system::StateFile::get_header
const SettingsFileHeader & get_header() const
Definition gx_json.h:267
gx_system::StateFile::create_reader
JsonParser * create_reader()
gx_system::StateFile::header
SettingsFileHeader header
Definition gx_json.h:260
gx_system::StateFile::open
void open()
gx_system::StateFile::set_filename
void set_filename(const string &fn)
gx_system::StateFile::ensure_is_current
void ensure_is_current()
gx_system::StateFile::StateFile
StateFile()
Definition gx_json.h:263
gx_system::StateFile::create_writer
JsonWriter * create_writer(bool *preserve_preset)
gx_system::StateFile::get_filename
string get_filename() const
Definition gx_json.h:268
gx_engine
Definition gx_convolver.h:37
gx_system
Definition gx_json.h:33
gx_system::PRESET_FLAG_INVALID
@ PRESET_FLAG_INVALID
Definition gx_json.h:294
gx_system::PRESET_FLAG_READONLY
@ PRESET_FLAG_READONLY
Definition gx_json.h:293
gx_system::PRESET_FLAG_VERSIONDIFF
@ PRESET_FLAG_VERSIONDIFF
Definition gx_json.h:292