diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c70c23..427475e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY ) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src2) add_subdirectory(src) add_subdirectory(src2) diff --git a/src2/CMakeLists.txt b/src2/CMakeLists.txt index 1517ac0..f28def2 100644 --- a/src2/CMakeLists.txt +++ b/src2/CMakeLists.txt @@ -1,11 +1,13 @@ set(SOURCES - component.cpp collection.cpp + loggable.cpp ) set(HEADERS - component.h collection.h + loggable.h ) target_sources(${PROJECT_NAME} PRIVATE ${SOURCES}) + +add_subdirectory(components) diff --git a/src2/component.cpp b/src2/component.cpp deleted file mode 100644 index fb8a3a6..0000000 --- a/src2/component.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "component.h" diff --git a/src2/component.h b/src2/component.h deleted file mode 100644 index 9ab4c5b..0000000 --- a/src2/component.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include - -#include "loggger.h" -#include "collection.h" - -class Component { -public: - enum State { - initial, - reading, - building, - ready - }; - - enum Type { - unknown, - file, - directory, - mason - }; - - Component(Logger* logger, Collection* collection); - virtual ~Component(); - - Type getType() const; - Type getState() const; - - virtual void read(const std::filesystem::path& path) = 0; - virtual void build(const std::filesystem::path& destination, const std::string& target) = 0; - -protected: - State state; - Type type; - Logger* logger; - Collection* collection; - std::filesystem::path location; -}; diff --git a/src2/components/CMakeLists.txt b/src2/components/CMakeLists.txt new file mode 100644 index 0000000..52b35d2 --- /dev/null +++ b/src2/components/CMakeLists.txt @@ -0,0 +1,11 @@ +set(SOURCES + component.cpp + file.cpp +) + +set(HEADERS + component.h + file.h +) + +target_sources(${PROJECT_NAME} PRIVATE ${SOURCES}) diff --git a/src2/components/component.cpp b/src2/components/component.cpp new file mode 100644 index 0000000..41a023e --- /dev/null +++ b/src2/components/component.cpp @@ -0,0 +1,23 @@ +#include "component.h" + +Component::Component(const std::shared_ptr& collection, const std::shared_ptr& 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; +} diff --git a/src2/components/component.h b/src2/components/component.h new file mode 100644 index 0000000..2dcf167 --- /dev/null +++ b/src2/components/component.h @@ -0,0 +1,53 @@ +#pragma once + +#include +#include +#include +#include + +#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, const std::shared_ptr& 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; + 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; +}; diff --git a/src2/components/file.cpp b/src2/components/file.cpp new file mode 100644 index 0000000..3e2f550 --- /dev/null +++ b/src2/components/file.cpp @@ -0,0 +1 @@ +#include "file.h" diff --git a/src2/components/file.h b/src2/components/file.h new file mode 100644 index 0000000..31ee68d --- /dev/null +++ b/src2/components/file.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +#include "component.h" + +class File : public Component { +public: + File(const std::shared_ptr& collection, const std::shared_ptr& logger); + +protected: + +}; diff --git a/src2/loggable.cpp b/src2/loggable.cpp new file mode 100644 index 0000000..4f74565 --- /dev/null +++ b/src2/loggable.cpp @@ -0,0 +1,37 @@ +#include "loggable.h" + +Loggable::Loggable(const std::shared_ptr& logger): + logger(logger) +{} + +void Loggable::log(Logger::Severity severity, const std::string& message) const { + logger->log(severity, message); +} + +void Loggable::debug(const std::string& message) const { + log(Logger::Severity::debug, message); +} + +void Loggable::info(const std::string& message) const { + log(Logger::Severity::info, message); +} + +void Loggable::minor(const std::string& message) const { + log(Logger::Severity::minor, message); +} + +void Loggable::major(const std::string& message) const { + log(Logger::Severity::major, message); +} + +void Loggable::warn(const std::string& message) const { + log(Logger::Severity::warning, message); +} + +void Loggable::error(const std::string& message) const { + log(Logger::Severity::error, message); +} + +void Loggable::fatal(const std::string& message) const { + log(Logger::Severity::fatal, message); +} diff --git a/src2/loggable.h b/src2/loggable.h new file mode 100644 index 0000000..006e4aa --- /dev/null +++ b/src2/loggable.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include "loggger.h" + +class Loggable { +public: + explicit Loggable(const std::shared_ptr& logger); + virtual ~Loggable() = default; + + void debug(const std::string& message) const; + void info(const std::string& message) const; + void minor(const std::string& message) const; + void major(const std::string& message) const; + void warn(const std::string& message) const; + void error(const std::string& message) const; + void fatal(const std::string& message) const; + +private: + void log(Logger::Severity severity, const std::string& message) const; + +private: + std::shared_ptr logger; +};