mason/src2/component.cpp

59 lines
1.3 KiB
C++

#include "component.h"
#include <array>
#include <string_view>
#include "collection.h"
constexpr std::array<std::string_view, Component::done + 1> stringStates {
"initial",
"reading",
"ready",
"building",
"error",
"done"
};
Component::Component(
const std::filesystem::path& path,
const std::shared_ptr<Collection>& collection,
const std::shared_ptr<Logger>& logger
):
Loggable(logger),
collection(collection),
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;
}
void Component::build(const std::filesystem::path& destination, const std::string& target) {
if (state != ready)
throw WrongState(state, "build");
state = building;
}
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() + '\"')
{}