From 32daf0235192c42ef9a34baa82c8223c52f61cc8 Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Wed, 8 Dec 2021 22:30:44 +0100 Subject: [PATCH] Added saving to binary, implementation of loading started --- src/project.cpp | 69 ++++++++++++++++++++++++++++++++++++++++--------- src/project.h | 2 ++ src/tt.cpp | 9 +++++-- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/project.cpp b/src/project.cpp index 4495abb..d1c3909 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include "project.h" Project::Project(std::string name){ @@ -9,25 +11,68 @@ Project::Project(std::string name){ } void Project::add_task(Task task){ - Project::tasks.push_back(task); - Project::active_task = Project::num_tasks; - Project::num_tasks++; + tasks.push_back(task); + active_task = num_tasks; + num_tasks++; } void Project::remove_task(int id){ - Project::tasks.erase(tasks.begin()+id); - Project::active_task = std::max(id-1,0); - Project::num_tasks--; + tasks.erase(tasks.begin()+id); + active_task = std::max(id-1,0); + num_tasks--; } void ProjectList::add_project(Project proj){ - ProjectList::projects.push_back(proj); - ProjectList::active_project = ProjectList::num_projects; - ProjectList::num_projects++; + projects.push_back(proj); + active_project = num_projects; + num_projects++; } void ProjectList::remove_project(int id){ - ProjectList::projects.erase(projects.begin()+id); - ProjectList::active_project = std::max(id-1,0); - ProjectList::num_projects--; + projects.erase(projects.begin()+id); + active_project = std::max(id-1,0); + num_projects--; +} + +void ProjectList::save(std::string file_name){ + std::ofstream of(file_name, std::ios::out | std::ios::binary); + if (!of){ + std::cout << "Could not open file " << file_name << " for writing!" << std::endl; + exit(1); + } + std::cout << num_projects << " " << num_projects << std::endl; + of.write((char*) &num_projects, sizeof(int)); + of.write((char*) &active_project, sizeof(int)); + for (int i=0; i