Skip to content

Commit 505946c

Browse files
refactor: move compiler to base
1 parent a357ddf commit 505946c

34 files changed

+202
-52
lines changed

cmake/lemon-base.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ set(LEMON_BASE_HEADERS
99
${LEMON_BASEDIR_BASE}/LemonLog.hpp
1010
${LEMON_BASEDIR_BASE}/LemonType.hpp
1111
${LEMON_BASEDIR_BASE}/LemonConfig.hpp
12+
${LEMON_BASEDIR_BASE}/settings.h
13+
${LEMON_BASEDIR_BASE}/compiler.h
1214
${LEMON_BASEDIR_BASE}/LemonTranslator.hpp
1315
${LEMON_BASEDIR_BASE}/LemonUtils.hpp
1416
${LEMON_BASEDIR_BASE}/LemonBaseApplication.hpp
1517
)
1618

1719
set(LEMON_BASE_SOURCES
1820
${LEMON_BASEDIR_BASE}/LemonConfig.cpp
21+
${LEMON_BASEDIR_BASE}/settings.cpp
22+
${LEMON_BASEDIR_BASE}/compiler.cpp
1923
${LEMON_BASEDIR_BASE}/LemonTranslator.cpp
2024
${LEMON_BASEDIR_BASE}/LemonUtils.cpp
2125
${LEMON_BASEDIR_BASE}/LemonBaseApplication.cpp

cmake/lemon-core.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
set(LEMON_BASEDIR_CORE ${CMAKE_SOURCE_DIR}/src/core)
66

77
set(LEMON_CORE_SOURCES
8-
${LEMON_BASEDIR_CORE}/settings.h
9-
${LEMON_BASEDIR_CORE}/settings.cpp
10-
${LEMON_BASEDIR_CORE}/compiler.h
11-
${LEMON_BASEDIR_CORE}/compiler.cpp
128
${LEMON_BASEDIR_CORE}/contest.cpp
139
${LEMON_BASEDIR_CORE}/contest.h
1410
${LEMON_BASEDIR_CORE}/testcase.h

makespec/BUILDVERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
88
1+
89

src/addcompilerwizard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "addcompilerwizard.h"
1111
#include "ui_addcompilerwizard.h"
1212
//
13-
#include "core/compiler.h"
13+
#include "base/compiler.h"
1414
//
1515
#include <QFileDialog>
1616
#include <QMessageBox>

src/addtaskdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "addtaskdialog.h"
1111
#include "ui_addtaskdialog.h"
1212
//
13-
#include "core/settings.h"
13+
#include "base/settings.h"
1414
//
1515

1616
AddTaskDialog::AddTaskDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AddTaskDialog)

src/addtestcaseswizard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "addtestcaseswizard.h"
1111
#include "ui_addtestcaseswizard.h"
1212
//
13-
#include "core/settings.h"
13+
#include "base/settings.h"
1414
//
1515
#include <QMessageBox>
1616
#include <algorithm>

src/advancedcompilersettingsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "advancedcompilersettingsdialog.h"
1111
#include "ui_advancedcompilersettingsdialog.h"
1212
//
13-
#include "core/compiler.h"
13+
#include "base/compiler.h"
1414
#include "environmentvariablesdialog.h"
1515
//
1616
#include <QFileDialog>

src/base/LemonBaseApplication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//
1010
#include "base/LemonLog.hpp"
1111
#include "base/LemonTranslator.hpp"
12-
#include "core/settings.h" // TODO: Config Refactor
12+
#include "base/settings.h" // TODO: Config Refactor
1313
//
1414
#include <QCoreApplication>
1515
//

src/base/LemonConfig.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,47 @@
66
*/
77

88
#include "LemonConfig.hpp"
9+
//
10+
#include "base/LemonUtils.hpp"
11+
#include "base/compiler.h"
12+
13+
namespace Lemon::base::config
14+
{
15+
16+
void LemonConfigJudge::read(const QJsonObject &json)
17+
{
18+
READ_JSON_INT(defaultFullScore)
19+
READ_JSON_INT(defaultTimeLimit)
20+
READ_JSON_INT(defaultMemoryLimit)
21+
READ_JSON_INT(compileTimeLimit)
22+
READ_JSON_INT(specialJudgeTimeLimit)
23+
READ_JSON_INT(fileSizeLimit)
24+
READ_JSON_INT(rejudgeTimes)
25+
26+
READ_JSON_STR(defaultInputFileExtension)
27+
READ_JSON_STR(defaultOutputFileExtension)
28+
READ_JSON_STR(diffPath)
29+
30+
READ_JSON_STRLIST(inputFileExtensions)
31+
READ_JSON_STRLIST(outputFileExtensions)
32+
READ_JSON_STRLIST(recentContest)
33+
34+
// CompilerList
35+
if (json.contains("compilerList") && json["compilerList"].isArray()) {
36+
QJsonArray _compilerList = json["compilerList"].toArray();
37+
compilerList.clear();
38+
compilerList.reserve(_compilerList.size());
39+
for (int compilerIndex = 0; compilerIndex < _compilerList.size(); ++compilerIndex) {
40+
QJsonObject compilerObject = _compilerList[compilerIndex].toObject();
41+
Compiler *compiler = new Compiler();
42+
compiler->read(compilerObject);
43+
compilerList.append(compiler);
44+
}
45+
}
46+
}
47+
48+
void LemonConfigJudge::write(QJsonObject &json) const {
49+
50+
}
51+
52+
} // namespace Lemon::base::config

src/base/LemonConfig.hpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
//
1010

1111
#include <base/LemonBase.hpp>
12-
#include <core/compiler.h>
1312
//
13+
#include <QJsonObject>
14+
15+
class Compiler;
1416

1517
namespace Lemon::base::config
1618
{
1719

18-
struct LemonConfigJudge
20+
class LemonConfigJudge
1921
{
22+
private:
2023
QList<Compiler *> compilerList;
2124
int defaultFullScore{};
2225
int defaultTimeLimit{};
@@ -31,13 +34,41 @@ namespace Lemon::base::config
3134
QStringList outputFileExtensions;
3235
QStringList recentContest;
3336
QString diffPath;
37+
38+
public:
39+
void read(const QJsonObject &json);
40+
void write(QJsonObject &json) const;
3441
};
3542

36-
struct LemonConfigUI
43+
class LemonConfigUI
3744
{
45+
private:
3846
QString language = "en_US";
3947
// Prepare for theme setting
4048
// QString theme = ;
49+
public:
50+
void read(const QJsonObject &json);
51+
void write(QJsonObject &json) const;
52+
};
53+
54+
class LemonConfig
55+
{
56+
private:
57+
LemonConfigJudge judgeConfig;
58+
LemonConfigUI uiConfig;
59+
int splashTime{};
60+
61+
public:
62+
enum SaveFormat
63+
{
64+
Json,
65+
Binary,
66+
Yaml
67+
};
68+
void read(const QJsonObject &json);
69+
void write(QJsonObject &json) const;
70+
bool loadConfig(SaveFormat saveFormat);
71+
bool saveConfig(SaveFormat saveFormat) const;
4172
};
4273

4374
} // namespace Lemon::base::config

0 commit comments

Comments
 (0)