mirai/src/core/Mirai.h

46 lines
1.2 KiB
C
Raw Normal View History

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>
#include <memory>
namespace mirai {
class Mirai {
public:
void loadFile(const std::string& path);
void save();
void addTask(std::string text, std::string date);
void removeTask(const TaskItem* taskItem);
std::weak_ptr<TasksView> getTasks();
const std::vector<std::string>& getTags();
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.
std::shared_ptr<std::vector<TasksFile>> files = std::make_shared<std::vector<TasksFile>>();
// 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;
};
}
#endif