moved to json

This commit is contained in:
ALEXks
2026-02-24 14:41:50 +03:00
parent b705b888f8
commit 96500475c0
13 changed files with 23001 additions and 64 deletions

View File

@@ -4,18 +4,22 @@
#include <set>
#include <vector>
#include <queue>
#include <iostream>
#include <fstream>
#include <math.h>
#include <thread>
#include <time.h>
#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
#endif
#include "File.h"
#include "Task.h"
#include "Array.h"
#include "Utils.h"
#ifndef _WIN32
#include <sys/time.h>
#include <unistd.h>
#endif
#include <time.h>
#include "json.hpp"
enum SupervisorState {
WorkspacesCreation, //0
@@ -58,12 +62,13 @@ public:
for (auto& elem : this->getElements())
elem->print();
}
void init(const char* fileName, int recordSize) {
state = WorkspacesCreation;
File* packedTasks = new File(fileName);
Text* lines = packedTasks->readLines();
const long length = lines->getLength() / recordSize;
const int length = lines->getLength() / recordSize;
int offset = 0;
for (int i = 0; i < length; ++i) {
this->add(new T(lines, offset));
@@ -72,6 +77,31 @@ public:
delete packedTasks;
delete lines;
}
void init(const char* fileName) {
state = WorkspacesCreation;
std::ifstream file(fileName);
if (!file.is_open()) {
printf("can not open file %s\n", fileName);
exit(-1);
}
nlohmann::json data = nlohmann::json::parse(file);
file.close();
if (data.contains("tasks")) {
auto tasks = data["tasks"];
int length = tasks.size();
for (size_t i = 0; i < tasks.size(); ++i)
this->add(new T(tasks[i]));
}
else {
printf("can not fine object 'tasks'\n");
exit(-1);
}
}
void changeState() {
switch (this->state) {
case WorkspacesCreation:
@@ -170,7 +200,7 @@ public:
killed = false;
while (activeTasks) {
long oldActiveTasks = activeTasks;
int oldActiveTasks = activeTasks;
emptyKeys.clear();
toDel.clear();
@@ -279,7 +309,7 @@ public:
void saveState() {
saveState(getStatePrefix() + printState());
}
void saveProgress(long long persentDone) {
void saveProgress(size_t persentDone) {
FILE* f = fopen("progress", "w");
if (f) {
fprintf(f, "%lld", persentDone);