Skip to content

Commit

Permalink
remember memory parameter in cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
TAR-ALEX committed May 12, 2024
1 parent 9d1e4d3 commit 3433ef5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
/Release/stickersolve-gui.exe
/gmon.out
/gmon.txt
/cfg.txt
/releases/
27 changes: 27 additions & 0 deletions src/ConfigParser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <fstream>
#include <iostream>
#include <string>

class ConfigFile {
public:
std::string path;
double maxMemory = 9;

ConfigFile(std::string path) : path(path) {}

void parse() {
std::fstream file{path, std::ios::in | std::ios::app};
if(!(file >> maxMemory)){
maxMemory = 9;
}
file.close();
}

void save() {
std::fstream file{path, std::ios::out | std::ios::trunc};
file << maxMemory;
file.close();
}
};
12 changes: 10 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "AspectRatioWidget.hpp"
#include "ConfigParser.h"
#include "NxNeditor.hpp"
#include "SelectColorButton.hpp"
#include "SelectColorPanel.hpp"
Expand All @@ -24,7 +25,10 @@
using namespace estd::shortnames;
using namespace std;

ConfigFile cfgFile{"./cfg.txt"};

int main(int argc, char** argv) {
cfgFile.parse();
cptr<QApplication> app = new QApplication(argc, argv);
cptr<QMainWindow> mw = new QMainWindow();

Expand Down Expand Up @@ -75,7 +79,7 @@ int main(int argc, char** argv) {
numSolutions->setRange(-1, INT_MAX);
searchDepth->setValue(14);
numSolutions->setValue(-1);
maxMemoryLimitGb->setValue(9);
maxMemoryLimitGb->setValue(cfgFile.maxMemory);
puzzleColumn->addLayout(configForm);
configForm->addRow(QObject::tr("Apply Moves:"), applyMoves);
configForm->addRow(new EQLayoutWidget<QHBoxLayout>({cleanBtn, swapScramble, resetToSolved, applyMovesBtn}));
Expand Down Expand Up @@ -242,5 +246,9 @@ int main(int argc, char** argv) {

QObject::connect(solveBtn, &QPushButton::clicked, [&]() { solveCallback(false); });
QObject::connect(solveIncrementalBtn, &QPushButton::clicked, [&]() { solveCallback(true); });
return app->exec();
QObject::connect(maxMemoryLimitGb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), [&](double val) { cfgFile.maxMemory = val; });

int errcode = app->exec();
cfgFile.save();
return errcode;
}

0 comments on commit 3433ef5

Please sign in to comment.