#include "component.h" #include #include #include "collection.h" constexpr std::array stringStates { "initial", "reading", "ready", "building", "error", "done" }; Component::Component( const std::filesystem::path& path, const std::shared_ptr& collection, const std::shared_ptr& 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() + '\"') {}