From 9dcdcf68f6a60741cbdd287e7eda23b4a21a080e Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sat, 19 Feb 2022 13:30:03 -0800 Subject: Fix build errors and update all dependencies to latest version - Fixed doctest executable not compiling - Fixed class accessibility error in Workflow_Main.cpp - Fixed selection of OpenGL loader in imgui OpenGL 2 & 3 backends - All loading is handled in our code now, the imgui_*_backend.cpp files are instructed to do nothing --- 3rdparty/imgui-node-editor/crude_json.cpp | 80 ++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) (limited to '3rdparty/imgui-node-editor/crude_json.cpp') diff --git a/3rdparty/imgui-node-editor/crude_json.cpp b/3rdparty/imgui-node-editor/crude_json.cpp index 34f117f..a9f7c70 100644 --- a/3rdparty/imgui-node-editor/crude_json.cpp +++ b/3rdparty/imgui-node-editor/crude_json.cpp @@ -1,4 +1,6 @@ -// Crude implementation of JSON value object and parser. +// Crude implementation of JSON value object and parser. +// +// VERSION 0.1 // // LICENSE // This software is dual-licensed to the public domain and under the following @@ -14,7 +16,10 @@ # include # include # include - +# if CRUDE_JSON_IO +# include +# include +# endif namespace crude_json { @@ -147,6 +152,22 @@ void value::push_back(value&& value) } } +size_t value::erase(const string& key) +{ + if (!is_object()) + return 0; + + auto& o = *object_ptr(m_Storage); + auto it = o.find(key); + + if (it == o.end()) + return 0; + + o.erase(it); + + return 1; +} + void value::swap(value& other) { using std::swap; @@ -811,4 +832,59 @@ value value::parse(const string& data) return v; } +# if CRUDE_JSON_IO +std::pair value::load(const string& path) +{ + // Modern C++, so beautiful... + std::unique_ptr file{nullptr, [](FILE* file) { if (file) fclose(file); }}; +# if defined(_MSC_VER) || (defined(__STDC_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__) + FILE* handle = nullptr; + if (fopen_s(&handle, path.c_str(), "rb") != 0) + return {value{}, false}; + file.reset(handle); +# else + file.reset(fopen(path.c_str(), "rb")); +# endif + + if (!file) + return {value{}, false}; + + fseek(file.get(), 0, SEEK_END); + auto size = static_cast(ftell(file.get())); + fseek(file.get(), 0, SEEK_SET); + + string data; + data.resize(size); + if (fread(const_cast(data.data()), size, 1, file.get()) != 1) + return {value{}, false}; + + return {parse(data), true}; +} + +bool value::save(const string& path, const int indent, const char indent_char) const +{ + // Modern C++, so beautiful... + std::unique_ptr file{nullptr, [](FILE* file) { if (file) fclose(file); }}; +# if defined(_MSC_VER) || (defined(__STDC_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__) + FILE* handle = nullptr; + if (fopen_s(&handle, path.c_str(), "wb") != 0) + return false; + file.reset(handle); +# else + file.reset(fopen(path.c_str(), "wb")); +# endif + + if (!file) + return false; + + auto data = dump(indent, indent_char); + + if (fwrite(data.data(), data.size(), 1, file.get()) != 1) + return false; + + return true; +} + +# endif + } // namespace crude_json -- cgit v1.2.3-70-g09d2