diff options
-rw-r--r-- | Artist.h | 12 | ||||
-rw-r--r-- | ArtistData.h | 9 | ||||
-rw-r--r-- | BlueTileBehavior.h | 1 | ||||
-rw-r--r-- | CSVParser.h | 2 | ||||
-rw-r--r-- | Canvas.h | 18 | ||||
-rw-r--r-- | CanvasData.h | 7 | ||||
-rw-r--r-- | Color.h | 8 | ||||
-rw-r--r-- | Deserializer.h | 20 | ||||
-rw-r--r-- | GrayTileBehavior.h | 2 | ||||
-rw-r--r-- | Museum.h | 11 | ||||
-rw-r--r-- | Parser.h | 14 | ||||
-rw-r--r-- | ParserStrategy.h | 15 | ||||
-rw-r--r-- | People.h | 16 | ||||
-rw-r--r-- | RedTileBehavior.h | 2 | ||||
-rw-r--r-- | TXTParser.h | 2 | ||||
-rw-r--r-- | Tile.h | 15 | ||||
-rw-r--r-- | TileAppearance.h | 2 | ||||
-rw-r--r-- | TileBehavior.h | 2 | ||||
-rw-r--r-- | TileData.h | 8 | ||||
-rw-r--r-- | View.h | 2 | ||||
-rw-r--r-- | ViewController.h | 2 | ||||
-rw-r--r-- | XMLParser.h | 2 | ||||
-rw-r--r-- | YellowTileBehavior.h | 2 | ||||
-rw-r--r-- | docs/class-diag.puml | 104 | ||||
-rw-r--r-- | main.cpp | 12 |
25 files changed, 241 insertions, 49 deletions
diff --git a/Artist.h b/Artist.h new file mode 100644 index 0000000..c14785b --- /dev/null +++ b/Artist.h @@ -0,0 +1,12 @@ +#pragma once + +#include "ArtistData.h" + +class Artist { +public: + void update(); + +private: + ArtistData data; +}; + diff --git a/ArtistData.h b/ArtistData.h new file mode 100644 index 0000000..ddee528 --- /dev/null +++ b/ArtistData.h @@ -0,0 +1,9 @@ +#pragma once + +typedef struct { + float x; + float y; + float vx; + float vy; +} ArtistData; + diff --git a/BlueTileBehavior.h b/BlueTileBehavior.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/BlueTileBehavior.h @@ -0,0 +1 @@ +#pragma once diff --git a/CSVParser.h b/CSVParser.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/CSVParser.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/Canvas.h b/Canvas.h new file mode 100644 index 0000000..e4dc65a --- /dev/null +++ b/Canvas.h @@ -0,0 +1,18 @@ +#pragma once + +#include <vector> +#include <memory> + +#include "CanvasData.h" +#include "Tile.h" + +class Canvas { +public: + virtual Tile & get_tile(unsigned x, unsigned y); + virtual void set_tile(unsigned x, unsigned y, std::unique_ptr<TileData> t); + +private: + CanvasData data; + std::vector<Tile> tiles; +}; + diff --git a/CanvasData.h b/CanvasData.h new file mode 100644 index 0000000..19812da --- /dev/null +++ b/CanvasData.h @@ -0,0 +1,7 @@ +#pragma once + +typedef struct { + unsigned rows; + unsigned columns; +} CanvasData; + @@ -0,0 +1,8 @@ +#pragma once + +typedef struct { + unsigned int red; + unsigned int green; + unsigned int blue; +} Color; + diff --git a/Deserializer.h b/Deserializer.h new file mode 100644 index 0000000..5123cc9 --- /dev/null +++ b/Deserializer.h @@ -0,0 +1,20 @@ +#pragma once + +#include <string> +#include <memory> + +#include "Museum.h" +#include "ArtistData.h" +#include "TileData.h" +#include "Color.h" + +class Deserializer { +public: + void set_target(Museum & m); + void add_artist(std::unique_ptr<ArtistData>); + void set_rows(unsigned int); + void set_cols(unsigned int); + void add_type(std::string, Color, unsigned int); + void add_tile(unsigned int x, unsigned int y, std::unique_ptr<TileData>); +}; + diff --git a/GrayTileBehavior.h b/GrayTileBehavior.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/GrayTileBehavior.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/Museum.h b/Museum.h new file mode 100644 index 0000000..f15a2fe --- /dev/null +++ b/Museum.h @@ -0,0 +1,11 @@ +#pragma once + +#include "People.h" +#include "Canvas.h" + +class Museum { +private: + People people; + Canvas canvas; +}; + diff --git a/Parser.h b/Parser.h new file mode 100644 index 0000000..c867f9e --- /dev/null +++ b/Parser.h @@ -0,0 +1,14 @@ +#pragma once + +#include "File.h" +#include "Deserializer.h" +#include "ParserStrategy.h" + +class Parser { +public: + static void parse(File & f, Deserializer & d); + +private: + static void register_strategy(ParserStrategy & p); +}; + diff --git a/ParserStrategy.h b/ParserStrategy.h new file mode 100644 index 0000000..c9f9eff --- /dev/null +++ b/ParserStrategy.h @@ -0,0 +1,15 @@ +#pragma once + +#include "File.h" +#include "Deserializer.h" + +class ParserStrategy { +public: + ParserStrategy() = default; + virtual ~ParserStrategy() = 0; + +public: + virtual void parse(File & f, Deserializer & d) = 0; + virtual unsigned int heuristic(File & f) = 0; +}; + diff --git a/People.h b/People.h new file mode 100644 index 0000000..ff30595 --- /dev/null +++ b/People.h @@ -0,0 +1,16 @@ +#pragma once + +#include <memory> +#include <vector> + +#include "Artist.h" +#include "ArtistData.h" + +class People { +public: + void add_artist(std::unique_ptr<ArtistData> data); + +private: + std::vector<Artist> artists; +}; + diff --git a/RedTileBehavior.h b/RedTileBehavior.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/RedTileBehavior.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/TXTParser.h b/TXTParser.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/TXTParser.h @@ -0,0 +1,2 @@ +#pragma once + @@ -0,0 +1,15 @@ +#pragma once + +#include "TileData.h" +#include "TileBehavior.h" +#include "TileAppearance.h" + +class Tile { +public: + TileData data; + +private: + TileBehavior behavior; + TileAppearance appearance; +}; + diff --git a/TileAppearance.h b/TileAppearance.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/TileAppearance.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/TileBehavior.h b/TileBehavior.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/TileBehavior.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/TileData.h b/TileData.h new file mode 100644 index 0000000..406947f --- /dev/null +++ b/TileData.h @@ -0,0 +1,8 @@ +#pragma once + +#include <string> + +typedef struct { + std::string type; +} TileData; + @@ -0,0 +1,2 @@ +#pragma once + diff --git a/ViewController.h b/ViewController.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/ViewController.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/XMLParser.h b/XMLParser.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/XMLParser.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/YellowTileBehavior.h b/YellowTileBehavior.h new file mode 100644 index 0000000..3f59c93 --- /dev/null +++ b/YellowTileBehavior.h @@ -0,0 +1,2 @@ +#pragma once + diff --git a/docs/class-diag.puml b/docs/class-diag.puml index 96a57f2..8d4fa68 100644 --- a/docs/class-diag.puml +++ b/docs/class-diag.puml @@ -3,10 +3,13 @@ ' TODO: ' - state snapshots (memento) ' - send commands from GUI +' - TileAppearance should have some kind of tile type -> color registry +' - everything added by the algorithms +' - artist collision behavior (both edges and artist-artist) !include style.ipuml -' !include hide-groups.ipuml +!include hide-groups.ipuml ' !include hide-details.ipuml class main as "main()" @@ -54,12 +57,18 @@ rectangle Group_FileReading as "File reading" <<group>> { } rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>> { - interface ParserStrategy { - + parse(File, Deserializer) - + heuristic(File) : unsigned int + class Parser { + + parse(File, Deserializer) <<static>> + -- + - register_strategy(ParserStrategy) <<static>> + } + interface ParserStrategy { + + parse(File, Deserializer) <<static>> + + heuristic(File) : unsigned int <<static>> } - ParserStrategy ..> File + ParserStrategy .> Parser + ParserStrategy <. Parser class CSVParser class XMLParser @@ -71,23 +80,16 @@ rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>> class Deserializer { + set_target(Museum &) - } - class PeopleDeserializer { + add_artist(uniq<ArtistData>) - } - class CanvasDeserializer { + set_rows(unsigned int) + set_cols(unsigned int) + add_type(string, Color, unsigned int) + add_tile(unsigned int x, unsigned int y, uniq<TileData>) } - PeopleDeserializer -up-|> Deserializer - CanvasDeserializer -up-|> Deserializer - - CSVParser -up-> PeopleDeserializer - XMLParser -up-> CanvasDeserializer - TXTParser -up-> CanvasDeserializer + CSVParser -up-> Deserializer + XMLParser -up-> Deserializer + TXTParser -up-> Deserializer ' ParserStrategy ..> Deserializer } @@ -95,20 +97,18 @@ rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>> rectangle Group_Model as "Model" <<group>> { class Canvas { + get_tile(x, y) - + set_tile(x, y) + + set_tile(x, y, TileData) - data : CanvasData - tiles : Tile[] } class People { - + add_artist(uniq<artists>) : void + + add_artist(uniq<ArtistData>) - artists : Artist[] } class Museum { - + load : - - artists : People + - people : People - canvas : Canvas } - ' TODO color : Color? class Tile { + data : TileData } @@ -130,6 +130,41 @@ rectangle Group_Model as "Model" <<group>> { + rows : unsigned int + columns : unsigned int } + rectangle Group_Tile_Appearance as "Tile appearance" <<group>> { + struct Color { + red : unsigned int + green : unsigned int + blue : unsigned int + } + class TileAppearance { + + color : Color + } + + TileAppearance --> Color + + Tile --> "state" TileAppearance + } + rectangle Group_Tile_Behavior as "Tile behavior" <<group>> { + interface TileBehavior + + together { + class GrayTileBehavior + class RedTileBehavior + class BlueTileBehavior + class YellowTileBehavior + + GrayTileBehavior -d[hidden]- RedTileBehavior + RedTileBehavior -d[hidden]- BlueTileBehavior + BlueTileBehavior -d[hidden]- YellowTileBehavior + } + + TileBehavior <|.. GrayTileBehavior + TileBehavior <|.. RedTileBehavior + TileBehavior <|.. BlueTileBehavior + TileBehavior <|.. YellowTileBehavior + + Tile --> "state" TileBehavior + } Museum --> People Museum --> Canvas @@ -139,11 +174,11 @@ rectangle Group_Model as "Model" <<group>> { Tile --> TileData Artist --> ArtistData - Canvas --> CanvasData + + Canvas -> CanvasData ' LAYOUT Artist -r[hidden] Tile - Tile -r[hidden] CanvasData } rectangle "Visualization" <<group>> { @@ -159,34 +194,11 @@ rectangle "Visualization" <<group>> { View --> SDL2 } -' class TileBehavior -' -' class GrayTileBehavior -' class RedTileBehavior -' class BlueTileBehavior -' class YellowTileBehavior -' -' TileBehavior <|-- GrayTileBehavior -' TileBehavior <|-- RedTileBehavior -' TileBehavior <|-- BlueTileBehavior -' TileBehavior <|-- YellowTileBehavior - -' struct Color { -' red : unsigned int -' green : unsigned int -' blue : unsigned int -' } - ' PeopleDeserializer <... People ' CanvasDeserializer <... Canvas ' Deserializer <... Museum -' class TileAppearance { -' + color : Color -' } -' -' TileAppearance .r Color - +ParserStrategy ..> File ' Museum .> Deserializer : friend Deserializer .> Museum @@ -1,12 +1,18 @@ #include <cstdio> #include "FileReader.h" +#include "Museum.h" +#include "Deserializer.h" +#include "Parser.h" int main(int argc, char** argv) { + Museum m {}; + Deserializer d {}; + for (int i = 1; i < argc; i++) { - File & r = FileReader::open(argv[i]); - printf("\n-- %s --\n%s\n", argv[i], r.read().c_str()); - r.close(); + File & f = FileReader::open(argv[i]); + Parser::parse(f, d); + f.close(); } return 0; |