just some more thoughts
This commit is contained in:
parent
ec63dc655b
commit
02df7de0c3
11 changed files with 163 additions and 143 deletions
65
src2/component.cpp
Normal file
65
src2/component.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include "component.h"
|
||||
|
||||
#include <array>
|
||||
#include <string_view>
|
||||
|
||||
constexpr std::array<std::string_view, Component::done + 1> stringStates {
|
||||
"initial",
|
||||
"reading",
|
||||
"ready",
|
||||
"building",
|
||||
"done"
|
||||
};
|
||||
|
||||
Component::Component(
|
||||
const std::filesystem::path& path,
|
||||
const std::shared_ptr<Collection>& collection,
|
||||
const std::shared_ptr<TaskManager>& taskManager,
|
||||
const std::shared_ptr<Logger>& logger
|
||||
):
|
||||
Loggable(logger),
|
||||
collection(collection),
|
||||
taskManager(taskManager),
|
||||
location(path)
|
||||
{}
|
||||
|
||||
void Component::read() {
|
||||
if (state != initial)
|
||||
throw WrongState(state, "read");
|
||||
|
||||
try {
|
||||
collection->addSource(location);
|
||||
} catch (const Collection::DuplicateSource e) {
|
||||
state = error;
|
||||
throw e;
|
||||
}
|
||||
state = reading;
|
||||
taskManager->queue(std::bind(&Component::performRead, this));
|
||||
}
|
||||
|
||||
void Component::build(const std::filesystem::path& destination, const std::string& target) {
|
||||
if (state != ready)
|
||||
throw WrongState(state, "build");
|
||||
|
||||
state = building;
|
||||
taskManager->queue(std::bind(&Component::performBuild, this, destination, target));
|
||||
}
|
||||
|
||||
void Component::performRead() {
|
||||
}
|
||||
|
||||
void Component::performBuild(std::filesystem::path destination, std::string target) {
|
||||
}
|
||||
|
||||
Component::State Component::getState() const {
|
||||
return state;
|
||||
}
|
||||
|
||||
Component::Type Component::getType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
Component::WrongState::WrongState(State state, const std::string& action):
|
||||
std::runtime_error("An attempt to perform action \"" + action
|
||||
+ "\" on a wrong state \"" + stringStates[state].data() + '\"')
|
||||
{}
|
Loading…
Add table
Add a link
Reference in a new issue