]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/expr.tex
2nd attempt at MDI in wxMotif, using wxNotebook this time (still some probs).
[wxWidgets.git] / docs / latex / wx / expr.tex
... / ...
CommitLineData
1\section{\class{wxExpr}}\label{wxexpr}
2
3The {\bf wxExpr} class is the building brick of expressions similar to Prolog
4clauses, or objects. It can represent an expression of type long integer, float, string, word,
5or list, and lists can be nested.
6
7\wxheading{Derived from}
8
9None
10
11\wxheading{See also}
12
13\helpref{wxExpr overview}{exproverview}, \helpref{wxExprDatabase}{wxexprdatabase}
14
15\latexignore{\rtfignore{\wxheading{Members}}}
16
17\membersection{wxExpr::wxExpr}\label{wxexprconstr}
18
19\func{}{wxExpr}{\param{const wxString\&}{functor}}
20
21Construct a new clause with this form, supplying the functor name. A clause is an object
22that will appear in the data file, with a list of attribute/value pairs.
23
24\func{}{wxExpr}{\param{wxExprType}{ type}, \param{const wxString\&}{ wordOrString = ``"}}
25
26Construct a new empty list, or a word (will be output with no quotes), or a string, depending on the
27value of {\it type}.
28
29{\it type} can be {\bf wxExprList}, {\bf wxExprWord}, or {\bf wxExprString}. If {\it type} is wxExprList,
30the value of {\it wordOrString} will be ignored.
31
32\func{}{wxExpr}{\param{long}{ value}}
33
34Construct an integer expression.
35
36\func{}{wxExpr}{\param{float}{ value}}
37
38Construct a floating point expression.
39
40\func{}{wxExpr}{\param{wxList* }{value}}
41
42Construct a list expression. The list's nodes' data should
43themselves be {\bf wxExpr}s.
44
45The current version of this library no longer uses the {\bf wxList}
46internally, so this constructor turns the list into its internal
47format (assuming a non-nested list) and then deletes the supplied
48list.
49
50\membersection{wxExpr::\destruct{wxExpr}}
51
52\func{}{\destruct{wxExpr}}{\void}
53
54Destructor.
55
56\membersection{wxExpr::AddAttributeValue}\label{wxexpraddattributevalue}
57
58Use these on clauses ONLY. Note that the functions for adding strings
59and words must be differentiated by function name which is why
60they are missing from this group (see \helpref{wxExpr::AddAttributeValueString}{wxexpraddattributevaluestring} and
61\rtfsp\helpref{wxExpr::AddAttributeValueWord}{wxexpraddattributevalueword}).
62
63\func{void}{AddAttributeValue}{\param{const wxString\&}{ attribute}, \param{float }{value}}
64
65Adds an attribute and floating point value pair to the clause.
66
67\func{void}{AddAttributeValue}{\param{const wxString\&}{ attribute}, \param{long }{value}}
68
69Adds an attribute and long integer value pair to the clause.
70
71\func{void}{AddAttributeValue}{\param{const wxString\&}{ attribute}, \param{wxList* }{value}}
72
73Adds an attribute and list value pair to the clause, converting the list into
74internal form and then deleting {\bf value}. Note that the list should not contain
75nested lists (except if in internal {\bf wxExpr} form.)
76
77\func{void}{AddAttributeValue}{\param{const wxString\&}{ attribute}, \param{wxExpr* }{value}}
78
79Adds an attribute and wxExpr value pair to the clause. Do not delete\rtfsp
80{\it value} once this function has been called.
81
82\membersection{wxExpr::AddAttributeValueString}\label{wxexpraddattributevaluestring}
83
84\func{void}{AddAttributeValueString}{\param{const wxString\&}{ attribute}, \param{const wxString\&}{ value}}
85
86Adds an attribute and string value pair to the clause.
87
88\membersection{wxExpr::AddAttributeValueStringList}\label{wxexpraddattributevaluestringlist}
89
90\func{void}{AddAttributeValueStringList}{\param{const wxString\&}{ attribute}, \param{wxList* }{value}}
91
92Adds an attribute and string list value pair to the clause.
93
94Note that the list passed to this function is a list of strings, NOT a list
95of {\bf wxExpr}s; it gets turned into a list of {\bf wxExpr}s
96automatically. This is a convenience function, since lists of strings
97are often manipulated in C++.
98
99\membersection{wxExpr::AddAttributeValueWord}\label{wxexpraddattributevalueword}
100
101\func{void}{AddAttributeValueWord}{\param{const wxString\&}{ attribute}, \param{const wxString\&}{ value}}
102
103Adds an attribute and word value pair to the clause.
104
105\membersection{wxExpr::Append}\label{wxexprappend}
106
107\func{void}{Append}{\param{wxExpr*}{ value}}
108
109Append the {\bf value} to the end of the list. `this' must be a list.
110
111\membersection{wxExpr::Arg}\label{wxexprarg}
112
113\constfunc{wxExpr* }{Arg}{\param{wxExprType}{ type}, \param{int}{ n}}
114
115Get nth arg of the given clause (starting from 1). NULL is returned if
116the expression is not a clause, or {\it n} is invalid, or the given type
117does not match the actual type. See also \helpref{wxExpr::Nth}{wxexprnth}.
118
119\membersection{wxExpr::Insert}\label{wxexprinsert}
120
121\func{void}{Insert}{\param{wxExpr* }{value}}
122
123Insert the {\bf value} at the start of the list. `this' must be a list.
124
125\membersection{wxExpr::GetAttributeValue}\label{wxexprgetattributevalue}
126
127These functions are the easiest way to retrieve attribute values, by
128passing a pointer to variable. If the attribute is present, the
129variable will be filled with the appropriate value. If not, the
130existing value is left alone. This style of retrieving attributes
131makes it easy to set variables to default values before calling these
132functions; no code is necessary to check whether the attribute is
133present or not.
134
135\constfunc{bool}{GetAttributeValue}{\param{const wxString\&}{ attribute}, \param{wxString\&}{ value}}
136
137Retrieve a string (or word) value.
138
139\constfunc{bool}{GetAttributeValue}{\param{const wxString\&}{ attribute}, \param{float\& }{value}}
140
141Retrieve a floating point value.
142
143\constfunc{bool}{GetAttributeValue}{\param{const wxString\&}{ attribute}, \param{int\& }{value}}
144
145Retrieve an integer value.
146
147\constfunc{bool}{GetAttributeValue}{\param{const wxString\&}{ attribute}, \param{long\& }{value}}
148
149Retrieve a long integer value.
150
151\constfunc{bool}{GetAttributeValue}{\param{const wxString\&}{ attribute}, \param{wxExpr**}{ value}}
152
153Retrieve a wxExpr pointer.
154
155\membersection{wxExpr::GetAttributeValueStringList}\label{wxexprgetattributestringlist}
156
157\constfunc{void}{GetAttributeValueStringList}{\param{const wxString\&}{attribute}, \param{wxList* }{value}}
158
159Use this on clauses ONLY. See above for comments on this style of
160attribute value retrieval. This function expects to receive a pointer to
161a new list (created by the calling application); it will append strings
162to the list if the attribute is present in the clause.
163
164\membersection{wxExpr::AttributeValue}\label{wxexprattributevalue}
165
166\constfunc{wxExpr*}{AttributeValue}{\param{const wxString\&}{ word}}
167
168Use this on clauses ONLY. Searches the clause for an attribute
169matching {\it word}, and returns the value associated with it.
170
171\membersection{wxExpr::Copy}\label{wxexprcopy}
172
173\constfunc{wxExpr*}{Copy}{\void}
174
175Recursively copies the expression, allocating new storage space.
176
177\membersection{wxExpr::DeleteAttributeValue}\label{wxexprdeletattributevalue}
178
179\func{void}{DeleteAttributeValue}{\param{const wxString\&}{ attribute}}
180
181Use this on clauses only. Deletes the attribute and its value (if any) from the
182clause.
183
184\membersection{wxExpr::Functor}\label{wxexprfunctor}
185
186\constfunc{wxString}{Functor}{\void}
187
188Use this on clauses only. Returns the clause's functor (object name).
189
190\membersection{wxExpr::GetClientData}\label{wxexprgetclientdata}
191
192\constfunc{wxObject*}{GetClientData}{\void}
193
194Retrieve arbitrary data stored with this clause. This can be useful when
195reading in data for storing a pointer to the C++ object, so when another
196clause makes a reference to this clause, its C++ object can be retrieved.
197See \helpref{wxExpr::SetClientData}{wxexprsetclientdata}.
198
199\membersection{wxExpr::GetFirst}\label{wxexprgetfirst}
200
201\constfunc{wxExpr*}{GetFirst}{\void}
202
203If this is a list expression (or clause), gets the first element in the list.
204
205See also \helpref{wxExpr::GetLast}{wxexprgetlast}, \helpref{wxExpr::GetNext}{wxexprgetnext}, \helpref{wxExpr::Nth}{wxexprnth}.
206
207\membersection{wxExpr::GetLast}\label{wxexprgetlast}
208
209\constfunc{wxExpr*}{GetLast}{\void}
210
211If this is a list expression (or clause), gets the last element in the list.
212
213See also \helpref{wxExpr::GetFirst}{wxexprgetfirst}, \helpref{wxExpr::GetNext}{wxexprgetnext}, \helpref{wxExpr::Nth}{wxexprnth}.
214
215\membersection{wxExpr::GetNext}\label{wxexprgetnext}
216
217\constfunc{wxExpr*}{GetNext}{\void}
218
219If this is a node in a list (any wxExpr may be a node in a list), gets the
220next element in the list.
221
222See also \helpref{wxExpr::GetFirst}{wxexprgetfirst}, \helpref{wxExpr::GetLast}{wxexprgetlast}, \helpref{wxExpr::Nth}{wxexprnth}.
223
224\membersection{wxExpr::IntegerValue}\label{wxexprintegervalue}
225
226\constfunc{long}{IntegerValue}{\void}
227
228Returns the integer value of the expression.
229
230\membersection{wxExpr::Nth}\label{wxexprnth}
231
232\constfunc{wxExpr*}{Nth}{\param{int}{ n}}
233
234Get nth arg of the given list expression (starting from 0). NULL is returned if
235the expression is not a list expression, or {\it n} is invalid. See also \helpref{wxExpr::Arg}{wxexprarg}.
236
237Normally, you would use attribute-value pairs to add and retrieve data
238from objects (clauses) in a data file. However, if the data gets complex,
239you may need to store attribute values as lists, and pick them apart
240yourself.
241
242\membersection{wxExpr::RealValue}\label{wxexprrealvalue}
243
244\constfunc{float}{RealValue}{\void}
245
246Returns the floating point value of the expression.
247
248\membersection{wxExpr::SetClientData}\label{wxexprsetclientdata}
249
250\func{void}{SetClientData}{\param{wxObject *}{data}}
251
252Associate arbitrary data with this clause. This can be useful when
253reading in data for storing a pointer to the C++ object, so when another
254clause makes a reference to this clause, its C++ object can be retrieved.
255See \helpref{wxExpr::GetClientData}{wxexprgetclientdata}.
256
257\membersection{wxExpr::StringValue}\label{wxexprstringvalue}
258
259\constfunc{wxString}{StringValue}{\void}
260
261Returns the string value of the expression.
262
263\membersection{wxExpr::Type}\label{wxexprtype}
264
265\constfunc{wxExprType}{Type}{\void}
266
267Returns the type of the expression. {\bf wxExprType} is defined as follows:
268
269\begin{verbatim}
270typedef enum {
271 wxExprNull,
272 wxExprInteger,
273 wxExprReal,
274 wxExprWord,
275 wxExprString,
276 wxExprList
277} wxExprType;
278\end{verbatim}
279
280\membersection{wxExpr::WordValue}\label{wxexprwordvalue}
281
282\constfunc{wxString}{WordValue}{\void}
283
284Returns the word value of the expression.
285
286\membersection{wxExpr::WriteLispExpr}\label{wxexprwritelistexpr}
287
288\func{void}{WriteLispExpr}{\param{ostream\&}{ stream}}
289
290Writes the expression or clause to the given stream in LISP format.
291Not normally needed, since the whole {\bf wxExprDatabase} will usually
292be written at once. Lists are enclosed in parentheses will no commas.
293
294\membersection{wxExpr::WritePrologClause}\label{wxexprwriteprologclause}
295
296\func{void}{WritePrologClause}{\param{ostream\&}{ stream}}
297
298Writes the clause to the given stream in Prolog format. Not normally needed, since
299the whole {\bf wxExprDatabase} will usually be written at once. The format is:
300functor, open parenthesis, list of comma-separated expressions, close parenthesis,
301full stop.
302
303\membersection{wxExpr::WriteExpr}\label{wxexprwriteexpr}
304
305\func{void}{WriteExpr}{\param{ostream\&}{ stream}}
306
307Writes the expression (not clause) to the given stream in Prolog
308format. Not normally needed, since the whole {\bf wxExprDatabase} will
309usually be written at once. Lists are written in square bracketed,
310comma-delimited format.
311
312\membersection{Functions and macros}
313
314Below are miscellaneous functions and macros associated with wxExpr objects.
315
316\func{bool}{wxExprIsFunctor}{\param{wxExpr *}{expr}, \param{const wxString\&}{ functor}}
317
318Checks that the functor of {\it expr} is {\it functor}.
319
320\func{void}{wxExprCleanUp}{\void}
321
322Cleans up the wxExpr system (YACC/LEX buffers) to avoid memory-checking warnings as the program exits.
323
324\begin{verbatim}
325#define wxMakeInteger(x) (new wxExpr((long)x))
326#define wxMakeReal(x) (new wxExpr((float)x))
327#define wxMakeString(x) (new wxExpr(PrologString, x))
328#define wxMakeWord(x) (new wxExpr(PrologWord, x))
329#define wxMake(x) (new wxExpr(x))
330\end{verbatim}
331
332Macros to help make wxExpr objects.
333
334\section{\class{wxExprDatabase}}\label{wxexprdatabase}
335
336The {\bf wxExprDatabase} class represents a database, or list,
337of Prolog-like expressions. Instances of this class are used for reading,
338writing and creating data files.
339
340\wxheading{Derived from}
341
342\helpref{wxList}{wxlist}\\
343\helpref{wxObject}{wxobject}
344
345\wxheading{See also}
346
347\helpref{wxExpr overview}{exproverview}, \helpref{wxExpr}{wxexpr}
348
349\latexignore{\rtfignore{\wxheading{Members}}}
350
351\membersection{wxExprDatabase::wxExprDatabase}\label{wxexprdatabaseconstr}
352
353\func{void}{wxExprDatabase}{\param{proioErrorHandler}{ handler = 0}}
354
355Construct a new, unhashed database, with an optional error handler. The
356error handler must be a function returning a bool and taking an integer and a string
357argument. When an error occurs when reading or writing a database, this function is
358called. The error is given as the first argument (currently one of WXEXPR\_ERROR\_GENERAL,
359WXEXPR\_ERROR\_SYNTAX) and an error message is given as the second argument. If FALSE
360is returned by the error handler, processing of the wxExpr operation stops.
361
362Another way of handling errors is simply to call \helpref{wxExprDatabase::GetErrorCount}{wxexprdatabasegeterrorcount} after
363the operation, to check whether errors have occurred, instead of installing an error handler.
364If the error count is more than zero, \helpref{wxExprDatabase::Write}{wxexprdatabasewrite} and
365\rtfsp\helpref{wxExprDatabase::Read}{wxexprdatabaseread} will return FALSE to
366the application.
367
368For example:
369
370\begin{verbatim}
371bool myErrorHandler(int err, chat *msg)
372{
373 if (err == WXEXPR_ERROR_SYNTAX)
374 {
375 wxMessageBox(msg, "Syntax error");
376 }
377 return FALSE;
378}
379
380wxExprDatabase database(myErrorHandler);
381\end{verbatim}
382
383
384\func{}{wxExprDatabase}{\param{wxExprType}{ type}, \param{const wxString\&}{attribute},
385\rtfsp\param{int}{ size = 500}, \param{proioErrorHandler}{ handler = 0}}
386
387Construct a new database hashed on a combination of the clause functor and
388a named attribute (often an integer identification).
389
390See above for an explanation of the error handler.
391
392\membersection{wxExprDatabase::\destruct{wxExprDatabase}}
393
394\func{}{\destruct{wxExprDatabase}}{\void}
395
396Delete the database and contents.
397
398\membersection{wxExprDatabase::Append}\label{wxexprdatabaseappend}
399
400\func{void}{Append}{\param{wxExpr* }{clause}}
401
402Append a clause to the end of the database. If the database is hashing,
403the functor and a user-specified attribute will be hashed upon, giving the
404option of random access in addition to linear traversal of the database.
405
406\membersection{wxExprDatabase::BeginFind}\label{wxexprdatabasebeginfind}
407
408\func{void}{BeginFind}{\void}
409
410Reset the current position to the start of the database. Subsequent
411\rtfsp\helpref{wxExprDatabase::FindClause}{wxexprdatabasefindclause} calls will move the pointer.
412
413\membersection{wxExprDatabase::ClearDatabase}\label{wxexprdatabasecleardatabase}
414
415\func{void}{ClearDatabase}{\void}
416
417Clears the contents of the database.
418
419\membersection{wxExprDatabase::FindClause}\label{wxexprdatabasefindclause}
420
421Various ways of retrieving clauses from the database. A return
422value of NULL indicates no (more) clauses matching the given criteria.
423Calling the functions repeatedly retrieves more matching clauses, if any.
424
425\func{wxExpr* }{FindClause}{\param{long}{ id}}
426
427Find a clause based on the special ``id'' attribute.
428
429\func{wxExpr* }{FindClause}{\param{const wxString\&}{ attribute}, \param{const wxString\&}{ value}}
430
431Find a clause which has the given attribute set to the given string or word value.
432
433\func{wxExpr*}{FindClause}{\param{const wxString\&}{ attribute}, \param{long}{ value}}
434
435Find a clause which has the given attribute set to the given integer value.
436
437\func{wxExpr*}{FindClause}{\param{const wxString\&}{ attribute}, \param{float}{ value}}
438
439Find a clause which has the given attribute set to the given floating point value.
440
441\membersection{wxExprDatabase::FindClauseByFunctor}\label{wxexprdatabasefindclausebyfunctor}
442
443\func{wxExpr*}{FindClauseByFunctor}{\param{const wxString\&}{ functor}}
444
445Find the next clause with the specified functor.
446
447\membersection{wxExprDatabase::GetErrorCount}\label{wxexprdatabasegeterrorcount}
448
449\constfunc{int}{GetErrorCount}{\void}
450
451Returns the number of errors encountered during the last read or write operation.
452
453\membersection{wxExprDatabase::HashFind}\label{wxexprdatabasehashfind}
454
455\constfunc{wxExpr*}{HashFind}{\param{const wxString\&}{ functor}, \param{long}{ value}}
456
457Finds the clause with the given functor and with the attribute specified
458in the database constructor having the given integer value.
459
460For example,
461
462\begin{verbatim}
463// Hash on a combination of functor and integer "id" attribute when reading in
464wxExprDatabase db(wxExprInteger, "id");
465
466// Read it in
467db.ReadProlog("data");
468
469// Retrieve a clause with specified functor and id
470wxExpr *clause = db.HashFind("node", 24);
471\end{verbatim}
472
473This would retrieve a clause which is written: {\tt node(id = 24, ..., )}.
474
475\func{wxExpr*}{HashFind}{\param{const wxString\&}{ functor}, \param{const wxString\&}{ value}}
476
477Finds the clause with the given functor and with the attribute specified
478in the database constructor having the given string value.
479
480\membersection{wxExprDatabase::Read}\label{wxexprdatabaseread}
481
482\func{bool}{Read}{\param{const wxString\&}{ filename}}
483
484Reads in the given file, returning TRUE if successful.
485
486\membersection{wxExprDatabase::ReadFromString}\label{wxexprdatabasereadfromstring}
487
488\func{bool}{ReadFromString}{\param{const wxString\&}{ buffer}}
489
490Reads a Prolog database from the given string buffer, returning TRUE if
491successful.
492
493\membersection{wxExprDatabase::WriteLisp}\label{wxexprdatabasewritelisp}
494
495\func{bool}{WriteLisp}{\param{ostream\& }{stream}}
496
497Writes the database as a LISP-format file.
498
499\membersection{wxExprDatabase::Write}\label{wxexprdatabasewrite}
500
501\func{bool}{Write}{\param{ostream\& }{stream}}
502
503Writes the database as a Prolog-format file.
504
505