mirror of
https://codeberg.org/vyn/mirai.git
synced 2025-07-03 18:23:19 +00:00
Format all c++ files
This commit is contained in:
parent
081e107b9b
commit
f8f49233dc
21 changed files with 683 additions and 599 deletions
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Mirai. Copyright (C) 2024 Vyn
|
||||
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
|
||||
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
|
@ -8,48 +8,64 @@
|
|||
#include "TaskItem.h"
|
||||
#include <memory>
|
||||
|
||||
namespace mirai {
|
||||
namespace mirai
|
||||
{
|
||||
|
||||
TasksFile::TasksFile(TasksFileConstructor params) : name(params.name), path(params.path) {
|
||||
for (const auto& task : params.tasks) {
|
||||
tasks.push_back(std::make_unique<TaskItem>(task));
|
||||
}
|
||||
sortByDate();
|
||||
}
|
||||
|
||||
const std::string& TasksFile::getName() const { return name; }
|
||||
const std::string& TasksFile::getPath() const { return path; }
|
||||
TasksPtrs& TasksFile::getTasks() { return tasks; }
|
||||
|
||||
void TasksFile::addTask(TaskItem taskItem) {
|
||||
tasks.push_back(std::make_unique<TaskItem>(taskItem));
|
||||
sortByDate();
|
||||
}
|
||||
|
||||
void TasksFile::addTask(std::string text, std::string date) {
|
||||
auto newTask = std::make_unique<TaskItem>(TaskItem{
|
||||
.text = text,
|
||||
.state = TODO,
|
||||
.date = date == "" ? "No date" : date
|
||||
});
|
||||
tasks.push_back(std::move(newTask));
|
||||
sortByDate();
|
||||
}
|
||||
|
||||
void TasksFile::removeTask(const TaskItem* taskToRemove) {
|
||||
tasks.erase(std::remove_if(tasks.begin(), tasks.end(), [&] (const std::unique_ptr<TaskItem>& taskInFilter){
|
||||
return taskInFilter.get() == taskToRemove;
|
||||
}));
|
||||
}
|
||||
|
||||
void TasksFile::sortByDate() {
|
||||
std::sort(tasks.begin(), tasks.end(), [] (const std::unique_ptr<TaskItem>& t1, const std::unique_ptr<TaskItem>& t2) {
|
||||
if (t1->hasDate() && !t2->hasDate()) {
|
||||
return true;
|
||||
} else if (!t1->hasDate() && t2->hasDate()) {
|
||||
return false;
|
||||
}
|
||||
return t1->date < t2->date;
|
||||
});
|
||||
TasksFile::TasksFile(TasksFileConstructor params) : name(params.name), path(params.path)
|
||||
{
|
||||
for (const auto &task : params.tasks) {
|
||||
tasks.push_back(std::make_unique<TaskItem>(task));
|
||||
}
|
||||
sortByDate();
|
||||
}
|
||||
|
||||
const std::string &TasksFile::getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
const std::string &TasksFile::getPath() const
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
TasksPtrs &TasksFile::getTasks()
|
||||
{
|
||||
return tasks;
|
||||
}
|
||||
|
||||
void TasksFile::addTask(TaskItem taskItem)
|
||||
{
|
||||
tasks.push_back(std::make_unique<TaskItem>(taskItem));
|
||||
sortByDate();
|
||||
}
|
||||
|
||||
void TasksFile::addTask(std::string text, std::string date)
|
||||
{
|
||||
auto newTask = std::make_unique<TaskItem>(
|
||||
TaskItem{.text = text, .state = TODO, .date = date == "" ? "No date" : date});
|
||||
tasks.push_back(std::move(newTask));
|
||||
sortByDate();
|
||||
}
|
||||
|
||||
void TasksFile::removeTask(const TaskItem *taskToRemove)
|
||||
{
|
||||
tasks.erase(std::remove_if(tasks.begin(), tasks.end(),
|
||||
[&](const std::unique_ptr<TaskItem> &taskInFilter) {
|
||||
return taskInFilter.get() == taskToRemove;
|
||||
}));
|
||||
}
|
||||
|
||||
void TasksFile::sortByDate()
|
||||
{
|
||||
std::sort(tasks.begin(), tasks.end(),
|
||||
[](const std::unique_ptr<TaskItem> &t1, const std::unique_ptr<TaskItem> &t2) {
|
||||
if (t1->hasDate() && !t2->hasDate()) {
|
||||
return true;
|
||||
} else if (!t1->hasDate() && t2->hasDate()) {
|
||||
return false;
|
||||
}
|
||||
return t1->date < t2->date;
|
||||
});
|
||||
}
|
||||
} // namespace mirai
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue