5 JsonFile::JsonFile(File file,
const Identifier& defaultProperty,
const String& defaultFormat)
6 : m_jsonFile(file), m_defaultProperty(defaultProperty), m_defaultFormat(defaultFormat)
12 catch (std::exception& ex)
16 static std::once_flag flag;
17 std::call_once(flag, [ex] {
18 std::cout <<
"JsonFile Error: " << ex.what() <<
"\n" << std::endl;
20 <<
"\t UnitTest detected. Silencing additional JsonFile exception logging to prevent nuisance "
26 std::cout <<
"JsonFile Error: " << ex.what() <<
"\n";
30 const bool deleteSuccess =
m_jsonFile.deleteFile();
39 "On using fallback default JSON format.");
42 catch (std::exception& ex)
46 static std::once_flag flag;
47 std::call_once(flag, [ex] {
48 std::cout <<
"JsonFile Error: " << ex.what() <<
"\n" << std::endl;
49 std::cout <<
"\t UnitTest detected. Silencing additional JsonFile exception logging to prevent "
50 "nuisance log spamming"
55 std::cout <<
"JsonFile Error: " << ex.what() <<
"\n";
64 jassert(
m_jsonFile.getFullPathName().isNotEmpty());
72 throw JsonException(
"File is invalid or empty and could not be initialised",
73 "On parsing the JSON file.");
94 TemporaryFile tempFile{
m_jsonFile, TemporaryFile::OptionFlags::useHiddenFile};
96 if (
auto fileOutputStream = std::unique_ptr<FileOutputStream>(tempFile.getFile().createOutputStream()))
99 fileOutputStream->setPosition(0);
100 fileOutputStream->truncate();
103 JSON::writeToStream(*fileOutputStream,
m_data);
106 fileOutputStream.reset();
108 const bool success = tempFile.overwriteTargetFileWithTemporary();
114 "\t with temporary file.",
115 "When saving JSON file");
124 "\t Reason: " + result.getErrorMessage().toStdString(),
125 "When creating JSON file");
140 catch (std::exception& ex)
144 static std::once_flag flag;
145 std::call_once(flag, [ex] {
146 std::cout <<
"JsonFile Error: " << ex.what() <<
"\n" << std::endl;
148 <<
"\t UnitTest detected. Silencing additional JsonFile exception logging to prevent nuisance "
154 std::cout <<
"JsonFile Error: " << ex.what() <<
"\n";
160 : std::runtime_error(whatHappened.getCharPointer())
An exception for the JSON file class.
Definition JsonFile.h:79
JsonException(const String &whatHappened, const String &whenDidItHappen)
Definition JsonFile.cpp:159
char const * what() const noexcept override
Definition JsonFile.cpp:165
String m_whenDidItHappen
Definition JsonFile.h:92
String when() const
Get the "when" status of the exception. This is the context behind the "what" action.
Definition JsonFile.cpp:167
void initialise()
Parse the file if it exists, or create it if it doesn't. Data is parsed to m_data;.
Definition JsonFile.cpp:61
void saveInternal()
Save any changes made to m_data back to the Json file.
Definition JsonFile.cpp:92
JsonFile(File jsonFile, const Identifier &defaultProperty, const String &defaultFormat)
Simple helper class for handling json files. It will attempt to create a json file with the given def...
Definition JsonFile.cpp:5
void createJsonFromDefaultFormat()
Generate the JSON file using the default format - used in cases where JSON fails to load.
Definition JsonFile.cpp:82
void save()
Call save internal.
Definition JsonFile.cpp:134
Identifier m_defaultProperty
Definition JsonFile.h:68
var m_data
The parsed json data.
Definition JsonFile.h:55
File m_jsonFile
The json file.
Definition JsonFile.h:60
String m_defaultFormat
Definition JsonFile.h:69
Definition AirAbsorptionFilter.cpp:2