mason/src2/components/component.h

54 lines
1.1 KiB
C++

#pragma once
#include <string>
#include <filesystem>
#include <memory>
#include <exception>
#include "loggable.h"
#include "loggger.h"
#include "collection.h"
class Component : protected Loggable {
public:
class WrongState;
enum State {
initial,
reading,
building,
ready
};
enum Type {
unknown,
file,
directory,
mason
};
Component(const std::shared_ptr<Collection>& collection, const std::shared_ptr<Logger>& logger);
virtual ~Component() override = default;
Type getType() const;
State getState() const;
virtual void read(const std::filesystem::path& path);
virtual void build(const std::filesystem::path& destination, const std::string& target) = 0;
protected:
State state;
Type type;
std::shared_ptr<Collection> collection;
std::filesystem::path location;
};
class Component::WrongState : public std::exception {
public:
WrongState(State state, const std::string& action);
const char* what() const noexcept( true ) override;
private:
State state;
std::string action;
};