mason/src2/collection.h

74 lines
2.1 KiB
C++

#pragma once
#include <string>
#include <filesystem>
#include <map>
#include <set>
#include <exception>
#include <string_view>
#include "loggable.h"
#include "component.h"
#include "download.h"
#include "taskmanager.h"
class Collection : protected Loggable {
using Sources = std::set<std::string>;
using Downloads = std::map<std::string, std::unique_ptr<Download>>;
using Components = std::map<std::string, std::unique_ptr<Component>>;
public:
class UnknownSource;
class DuplicateSource;
class DuplicatePath;
Collection(
const std::filesystem::path& destination,
const std::string& target,
const std::shared_ptr<Logger>& logger,
const std::shared_ptr<TaskManager>& taskManager
);
unsigned int sourcesTotal() const;
unsigned int sourcesPending() const;
unsigned int sourcesError() const;
unsigned int sourcesSuccess() const;
bool hasSource(const std::string& source) const;
void addSource(const std::string& source);
private:
void sourceDownaloded(const std::string& source, TaskManager::Error err);
void sourceRead(const std::string& source, TaskManager::Error err);
void sourceBuilt(const std::string& source, TaskManager::Error err);
bool isRemote(const std::string& source);
void queueDownload(const std::string& source);
void queueRead(const std::string& source, const std::filesystem::path& location);
private:
std::filesystem::path destination;
std::string target;
std::shared_ptr<TaskManager> taskManager;
Sources knownSources;
Sources successSources;
Downloads downloadingSources;
Components readingSources;
Components buildingSources;
};
class Collection::UnknownSource : public std::runtime_error {
public:
explicit UnknownSource(const std::string& source);
};
class Collection::DuplicateSource : public std::runtime_error {
public:
explicit DuplicateSource(const std::string& source);
};
class Collection::DuplicatePath : public std::runtime_error {
public:
explicit DuplicatePath(const std::string& source, const std::filesystem::path& path);
};