-
Notifications
You must be signed in to change notification settings - Fork 1
/
DataStructs.pas
231 lines (177 loc) · 5.83 KB
/
DataStructs.pas
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
unit DataStructs;
interface
uses
System.Generics.Collections, System.Generics.Defaults, System.Classes,
Vcl.Graphics;
type
{
TSong class represents a song. A song is the most granular unit, representing
what is actually stored in the playlist. The other classes are meant to make
songs more easily classifiable.
A song has a name, a list of genres (all of which are stored in a string), and
a track number (used for sorting in the table). There are also the associated
band and album names, which allow songs to be narrowed down easily.
As with all classes for this program, there is also a boolean to designate it
as a favorite.
}
TSong = class
private
songName, bandName, albumName: String;
public
isFavorite: Boolean;
tags: TStringList;
color: TColor;
track: Integer;
property name: String read songName;
property trackNo: Integer read track write track;
//relational properties
property band: String read bandName;
property album: String read albumName;
constructor Create(const songName, bandName, albumName: String; trackNo: Integer); overload;
constructor Create(const songName, bandName, albumName: String; trackNo: Integer; fav: Boolean; color: TColor); overload;
procedure AddTags(toAdd: TStrings);
end;
{
TAlbum class represents an album. An album is the middleman between bands and
songs. A band has a list of albums, while an album has a list of songs.
An album has a name and a year that it came out, along with the aforementioned
list of songs. And of course, albums can be designated as favorites as well.
Albums have an associated band as well, allowing an easy way to narrow down
albums when querying.
}
TAlbum = class
private
albumName, bandName: String;
public
isFavorite: Boolean;
tags: TStringList;
color: TColor;
albumYear: Integer;
songs: TDictionary<String, TSong>;
property name: String read albumName;
property year: Integer read albumYear write albumYear;
//relational property
property band: String read bandName;
constructor Create(const albumName, bandName: String; albumYear: Integer); overload;
constructor Create(const albumName, bandName: String; albumYear: Integer; fav: Boolean; color: TColor); overload;
procedure AddTags(toAdd: TStrings);
end;
{
TBand is the most general of the classes for this program. It is the least
granular, as any given band is likely to have a few albums and anywhere from
a few to hundreds of songs.
A band has a name and a list of albums, and can be designated as a favorite.
}
TBand = class
private
bandName: String;
public
isFavorite: Boolean;
tags: TStringList;
color: TColor;
albums: TDictionary<String, TAlbum>;
property name: String read bandName;
constructor Create(const bandName: String); overload;
constructor Create(const bandName: String; fav: Boolean; color: TColor); overload;
procedure AddTags(toAdd: TStrings);
end;
implementation
//==============================================================================
// TSong Methods
//==============================================================================
//constructor without fav
constructor TSong.Create(const songName, bandName, albumName: String; trackNo: Integer);
begin
self.songName := songName;
self.track := trackNo;
self.bandName := bandName;
self.albumName := albumName;
isFavorite := false;
tags := TStringList.Create;
color := clWhite;
end;
//constructor with fav
constructor TSong.Create(const songName, bandName, albumName: string; trackNo: Integer; fav: Boolean; color: TColor);
begin
self.songName := songName;
self.track := trackNo;
self.bandName := bandName;
self.albumName := albumName;
isFavorite := fav;
tags := TStringList.Create;
self.color := color;
end;
procedure TSong.AddTags(toAdd: TStrings);
var
at: String;
begin
for at in toAdd do
begin
if tags.IndexOf(at) = -1 then
tags.Add(at);
end;
end;
//==============================================================================
// TAlbum Methods
//==============================================================================
constructor TAlbum.Create(const albumName, bandName: String; albumYear: Integer);
begin
self.albumName := albumName;
self.albumYear := albumYear;
self.bandName := bandName;
isFavorite := false;
tags := TStringList.Create;
color := clWhite;
songs := TDictionary<String, TSong>.Create;
end;
//constructor with id and fav
constructor TAlbum.Create(const albumName, bandName: String; albumYear: Integer; fav: Boolean; color: TColor);
begin
self.albumName := albumName;
self.albumYear := albumYear;
self.bandName := bandName;
isFavorite := fav;
tags := TStringList.Create;
self.color := color;
songs := TDictionary<String, TSong>.Create;
end;
procedure TAlbum.AddTags(toAdd: TStrings);
var
at: String;
begin
for at in toAdd do
begin
if tags.IndexOf(at) = -1 then
tags.Add(at);
end;
end;
//==============================================================================
// TBand Methods
//==============================================================================
constructor TBand.Create(const bandName: String);
begin
self.bandName := bandName;
isFavorite := false;
tags := TStringList.Create;
color := clWhite;
albums := TDictionary<String, TAlbum>.Create;
end;
constructor TBand.Create(const bandName: String; fav: Boolean; color: TColor);
begin
self.bandName := bandName;
isFavorite := fav;
tags := TStringList.Create;
self.color := color;
albums := TDictionary<String, TAlbum>.Create;
end;
procedure TBand.AddTags(toAdd: TStrings);
var
at: String;
begin
for at in toAdd do
begin
if tags.IndexOf(at) = -1 then
tags.Add(at);
end;
end;
end.