mason/src/component.h

67 lines
1.3 KiB
C
Raw Normal View History

2023-09-20 19:45:22 +00:00
#pragma once
#include <string>
#include <filesystem>
2023-09-26 17:36:40 +00:00
#include <fstream>
2023-09-20 19:45:22 +00:00
#include <memory>
#include <exception>
2023-09-26 17:36:40 +00:00
#include <optional>
2023-09-20 19:45:22 +00:00
#include <functional>
2023-09-26 17:36:40 +00:00
#include <array>
#include <string_view>
#include <nlohmann/json.hpp>
2023-09-20 19:45:22 +00:00
#include "loggable.h"
#include "loggger.h"
class Collection;
2023-09-20 19:45:22 +00:00
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,
2023-09-27 23:30:57 +00:00
const std::weak_ptr<Collection>& collection,
2023-09-20 19:45:22 +00:00
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);
2023-09-26 17:36:40 +00:00
private:
void tryReadingBuildScenarios();
bool readAsMason();
bool errorScenario(const std::string& message);
2023-09-20 19:45:22 +00:00
private:
State state;
Type type;
2023-09-27 23:30:57 +00:00
std::weak_ptr<Collection> collection;
2023-09-20 19:45:22 +00:00
std::filesystem::path location;
2023-09-26 17:36:40 +00:00
std::optional<nlohmann::json> scenario;
2023-09-20 19:45:22 +00:00
};
class Component::WrongState : public std::runtime_error {
public:
explicit WrongState(State state, const std::string& action);
};