Contents Up Previous Next 原文へのリンク

wxExpr

The wxExpr 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.

Derived from

None

Include files

<wx/wxexpr.h>

See also

wxExpr overview, wxExprDatabase

Members

wxExpr::wxExpr
wxExpr::~wxExpr
wxExpr::AddAttributeValue
wxExpr::AddAttributeValueString
wxExpr::AddAttributeValueStringList
wxExpr::AddAttributeValueWord
wxExpr::Append
wxExpr::Arg
wxExpr::Insert
wxExpr::GetAttributeValue
wxExpr::GetAttributeValueStringList
wxExpr::AttributeValue
wxExpr::Copy
wxExpr::DeleteAttributeValue
wxExpr::Functor
wxExpr::GetClientData
wxExpr::GetFirst
wxExpr::GetLast
wxExpr::GetNext
wxExpr::IntegerValue
wxExpr::Nth
wxExpr::RealValue
wxExpr::SetClientData
wxExpr::StringValue
wxExpr::Type
wxExpr::WordValue
wxExpr::WriteClause
wxExpr::WriteExpr
Functions and macros


wxExpr::wxExpr

wxExpr(const wxString&functor)

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.

wxExpr(wxExprType type, const wxString& wordOrString = "")

Construct a new empty list, or a word (will be output with no quotes), or a string, depending on the value of type.

type can be wxExprList, wxExprWord, or wxExprString. If type is wxExprList, the value of wordOrString will be ignored.

wxExpr(long value)

Construct an integer expression.

wxExpr(float value)

Construct a floating point expression.

wxExpr(wxList* value)

Construct a list expression. The list's nodes' data should themselves be wxExprs.

wxExpr no longer uses the wxList internally, so this constructor turns the list into its internal format (assuming a non-nested list) and then deletes the supplied list.


wxExpr::~wxExpr

~wxExpr()

Destructor.


wxExpr::AddAttributeValue

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 wxExpr::AddAttributeValueString and wxExpr::AddAttributeValueWord).

void AddAttributeValue(const wxString& attribute, float value)

Adds an attribute and floating point value pair to the clause.

void AddAttributeValue(const wxString& attribute, long value)

Adds an attribute and long integer value pair to the clause.

void AddAttributeValue(const wxString& attribute, wxList* value)

Adds an attribute and list value pair to the clause, converting the list into internal form and then deleting value. Note that the list should not contain nested lists (except if in internal wxExpr form.)

void AddAttributeValue(const wxString& attribute, wxExpr* value)

Adds an attribute and wxExpr value pair to the clause. Do not delete value once this function has been called.


wxExpr::AddAttributeValueString

void AddAttributeValueString(const wxString& attribute, const wxString& value)

Adds an attribute and string value pair to the clause.


wxExpr::AddAttributeValueStringList

void AddAttributeValueStringList(const wxString& attribute, wxList* value)

Adds an attribute and string list value pair to the clause.

Note that the list passed to this function is a list of strings, NOT a list of wxExprs; it gets turned into a list of wxExprs automatically. This is a convenience function, since lists of strings are often manipulated in C++.


wxExpr::AddAttributeValueWord

void AddAttributeValueWord(const wxString& attribute, const wxString& value)

Adds an attribute and word value pair to the clause.


wxExpr::Append

void Append(wxExpr* value)

Append the value to the end of the list. 'this' must be a list.


wxExpr::Arg

wxExpr* Arg(wxExprType type, int n) const

Get nth arg of the given clause (starting from 1). NULL is returned if the expression is not a clause, or n is invalid, or the given type does not match the actual type. See also wxExpr::Nth.


wxExpr::Insert

void Insert(wxExpr* value)

Insert the value at the start of the list. 'this' must be a list.


wxExpr::GetAttributeValue

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.

bool GetAttributeValue(const wxString& attribute, wxString& value) const

Retrieve a string (or word) value.

bool GetAttributeValue(const wxString& attribute, float& value) const

Retrieve a floating point value.

bool GetAttributeValue(const wxString& attribute, int& value) const

Retrieve an integer value.

bool GetAttributeValue(const wxString& attribute, long& value) const

Retrieve a long integer value.

bool GetAttributeValue(const wxString& attribute, wxExpr** value) const

Retrieve a wxExpr pointer.


wxExpr::GetAttributeValueStringList

void GetAttributeValueStringList(const wxString&attribute, wxList* value) const

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.


wxExpr::AttributeValue

wxExpr* AttributeValue(const wxString& word) const

Use this on clauses ONLY. Searches the clause for an attribute matching word, and returns the value associated with it.


wxExpr::Copy

wxExpr* Copy() const

Recursively copies the expression, allocating new storage space.


wxExpr::DeleteAttributeValue

void DeleteAttributeValue(const wxString& attribute)

Use this on clauses only. Deletes the attribute and its value (if any) from the clause.


wxExpr::Functor

wxString Functor() const

Use this on clauses only. Returns the clause's functor (object name).


wxExpr::GetClientData

wxObject* GetClientData() const

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 wxExpr::SetClientData.


wxExpr::GetFirst

wxExpr* GetFirst() const

If this is a list expression (or clause), gets the first element in the list.

See also wxExpr::GetLast, wxExpr::GetNext, wxExpr::Nth.


wxExpr::GetLast

wxExpr* GetLast() const

If this is a list expression (or clause), gets the last element in the list.

See also wxExpr::GetFirst, wxExpr::GetNext, wxExpr::Nth.


wxExpr::GetNext

wxExpr* GetNext() const

If this is a node in a list (any wxExpr may be a node in a list), gets the next element in the list.

See also wxExpr::GetFirst, wxExpr::GetLast, wxExpr::Nth.


wxExpr::IntegerValue

long IntegerValue() const

Returns the integer value of the expression.


wxExpr::Nth

wxExpr* Nth(int n) const

Get nth arg of the given list expression (starting from 0). NULL is returned if the expression is not a list expression, or n is invalid. See also wxExpr::Arg.

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.


wxExpr::RealValue

float RealValue() const

Returns the floating point value of the expression.


wxExpr::SetClientData

void SetClientData(wxObject *data)

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 wxExpr::GetClientData.


wxExpr::StringValue

wxString StringValue() const

Returns the string value of the expression.


wxExpr::Type

wxExprType Type() const

Returns the type of the expression. wxExprType is defined as follows:

typedef enum {
    wxExprNull,
    wxExprInteger,
    wxExprReal,
    wxExprWord,
    wxExprString,
    wxExprList
} wxExprType;

wxExpr::WordValue

wxString WordValue() const

Returns the word value of the expression.


wxExpr::WriteClause

void WriteClause(FILE * stream)

Writes the clause to the given stream in Prolog format. Not normally needed, since the whole wxExprDatabase will usually be written at once. The format is: functor, open parenthesis, list of comma-separated expressions, close parenthesis, full stop.


wxExpr::WriteExpr

void WriteExpr(FILE * stream)

Writes the expression (not clause) to the given stream in Prolog format. Not normally needed, since the whole wxExprDatabase will usually be written at once. Lists are written in square bracketed, comma-delimited format.


Functions and macros

Below are miscellaneous functions and macros associated with wxExpr objects.

bool wxExprIsFunctor(wxExpr *expr, const wxString& functor)

Checks that the functor of expr is functor.

void wxExprCleanUp()

Cleans up the wxExpr system (YACC/LEX buffers) to avoid memory-checking warnings as the program exits.

#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))
Macros to help make wxExpr objects.