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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Mirai.h"
|
2024-08-31 09:42:46 +02:00
|
|
|
#include "Config.h"
|
2024-10-11 16:26:13 +02:00
|
|
|
#include "Source.h"
|
|
|
|
#include "SourceDataProvider.h"
|
2024-04-30 18:18:54 +02:00
|
|
|
#include "cpp-utils/debug.h"
|
2024-04-14 14:11:41 +02:00
|
|
|
#include "utils.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
#include <optional>
|
|
|
|
#include <ostream>
|
|
|
|
#include <vector>
|
2024-04-10 16:53:18 +02:00
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
namespace mirai
|
|
|
|
{
|
2024-04-10 16:53:18 +02:00
|
|
|
|
2024-10-11 16:26:13 +02:00
|
|
|
void Mirai::loadSource(std::unique_ptr<SourceDataProvider> &&resource)
|
2024-04-13 11:52:42 +02:00
|
|
|
{
|
2024-10-11 16:26:13 +02:00
|
|
|
SourceDataProvider *sourceDataProvider = resource.release();
|
|
|
|
sourceDataProvider->load();
|
|
|
|
sources_.push_back(
|
|
|
|
std::make_unique<Source>(SourceConstructor{.sourceDataProvider = sourceDataProvider})
|
|
|
|
);
|
2024-05-09 14:39:10 +02:00
|
|
|
};
|
2024-04-22 15:45:26 +02:00
|
|
|
|
2024-09-02 11:52:06 +02:00
|
|
|
void Mirai::unloadAllSources()
|
2024-04-22 15:45:26 +02:00
|
|
|
{
|
2024-09-02 11:52:06 +02:00
|
|
|
sources_.clear();
|
2024-04-13 11:52:42 +02:00
|
|
|
}
|
2024-04-10 16:53:18 +02:00
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
void Mirai::save()
|
|
|
|
{
|
2024-10-11 16:26:13 +02:00
|
|
|
for (auto &source : sources_) {
|
|
|
|
if (source->isDirty()) {
|
|
|
|
source->save();
|
2024-04-14 14:11:41 +02:00
|
|
|
}
|
2024-04-10 16:53:18 +02:00
|
|
|
}
|
2024-04-13 11:52:42 +02:00
|
|
|
}
|
2024-04-10 16:53:18 +02:00
|
|
|
|
2024-10-11 16:26:13 +02:00
|
|
|
std::vector<std::unique_ptr<Source>> &Mirai::getSources()
|
2024-04-14 14:11:41 +02:00
|
|
|
{
|
2024-09-02 11:52:06 +02:00
|
|
|
return sources_;
|
2024-04-14 14:11:41 +02:00
|
|
|
}
|
|
|
|
|
2024-10-11 16:26:13 +02:00
|
|
|
Source *Mirai::getSourceById(int id)
|
2024-09-02 11:52:06 +02:00
|
|
|
{
|
|
|
|
if (id >= sources_.size()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return sources_.at(id).get();
|
|
|
|
}
|
|
|
|
|
2024-04-13 11:52:42 +02:00
|
|
|
} // namespace mirai
|