Skip to content

Commit

Permalink
refactor: basic read & write
Browse files Browse the repository at this point in the history
  • Loading branch information
CoelacanthusHex committed Nov 11, 2020
1 parent 1cfca7c commit 90e235f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
54 changes: 53 additions & 1 deletion src/base/LemonConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,58 @@ namespace Lemon::base::config {
}
}

void LemonConfigJudge::write(QJsonObject &json) const {}
void LemonConfigJudge::write(QJsonObject &json) const {
WRITE_JSON(defaultFullScore)
WRITE_JSON(defaultTimeLimit)
WRITE_JSON(defaultMemoryLimit)
WRITE_JSON(compileTimeLimit)
WRITE_JSON(specialJudgeTimeLimit)
WRITE_JSON(fileSizeLimit)
WRITE_JSON(rejudgeTimes)

WRITE_JSON(defaultInputFileExtension)
WRITE_JSON(defaultOutputFileExtension)
WRITE_JSON(diffPath)

WRITE_JSON_STRLIST(inputFileExtensions)
WRITE_JSON_STRLIST(outputFileExtensions)
WRITE_JSON_STRLIST(recentContest)

QJsonArray _compilerList;
for (const auto &compiler : compilerList) {
QJsonObject compilerObject;
compiler->write(compilerObject);
_compilerList.append(compilerObject);
}
json["compilerList"] = _compilerList;
}

void LemonConfigUI::read(const QJsonObject &json) {
READ_JSON_STR(language)
READ_JSON_STR(theme)
}

void LemonConfigUI::write(QJsonObject &json) const {
WRITE_JSON(language)
WRITE_JSON(theme)
}

void LemonConfig::read(const QJsonObject &json) {
READ_JSON_OBJECT(judgeConfig)
READ_JSON_OBJECT(uiConfig)

READ_JSON_INT(splashTime)
}

void LemonConfig::write(QJsonObject &json) const {
WRITE_JSON_OBJECT(judgeConfig)
WRITE_JSON_OBJECT(uiConfig)

WRITE_JSON(splashTime)
}

auto LemonConfig::loadConfig(SaveFormat saveFormat) -> bool {}

auto LemonConfig::saveConfig(SaveFormat saveFormat) const -> bool {}

} // namespace Lemon::base::config
4 changes: 3 additions & 1 deletion src/base/LemonConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ namespace Lemon::base::config {
private:
QString language = "en_US";
// Prepare for theme setting
// QString theme = ;
// TODO: Theme support
QString theme = "";

public:
void read(const QJsonObject &json);
void write(QJsonObject &json) const;
Expand Down
8 changes: 8 additions & 0 deletions src/base/LemonUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@
if (json.contains("___x") && json["___x"].isString()) \
___x = json["___x"].toString().split(QLatin1Char(';'), QString::SkipEmptyParts);
#endif
#define READ_JSON_OBJECT(___x) \
if (json.contains("___x") && json["___x"].isObject()) { \
___x.read(json["___x"].toObject()); \
}

#define WRITE_JSON(___x) json["___x"] = ___x;
#define WRITE_JSON_STRLIST(___x) json["___x"] = ___x.join(QLatin1Char(';'));
#define WRITE_JSON_OBJECT(___x) \
QJsonObject _##___x; \
judgeConfig.write(_##___x); \
json["___x"] = _##___x;

namespace Lemon::common {

Expand Down

0 comments on commit 90e235f

Please sign in to comment.