From b49f461ce4b183290d1a4a6101539def67f4668e Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 19 Apr 2012 10:54:24 +0000 Subject: [PATCH] Core: LoadFromJsonFile, StoreToJsonFile git-svn-id: svn://ultimatepp.org/upp/trunk@4825 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/JSON.cpp | 5 +++++ uppsrc/Core/JSON.h | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/uppsrc/Core/JSON.cpp b/uppsrc/Core/JSON.cpp index be682203d..32b5797a5 100644 --- a/uppsrc/Core/JSON.cpp +++ b/uppsrc/Core/JSON.cpp @@ -304,4 +304,9 @@ template<> void Jsonize(JsonIO& io, Time& var) var.year, var.month, var.day, var.hour, var.minute, var.second)); } +String sJsonFile(const char *file) +{ + return file ? String(file) : ConfigFile(GetExeTitle() + ".json"); +} + END_UPP_NAMESPACE diff --git a/uppsrc/Core/JSON.h b/uppsrc/Core/JSON.h index 11c34f5ce..4ee2d6b95 100644 --- a/uppsrc/Core/JSON.h +++ b/uppsrc/Core/JSON.h @@ -174,6 +174,20 @@ bool LoadFromJson(T& var, const char *json) return true; } +String sJsonFile(const char *file); + +template +bool StoreAsJsonFile(const T& var, const char *file, bool pretty = false) +{ + return SaveFile(sJsonFile(file), StoreAsJson(var, pretty));; +} + +template +bool LoadFromJsonFile(T& var, const char *file = NULL) +{ + return LoadFromJson(var, LoadFile(sJsonFile(file))); +} + template<> void Jsonize(JsonIO& io, int& var); template<> void Jsonize(JsonIO& io, int64& var); template<> void Jsonize(JsonIO& io, double& var);