aboutsummaryrefslogtreecommitdiff
path: root/docs/class-diag.puml
blob: 389395a2b4f2002b4139a192180c87d72598a556 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
@startuml

!include style.ipuml

' !include hide-groups.ipuml
' !include hide-details.ipuml

class main as "main()"
hide main circle
hide main members

exception Exception {
	+ Exception(const char* fmt, ...)
	+ what() : const char*
	--
	# error : char*
	# va_format(va_list args, const char* fmt)
}

together { /' LAYOUT '/
rectangle Group_FileReading as "File reading" <<group>> {
	class FileReader <<Factory>> {
		+open(url) : FileStrategy&
	}
	interface FileStrategy {
		+ read() : string
		+ close()
		--
		# open(string url)
		# clone() : FileStrategy* <<const>>
	}
	class LocalFile {
		- instance : LocalFile <<static>>
	}
	class HTTPFile {
		- instance : HTTPFile <<static>>
	}
	package CPR { }

	FileStrategy <|.. LocalFile
	FileStrategy <|.. HTTPFile

	FileStrategy <. FileReader
	FileStrategy .> FileReader

	HTTPFile -> CPR

	' LAYOUT
	LocalFile -r[hidden] HTTPFile
}
rectangle Group_ParsingDeserialization as "Parsing & deserialization" <<group>> {
	class Parser {
		+ parse(FileStrategy &, Deserializer &) <<static>>
		+ register_strategy(ParserStrategy *) <<static>>
		--
		- get_collection() : ParserCollection <<static>>
	}
	interface ParserStrategy  {
		+ parse(FileStrategy &, Deserializer &) <<static>>
		+ heuristic(FileStrategy &) : unsigned int <<static>>
	}

	ParserStrategy .> Parser
	ParserStrategy <. Parser

	class CSVParser
	class XMLParser
	class TXTParser

	package pugixml { }

	CSVParser ..|> ParserStrategy
	TXTParser ..|> ParserStrategy
	XMLParser ..|> ParserStrategy

	XMLParser -> pugixml

	class Deserializer {
		+ Deserializer(Museum &)
		--
		+ set_canvas(CanvasData)
		+ set_tile(TileData)
		+ add_artist(ArtistData)
		+ add_type(type : string, Color, weight : unsigned int)
	}

	CSVParser -up-> Deserializer
	XMLParser -up-> Deserializer
	TXTParser -up-> Deserializer

	' LAYOUT
	CSVParser -r[hidden] TXTParser
	TXTParser -r[hidden] XMLParser
}
} /' LAYOUT '/

together { /' LAYOUT '/
rectangle Group_Model as "Model" <<group>> {
	class Museum {
		+ people : People
		+ canvas : Canvas
		--
		+ update()
		--
		- paused : bool <<+get>> <<+set>>
		- jump : unsigned long
		--
		- working : bool
		- worker : thread *
		- work()
	}
	class Canvas {
		+ Canvas(Museum &)
		--
		+ get_tile(x, y) : Tile &
		+ set_tile(TileData)
		--
		+ update()
		+ data : CanvasData
		+ set_data(CanvasData)
		--
		- tiles : vector<Tile *>
		- museum : Museum &
	}
	class People {
		+ People(Museum &)
		--
		+ add_artist(ArtistData)
		+ remove_artist(Artist &)
		+ get_artists() : forward_list<Artist *>
		--
		- artists : forward_list<Artist *>
		- artist_count : size_t
		- museum : Museum &
		--
		- deleted_artists : forward_list<Artist *>
		- cleanup()
	}
	class Tile {
		+ data : TileData
		+ color : Color
		+ behavior : uniq<TileBehaviorStrategy>
		+ set_data(TileData &)
		+ set_type(type : const string &)
		+ update()
		+ step(Artist *)
		+ get_neighbor(dx, dy) : Tile *
		--
		- museum : Museum &
	}
	struct TileData {
		+ x : unsigned int
		+ y : unsigned int
		+ type : string
	}
	class Artist {
		+ update()
		+ step : bool
		+ color : Color
		+ data : ArtistData
		--
		- data : ArtistData
		- museum : Museum &
	}
	struct ArtistData {
		+ x : float
		+ y : float
		+ vx : float
		+ vy : float
	}
	struct CanvasData {
		+ rows : unsigned int
		+ columns : unsigned int
	}

	Museum --> People
	Museum --> Canvas

	Canvas --> Tile
	People --> Artist

	Tile   -> TileData
	Artist -l> ArtistData
	Canvas -> CanvasData

	' LAYOUT
	Artist -r[hidden] Tile
}
rectangle Group_TileAppearance as "Tile appearance" <<group>> {
	struct Color {
		red : unsigned int
		green : unsigned int
		blue : unsigned int
	}
	class TileAppearance {
		+ get_color(string) : Color <<static>>
		+ register_color(string, Color) <<static>>
	}

	Tile --> Color

	Color <.. TileAppearance
}
rectangle Group_TileBehavior as "Tile behavior" <<group>> {
	interface TileBehaviorStrategy {
		+ step(Artist *)
		+ update(Tile &)
		+ clone(Museum &) : uniq<TileBehaviorStrategy>
		--
		# TileBehaviorStrategy(type : string)
		# TileBehaviorStrategy()
		--
		# interactions : unsigned int
		# museum : Museum *
	}

	class TileBehavior {
		+ get_strategy(string) : TileBehaviorStrategy & <<static>>
		+ register_strategy(string, TileBehaviorStrategy *) <<static>>
		--
		- get_collection() : TileBehaviorCollection & <<static>>
	}

	together {
		class NullTileBehavior {
			- type = "" <<static constexpr>>
		}
		class GrayTileBehavior {
			- type = "G" : <<static constexpr>>
		}
		class RedTileBehavior {
			- type = "R" : <<static constexpr>>
		}
		class BlueTileBehavior {
			- type = "B" : <<static constexpr>>
			--
			- dx : int
			- dy : int
		}
		class YellowTileBehavior {
			- type = "Y" : <<static constexpr>>
			--
			- last_interactions : unsigned int
		}

		' LAYOUT
		TileBehavior -d[hidden]- NullTileBehavior
		NullTileBehavior -d[hidden]- GrayTileBehavior
		GrayTileBehavior -d[hidden]- RedTileBehavior
		RedTileBehavior -d[hidden]- BlueTileBehavior
		BlueTileBehavior -d[hidden]- YellowTileBehavior
	}

	TileBehaviorStrategy <|.[norank]. NullTileBehavior
	TileBehaviorStrategy <|.[norank]. GrayTileBehavior
	TileBehaviorStrategy <|.[norank]. RedTileBehavior
	TileBehaviorStrategy <|.[norank]. BlueTileBehavior
	TileBehaviorStrategy <|.[norank]. YellowTileBehavior

	Tile --> "state" TileBehavior

	TileBehavior .l> TileBehaviorStrategy
	TileBehavior <. TileBehaviorStrategy
}
} /' LAYOUT '/

together { /' LAYOUT '/
rectangle Group_Commands as "Commands" <<group>> {
	class Command {
		# museum : Museum&
		# view : View&
		# controller : ViewController&
		--
		+ Command(command : const Command *)
		+ Command(museum, view, controller)
	}

	class MuseumPauseCommand {
		+ toggle()
		+ set(paused : bool)
	}
	class OpenFileGUICommand {
		+ execute()
	}
	class ArtistVisibilityCommand {
		+ toggle()
		+ set(paused : bool)
	}
	class LoadFilesCommand {
		+ execute(files)
	}
	class TileDecayCommand {
		+ execute(x, y)
	}

	Command <|-u- MuseumPauseCommand
	Command <|-u- OpenFileGUICommand
	Command <|-u- ArtistVisibilityCommand
	Command <|-u- TileDecayCommand
	Command <|-d- LoadFilesCommand
}
rectangle Group_Visualization as "Visualization" <<group>> {
	struct Rectangle {
		x : unsigned int
		y : unsigned int
		width : unsigned int
		height : unsigned int
	}
	enum MouseCode { }
	enum KeyboardCode { }
	package SDL3 { }

	class View {
		+ window_size(width, height)
		+ dialog_file(callback : fn(files : vec<string>, data), data)
		+ draw_rect(Rectangle, Color)
		--
		- window : SDL_Window *
		- renderer : SDL_Renderer *
		--
		+ open : bool
		- worker : thread *
		- work()
	}
	class ViewController {
		+ update()
		+ ev_keydown(KeyboardCode);
		+ ev_mousedown(MouseCode);
		+ ev_mousemove(x, y);
		--
		- draw_artists : bool <<+get>> <<+set>>
		- cmd_base : const Command *
	}

	ViewController ..> View
	ViewController <-- View
	View --> SDL3

	View .> Rectangle
	ViewController .> KeyboardCode
	ViewController .> MouseCode
}
} /' LAYOUT '/

Command .[norank]> Museum
Command .[norank]> View
Command .[norank]> ViewController

ParserStrategy ..> FileStrategy
Deserializer .> Museum

ViewController -[norank]> Command

main -d-> Museum
main -u-> LoadFilesCommand
main -[norank]> Deserializer
main -[norank]> View
main .l> Exception

' LAYOUT
Group_TileBehavior -r[hidden] Group_TileAppearance
Group_Model -r[hidden] Group_ParsingDeserialization
Group_Commands -r[hidden] Group_Visualization

@enduml