just some refactoring thoughts
This commit is contained in:
parent
198677fc18
commit
b92b66c101
10 changed files with 159 additions and 5 deletions
11
src2/CMakeLists.txt
Normal file
11
src2/CMakeLists.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
set(SOURCES
|
||||
component.cpp
|
||||
collection.cpp
|
||||
)
|
||||
|
||||
set(HEADERS
|
||||
component.h
|
||||
collection.h
|
||||
)
|
||||
|
||||
target_sources(${PROJECT_NAME} PRIVATE ${SOURCES})
|
1
src2/collection.cpp
Normal file
1
src2/collection.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
#include "collection.h"
|
59
src2/collection.h
Normal file
59
src2/collection.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <exception>
|
||||
|
||||
class Collection {
|
||||
public:
|
||||
class UnknownSource;
|
||||
class DuplicateSource;
|
||||
class DuplicatePath;
|
||||
|
||||
Collection();
|
||||
|
||||
unsigned int sourcesTotal() const;
|
||||
unsigned int sourcesPending() const;
|
||||
unsigned int sourcesError() const;
|
||||
unsigned int sourcesSuccess() const;
|
||||
|
||||
bool hasSource(const std::string& source) const;
|
||||
void addSource(const std::string& source);
|
||||
void sourceError(const std::string& source);
|
||||
void sourceSuccess(const std::string& source, const std::filesystem::path& path);
|
||||
|
||||
private:
|
||||
std::set<std::string> errorSources;
|
||||
std::set<std::string> pendingSources;
|
||||
std::map<std::string, std::filesystem::path> successSources; //would be nice to have a bimap here
|
||||
};
|
||||
|
||||
class Collection::UnknownSource : public std::exception {
|
||||
public:
|
||||
UnknownSource(const std::string& source);
|
||||
|
||||
const char* what() const noexcept( true ) override;
|
||||
private:
|
||||
std::string source;
|
||||
};
|
||||
|
||||
class Collection::DuplicateSource : public std::exception {
|
||||
public:
|
||||
DuplicateSource(const std::string& source);
|
||||
|
||||
const char* what() const noexcept( true ) override;
|
||||
private:
|
||||
std::string source;
|
||||
};
|
||||
|
||||
class Collection::DuplicatePath : public std::exception {
|
||||
public:
|
||||
DuplicatePath(const std::string& source, const std::filesystem::path& path);
|
||||
|
||||
const char* what() const noexcept( true ) override;
|
||||
private:
|
||||
std::string source;
|
||||
std::filesystem::path path;
|
||||
};
|
1
src2/component.cpp
Normal file
1
src2/component.cpp
Normal file
|
@ -0,0 +1 @@
|
|||
#include "component.h"
|
40
src2/component.h
Normal file
40
src2/component.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
#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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue