mirai/src/core/Mirai.h

56 lines
1.5 KiB
C
Raw Normal View History

2024-04-13 11:52:42 +02:00
/*
2024-04-10 16:53:18 +02:00
* 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
*/
#ifndef MIRAI_MIRAI_H
#define MIRAI_MIRAI_H
#include "TaskItem.h"
#include "TasksFile.h"
#include "TasksView.h"
#include "TodoMd.h"
#include <algorithm>
2024-04-14 14:11:41 +02:00
#include <functional>
2024-04-10 16:53:18 +02:00
#include <memory>
2024-04-14 14:11:41 +02:00
#include <optional>
#include <string>
2024-04-10 16:53:18 +02:00
2024-04-13 11:52:42 +02:00
namespace mirai
{
class Mirai
{
public:
void loadFile(const std::string &path);
void save();
2024-04-14 14:11:41 +02:00
void addTask(TaskItemData taskItem);
2024-04-13 11:52:42 +02:00
void addTask(std::string text, std::string date);
void removeTask(const TaskItem *taskItem);
2024-04-14 14:11:41 +02:00
void addFile(TasksFileConfig config);
std::optional<std::reference_wrapper<TasksFile>> getFileByPath(const std::string &path);
2024-04-13 11:52:42 +02:00
2024-04-14 14:11:41 +02:00
std::vector<std::unique_ptr<TasksFile>> &getFiles();
2024-04-13 11:52:42 +02:00
std::weak_ptr<TasksView> getTasks();
const std::vector<std::string> &getTags();
void reloadTags();
2024-04-13 11:52:42 +02:00
private:
// The `TasksFile`s are shared to the views, their lifetime can outlive
// this (Mirai) object
// because we can't control if the caller will keep the main object alive.
2024-04-14 14:11:41 +02:00
std::shared_ptr<std::vector<std::unique_ptr<TasksFile>>> files =
std::make_shared<std::vector<std::unique_ptr<TasksFile>>>();
2024-04-13 11:52:42 +02:00
// We keep a vector of shared_ptr because we need the ref counting mechanism to know
// if we have to remove the view (not used) or tell the view to update() on
// some changes.
std::vector<std::shared_ptr<TasksView>> views;
std::vector<std::string> tags;
};
} // namespace mirai
2024-04-10 16:53:18 +02:00
#endif