1 \section{\class{wxExpr
}}\label{wxexpr
}
3 The
{\bf wxExpr
} class is the building brick of expressions similar to Prolog
4 clauses, or objects. It can represent an expression of type long integer, float, string, word,
5 or list, and lists can be nested.
7 \wxheading{Derived from
}
13 \helpref{wxExpr overview
}{exproverview
},
\helpref{wxExprDatabase
}{wxexprdatabase
}
15 \latexignore{\rtfignore{\wxheading{Members
}}}
17 \membersection{wxExpr::wxExpr
}\label{wxexprconstr
}
19 \func{}{wxExpr
}{\param{const wxString\&
}{functor
}}
21 Construct a new clause with this form, supplying the functor name. A clause is an object
22 that will appear in the data file, with a list of attribute/value pairs.
24 \func{}{wxExpr
}{\param{wxExprType
}{ type
},
\param{const wxString\&
}{ wordOrString = ``"
}}
26 Construct a new empty list, or a word (will be output with no quotes), or a string, depending on the
29 {\it type
} can be
{\bf wxExprList
},
{\bf wxExprWord
}, or
{\bf wxExprString
}. If
{\it type
} is wxExprList,
30 the value of
{\it wordOrString
} will be ignored.
32 \func{}{wxExpr
}{\param{long
}{ value
}}
34 Construct an integer expression.
36 \func{}{wxExpr
}{\param{float
}{ value
}}
38 Construct a floating point expression.
40 \func{}{wxExpr
}{\param{wxList*
}{value
}}
42 Construct a list expression. The list's nodes' data should
43 themselves be
{\bf wxExpr
}s.
45 The current version of this library no longer uses the
{\bf wxList
}
46 internally, so this constructor turns the list into its internal
47 format (assuming a non-nested list) and then deletes the supplied
50 \membersection{wxExpr::
\destruct{wxExpr
}}
52 \func{}{\destruct{wxExpr
}}{\void}
56 \membersection{wxExpr::AddAttributeValue
}\label{wxexpraddattributevalue
}
58 Use these on clauses ONLY. Note that the functions for adding strings
59 and words must be differentiated by function name which is why
60 they are missing from this group (see
\helpref{wxExpr::AddAttributeValueString
}{wxexpraddattributevaluestring
} and
61 \rtfsp\helpref{wxExpr::AddAttributeValueWord
}{wxexpraddattributevalueword
}).
63 \func{void
}{AddAttributeValue
}{\param{const wxString\&
}{ attribute
},
\param{float
}{value
}}
65 Adds an attribute and floating point value pair to the clause.
67 \func{void
}{AddAttributeValue
}{\param{const wxString\&
}{ attribute
},
\param{long
}{value
}}
69 Adds an attribute and long integer value pair to the clause.
71 \func{void
}{AddAttributeValue
}{\param{const wxString\&
}{ attribute
},
\param{wxList*
}{value
}}
73 Adds an attribute and list value pair to the clause, converting the list into
74 internal form and then deleting
{\bf value
}. Note that the list should not contain
75 nested lists (except if in internal
{\bf wxExpr
} form.)
77 \func{void
}{AddAttributeValue
}{\param{const wxString\&
}{ attribute
},
\param{wxExpr*
}{value
}}
79 Adds an attribute and wxExpr value pair to the clause. Do not delete
\rtfsp
80 {\it value
} once this function has been called.
82 \membersection{wxExpr::AddAttributeValueString
}\label{wxexpraddattributevaluestring
}
84 \func{void
}{AddAttributeValueString
}{\param{const wxString\&
}{ attribute
},
\param{const wxString\&
}{ value
}}
86 Adds an attribute and string value pair to the clause.
88 \membersection{wxExpr::AddAttributeValueStringList
}\label{wxexpraddattributevaluestringlist
}
90 \func{void
}{AddAttributeValueStringList
}{\param{const wxString\&
}{ attribute
},
\param{wxList*
}{value
}}
92 Adds an attribute and string list value pair to the clause.
94 Note that the list passed to this function is a list of strings, NOT a list
95 of
{\bf wxExpr
}s; it gets turned into a list of
{\bf wxExpr
}s
96 automatically. This is a convenience function, since lists of strings
97 are often manipulated in C++.
99 \membersection{wxExpr::AddAttributeValueWord
}\label{wxexpraddattributevalueword
}
101 \func{void
}{AddAttributeValueWord
}{\param{const wxString\&
}{ attribute
},
\param{const wxString\&
}{ value
}}
103 Adds an attribute and word value pair to the clause.
105 \membersection{wxExpr::Append
}\label{wxexprappend
}
107 \func{void
}{Append
}{\param{wxExpr*
}{ value
}}
109 Append the
{\bf value
} to the end of the list. `this' must be a list.
111 \membersection{wxExpr::Arg
}\label{wxexprarg
}
113 \constfunc{wxExpr*
}{Arg
}{\param{wxExprType
}{ type
},
\param{int
}{ n
}}
115 Get nth arg of the given clause (starting from
1). NULL is returned if
116 the expression is not a clause, or
{\it n
} is invalid, or the given type
117 does not match the actual type. See also
\helpref{wxExpr::Nth
}{wxexprnth
}.
119 \membersection{wxExpr::Insert
}\label{wxexprinsert
}
121 \func{void
}{Insert
}{\param{wxExpr*
}{value
}}
123 Insert the
{\bf value
} at the start of the list. `this' must be a list.
125 \membersection{wxExpr::GetAttributeValue
}\label{wxexprgetattributevalue
}
127 These functions are the easiest way to retrieve attribute values, by
128 passing a pointer to variable. If the attribute is present, the
129 variable will be filled with the appropriate value. If not, the
130 existing value is left alone. This style of retrieving attributes
131 makes it easy to set variables to default values before calling these
132 functions; no code is necessary to check whether the attribute is
135 \constfunc{bool
}{GetAttributeValue
}{\param{const wxString\&
}{ attribute
},
\param{wxString\&
}{ value
}}
137 Retrieve a string (or word) value.
139 \constfunc{bool
}{GetAttributeValue
}{\param{const wxString\&
}{ attribute
},
\param{float\&
}{value
}}
141 Retrieve a floating point value.
143 \constfunc{bool
}{GetAttributeValue
}{\param{const wxString\&
}{ attribute
},
\param{int\&
}{value
}}
145 Retrieve an integer value.
147 \constfunc{bool
}{GetAttributeValue
}{\param{const wxString\&
}{ attribute
},
\param{long\&
}{value
}}
149 Retrieve a long integer value.
151 \constfunc{bool
}{GetAttributeValue
}{\param{const wxString\&
}{ attribute
},
\param{wxExpr**
}{ value
}}
153 Retrieve a wxExpr pointer.
155 \membersection{wxExpr::GetAttributeValueStringList
}\label{wxexprgetattributestringlist
}
157 \constfunc{void
}{GetAttributeValueStringList
}{\param{const wxString\&
}{attribute
},
\param{wxList*
}{value
}}
159 Use this on clauses ONLY. See above for comments on this style of
160 attribute value retrieval. This function expects to receive a pointer to
161 a new list (created by the calling application); it will append strings
162 to the list if the attribute is present in the clause.
164 \membersection{wxExpr::AttributeValue
}\label{wxexprattributevalue
}
166 \constfunc{wxExpr*
}{AttributeValue
}{\param{const wxString\&
}{ word
}}
168 Use this on clauses ONLY. Searches the clause for an attribute
169 matching
{\it word
}, and returns the value associated with it.
171 \membersection{wxExpr::Copy
}\label{wxexprcopy
}
173 \constfunc{wxExpr*
}{Copy
}{\void}
175 Recursively copies the expression, allocating new storage space.
177 \membersection{wxExpr::DeleteAttributeValue
}\label{wxexprdeletattributevalue
}
179 \func{void
}{DeleteAttributeValue
}{\param{const wxString\&
}{ attribute
}}
181 Use this on clauses only. Deletes the attribute and its value (if any) from the
184 \membersection{wxExpr::Functor
}\label{wxexprfunctor
}
186 \constfunc{wxString
}{Functor
}{\void}
188 Use this on clauses only. Returns the clause's functor (object name).
190 \membersection{wxExpr::GetClientData
}\label{wxexprgetclientdata
}
192 \constfunc{wxObject*
}{GetClientData
}{\void}
194 Retrieve arbitrary data stored with this clause. This can be useful when
195 reading in data for storing a pointer to the C++ object, so when another
196 clause makes a reference to this clause, its C++ object can be retrieved.
197 See
\helpref{wxExpr::SetClientData
}{wxexprsetclientdata
}.
199 \membersection{wxExpr::GetFirst
}\label{wxexprgetfirst
}
201 \constfunc{wxExpr*
}{GetFirst
}{\void}
203 If this is a list expression (or clause), gets the first element in the list.
205 See also
\helpref{wxExpr::GetLast
}{wxexprgetlast
},
\helpref{wxExpr::GetNext
}{wxexprgetnext
},
\helpref{wxExpr::Nth
}{wxexprnth
}.
207 \membersection{wxExpr::GetLast
}\label{wxexprgetlast
}
209 \constfunc{wxExpr*
}{GetLast
}{\void}
211 If this is a list expression (or clause), gets the last element in the list.
213 See also
\helpref{wxExpr::GetFirst
}{wxexprgetfirst
},
\helpref{wxExpr::GetNext
}{wxexprgetnext
},
\helpref{wxExpr::Nth
}{wxexprnth
}.
215 \membersection{wxExpr::GetNext
}\label{wxexprgetnext
}
217 \constfunc{wxExpr*
}{GetNext
}{\void}
219 If this is a node in a list (any wxExpr may be a node in a list), gets the
220 next element in the list.
222 See also
\helpref{wxExpr::GetFirst
}{wxexprgetfirst
},
\helpref{wxExpr::GetLast
}{wxexprgetlast
},
\helpref{wxExpr::Nth
}{wxexprnth
}.
224 \membersection{wxExpr::IntegerValue
}\label{wxexprintegervalue
}
226 \constfunc{long
}{IntegerValue
}{\void}
228 Returns the integer value of the expression.
230 \membersection{wxExpr::Nth
}\label{wxexprnth
}
232 \constfunc{wxExpr*
}{Nth
}{\param{int
}{ n
}}
234 Get nth arg of the given list expression (starting from
0). NULL is returned if
235 the expression is not a list expression, or
{\it n
} is invalid. See also
\helpref{wxExpr::Arg
}{wxexprarg
}.
237 Normally, you would use attribute-value pairs to add and retrieve data
238 from objects (clauses) in a data file. However, if the data gets complex,
239 you may need to store attribute values as lists, and pick them apart
242 \membersection{wxExpr::RealValue
}\label{wxexprrealvalue
}
244 \constfunc{float
}{RealValue
}{\void}
246 Returns the floating point value of the expression.
248 \membersection{wxExpr::SetClientData
}\label{wxexprsetclientdata
}
250 \func{void
}{SetClientData
}{\param{wxObject *
}{data
}}
252 Associate arbitrary data with this clause. This can be useful when
253 reading in data for storing a pointer to the C++ object, so when another
254 clause makes a reference to this clause, its C++ object can be retrieved.
255 See
\helpref{wxExpr::GetClientData
}{wxexprgetclientdata
}.
257 \membersection{wxExpr::StringValue
}\label{wxexprstringvalue
}
259 \constfunc{wxString
}{StringValue
}{\void}
261 Returns the string value of the expression.
263 \membersection{wxExpr::Type
}\label{wxexprtype
}
265 \constfunc{wxExprType
}{Type
}{\void}
267 Returns the type of the expression.
{\bf wxExprType
} is defined as follows:
280 \membersection{wxExpr::WordValue
}\label{wxexprwordvalue
}
282 \constfunc{wxString
}{WordValue
}{\void}
284 Returns the word value of the expression.
286 \membersection{wxExpr::WriteLispExpr
}\label{wxexprwritelistexpr
}
288 \func{void
}{WriteLispExpr
}{\param{ostream\&
}{ stream
}}
290 Writes the expression or clause to the given stream in LISP format.
291 Not normally needed, since the whole
{\bf wxExprDatabase
} will usually
292 be written at once. Lists are enclosed in parentheses will no commas.
294 \membersection{wxExpr::WritePrologClause
}\label{wxexprwriteprologclause
}
296 \func{void
}{WritePrologClause
}{\param{ostream\&
}{ stream
}}
298 Writes the clause to the given stream in Prolog format. Not normally needed, since
299 the whole
{\bf wxExprDatabase
} will usually be written at once. The format is:
300 functor, open parenthesis, list of comma-separated expressions, close parenthesis,
303 \membersection{wxExpr::WriteExpr
}\label{wxexprwriteexpr
}
305 \func{void
}{WriteExpr
}{\param{ostream\&
}{ stream
}}
307 Writes the expression (not clause) to the given stream in Prolog
308 format. Not normally needed, since the whole
{\bf wxExprDatabase
} will
309 usually be written at once. Lists are written in square bracketed,
310 comma-delimited format.
312 \membersection{Functions and macros
}
314 Below are miscellaneous functions and macros associated with wxExpr objects.
316 \func{bool
}{wxExprIsFunctor
}{\param{wxExpr *
}{expr
},
\param{const wxString\&
}{ functor
}}
318 Checks that the functor of
{\it expr
} is
{\it functor
}.
320 \func{void
}{wxExprCleanUp
}{\void}
322 Cleans up the wxExpr system (YACC/LEX buffers) to avoid memory-checking warnings as the program exits.
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))
332 Macros to help make wxExpr objects.
334 \section{\class{wxExprDatabase
}}\label{wxexprdatabase
}
336 The
{\bf wxExprDatabase
} class represents a database, or list,
337 of Prolog-like expressions. Instances of this class are used for reading,
338 writing and creating data files.
340 \wxheading{Derived from
}
342 \helpref{wxList
}{wxlist
}\\
343 \helpref{wxObject
}{wxobject
}
347 \helpref{wxExpr overview
}{exproverview
},
\helpref{wxExpr
}{wxexpr
}
349 \latexignore{\rtfignore{\wxheading{Members
}}}
351 \membersection{wxExprDatabase::wxExprDatabase
}\label{wxexprdatabaseconstr
}
353 \func{void
}{wxExprDatabase
}{\param{proioErrorHandler
}{ handler =
0}}
355 Construct a new, unhashed database, with an optional error handler. The
356 error handler must be a function returning a bool and taking an integer and a string
357 argument. When an error occurs when reading or writing a database, this function is
358 called. The error is given as the first argument (currently one of WXEXPR
\_ERROR\_GENERAL,
359 WXEXPR
\_ERROR\_SYNTAX) and an error message is given as the second argument. If FALSE
360 is returned by the error handler, processing of the wxExpr operation stops.
362 Another way of handling errors is simply to call
\helpref{wxExprDatabase::GetErrorCount
}{wxexprdatabasegeterrorcount
} after
363 the operation, to check whether errors have occurred, instead of installing an error handler.
364 If the error count is more than zero,
\helpref{wxExprDatabase::Write
}{wxexprdatabasewrite
} and
365 \rtfsp\helpref{wxExprDatabase::Read
}{wxexprdatabaseread
} will return FALSE to
371 bool myErrorHandler(int err, chat *msg)
373 if (err == WXEXPR_ERROR_SYNTAX)
375 wxMessageBox(msg, "Syntax error");
380 wxExprDatabase database(myErrorHandler);
384 \func{}{wxExprDatabase
}{\param{wxExprType
}{ type
},
\param{const wxString\&
}{attribute
},
385 \rtfsp\param{int
}{ size =
500},
\param{proioErrorHandler
}{ handler =
0}}
387 Construct a new database hashed on a combination of the clause functor and
388 a named attribute (often an integer identification).
390 See above for an explanation of the error handler.
392 \membersection{wxExprDatabase::
\destruct{wxExprDatabase
}}
394 \func{}{\destruct{wxExprDatabase
}}{\void}
396 Delete the database and contents.
398 \membersection{wxExprDatabase::Append
}\label{wxexprdatabaseappend
}
400 \func{void
}{Append
}{\param{wxExpr*
}{clause
}}
402 Append a clause to the end of the database. If the database is hashing,
403 the functor and a user-specified attribute will be hashed upon, giving the
404 option of random access in addition to linear traversal of the database.
406 \membersection{wxExprDatabase::BeginFind
}\label{wxexprdatabasebeginfind
}
408 \func{void
}{BeginFind
}{\void}
410 Reset the current position to the start of the database. Subsequent
411 \rtfsp\helpref{wxExprDatabase::FindClause
}{wxexprdatabasefindclause
} calls will move the pointer.
413 \membersection{wxExprDatabase::ClearDatabase
}\label{wxexprdatabasecleardatabase
}
415 \func{void
}{ClearDatabase
}{\void}
417 Clears the contents of the database.
419 \membersection{wxExprDatabase::FindClause
}\label{wxexprdatabasefindclause
}
421 Various ways of retrieving clauses from the database. A return
422 value of NULL indicates no (more) clauses matching the given criteria.
423 Calling the functions repeatedly retrieves more matching clauses, if any.
425 \func{wxExpr*
}{FindClause
}{\param{long
}{ id
}}
427 Find a clause based on the special ``id'' attribute.
429 \func{wxExpr*
}{FindClause
}{\param{const wxString\&
}{ attribute
},
\param{const wxString\&
}{ value
}}
431 Find a clause which has the given attribute set to the given string or word value.
433 \func{wxExpr*
}{FindClause
}{\param{const wxString\&
}{ attribute
},
\param{long
}{ value
}}
435 Find a clause which has the given attribute set to the given integer value.
437 \func{wxExpr*
}{FindClause
}{\param{const wxString\&
}{ attribute
},
\param{float
}{ value
}}
439 Find a clause which has the given attribute set to the given floating point value.
441 \membersection{wxExprDatabase::FindClauseByFunctor
}\label{wxexprdatabasefindclausebyfunctor
}
443 \func{wxExpr*
}{FindClauseByFunctor
}{\param{const wxString\&
}{ functor
}}
445 Find the next clause with the specified functor.
447 \membersection{wxExprDatabase::GetErrorCount
}\label{wxexprdatabasegeterrorcount
}
449 \constfunc{int
}{GetErrorCount
}{\void}
451 Returns the number of errors encountered during the last read or write operation.
453 \membersection{wxExprDatabase::HashFind
}\label{wxexprdatabasehashfind
}
455 \constfunc{wxExpr*
}{HashFind
}{\param{const wxString\&
}{ functor
},
\param{long
}{ value
}}
457 Finds the clause with the given functor and with the attribute specified
458 in the database constructor having the given integer value.
463 // Hash on a combination of functor and integer "id" attribute when reading in
464 wxExprDatabase db(wxExprInteger, "id");
467 db.ReadProlog("data");
469 // Retrieve a clause with specified functor and id
470 wxExpr *clause = db.HashFind("node",
24);
473 This would retrieve a clause which is written:
{\tt node(id =
24, ..., )
}.
475 \func{wxExpr*
}{HashFind
}{\param{const wxString\&
}{ functor
},
\param{const wxString\&
}{ value
}}
477 Finds the clause with the given functor and with the attribute specified
478 in the database constructor having the given string value.
480 \membersection{wxExprDatabase::Read
}\label{wxexprdatabaseread
}
482 \func{bool
}{Read
}{\param{const wxString\&
}{ filename
}}
484 Reads in the given file, returning TRUE if successful.
486 \membersection{wxExprDatabase::ReadFromString
}\label{wxexprdatabasereadfromstring
}
488 \func{bool
}{ReadFromString
}{\param{const wxString\&
}{ buffer
}}
490 Reads a Prolog database from the given string buffer, returning TRUE if
493 \membersection{wxExprDatabase::WriteLisp
}\label{wxexprdatabasewritelisp
}
495 \func{bool
}{WriteLisp
}{\param{ostream\&
}{stream
}}
497 Writes the database as a LISP-format file.
499 \membersection{wxExprDatabase::Write
}\label{wxexprdatabasewrite
}
501 \func{bool
}{Write
}{\param{ostream\&
}{stream
}}
503 Writes the database as a Prolog-format file.