1
0
mirror of https://gitlab.com/rnger/amath synced 2025-10-06 02:49:59 +00:00
Files
amath/doc/man/man3/VariableList.3
2017-01-24 22:03:15 +01:00

368 lines
7.8 KiB
Groff

.TH "VariableList" 3 "Tue Jan 24 2017" "Version 1.6.2" "amath" \" -*- nroff -*-
.ad l
.nh
.SH NAME
VariableList \- A list of user defined variables\&.
.SH SYNOPSIS
.br
.PP
.PP
\fC#include <values\&.h>\fP
.SS "Public Member Functions"
.in +1c
.ti -1c
.RI "\fBVariableList\fP ()"
.br
.ti -1c
.RI "\fB~VariableList\fP ()"
.br
.ti -1c
.RI "void \fBClear\fP ()"
.br
.ti -1c
.RI "\fBbool\fP \fBDelete\fP (const char *name)"
.br
.ti -1c
.RI "\fBVariable\fP * \fBGetFirstVariable\fP ()"
.br
.ti -1c
.RI "\fBVariable\fP * \fBGetVariable\fP (const char *name)"
.br
.ti -1c
.RI "\fBVariable\fP * \fBCreateVariable\fP (const char *name)"
.br
.ti -1c
.RI "\fBVariable\fP * \fBInsertTemporaryVariable\fP (\fBVariable\fP *variable)"
.br
.ti -1c
.RI "void \fBRemoveTemporaryVariable\fP ()"
.br
.ti -1c
.RI "char * \fBList\fP ()"
.br
.ti -1c
.RI "char * \fBListDefinitions\fP ()"
.br
.in -1c
.SS "Private Member Functions"
.in +1c
.ti -1c
.RI "char * \fBListContent\fP (\fBbool\fP cmdFormat)"
.br
.in -1c
.SS "Private Attributes"
.in +1c
.ti -1c
.RI "\fBCharBuffer\fP * \fBbuf\fP"
.br
.ti -1c
.RI "\fBVariable\fP * \fBfirst\fP"
.br
.in -1c
.SH "Detailed Description"
.PP
A list of user defined variables\&.
.PP
Definition at line 46 of file values\&.h\&.
.SH "Constructor & Destructor Documentation"
.PP
.SS "VariableList::VariableList ()"
.PP
Definition at line 86 of file values\&.cpp\&.
.PP
References buf, CharBuffer::CharBuffer(), and first\&.
.PP
Referenced by Program::Program()\&.
.PP
.nf
87 {
88 first = NOMEM;
89 buf = new CharBuffer();
90 }
.fi
.SS "VariableList::~VariableList ()"
.PP
Definition at line 92 of file values\&.cpp\&.
.PP
References buf, and first\&.
.PP
.nf
93 {
94 if (first != NOMEM) {
95 delete first;
96 }
97
98 delete buf;
99 }
.fi
.SH "Member Function Documentation"
.PP
.SS "void VariableList::Clear ()"
.PP
Definition at line 101 of file values\&.cpp\&.
.PP
References buf, CharBuffer::ClearBuffer(), and first\&.
.PP
Referenced by DeleteStatement::Execute()\&.
.PP
.nf
102 {
103 if (first != NOMEM) {
104 delete first;
105 first = NOMEM;
106 }
107
108 buf->ClearBuffer();
109 }
.fi
.SS "\fBVariable\fP * VariableList::CreateVariable (const char * name)"
.PP
Definition at line 159 of file values\&.cpp\&.
.PP
References first, Variable::GetName(), Variable::Next, StrIsEqual(), and Variable::Variable()\&.
.PP
Referenced by Parser::ParseIdent()\&.
.PP
.nf
160 {
161 if (first == NOMEM) {
162 first = new Variable(name);
163 return first;
164 }
165
166 Variable* current = first;
167 Variable* last = NOMEM;
168
169 while (current != NOMEM) {
170 if (StrIsEqual(name, current->GetName())) {
171 return current;
172 }
173
174 last = current;
175 current = current->Next;
176 }
177
178 current = new Variable(name);
179 last->Next = current;
180
181 return current;
182 }
.fi
.SS "\fBbool\fP VariableList::Delete (const char * name)"
.PP
Definition at line 111 of file values\&.cpp\&.
.PP
References Variable::chainDelete, first, GetVariable(), and Variable::Next\&.
.PP
Referenced by DeleteStatement::Execute()\&.
.PP
.nf
112 {
113 Variable* var = GetVariable(name);
114
115 if (var == NOMEM) {
116 return false;
117 }
118
119 if (var == first) {
120 first = var->Next;
121 var->chainDelete = false;
122 delete var;
123 return true;
124 }
125
126 Variable *current = first->Next;
127 Variable *last = first;
128
129 while (current != var) {
130 current = current->Next;
131 last = last->Next;
132 }
133
134 last->Next = var->Next;
135
136 // Only delete this variable\&. Not the whole chain\&.
137 var->chainDelete = false;
138 delete var;
139
140 return true;
141 }
.fi
.SS "\fBVariable\fP * VariableList::GetFirstVariable ()"
.PP
Definition at line 143 of file values\&.cpp\&.
.PP
References first\&.
.PP
Referenced by ListContent()\&.
.PP
.nf
144 {
145 return first;
146 }
.fi
.SS "\fBVariable\fP * VariableList::GetVariable (const char * name)"
.PP
Definition at line 148 of file values\&.cpp\&.
.PP
References first, Variable::GetName(), Variable::Next, and StrIsEqual()\&.
.PP
Referenced by Delete(), and Parser::ParseIdent()\&.
.PP
.nf
149 {
150 Variable* current = first;
151
152 while (current != NOMEM && !StrIsEqual(current->GetName(), name)) {
153 current = current->Next;
154 }
155
156 return current;
157 }
.fi
.SS "\fBVariable\fP * VariableList::InsertTemporaryVariable (\fBVariable\fP * variable)"
.PP
Definition at line 184 of file values\&.cpp\&.
.PP
References first, and Variable::Next\&.
.PP
Referenced by Parser::ParseFunctionDef()\&.
.PP
.nf
185 {
186 // Temporary variables are always inserted at the beginning of the list\&.
187 Variable* oldFirst = first;
188 first = variable;
189 variable->Next = oldFirst;
190
191 return variable;
192 }
.fi
.SS "char * VariableList::List ()"
.PP
Definition at line 202 of file values\&.cpp\&.
.PP
References ListContent()\&.
.PP
Referenced by ListVariablesStatement::Execute()\&.
.PP
.nf
203 {
204 return ListContent(false);
205 }
.fi
.SS "char * VariableList::ListContent (\fBbool\fP cmdFormat)\fC [private]\fP"
.PP
Definition at line 212 of file values\&.cpp\&.
.PP
References CharBuffer::Append(), buf, CharBuffer::Empty(), CharBuffer::EnsureSize(), GetFirstVariable(), Variable::GetName(), CharBuffer::GetString(), NumeralSystem::GetText(), Variable::GetValue(), Variable::Next, Program::Output, and StrLen()\&.
.PP
Referenced by List(), and ListDefinitions()\&.
.PP
.nf
213 {
214 buf->Empty();
215
216 if (GetFirstVariable() == NOMEM) {
217 return (char*)(cmdFormat ? NOMEM : HELPVARSNDEF);
218 }
219
220 int len = 0;
221 Variable* current = GetFirstVariable();
222
223 while (current != NOMEM) {
224 len += StrLen(current->GetName());
225 len += 3;
226 len += 32; // Max length of value
227 len += cmdFormat ? 2 : 1;
228 current = current->Next;
229 }
230
231 current = GetFirstVariable();
232
233 buf->EnsureSize(len);
234
235 while (current != NOMEM) {
236 buf->Append(current->GetName());
237 buf->Append(" = ");
238
239 Number *num = current->GetValue();
240 const char *val = Program->Output->GetText(num);
241 buf->Append(val);
242 delete num;
243
244 if (cmdFormat) {
245 buf->Append(';');
246 }
247
248 buf->Append(NEWLINE);
249 current = current->Next;
250 }
251
252 return buf->GetString();
253 }
.fi
.SS "char * VariableList::ListDefinitions ()"
.PP
Definition at line 207 of file values\&.cpp\&.
.PP
References ListContent()\&.
.PP
Referenced by SaveStatement::Execute()\&.
.PP
.nf
208 {
209 return ListContent(true);
210 }
.fi
.SS "void VariableList::RemoveTemporaryVariable ()"
.PP
Definition at line 194 of file values\&.cpp\&.
.PP
References first, and Variable::Next\&.
.PP
Referenced by Parser::ParseFunctionDef()\&.
.PP
.nf
195 {
196 // Temporary variables are not owned by the variable list\&. Do not free memory\&.
197 Variable *newFirst = first->Next;
198 first->Next = NOMEM;
199 first = newFirst;
200 }
.fi
.SH "Member Data Documentation"
.PP
.SS "\fBCharBuffer\fP* VariableList::buf\fC [private]\fP"
.PP
Definition at line 64 of file values\&.h\&.
.PP
Referenced by Clear(), ListContent(), VariableList(), and ~VariableList()\&.
.SS "\fBVariable\fP* VariableList::first\fC [private]\fP"
.PP
Definition at line 65 of file values\&.h\&.
.PP
Referenced by Clear(), CreateVariable(), Delete(), GetFirstVariable(), GetVariable(), InsertTemporaryVariable(), RemoveTemporaryVariable(), VariableList(), and ~VariableList()\&.
.SH "Author"
.PP
Generated automatically by Doxygen for amath from the source code\&.