aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt30
-rw-r--r--CreateArtistTileBehavior.cpp (renamed from YellowTileBehavior.cpp)0
-rw-r--r--CreateArtistTileBehavior.h (renamed from YellowTileBehavior.h)0
-rw-r--r--DeleteArtistTileBehavior.cpp (renamed from RedTileBehavior.cpp)0
-rw-r--r--DeleteArtistTileBehavior.h (renamed from RedTileBehavior.h)0
-rw-r--r--FileReader.cpp35
-rw-r--r--FileReader.h32
-rw-r--r--FileReaderFactory.cpp36
-rw-r--r--FileReaderFactory.h27
-rw-r--r--FileStrategy.cpp9
-rw-r--r--FileStrategy.h25
-rw-r--r--HTTPFileReader.cpp (renamed from HTTPFile.cpp)0
-rw-r--r--HTTPFileReader.h (renamed from HTTPFile.h)0
-rw-r--r--LocalFileReader.cpp (renamed from LocalFile.cpp)0
-rw-r--r--LocalFileReader.h (renamed from LocalFile.h)0
-rw-r--r--MuseumDeserializer.cpp (renamed from Deserializer.cpp)0
-rw-r--r--MuseumDeserializer.h (renamed from Deserializer.h)0
-rw-r--r--Parser.h15
-rw-r--r--ParserFactory.cpp (renamed from Parser.cpp)0
-rw-r--r--ParserFactory.h20
-rw-r--r--ParserStrategy.h11
-rw-r--r--SetNeighborTileBehavior.cpp (renamed from BlueTileBehavior.cpp)0
-rw-r--r--SetNeighborTileBehavior.h (renamed from BlueTileBehavior.h)0
-rw-r--r--StepTileBehavior.cpp (renamed from GrayTileBehavior.cpp)0
-rw-r--r--StepTileBehavior.h (renamed from GrayTileBehavior.h)0
-rw-r--r--StepTileCommand.cpp (renamed from TileDecayCommand.cpp)0
-rw-r--r--StepTileCommand.h (renamed from TileDecayCommand.h)0
-rw-r--r--TileBehavior.cpp19
-rw-r--r--TileBehavior.h27
-rw-r--r--TileBehaviorFactory.cpp20
-rw-r--r--TileBehaviorFactory.h21
-rw-r--r--TileBehaviorStrategy.cpp11
-rw-r--r--TileBehaviorStrategy.h24
-rw-r--r--TileColorFactory.cpp (renamed from TileAppearance.cpp)0
-rw-r--r--TileColorFactory.h (renamed from TileAppearance.h)0
-rw-r--r--ToggleArtistVisibilityCommand.cpp (renamed from ArtistVisibilityCommand.cpp)0
-rw-r--r--ToggleArtistVisibilityCommand.h (renamed from ArtistVisibilityCommand.h)0
-rw-r--r--ToggleMuseumPauseCommand.cpp (renamed from MuseumPauseCommand.cpp)0
-rw-r--r--ToggleMuseumPauseCommand.h (renamed from MuseumPauseCommand.h)0
39 files changed, 181 insertions, 181 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a74a6b3..c946384 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,26 +17,26 @@ project(main C CXX)
add_executable(main
main.cpp
util.cpp
- FileStrategy.cpp
- HTTPFile.cpp
- LocalFile.cpp
- Exception.cpp
FileReader.cpp
+ HTTPFileReader.cpp
+ LocalFileReader.cpp
+ Exception.cpp
+ FileReaderFactory.cpp
Canvas.cpp
- Parser.cpp
+ ParserFactory.cpp
CSVParser.cpp
XMLParser.cpp
# TXTParser.cpp
- Deserializer.cpp
+ MuseumDeserializer.cpp
Tile.cpp
- TileAppearance.cpp
- TileBehaviorStrategy.cpp
+ TileColorFactory.cpp
TileBehavior.cpp
+ TileBehaviorFactory.cpp
NullTileBehavior.cpp
- YellowTileBehavior.cpp
- BlueTileBehavior.cpp
- RedTileBehavior.cpp
- GrayTileBehavior.cpp
+ CreateArtistTileBehavior.cpp
+ SetNeighborTileBehavior.cpp
+ DeleteArtistTileBehavior.cpp
+ StepTileBehavior.cpp
ViewController.cpp
View.cpp
Museum.cpp
@@ -45,9 +45,9 @@ add_executable(main
Command.cpp
OpenFileGUICommand.cpp
LoadFilesCommand.cpp
- MuseumPauseCommand.cpp
- ArtistVisibilityCommand.cpp
- TileDecayCommand.cpp
+ ToggleMuseumPauseCommand.cpp
+ ToggleArtistVisibilityCommand.cpp
+ StepTileCommand.cpp
TimeTravelCommand.cpp
)
diff --git a/YellowTileBehavior.cpp b/CreateArtistTileBehavior.cpp
index ae0cd7c..ae0cd7c 100644
--- a/YellowTileBehavior.cpp
+++ b/CreateArtistTileBehavior.cpp
diff --git a/YellowTileBehavior.h b/CreateArtistTileBehavior.h
index 6abd67f..6abd67f 100644
--- a/YellowTileBehavior.h
+++ b/CreateArtistTileBehavior.h
diff --git a/RedTileBehavior.cpp b/DeleteArtistTileBehavior.cpp
index 091a251..091a251 100644
--- a/RedTileBehavior.cpp
+++ b/DeleteArtistTileBehavior.cpp
diff --git a/RedTileBehavior.h b/DeleteArtistTileBehavior.h
index 0b2b0d4..0b2b0d4 100644
--- a/RedTileBehavior.h
+++ b/DeleteArtistTileBehavior.h
diff --git a/FileReader.cpp b/FileReader.cpp
index 4b72b11..b76de50 100644
--- a/FileReader.cpp
+++ b/FileReader.cpp
@@ -1,36 +1,9 @@
-#include <memory>
+#include <string>
-#include "FileReaderFactory.h"
#include "FileReader.h"
+#include "FileReaderFactory.h"
-using namespace std;
-
-unique_ptr<FileReader> FileReaderFactory::open(const std::string url) {
- FileReader * reader = find_reader(url)->clone();
- reader->open(url);
- return unique_ptr<FileReader>(reader);
-}
-
-void FileReaderFactory::register_strategy(const std::string type, const FileReader * node) {
- static FactoryMap & map = get_map();
- map[type] = node;
-}
-
-FactoryMap & FileReaderFactory::get_map() {
- static FactoryMap map;
- return map;
-}
-
-const FileReader * FileReaderFactory::find_reader(const std::string type) {
- static FactoryMap & map = get_map();
-
- // try to find protocol by prefix
- for (auto item : map) {
- if (!type.starts_with(item.first)) continue;
- return item.second;
- }
-
- // fallback is local file
- return map.find("file://")->second;
+FileReader::FileReader(const std::string protocol) {
+ FileReaderFactory::register_strategy(protocol, this);
}
diff --git a/FileReader.h b/FileReader.h
index 0829985..f896ec8 100644
--- a/FileReader.h
+++ b/FileReader.h
@@ -1,27 +1,25 @@
#pragma once
-#include <string>
-#include <map>
-#include <memory>
-
-#include "FileReader.h"
+class FileReaderFactory;
-using FactoryMap = std::map<std::string, const FileReader *>;
+#include <string>
-class FileReaderFactory {
+class FileReader {
+protected:
+ virtual void open(const std::string url) = 0;
public:
- static std::unique_ptr<FileReader> open(const std::string url);
+ virtual void close() = 0;
+ virtual const std::string read() = 0;
-private:
- FileReaderFactory() = default;
- virtual ~FileReaderFactory() = default;
+public:
+ virtual ~FileReader() = default;
-private:
- static void register_strategy(const std::string type, const FileReader * node);
- static FactoryMap & get_map();
- static const FileReader * find_reader(const std::string type);
+protected:
+ FileReader() = default;
+ virtual FileReader * clone() const = 0;
-private:
- friend FileReader;
+protected:
+ FileReader(const std::string protocol);
+ friend FileReaderFactory;
};
diff --git a/FileReaderFactory.cpp b/FileReaderFactory.cpp
new file mode 100644
index 0000000..4b72b11
--- /dev/null
+++ b/FileReaderFactory.cpp
@@ -0,0 +1,36 @@
+#include <memory>
+
+#include "FileReaderFactory.h"
+#include "FileReader.h"
+
+using namespace std;
+
+unique_ptr<FileReader> FileReaderFactory::open(const std::string url) {
+ FileReader * reader = find_reader(url)->clone();
+ reader->open(url);
+ return unique_ptr<FileReader>(reader);
+}
+
+void FileReaderFactory::register_strategy(const std::string type, const FileReader * node) {
+ static FactoryMap & map = get_map();
+ map[type] = node;
+}
+
+FactoryMap & FileReaderFactory::get_map() {
+ static FactoryMap map;
+ return map;
+}
+
+const FileReader * FileReaderFactory::find_reader(const std::string type) {
+ static FactoryMap & map = get_map();
+
+ // try to find protocol by prefix
+ for (auto item : map) {
+ if (!type.starts_with(item.first)) continue;
+ return item.second;
+ }
+
+ // fallback is local file
+ return map.find("file://")->second;
+}
+
diff --git a/FileReaderFactory.h b/FileReaderFactory.h
new file mode 100644
index 0000000..0829985
--- /dev/null
+++ b/FileReaderFactory.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <string>
+#include <map>
+#include <memory>
+
+#include "FileReader.h"
+
+using FactoryMap = std::map<std::string, const FileReader *>;
+
+class FileReaderFactory {
+public:
+ static std::unique_ptr<FileReader> open(const std::string url);
+
+private:
+ FileReaderFactory() = default;
+ virtual ~FileReaderFactory() = default;
+
+private:
+ static void register_strategy(const std::string type, const FileReader * node);
+ static FactoryMap & get_map();
+ static const FileReader * find_reader(const std::string type);
+
+private:
+ friend FileReader;
+};
+
diff --git a/FileStrategy.cpp b/FileStrategy.cpp
deleted file mode 100644
index b76de50..0000000
--- a/FileStrategy.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string>
-
-#include "FileReader.h"
-#include "FileReaderFactory.h"
-
-FileReader::FileReader(const std::string protocol) {
- FileReaderFactory::register_strategy(protocol, this);
-}
-
diff --git a/FileStrategy.h b/FileStrategy.h
deleted file mode 100644
index f896ec8..0000000
--- a/FileStrategy.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-class FileReaderFactory;
-
-#include <string>
-
-class FileReader {
-protected:
- virtual void open(const std::string url) = 0;
-public:
- virtual void close() = 0;
- virtual const std::string read() = 0;
-
-public:
- virtual ~FileReader() = default;
-
-protected:
- FileReader() = default;
- virtual FileReader * clone() const = 0;
-
-protected:
- FileReader(const std::string protocol);
- friend FileReaderFactory;
-};
-
diff --git a/HTTPFile.cpp b/HTTPFileReader.cpp
index d7f5dd4..d7f5dd4 100644
--- a/HTTPFile.cpp
+++ b/HTTPFileReader.cpp
diff --git a/HTTPFile.h b/HTTPFileReader.h
index 4b05e18..4b05e18 100644
--- a/HTTPFile.h
+++ b/HTTPFileReader.h
diff --git a/LocalFile.cpp b/LocalFileReader.cpp
index 1f9d574..1f9d574 100644
--- a/LocalFile.cpp
+++ b/LocalFileReader.cpp
diff --git a/LocalFile.h b/LocalFileReader.h
index 6ea4f84..6ea4f84 100644
--- a/LocalFile.h
+++ b/LocalFileReader.h
diff --git a/Deserializer.cpp b/MuseumDeserializer.cpp
index fca8d50..fca8d50 100644
--- a/Deserializer.cpp
+++ b/MuseumDeserializer.cpp
diff --git a/Deserializer.h b/MuseumDeserializer.h
index 7fecf56..7fecf56 100644
--- a/Deserializer.h
+++ b/MuseumDeserializer.h
diff --git a/Parser.h b/Parser.h
index 5430366..01efb3c 100644
--- a/Parser.h
+++ b/Parser.h
@@ -2,19 +2,10 @@
#include "FileReader.h"
#include "MuseumDeserializer.h"
-#include "Parser.h"
-
-class ParserFactory {
- typedef std::vector<Parser*> ParserCollection;
+class Parser {
public:
- static void parse(FileReader & f, MuseumDeserializer & d);
- static void register_strategy(Parser * p);
-
-private:
- static ParserCollection & get_collection() {
- static ParserCollection c = {};
- return c;
- }
+ virtual void parse(FileReader & f, MuseumDeserializer & d) = 0;
+ virtual unsigned int heuristic(FileReader & f) = 0;
};
diff --git a/Parser.cpp b/ParserFactory.cpp
index 49c4d00..49c4d00 100644
--- a/Parser.cpp
+++ b/ParserFactory.cpp
diff --git a/ParserFactory.h b/ParserFactory.h
new file mode 100644
index 0000000..5430366
--- /dev/null
+++ b/ParserFactory.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "FileReader.h"
+#include "MuseumDeserializer.h"
+#include "Parser.h"
+
+class ParserFactory {
+ typedef std::vector<Parser*> ParserCollection;
+
+public:
+ static void parse(FileReader & f, MuseumDeserializer & d);
+ static void register_strategy(Parser * p);
+
+private:
+ static ParserCollection & get_collection() {
+ static ParserCollection c = {};
+ return c;
+ }
+};
+
diff --git a/ParserStrategy.h b/ParserStrategy.h
deleted file mode 100644
index 01efb3c..0000000
--- a/ParserStrategy.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-#include "FileReader.h"
-#include "MuseumDeserializer.h"
-
-class Parser {
-public:
- virtual void parse(FileReader & f, MuseumDeserializer & d) = 0;
- virtual unsigned int heuristic(FileReader & f) = 0;
-};
-
diff --git a/BlueTileBehavior.cpp b/SetNeighborTileBehavior.cpp
index d934d4b..d934d4b 100644
--- a/BlueTileBehavior.cpp
+++ b/SetNeighborTileBehavior.cpp
diff --git a/BlueTileBehavior.h b/SetNeighborTileBehavior.h
index d316420..d316420 100644
--- a/BlueTileBehavior.h
+++ b/SetNeighborTileBehavior.h
diff --git a/GrayTileBehavior.cpp b/StepTileBehavior.cpp
index 2023bb8..2023bb8 100644
--- a/GrayTileBehavior.cpp
+++ b/StepTileBehavior.cpp
diff --git a/GrayTileBehavior.h b/StepTileBehavior.h
index d044fe7..d044fe7 100644
--- a/GrayTileBehavior.h
+++ b/StepTileBehavior.h
diff --git a/TileDecayCommand.cpp b/StepTileCommand.cpp
index ff5c6b2..ff5c6b2 100644
--- a/TileDecayCommand.cpp
+++ b/StepTileCommand.cpp
diff --git a/TileDecayCommand.h b/StepTileCommand.h
index ce9dccd..ce9dccd 100644
--- a/TileDecayCommand.h
+++ b/StepTileCommand.h
diff --git a/TileBehavior.cpp b/TileBehavior.cpp
index 99301ac..9de896e 100644
--- a/TileBehavior.cpp
+++ b/TileBehavior.cpp
@@ -1,20 +1,11 @@
#include "TileBehaviorFactory.h"
-#include "Exception.h"
+#include "TileBehavior.h"
-using namespace std;
-
-TileBehavior & TileBehaviorFactory::get_strategy(string type) {
- auto & type_map = TileBehaviorFactory::get_collection();
-
- if (type_map.contains(type))
- return *type_map.at(type);
-
- throw Exception("unknown behavior for tile type \"%s\"", type.c_str());
+TileBehavior::TileBehavior(const std::string type) {
+ TileBehaviorFactory::register_strategy(type, this);
}
-void TileBehaviorFactory::register_strategy(string type, TileBehavior * strategy) {
- auto & type_map = TileBehaviorFactory::get_collection();
-
- type_map[type] = strategy;
+void TileBehavior::step(Artist *) {
+ this->interactions++;
}
diff --git a/TileBehavior.h b/TileBehavior.h
index 33cd795..b79e7f5 100644
--- a/TileBehavior.h
+++ b/TileBehavior.h
@@ -1,21 +1,24 @@
#pragma once
-#include <map>
#include <string>
+#include <memory>
-#include "TileBehavior.h"
-
-class TileBehaviorFactory {
- typedef std::map<std::string, TileBehavior *> TileBehaviorCollection;
+class Tile;
+class Museum;
+class Artist;
+class TileBehavior {
public:
- static TileBehavior & get_strategy(std::string);
- static void register_strategy(std::string, TileBehavior *);
+ virtual void step(Artist *);
+ virtual void update(Tile &) = 0;
+ virtual std::unique_ptr<TileBehavior> clone(Museum & m) = 0;
+
+protected:
+ TileBehavior(const std::string type);
+ TileBehavior() = default;
-private:
- static TileBehaviorCollection & get_collection() {
- static TileBehaviorCollection c = {};
- return c;
- }
+protected:
+ unsigned int interactions = 0;
+ Museum * museum = nullptr;
};
diff --git a/TileBehaviorFactory.cpp b/TileBehaviorFactory.cpp
new file mode 100644
index 0000000..99301ac
--- /dev/null
+++ b/TileBehaviorFactory.cpp
@@ -0,0 +1,20 @@
+#include "TileBehaviorFactory.h"
+#include "Exception.h"
+
+using namespace std;
+
+TileBehavior & TileBehaviorFactory::get_strategy(string type) {
+ auto & type_map = TileBehaviorFactory::get_collection();
+
+ if (type_map.contains(type))
+ return *type_map.at(type);
+
+ throw Exception("unknown behavior for tile type \"%s\"", type.c_str());
+}
+
+void TileBehaviorFactory::register_strategy(string type, TileBehavior * strategy) {
+ auto & type_map = TileBehaviorFactory::get_collection();
+
+ type_map[type] = strategy;
+}
+
diff --git a/TileBehaviorFactory.h b/TileBehaviorFactory.h
new file mode 100644
index 0000000..33cd795
--- /dev/null
+++ b/TileBehaviorFactory.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <map>
+#include <string>
+
+#include "TileBehavior.h"
+
+class TileBehaviorFactory {
+ typedef std::map<std::string, TileBehavior *> TileBehaviorCollection;
+
+public:
+ static TileBehavior & get_strategy(std::string);
+ static void register_strategy(std::string, TileBehavior *);
+
+private:
+ static TileBehaviorCollection & get_collection() {
+ static TileBehaviorCollection c = {};
+ return c;
+ }
+};
+
diff --git a/TileBehaviorStrategy.cpp b/TileBehaviorStrategy.cpp
deleted file mode 100644
index 9de896e..0000000
--- a/TileBehaviorStrategy.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "TileBehaviorFactory.h"
-#include "TileBehavior.h"
-
-TileBehavior::TileBehavior(const std::string type) {
- TileBehaviorFactory::register_strategy(type, this);
-}
-
-void TileBehavior::step(Artist *) {
- this->interactions++;
-}
-
diff --git a/TileBehaviorStrategy.h b/TileBehaviorStrategy.h
deleted file mode 100644
index b79e7f5..0000000
--- a/TileBehaviorStrategy.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-
-#include <string>
-#include <memory>
-
-class Tile;
-class Museum;
-class Artist;
-
-class TileBehavior {
-public:
- virtual void step(Artist *);
- virtual void update(Tile &) = 0;
- virtual std::unique_ptr<TileBehavior> clone(Museum & m) = 0;
-
-protected:
- TileBehavior(const std::string type);
- TileBehavior() = default;
-
-protected:
- unsigned int interactions = 0;
- Museum * museum = nullptr;
-};
-
diff --git a/TileAppearance.cpp b/TileColorFactory.cpp
index 7c5b080..7c5b080 100644
--- a/TileAppearance.cpp
+++ b/TileColorFactory.cpp
diff --git a/TileAppearance.h b/TileColorFactory.h
index 83dfeed..83dfeed 100644
--- a/TileAppearance.h
+++ b/TileColorFactory.h
diff --git a/ArtistVisibilityCommand.cpp b/ToggleArtistVisibilityCommand.cpp
index 6c22dbc..6c22dbc 100644
--- a/ArtistVisibilityCommand.cpp
+++ b/ToggleArtistVisibilityCommand.cpp
diff --git a/ArtistVisibilityCommand.h b/ToggleArtistVisibilityCommand.h
index 47e2158..47e2158 100644
--- a/ArtistVisibilityCommand.h
+++ b/ToggleArtistVisibilityCommand.h
diff --git a/MuseumPauseCommand.cpp b/ToggleMuseumPauseCommand.cpp
index 57176af..57176af 100644
--- a/MuseumPauseCommand.cpp
+++ b/ToggleMuseumPauseCommand.cpp
diff --git a/MuseumPauseCommand.h b/ToggleMuseumPauseCommand.h
index 15d1388..15d1388 100644
--- a/MuseumPauseCommand.h
+++ b/ToggleMuseumPauseCommand.h