some more thoughts for refactoring

This commit is contained in:
Blue 2023-09-18 15:59:43 -03:00
parent b92b66c101
commit 78b7407368
Signed by: blue
GPG key ID: 9B203B252A63EE38
11 changed files with 169 additions and 43 deletions

View file

@ -0,0 +1,11 @@
set(SOURCES
component.cpp
file.cpp
)
set(HEADERS
component.h
file.h
)
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})

View file

@ -0,0 +1,23 @@
#include "component.h"
Component::Component(const std::shared_ptr<Collection>& collection, const std::shared_ptr<Logger>& logger):
Loggable(logger),
collection(collection)
{}
void Component::read(const std::filesystem::path& path) {
if (state != initial)
throw WrongState(state, "read");
location = path;
state = reading;
}
Component::State Component::getState() const {
return state;
}
Component::Type Component::getType() const {
return type;
}

View file

@ -0,0 +1,53 @@
#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;
};

1
src2/components/file.cpp Normal file
View file

@ -0,0 +1 @@
#include "file.h"

14
src2/components/file.h Normal file
View file

@ -0,0 +1,14 @@
#pragma once
#include <filesystem>
#include <memory>
#include "component.h"
class File : public Component {
public:
File(const std::shared_ptr<Collection>& collection, const std::shared_ptr<Logger>& logger);
protected:
};