Krotos Modules 3
Loading...
Searching...
No Matches
JsonFile.h
Go to the documentation of this file.
1#pragma once
2namespace krotos
3{
4
5 class JsonFile
6 {
7 public:
23 JsonFile(File jsonFile, const Identifier& defaultProperty, const String& defaultFormat);
24
28 var getDefaultProperty() const { return m_data.getProperty(m_defaultProperty, var()); }
29
35 const String& getDefaultFormat() const { return m_defaultFormat; }
36
37 protected:
41 void initialise();
45 void save();
46
51
55 var m_data;
56
61
62 private:
66 void saveInternal();
67
70 };
71
78 class JsonException final : public std::runtime_error
79 {
80 public:
81 JsonException(const String& whatHappened, const String& whenDidItHappen);
82
83 char const* what() const noexcept override;
84
89 String when() const;
90
91 private:
93 };
94
95} // namespace krotos
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
Definition JsonFile.h:6
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
var getDefaultProperty() const
Get the variant for the default property.
Definition JsonFile.h:28
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
const String & getDefaultFormat() const
Gets the underlying default formatted json, this is used as a fallback when an invalid input is passe...
Definition JsonFile.h:35
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