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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
|
<HTML>
<head><title>wxExpr</title></head>
<BODY BGCOLOR=#FFFFFF>
<A NAME="wxexpr"></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="wx85.htm#wxevthandler"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="wx87.htm#wxexprdatabase"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>
<H2>wxExpr</H2>
<P>
The <B>wxExpr</B> class is the building brick of expressions similar to Prolog
clauses, or objects. It can represent an expression of type long integer, float, string, word,
or list, and lists can be nested.<P>
<B><FONT COLOR="#FF0000">Derived from</FONT></B><P>
None<P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
<wx/wxexpr.h><P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx310.htm#exproverview">wxExpr overview</A>, <A HREF="wx87.htm#wxexprdatabase">wxExprDatabase</A><P>
<B><FONT COLOR="#FF0000">Members</FONT></B><P>
<A HREF="#wxexprconstr">wxExpr::wxExpr</A><BR>
<A HREF="#topic358">wxExpr::~wxExpr</A><BR>
<A HREF="#wxexpraddattributevalue">wxExpr::AddAttributeValue</A><BR>
<A HREF="#wxexpraddattributevaluestring">wxExpr::AddAttributeValueString</A><BR>
<A HREF="#wxexpraddattributevaluestringlist">wxExpr::AddAttributeValueStringList</A><BR>
<A HREF="#wxexpraddattributevalueword">wxExpr::AddAttributeValueWord</A><BR>
<A HREF="#wxexprappend">wxExpr::Append</A><BR>
<A HREF="#wxexprarg">wxExpr::Arg</A><BR>
<A HREF="#wxexprinsert">wxExpr::Insert</A><BR>
<A HREF="#wxexprgetattributevalue">wxExpr::GetAttributeValue</A><BR>
<A HREF="#wxexprgetattributestringlist">wxExpr::GetAttributeValueStringList</A><BR>
<A HREF="#wxexprattributevalue">wxExpr::AttributeValue</A><BR>
<A HREF="#wxexprcopy">wxExpr::Copy</A><BR>
<A HREF="#wxexprdeletattributevalue">wxExpr::DeleteAttributeValue</A><BR>
<A HREF="#wxexprfunctor">wxExpr::Functor</A><BR>
<A HREF="#wxexprgetclientdata">wxExpr::GetClientData</A><BR>
<A HREF="#wxexprgetfirst">wxExpr::GetFirst</A><BR>
<A HREF="#wxexprgetlast">wxExpr::GetLast</A><BR>
<A HREF="#wxexprgetnext">wxExpr::GetNext</A><BR>
<A HREF="#wxexprintegervalue">wxExpr::IntegerValue</A><BR>
<A HREF="#wxexprnth">wxExpr::Nth</A><BR>
<A HREF="#wxexprrealvalue">wxExpr::RealValue</A><BR>
<A HREF="#wxexprsetclientdata">wxExpr::SetClientData</A><BR>
<A HREF="#wxexprstringvalue">wxExpr::StringValue</A><BR>
<A HREF="#wxexprtype">wxExpr::Type</A><BR>
<A HREF="#wxexprwordvalue">wxExpr::WordValue</A><BR>
<A HREF="#wxexprwritelistexpr">wxExpr::WriteLispExpr</A><BR>
<A HREF="#wxexprwriteprologclause">wxExpr::WritePrologClause</A><BR>
<A HREF="#wxexprwriteexpr">wxExpr::WriteExpr</A><BR>
<A HREF="#topic359">Functions and macros</A><BR>
<P>
<HR>
<A NAME="wxexprconstr"></A>
<H3>wxExpr::wxExpr</H3>
<P>
<B></B> <B>wxExpr</B>(<B>const wxString&</B><I>functor</I>)<P>
Construct a new clause with this form, supplying the functor name. A clause is an object
that will appear in the data file, with a list of attribute/value pairs.<P>
<B></B> <B>wxExpr</B>(<B>wxExprType</B><I> type</I>, <B>const wxString&</B><I> wordOrString = ""</I>)<P>
Construct a new empty list, or a word (will be output with no quotes), or a string, depending on the
value of <I>type</I>.<P>
<I>type</I> can be <B>wxExprList</B>, <B>wxExprWord</B>, or <B>wxExprString</B>. If <I>type</I> is wxExprList,
the value of <I>wordOrString</I> will be ignored.<P>
<B></B> <B>wxExpr</B>(<B>long</B><I> value</I>)<P>
Construct an integer expression.<P>
<B></B> <B>wxExpr</B>(<B>float</B><I> value</I>)<P>
Construct a floating point expression.<P>
<B></B> <B>wxExpr</B>(<B>wxList* </B><I>value</I>)<P>
Construct a list expression. The list's nodes' data should
themselves be <B>wxExpr</B>s.<P>
The current version of this library no longer uses the <B>wxList</B>
internally, so this constructor turns the list into its internal
format (assuming a non-nested list) and then deletes the supplied
list.<P>
<HR>
<A NAME="topic358"></A>
<H3>wxExpr::~wxExpr</H3>
<P>
<B></B> <B>~wxExpr</B>()<P>
Destructor.<P>
<HR>
<A NAME="wxexpraddattributevalue"></A>
<H3>wxExpr::AddAttributeValue</H3>
<P>
Use these on clauses ONLY. Note that the functions for adding strings
and words must be differentiated by function name which is why
they are missing from this group (see <A HREF="wx86.htm#wxexpraddattributevaluestring">wxExpr::AddAttributeValueString</A> and
<A HREF="wx86.htm#wxexpraddattributevalueword">wxExpr::AddAttributeValueWord</A>).<P>
<B>void</B> <B>AddAttributeValue</B>(<B>const wxString&</B><I> attribute</I>, <B>float </B><I>value</I>)<P>
Adds an attribute and floating point value pair to the clause.<P>
<B>void</B> <B>AddAttributeValue</B>(<B>const wxString&</B><I> attribute</I>, <B>long </B><I>value</I>)<P>
Adds an attribute and long integer value pair to the clause.<P>
<B>void</B> <B>AddAttributeValue</B>(<B>const wxString&</B><I> attribute</I>, <B>wxList* </B><I>value</I>)<P>
Adds an attribute and list value pair to the clause, converting the list into
internal form and then deleting <B>value</B>. Note that the list should not contain
nested lists (except if in internal <B>wxExpr</B> form.)<P>
<B>void</B> <B>AddAttributeValue</B>(<B>const wxString&</B><I> attribute</I>, <B>wxExpr* </B><I>value</I>)<P>
Adds an attribute and wxExpr value pair to the clause. Do not delete
<I>value</I> once this function has been called.<P>
<HR>
<A NAME="wxexpraddattributevaluestring"></A>
<H3>wxExpr::AddAttributeValueString</H3>
<P>
<B>void</B> <B>AddAttributeValueString</B>(<B>const wxString&</B><I> attribute</I>, <B>const wxString&</B><I> value</I>)<P>
Adds an attribute and string value pair to the clause.<P>
<HR>
<A NAME="wxexpraddattributevaluestringlist"></A>
<H3>wxExpr::AddAttributeValueStringList</H3>
<P>
<B>void</B> <B>AddAttributeValueStringList</B>(<B>const wxString&</B><I> attribute</I>, <B>wxList* </B><I>value</I>)<P>
Adds an attribute and string list value pair to the clause.<P>
Note that the list passed to this function is a list of strings, NOT a list
of <B>wxExpr</B>s; it gets turned into a list of <B>wxExpr</B>s
automatically. This is a convenience function, since lists of strings
are often manipulated in C++.<P>
<HR>
<A NAME="wxexpraddattributevalueword"></A>
<H3>wxExpr::AddAttributeValueWord</H3>
<P>
<B>void</B> <B>AddAttributeValueWord</B>(<B>const wxString&</B><I> attribute</I>, <B>const wxString&</B><I> value</I>)<P>
Adds an attribute and word value pair to the clause.<P>
<HR>
<A NAME="wxexprappend"></A>
<H3>wxExpr::Append</H3>
<P>
<B>void</B> <B>Append</B>(<B>wxExpr*</B><I> value</I>)<P>
Append the <B>value</B> to the end of the list. 'this' must be a list.<P>
<HR>
<A NAME="wxexprarg"></A>
<H3>wxExpr::Arg</H3>
<P>
<B>wxExpr* </B> <B>Arg</B>(<B>wxExprType</B><I> type</I>, <B>int</B><I> n</I>) <B>const</B><P>
Get nth arg of the given clause (starting from 1). NULL is returned if
the expression is not a clause, or <I>n</I> is invalid, or the given type
does not match the actual type. See also <A HREF="wx86.htm#wxexprnth">wxExpr::Nth</A>.<P>
<HR>
<A NAME="wxexprinsert"></A>
<H3>wxExpr::Insert</H3>
<P>
<B>void</B> <B>Insert</B>(<B>wxExpr* </B><I>value</I>)<P>
Insert the <B>value</B> at the start of the list. 'this' must be a list.<P>
<HR>
<A NAME="wxexprgetattributevalue"></A>
<H3>wxExpr::GetAttributeValue</H3>
<P>
These functions are the easiest way to retrieve attribute values, by
passing a pointer to variable. If the attribute is present, the
variable will be filled with the appropriate value. If not, the
existing value is left alone. This style of retrieving attributes
makes it easy to set variables to default values before calling these
functions; no code is necessary to check whether the attribute is
present or not.<P>
<B>bool</B> <B>GetAttributeValue</B>(<B>const wxString&</B><I> attribute</I>, <B>wxString&</B><I> value</I>) <B>const</B><P>
Retrieve a string (or word) value.<P>
<B>bool</B> <B>GetAttributeValue</B>(<B>const wxString&</B><I> attribute</I>, <B>float& </B><I>value</I>) <B>const</B><P>
Retrieve a floating point value.<P>
<B>bool</B> <B>GetAttributeValue</B>(<B>const wxString&</B><I> attribute</I>, <B>int& </B><I>value</I>) <B>const</B><P>
Retrieve an integer value.<P>
<B>bool</B> <B>GetAttributeValue</B>(<B>const wxString&</B><I> attribute</I>, <B>long& </B><I>value</I>) <B>const</B><P>
Retrieve a long integer value.<P>
<B>bool</B> <B>GetAttributeValue</B>(<B>const wxString&</B><I> attribute</I>, <B>wxExpr**</B><I> value</I>) <B>const</B><P>
Retrieve a wxExpr pointer.<P>
<HR>
<A NAME="wxexprgetattributestringlist"></A>
<H3>wxExpr::GetAttributeValueStringList</H3>
<P>
<B>void</B> <B>GetAttributeValueStringList</B>(<B>const wxString&</B><I>attribute</I>, <B>wxList* </B><I>value</I>) <B>const</B><P>
Use this on clauses ONLY. See above for comments on this style of
attribute value retrieval. This function expects to receive a pointer to
a new list (created by the calling application); it will append strings
to the list if the attribute is present in the clause.<P>
<HR>
<A NAME="wxexprattributevalue"></A>
<H3>wxExpr::AttributeValue</H3>
<P>
<B>wxExpr*</B> <B>AttributeValue</B>(<B>const wxString&</B><I> word</I>) <B>const</B><P>
Use this on clauses ONLY. Searches the clause for an attribute
matching <I>word</I>, and returns the value associated with it.<P>
<HR>
<A NAME="wxexprcopy"></A>
<H3>wxExpr::Copy</H3>
<P>
<B>wxExpr*</B> <B>Copy</B>() <B>const</B><P>
Recursively copies the expression, allocating new storage space.<P>
<HR>
<A NAME="wxexprdeletattributevalue"></A>
<H3>wxExpr::DeleteAttributeValue</H3>
<P>
<B>void</B> <B>DeleteAttributeValue</B>(<B>const wxString&</B><I> attribute</I>)<P>
Use this on clauses only. Deletes the attribute and its value (if any) from the
clause.<P>
<HR>
<A NAME="wxexprfunctor"></A>
<H3>wxExpr::Functor</H3>
<P>
<B>wxString</B> <B>Functor</B>() <B>const</B><P>
Use this on clauses only. Returns the clause's functor (object name).<P>
<HR>
<A NAME="wxexprgetclientdata"></A>
<H3>wxExpr::GetClientData</H3>
<P>
<B>wxObject*</B> <B>GetClientData</B>() <B>const</B><P>
Retrieve arbitrary data stored with this clause. This can be useful when
reading in data for storing a pointer to the C++ object, so when another
clause makes a reference to this clause, its C++ object can be retrieved.
See <A HREF="wx86.htm#wxexprsetclientdata">wxExpr::SetClientData</A>.<P>
<HR>
<A NAME="wxexprgetfirst"></A>
<H3>wxExpr::GetFirst</H3>
<P>
<B>wxExpr*</B> <B>GetFirst</B>() <B>const</B><P>
If this is a list expression (or clause), gets the first element in the list.<P>
See also <A HREF="wx86.htm#wxexprgetlast">wxExpr::GetLast</A>, <A HREF="wx86.htm#wxexprgetnext">wxExpr::GetNext</A>, <A HREF="wx86.htm#wxexprnth">wxExpr::Nth</A>.<P>
<HR>
<A NAME="wxexprgetlast"></A>
<H3>wxExpr::GetLast</H3>
<P>
<B>wxExpr*</B> <B>GetLast</B>() <B>const</B><P>
If this is a list expression (or clause), gets the last element in the list.<P>
See also <A HREF="wx86.htm#wxexprgetfirst">wxExpr::GetFirst</A>, <A HREF="wx86.htm#wxexprgetnext">wxExpr::GetNext</A>, <A HREF="wx86.htm#wxexprnth">wxExpr::Nth</A>.<P>
<HR>
<A NAME="wxexprgetnext"></A>
<H3>wxExpr::GetNext</H3>
<P>
<B>wxExpr*</B> <B>GetNext</B>() <B>const</B><P>
If this is a node in a list (any wxExpr may be a node in a list), gets the
next element in the list.<P>
See also <A HREF="wx86.htm#wxexprgetfirst">wxExpr::GetFirst</A>, <A HREF="wx86.htm#wxexprgetlast">wxExpr::GetLast</A>, <A HREF="wx86.htm#wxexprnth">wxExpr::Nth</A>.<P>
<HR>
<A NAME="wxexprintegervalue"></A>
<H3>wxExpr::IntegerValue</H3>
<P>
<B>long</B> <B>IntegerValue</B>() <B>const</B><P>
Returns the integer value of the expression.<P>
<HR>
<A NAME="wxexprnth"></A>
<H3>wxExpr::Nth</H3>
<P>
<B>wxExpr*</B> <B>Nth</B>(<B>int</B><I> n</I>) <B>const</B><P>
Get nth arg of the given list expression (starting from 0). NULL is returned if
the expression is not a list expression, or <I>n</I> is invalid. See also <A HREF="wx86.htm#wxexprarg">wxExpr::Arg</A>.<P>
Normally, you would use attribute-value pairs to add and retrieve data
from objects (clauses) in a data file. However, if the data gets complex,
you may need to store attribute values as lists, and pick them apart
yourself.<P>
<HR>
<A NAME="wxexprrealvalue"></A>
<H3>wxExpr::RealValue</H3>
<P>
<B>float</B> <B>RealValue</B>() <B>const</B><P>
Returns the floating point value of the expression.<P>
<HR>
<A NAME="wxexprsetclientdata"></A>
<H3>wxExpr::SetClientData</H3>
<P>
<B>void</B> <B>SetClientData</B>(<B>wxObject *</B><I>data</I>)<P>
Associate arbitrary data with this clause. This can be useful when
reading in data for storing a pointer to the C++ object, so when another
clause makes a reference to this clause, its C++ object can be retrieved.
See <A HREF="wx86.htm#wxexprgetclientdata">wxExpr::GetClientData</A>.<P>
<HR>
<A NAME="wxexprstringvalue"></A>
<H3>wxExpr::StringValue</H3>
<P>
<B>wxString</B> <B>StringValue</B>() <B>const</B><P>
Returns the string value of the expression.<P>
<HR>
<A NAME="wxexprtype"></A>
<H3>wxExpr::Type</H3>
<P>
<B>wxExprType</B> <B>Type</B>() <B>const</B><P>
Returns the type of the expression. <B>wxExprType</B> is defined as follows:<P>
<PRE>
typedef enum {
wxExprNull,
wxExprInteger,
wxExprReal,
wxExprWord,
wxExprString,
wxExprList
} wxExprType;
</PRE>
<HR>
<A NAME="wxexprwordvalue"></A>
<H3>wxExpr::WordValue</H3>
<P>
<B>wxString</B> <B>WordValue</B>() <B>const</B><P>
Returns the word value of the expression.<P>
<HR>
<A NAME="wxexprwritelistexpr"></A>
<H3>wxExpr::WriteLispExpr</H3>
<P>
<B>void</B> <B>WriteLispExpr</B>(<B>ostream&</B><I> stream</I>)<P>
Writes the expression or clause to the given stream in LISP format.
Not normally needed, since the whole <B>wxExprDatabase</B> will usually
be written at once. Lists are enclosed in parentheses will no commas.<P>
<HR>
<A NAME="wxexprwriteprologclause"></A>
<H3>wxExpr::WritePrologClause</H3>
<P>
<B>void</B> <B>WritePrologClause</B>(<B>ostream&</B><I> stream</I>)<P>
Writes the clause to the given stream in Prolog format. Not normally needed, since
the whole <B>wxExprDatabase</B> will usually be written at once. The format is:
functor, open parenthesis, list of comma-separated expressions, close parenthesis,
full stop.<P>
<HR>
<A NAME="wxexprwriteexpr"></A>
<H3>wxExpr::WriteExpr</H3>
<P>
<B>void</B> <B>WriteExpr</B>(<B>ostream&</B><I> stream</I>)<P>
Writes the expression (not clause) to the given stream in Prolog
format. Not normally needed, since the whole <B>wxExprDatabase</B> will
usually be written at once. Lists are written in square bracketed,
comma-delimited format.<P>
<HR>
<A NAME="topic359"></A>
<H3>Functions and macros</H3>
<P>
Below are miscellaneous functions and macros associated with wxExpr objects.<P>
<B>bool</B> <B>wxExprIsFunctor</B>(<B>wxExpr *</B><I>expr</I>, <B>const wxString&</B><I> functor</I>)<P>
Checks that the functor of <I>expr</I> is <I>functor</I>.<P>
<B>void</B> <B>wxExprCleanUp</B>()<P>
Cleans up the wxExpr system (YACC/LEX buffers) to avoid memory-checking warnings as the program exits.<P>
<PRE>
#define wxMakeInteger(x) (new wxExpr((long)x))
#define wxMakeReal(x) (new wxExpr((float)x))
#define wxMakeString(x) (new wxExpr(PrologString, x))
#define wxMakeWord(x) (new wxExpr(PrologWord, x))
#define wxMake(x) (new wxExpr(x))
</PRE>
Macros to help make wxExpr objects.<P>
</BODY></HTML>
|