Summary Files Commits Branches @commit @diff @stats
path: root / Year 1 / Object-oriented Programming / Project 2 / docs / latex / classList.tex
blob: 8c14ca85c1b4ac0e57482766b52d972db40aed51 (plain) (blame)
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
\hypertarget{classList}{}\doxysection{List\texorpdfstring{$<$}{<} T \texorpdfstring{$>$}{>} Class Template Reference}
\label{classList}\index{List$<$ T $>$@{List$<$ T $>$}}


Templated class that stores an array of elements in dynamic memory.  




{\ttfamily \#include $<$List.\+hpp$>$}

\doxysubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{classList_a93cd36efc12aa5ef5fc28866edce7e61}\label{classList_a93cd36efc12aa5ef5fc28866edce7e61}} 
{\bfseries List} (const T $\ast$elements, unsigned elements\+Count)
\begin{DoxyCompactList}\small\item\em Copies all elements in given array. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{classList_a40212635a3d75dfc14e9473271467b04}\label{classList_a40212635a3d75dfc14e9473271467b04}} 
{\bfseries List} (unsigned length)
\begin{DoxyCompactList}\small\item\em Allocates memory for the given length. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{classList_abfec4f2e7990d06c143852ecfdf907bb}{add}} (const T \&element)
\begin{DoxyCompactList}\small\item\em Adds an element. \end{DoxyCompactList}\item 
void \mbox{\hyperlink{classList_ae4586debf72af33bccb3c2fbfce420e8}{insert\+At}} (const T \&element, unsigned index)
\begin{DoxyCompactList}\small\item\em Inserts element at given index. \end{DoxyCompactList}\item 
bool \mbox{\hyperlink{classList_ad9c0a5b5bca6286f458d6fab280de65a}{remove\+At}} (unsigned index)
\begin{DoxyCompactList}\small\item\em Removes element at index. \end{DoxyCompactList}\item 
unsigned \mbox{\hyperlink{classList_a3804f03273ef5e339b504e439c5b6534}{find\+Index}} (const T \&element) const
\begin{DoxyCompactList}\small\item\em Finds the index of element. \end{DoxyCompactList}\item 
bool \mbox{\hyperlink{classList_a163a070c7d5dc77ca3c1726b8f2d4bc1}{contain}} (const T \&element) const
\item 
\mbox{\Hypertarget{classList_a321bb581943398344aad07198d1f02ac}\label{classList_a321bb581943398344aad07198d1f02ac}} 
T \& {\bfseries operator\mbox{[}$\,$\mbox{]}} (unsigned index)
\begin{DoxyCompactList}\small\item\em Returns reference to element at index. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{classList_a5fa582de3aec5094a871852b658cf853}\label{classList_a5fa582de3aec5094a871852b658cf853}} 
const T \& {\bfseries operator\mbox{[}$\,$\mbox{]}} (unsigned index) const
\begin{DoxyCompactList}\small\item\em Returns constant reference to element at index. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{classList_a1e380d73cf889304a7468762ade0410c}\label{classList_a1e380d73cf889304a7468762ade0410c}} 
const T $\ast$ {\bfseries raw\+\_\+data} () const
\begin{DoxyCompactList}\small\item\em Returns raw array of data. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{classList_ae296516a252e11963dbf963727ce429a}\label{classList_ae296516a252e11963dbf963727ce429a}} 
void {\bfseries clear} ()
\begin{DoxyCompactList}\small\item\em Removes all data. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{classList_aa4332ce5a589da28528f035ded6d41e5}\label{classList_aa4332ce5a589da28528f035ded6d41e5}} 
\mbox{\hyperlink{classList}{List}}$<$ T $>$ \& {\bfseries operator+=} (const \mbox{\hyperlink{classList}{List}}$<$ T $>$ other)
\begin{DoxyCompactList}\small\item\em Appends elements from other list. \end{DoxyCompactList}\item 
std\+::istream \& \mbox{\hyperlink{classList_a5e3581ee07649f462aa8bb3221a5466e}{read}} (std\+::istream \&istr)
\begin{DoxyCompactList}\small\item\em Reads from stream. \end{DoxyCompactList}\item 
std\+::ostream \& \mbox{\hyperlink{classList_a8d2babffd2fb4a5e0a40dbd306e19956}{write}} (std\+::ostream \&ostr) const
\begin{DoxyCompactList}\small\item\em Writes to stream. \end{DoxyCompactList}\item 
unsigned \mbox{\hyperlink{classList_aa32109b77dccd8241b125ebabdda876c}{get\+\_\+length}} () const
\begin{DoxyCompactList}\small\item\em Returns the length. \end{DoxyCompactList}\item 
unsigned \mbox{\hyperlink{classList_a3c1e3a3fc085f5b7ae68514c4758687b}{get\+\_\+count}} () const
\begin{DoxyCompactList}\small\item\em Returns the count. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{classList_a248952759645a68a4a1ea5aa31bc089f}\label{classList_a248952759645a68a4a1ea5aa31bc089f}} 
\mbox{\hyperlink{classList}{List}} \& {\bfseries operator=} (const \mbox{\hyperlink{classList}{List}} \&other)
\item 
\mbox{\Hypertarget{classList_a43ce719b9dcc8aa532bad580c44e99f6}\label{classList_a43ce719b9dcc8aa532bad580c44e99f6}} 
{\bfseries List} (const \mbox{\hyperlink{classList}{List}} \&other)
\item 
\mbox{\Hypertarget{classList_a25feb644d97345e4f36bf54c7aab4ade}\label{classList_a25feb644d97345e4f36bf54c7aab4ade}} 
{\bfseries List} (\mbox{\hyperlink{classList}{List}} \&\&other)
\item 
\mbox{\Hypertarget{classList_a3be35847f78c9fdb37c957eff55c1608}\label{classList_a3be35847f78c9fdb37c957eff55c1608}} 
\mbox{\hyperlink{classList}{List}} \& {\bfseries operator=} (\mbox{\hyperlink{classList}{List}} \&\&other)
\end{DoxyCompactItemize}
\doxysubsection*{Protected Member Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{classList_a302d78384a6516a4d4dede84d4f0968e}\label{classList_a302d78384a6516a4d4dede84d4f0968e}} 
void {\bfseries resize} ()
\item 
\mbox{\Hypertarget{classList_a29cb6681b3f5514f747d04661b08cfd6}\label{classList_a29cb6681b3f5514f747d04661b08cfd6}} 
void {\bfseries free} ()
\item 
\mbox{\Hypertarget{classList_aef2dcec4a271f7ba2f71ef164535e273}\label{classList_aef2dcec4a271f7ba2f71ef164535e273}} 
void {\bfseries copy\+From} (const \mbox{\hyperlink{classList}{List}} \&other)
\end{DoxyCompactItemize}
\doxysubsection*{Protected Attributes}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{classList_ab28a0d67da45b5d3bb755c72105a516c}\label{classList_ab28a0d67da45b5d3bb755c72105a516c}} 
T $\ast$ {\bfseries elements}
\item 
\mbox{\Hypertarget{classList_af44323f3a486341510ad97b6bceda1be}\label{classList_af44323f3a486341510ad97b6bceda1be}} 
unsigned {\bfseries length}
\item 
\mbox{\Hypertarget{classList_a66db5f1795dd0530911f32552ddd9815}\label{classList_a66db5f1795dd0530911f32552ddd9815}} 
unsigned {\bfseries count}
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
\subsubsection*{template$<$typename T$>$\newline
class List$<$ T $>$}
Templated class that stores an array of elements in dynamic memory. 

\begin{DoxyWarning}{Warning}
\mbox{\hyperlink{classList_a3804f03273ef5e339b504e439c5b6534}{find\+Index()}}, \mbox{\hyperlink{classList_a163a070c7d5dc77ca3c1726b8f2d4bc1}{contain()}}, \mbox{\hyperlink{classList_a5e3581ee07649f462aa8bb3221a5466e}{read()}}, \mbox{\hyperlink{classList_a8d2babffd2fb4a5e0a40dbd306e19956}{write()}}, operator$<$$<$() and operator$>$$>$() require the type to have defined a couple of functions. 
\end{DoxyWarning}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{classList_a3804f03273ef5e339b504e439c5b6534}{find\+Index()}} 

\mbox{\hyperlink{classList_a163a070c7d5dc77ca3c1726b8f2d4bc1}{contain()}} 

\mbox{\hyperlink{classList_a5e3581ee07649f462aa8bb3221a5466e}{read()}} 

\mbox{\hyperlink{classList_a8d2babffd2fb4a5e0a40dbd306e19956}{write()}} 

\mbox{\hyperlink{List_8hpp_ac8590f4d4ba6c820c34afe14df54f2c2}{operator$<$$<$()}} 

\mbox{\hyperlink{List_8hpp_a7469c3479753bfbada761697c539aa07}{operator$>$$>$()}} 
\end{DoxySeeAlso}


\doxysubsection{Member Function Documentation}
\mbox{\Hypertarget{classList_abfec4f2e7990d06c143852ecfdf907bb}\label{classList_abfec4f2e7990d06c143852ecfdf907bb}} 
\index{List$<$ T $>$@{List$<$ T $>$}!add@{add}}
\index{add@{add}!List$<$ T $>$@{List$<$ T $>$}}
\doxysubsubsection{\texorpdfstring{add()}{add()}}
{\footnotesize\ttfamily template$<$typename T $>$ \\
void \mbox{\hyperlink{classList}{List}}$<$ T $>$\+::add (\begin{DoxyParamCaption}\item[{const T \&}]{element }\end{DoxyParamCaption})}



Adds an element. 

Resizes internal array if there is no space for additional elements. \mbox{\Hypertarget{classList_a163a070c7d5dc77ca3c1726b8f2d4bc1}\label{classList_a163a070c7d5dc77ca3c1726b8f2d4bc1}} 
\index{List$<$ T $>$@{List$<$ T $>$}!contain@{contain}}
\index{contain@{contain}!List$<$ T $>$@{List$<$ T $>$}}
\doxysubsubsection{\texorpdfstring{contain()}{contain()}}
{\footnotesize\ttfamily template$<$typename T $>$ \\
bool \mbox{\hyperlink{classList}{List}}$<$ T $>$\+::contain (\begin{DoxyParamCaption}\item[{const T \&}]{element }\end{DoxyParamCaption}) const}

\begin{DoxyReturn}{Returns}
Whether the element is contained in the current \mbox{\hyperlink{classList}{List}}
\end{DoxyReturn}
\begin{DoxyWarning}{Warning}
Function depends on \mbox{\hyperlink{classList_a3804f03273ef5e339b504e439c5b6534}{find\+Index()}}, which means the same \char`\"{}compare\char`\"{} function must be defined in the type 
\end{DoxyWarning}
\begin{DoxySeeAlso}{See also}
\mbox{\hyperlink{classList_a3804f03273ef5e339b504e439c5b6534}{find\+Index()}} 
\end{DoxySeeAlso}
\mbox{\Hypertarget{classList_a3804f03273ef5e339b504e439c5b6534}\label{classList_a3804f03273ef5e339b504e439c5b6534}} 
\index{List$<$ T $>$@{List$<$ T $>$}!findIndex@{findIndex}}
\index{findIndex@{findIndex}!List$<$ T $>$@{List$<$ T $>$}}
\doxysubsubsection{\texorpdfstring{findIndex()}{findIndex()}}
{\footnotesize\ttfamily template$<$typename T $>$ \\
unsigned \mbox{\hyperlink{classList}{List}}$<$ T $>$\+::find\+Index (\begin{DoxyParamCaption}\item[{const T \&}]{element }\end{DoxyParamCaption}) const}



Finds the index of element. 

\begin{DoxyReturn}{Returns}
Index of element. If element isn\textquotesingle{}t found, returns the count of element.
\end{DoxyReturn}
\begin{DoxyWarning}{Warning}
The function depends on the type having a function \char`\"{}compare\char`\"{} defined, which takes two elements and returns a number \texorpdfstring{$<$}{<}0 if elem1 \texorpdfstring{$<$}{<} elem2, \texorpdfstring{$>$}{>}0 if elem1 \texorpdfstring{$>$}{>} elem2, 0 if elem1 == elem2 
\end{DoxyWarning}
\begin{DoxyNote}{Note}
Searching is done linearly 
\end{DoxyNote}
\mbox{\Hypertarget{classList_a3c1e3a3fc085f5b7ae68514c4758687b}\label{classList_a3c1e3a3fc085f5b7ae68514c4758687b}} 
\index{List$<$ T $>$@{List$<$ T $>$}!get\_count@{get\_count}}
\index{get\_count@{get\_count}!List$<$ T $>$@{List$<$ T $>$}}
\doxysubsubsection{\texorpdfstring{get\_count()}{get\_count()}}
{\footnotesize\ttfamily template$<$typename T $>$ \\
unsigned \mbox{\hyperlink{classList}{List}}$<$ T $>$\+::get\+\_\+count}



Returns the count. 

Count is the amount of elements that are stored. \mbox{\Hypertarget{classList_aa32109b77dccd8241b125ebabdda876c}\label{classList_aa32109b77dccd8241b125ebabdda876c}} 
\index{List$<$ T $>$@{List$<$ T $>$}!get\_length@{get\_length}}
\index{get\_length@{get\_length}!List$<$ T $>$@{List$<$ T $>$}}
\doxysubsubsection{\texorpdfstring{get\_length()}{get\_length()}}
{\footnotesize\ttfamily template$<$typename T $>$ \\
unsigned \mbox{\hyperlink{classList}{List}}$<$ T $>$\+::get\+\_\+length}



Returns the length. 

Length is the size of the underlying array (allocated memory). \mbox{\Hypertarget{classList_ae4586debf72af33bccb3c2fbfce420e8}\label{classList_ae4586debf72af33bccb3c2fbfce420e8}} 
\index{List$<$ T $>$@{List$<$ T $>$}!insertAt@{insertAt}}
\index{insertAt@{insertAt}!List$<$ T $>$@{List$<$ T $>$}}
\doxysubsubsection{\texorpdfstring{insertAt()}{insertAt()}}
{\footnotesize\ttfamily template$<$typename T $>$ \\
void \mbox{\hyperlink{classList}{List}}$<$ T $>$\+::insert\+At (\begin{DoxyParamCaption}\item[{const T \&}]{element,  }\item[{unsigned}]{index }\end{DoxyParamCaption})}



Inserts element at given index. 

If index is after the last element, the element is just added. Otherwise all elements after the index are shifted right and element is put in place.

Resizes internal array if there is no space for additional elements. \mbox{\Hypertarget{classList_a5e3581ee07649f462aa8bb3221a5466e}\label{classList_a5e3581ee07649f462aa8bb3221a5466e}} 
\index{List$<$ T $>$@{List$<$ T $>$}!read@{read}}
\index{read@{read}!List$<$ T $>$@{List$<$ T $>$}}
\doxysubsubsection{\texorpdfstring{read()}{read()}}
{\footnotesize\ttfamily template$<$typename T $>$ \\
std\+::istream \& \mbox{\hyperlink{classList}{List}}$<$ T $>$\+::read (\begin{DoxyParamCaption}\item[{std\+::istream \&}]{istr }\end{DoxyParamCaption})}



Reads from stream. 


\begin{DoxyParams}{Parameters}
{\em istr} & An input stream\\
\hline
\end{DoxyParams}
Directly reads bytes from stream (calls \mbox{\hyperlink{classList_a5e3581ee07649f462aa8bb3221a5466e}{read()}} function). Any stored values are deleted and replaced with those from the stream.

\begin{DoxyWarning}{Warning}
The function depends on the type having a function \char`\"{}read\char`\"{} defined, which takes an std\+::istream\& and writes it\textquotesingle{}s data to it. Return type doesn\textquotesingle{}t matter. 
\end{DoxyWarning}
\begin{DoxyRemark}{Remarks}
Doesn\textquotesingle{}t alter the stream in any other way. 
\end{DoxyRemark}
\begin{DoxyNote}{Note}
Best used with binary ifstream 
\end{DoxyNote}
\mbox{\Hypertarget{classList_ad9c0a5b5bca6286f458d6fab280de65a}\label{classList_ad9c0a5b5bca6286f458d6fab280de65a}} 
\index{List$<$ T $>$@{List$<$ T $>$}!removeAt@{removeAt}}
\index{removeAt@{removeAt}!List$<$ T $>$@{List$<$ T $>$}}
\doxysubsubsection{\texorpdfstring{removeAt()}{removeAt()}}
{\footnotesize\ttfamily template$<$typename T $>$ \\
bool \mbox{\hyperlink{classList}{List}}$<$ T $>$\+::remove\+At (\begin{DoxyParamCaption}\item[{unsigned}]{index }\end{DoxyParamCaption})}



Removes element at index. 

\begin{DoxyReturn}{Returns}
Wether element could be removed
\end{DoxyReturn}
If index is after that of the last element, nothing is done and false is returned. Otherwise elements after index are shifted right and count is reduced. \mbox{\Hypertarget{classList_a8d2babffd2fb4a5e0a40dbd306e19956}\label{classList_a8d2babffd2fb4a5e0a40dbd306e19956}} 
\index{List$<$ T $>$@{List$<$ T $>$}!write@{write}}
\index{write@{write}!List$<$ T $>$@{List$<$ T $>$}}
\doxysubsubsection{\texorpdfstring{write()}{write()}}
{\footnotesize\ttfamily template$<$typename T $>$ \\
std\+::ostream \& \mbox{\hyperlink{classList}{List}}$<$ T $>$\+::write (\begin{DoxyParamCaption}\item[{std\+::ostream \&}]{ostr }\end{DoxyParamCaption}) const}



Writes to stream. 


\begin{DoxyParams}{Parameters}
{\em ostr} & An output stream\\
\hline
\end{DoxyParams}
Directly writes bytes to stream (calls \mbox{\hyperlink{classList_a8d2babffd2fb4a5e0a40dbd306e19956}{write()}} function).

\begin{DoxyWarning}{Warning}
The function depends on the type having a function \char`\"{}write\char`\"{} defined, which takes an std\+::ostream\& and writes it\textquotesingle{}s data to it. Return type doesn\textquotesingle{}t matter. 
\end{DoxyWarning}
\begin{DoxyRemark}{Remarks}
Doesn\textquotesingle{}t alter the stream in any other way. 
\end{DoxyRemark}
\begin{DoxyNote}{Note}
Best used with binary ofstream 
\end{DoxyNote}


The documentation for this class was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
src/\+Generic/\+List/\mbox{\hyperlink{List_8hpp}{List.\+hpp}}\end{DoxyCompactItemize}