mason/src2/component.h
2023-09-26 14:36:40 -03:00

67 lines
1.3 KiB
C++

#pragma once
#include <string>
#include <filesystem>
#include <fstream>
#include <memory>
#include <exception>
#include <optional>
#include <functional>
#include <array>
#include <string_view>
#include <nlohmann/json.hpp>
#include "loggable.h"
#include "loggger.h"
class Collection;
class Component : protected Loggable {
public:
class WrongState;
enum State {
initial,
reading,
ready,
building,
error,
done
};
enum Type {
unknown,
file,
directory,
mason
};
Component(
const std::filesystem::path& path,
const std::shared_ptr<Collection>& collection,
const std::shared_ptr<Logger>& logger
);
Type getType() const;
State getState() const;
void read();
void build(const std::filesystem::path& destination, const std::string& target);
private:
void tryReadingBuildScenarios();
bool readAsMason();
bool errorScenario(const std::string& message);
private:
State state;
Type type;
std::shared_ptr<Collection> collection;
std::filesystem::path location;
std::optional<nlohmann::json> scenario;
};
class Component::WrongState : public std::runtime_error {
public:
explicit WrongState(State state, const std::string& action);
};