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
|
<HTML>
<head><title>wxExprDatabase</title></head>
<BODY BGCOLOR=#FFFFFF>
<A NAME="wxexprdatabase"></A><CENTER>
<A HREF="wx.htm"><img align=center src="contents.gif" BORDER=0 ALT="Contents"></A> <A HREF="wx22.htm#classref"><img align=center src="up.gif" BORDER=0 ALT="Up"></A> <A HREF="wx86.htm#wxexpr"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="wx88.htm#wxfile"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>
<H2>wxExprDatabase</H2>
<P>
The <B>wxExprDatabase</B> class represents a database, or list,
of Prolog-like expressions. Instances of this class are used for reading,
writing and creating data files.<P>
<B><FONT COLOR="#FF0000">Derived from</FONT></B><P>
<A HREF="wx127.htm#wxlist">wxList</A><BR>
<A HREF="wx158.htm#wxobject">wxObject</A><P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx310.htm#exproverview">wxExpr overview</A>, <A HREF="wx86.htm#wxexpr">wxExpr</A><P>
<B><FONT COLOR="#FF0000">Members</FONT></B><P>
<A HREF="#wxexprdatabaseconstr">wxExprDatabase::wxExprDatabase</A><BR>
<A HREF="#topic360">wxExprDatabase::~wxExprDatabase</A><BR>
<A HREF="#wxexprdatabaseappend">wxExprDatabase::Append</A><BR>
<A HREF="#wxexprdatabasebeginfind">wxExprDatabase::BeginFind</A><BR>
<A HREF="#wxexprdatabasecleardatabase">wxExprDatabase::ClearDatabase</A><BR>
<A HREF="#wxexprdatabasefindclause">wxExprDatabase::FindClause</A><BR>
<A HREF="#wxexprdatabasefindclausebyfunctor">wxExprDatabase::FindClauseByFunctor</A><BR>
<A HREF="#wxexprdatabasegeterrorcount">wxExprDatabase::GetErrorCount</A><BR>
<A HREF="#wxexprdatabasehashfind">wxExprDatabase::HashFind</A><BR>
<A HREF="#wxexprdatabaseread">wxExprDatabase::Read</A><BR>
<A HREF="#wxexprdatabasereadfromstring">wxExprDatabase::ReadFromString</A><BR>
<A HREF="#wxexprdatabasewritelisp">wxExprDatabase::WriteLisp</A><BR>
<A HREF="#wxexprdatabasewrite">wxExprDatabase::Write</A><BR>
<P>
<HR>
<A NAME="wxexprdatabaseconstr"></A>
<H3>wxExprDatabase::wxExprDatabase</H3>
<P>
<B>void</B> <B>wxExprDatabase</B>(<B>proioErrorHandler</B><I> handler = 0</I>)<P>
Construct a new, unhashed database, with an optional error handler. The
error handler must be a function returning a bool and taking an integer and a string
argument. When an error occurs when reading or writing a database, this function is
called. The error is given as the first argument (currently one of WXEXPR_ERROR_GENERAL,
WXEXPR_ERROR_SYNTAX) and an error message is given as the second argument. If FALSE
is returned by the error handler, processing of the wxExpr operation stops.<P>
Another way of handling errors is simply to call <A HREF="wx87.htm#wxexprdatabasegeterrorcount">wxExprDatabase::GetErrorCount</A> after
the operation, to check whether errors have occurred, instead of installing an error handler.
If the error count is more than zero, <A HREF="wx87.htm#wxexprdatabasewrite">wxExprDatabase::Write</A> and
<A HREF="wx87.htm#wxexprdatabaseread">wxExprDatabase::Read</A> will return FALSE to
the application.<P>
For example:<P>
<PRE>
bool myErrorHandler(int err, chat *msg)
{
if (err == WXEXPR_ERROR_SYNTAX)
{
wxMessageBox(msg, "Syntax error");
}
return FALSE;
}
wxExprDatabase database(myErrorHandler);
</PRE>
<B></B> <B>wxExprDatabase</B>(<B>wxExprType</B><I> type</I>, <B>const wxString&</B><I>attribute</I>,
<B>int</B><I> size = 500</I>, <B>proioErrorHandler</B><I> handler = 0</I>)<P>
Construct a new database hashed on a combination of the clause functor and
a named attribute (often an integer identification).<P>
See above for an explanation of the error handler.<P>
<HR>
<A NAME="topic360"></A>
<H3>wxExprDatabase::~wxExprDatabase</H3>
<P>
<B></B> <B>~wxExprDatabase</B>()<P>
Delete the database and contents.<P>
<HR>
<A NAME="wxexprdatabaseappend"></A>
<H3>wxExprDatabase::Append</H3>
<P>
<B>void</B> <B>Append</B>(<B>wxExpr* </B><I>clause</I>)<P>
Append a clause to the end of the database. If the database is hashing,
the functor and a user-specified attribute will be hashed upon, giving the
option of random access in addition to linear traversal of the database.<P>
<HR>
<A NAME="wxexprdatabasebeginfind"></A>
<H3>wxExprDatabase::BeginFind</H3>
<P>
<B>void</B> <B>BeginFind</B>()<P>
Reset the current position to the start of the database. Subsequent
<A HREF="wx87.htm#wxexprdatabasefindclause">wxExprDatabase::FindClause</A> calls will move the pointer.<P>
<HR>
<A NAME="wxexprdatabasecleardatabase"></A>
<H3>wxExprDatabase::ClearDatabase</H3>
<P>
<B>void</B> <B>ClearDatabase</B>()<P>
Clears the contents of the database.<P>
<HR>
<A NAME="wxexprdatabasefindclause"></A>
<H3>wxExprDatabase::FindClause</H3>
<P>
Various ways of retrieving clauses from the database. A return
value of NULL indicates no (more) clauses matching the given criteria.
Calling the functions repeatedly retrieves more matching clauses, if any.<P>
<B>wxExpr* </B> <B>FindClause</B>(<B>long</B><I> id</I>)<P>
Find a clause based on the special "id'' attribute.<P>
<B>wxExpr* </B> <B>FindClause</B>(<B>const wxString&</B><I> attribute</I>, <B>const wxString&</B><I> value</I>)<P>
Find a clause which has the given attribute set to the given string or word value.<P>
<B>wxExpr*</B> <B>FindClause</B>(<B>const wxString&</B><I> attribute</I>, <B>long</B><I> value</I>)<P>
Find a clause which has the given attribute set to the given integer value.<P>
<B>wxExpr*</B> <B>FindClause</B>(<B>const wxString&</B><I> attribute</I>, <B>float</B><I> value</I>)<P>
Find a clause which has the given attribute set to the given floating point value.<P>
<HR>
<A NAME="wxexprdatabasefindclausebyfunctor"></A>
<H3>wxExprDatabase::FindClauseByFunctor</H3>
<P>
<B>wxExpr*</B> <B>FindClauseByFunctor</B>(<B>const wxString&</B><I> functor</I>)<P>
Find the next clause with the specified functor.<P>
<HR>
<A NAME="wxexprdatabasegeterrorcount"></A>
<H3>wxExprDatabase::GetErrorCount</H3>
<P>
<B>int</B> <B>GetErrorCount</B>() <B>const</B><P>
Returns the number of errors encountered during the last read or write operation.<P>
<HR>
<A NAME="wxexprdatabasehashfind"></A>
<H3>wxExprDatabase::HashFind</H3>
<P>
<B>wxExpr*</B> <B>HashFind</B>(<B>const wxString&</B><I> functor</I>, <B>long</B><I> value</I>) <B>const</B><P>
Finds the clause with the given functor and with the attribute specified
in the database constructor having the given integer value.<P>
For example,<P>
<PRE>
// Hash on a combination of functor and integer "id" attribute when reading in
wxExprDatabase db(wxExprInteger, "id");
// Read it in
db.ReadProlog("data");
// Retrieve a clause with specified functor and id
wxExpr *clause = db.HashFind("node", 24);
</PRE>
This would retrieve a clause which is written: <TT>node(id = 24, ..., )</TT>.<P>
<B>wxExpr*</B> <B>HashFind</B>(<B>const wxString&</B><I> functor</I>, <B>const wxString&</B><I> value</I>)<P>
Finds the clause with the given functor and with the attribute specified
in the database constructor having the given string value.<P>
<HR>
<A NAME="wxexprdatabaseread"></A>
<H3>wxExprDatabase::Read</H3>
<P>
<B>bool</B> <B>Read</B>(<B>const wxString&</B><I> filename</I>)<P>
Reads in the given file, returning TRUE if successful.<P>
<HR>
<A NAME="wxexprdatabasereadfromstring"></A>
<H3>wxExprDatabase::ReadFromString</H3>
<P>
<B>bool</B> <B>ReadFromString</B>(<B>const wxString&</B><I> buffer</I>)<P>
Reads a Prolog database from the given string buffer, returning TRUE if
successful.<P>
<HR>
<A NAME="wxexprdatabasewritelisp"></A>
<H3>wxExprDatabase::WriteLisp</H3>
<P>
<B>bool</B> <B>WriteLisp</B>(<B>ostream& </B><I>stream</I>)<P>
Writes the database as a LISP-format file.<P>
<HR>
<A NAME="wxexprdatabasewrite"></A>
<H3>wxExprDatabase::Write</H3>
<P>
<B>bool</B> <B>Write</B>(<B>ostream& </B><I>stream</I>)<P>
<B>bool</B> <B>Write</B>(<B>const wxString&</B><I> filename</I>)<P>
Writes the database as a Prolog-format file.<P>
</BODY></HTML>
|