Skip to content

Commit 7559390

Browse files
refactor: basic read & write
1 parent 49d7309 commit 7559390

File tree

3 files changed

+64
-2
lines changed

3 files changed

+64
-2
lines changed

src/base/LemonConfig.cpp

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,58 @@ namespace Lemon::base::config {
4343
}
4444
}
4545

46-
void LemonConfigJudge::write(QJsonObject &json) const {}
46+
void LemonConfigJudge::write(QJsonObject &json) const {
47+
WRITE_JSON(defaultFullScore)
48+
WRITE_JSON(defaultTimeLimit)
49+
WRITE_JSON(defaultMemoryLimit)
50+
WRITE_JSON(compileTimeLimit)
51+
WRITE_JSON(specialJudgeTimeLimit)
52+
WRITE_JSON(fileSizeLimit)
53+
WRITE_JSON(rejudgeTimes)
54+
55+
WRITE_JSON(defaultInputFileExtension)
56+
WRITE_JSON(defaultOutputFileExtension)
57+
WRITE_JSON(diffPath)
58+
59+
WRITE_JSON_STRLIST(inputFileExtensions)
60+
WRITE_JSON_STRLIST(outputFileExtensions)
61+
WRITE_JSON_STRLIST(recentContest)
62+
63+
QJsonArray _compilerList;
64+
for (const auto &compiler : compilerList) {
65+
QJsonObject compilerObject;
66+
compiler->write(compilerObject);
67+
_compilerList.append(compilerObject);
68+
}
69+
json["compilerList"] = _compilerList;
70+
}
71+
72+
void LemonConfigUI::read(const QJsonObject &json) {
73+
READ_JSON_STR(language)
74+
READ_JSON_STR(theme)
75+
}
76+
77+
void LemonConfigUI::write(QJsonObject &json) const {
78+
WRITE_JSON(language)
79+
WRITE_JSON(theme)
80+
}
81+
82+
void LemonConfig::read(const QJsonObject &json) {
83+
READ_JSON_OBJECT(judgeConfig)
84+
READ_JSON_OBJECT(uiConfig)
85+
86+
READ_JSON_INT(splashTime)
87+
}
88+
89+
void LemonConfig::write(QJsonObject &json) const {
90+
WRITE_JSON_OBJECT(judgeConfig)
91+
WRITE_JSON_OBJECT(uiConfig)
92+
93+
WRITE_JSON(splashTime)
94+
}
95+
96+
auto LemonConfig::loadConfig(SaveFormat saveFormat) -> bool {}
97+
98+
auto LemonConfig::saveConfig(SaveFormat saveFormat) const -> bool {}
4799

48100
} // namespace Lemon::base::config

src/base/LemonConfig.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ namespace Lemon::base::config {
4242
private:
4343
QString language = "en_US";
4444
// Prepare for theme setting
45-
// QString theme = ;
45+
// TODO: Theme support
46+
QString theme = "";
47+
4648
public:
4749
void read(const QJsonObject &json);
4850
void write(QJsonObject &json) const;

src/base/LemonUtils.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@
3030
if (json.contains("___x") && json["___x"].isString()) \
3131
___x = json["___x"].toString().split(QLatin1Char(';'), QString::SkipEmptyParts);
3232
#endif
33+
#define READ_JSON_OBJECT(___x) \
34+
if (json.contains("___x") && json["___x"].isObject()) { \
35+
___x.read(json["___x"].toObject()); \
36+
}
3337

3438
#define WRITE_JSON(___x) json["___x"] = ___x;
3539
#define WRITE_JSON_STRLIST(___x) json["___x"] = ___x.join(QLatin1Char(';'));
40+
#define WRITE_JSON_OBJECT(___x) \
41+
QJsonObject _##___x; \
42+
judgeConfig.write(_##___x); \
43+
json["___x"] = _##___x;
3644

3745
namespace Lemon::common {
3846

0 commit comments

Comments
 (0)