X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/34138703c3997ce676a1e713d9ff9eb020640da7..bbc1265c400d44962621a6b2c7c36ccff097207c:/include/wx/wxexpr.h?ds=sidebyside diff --git a/include/wx/wxexpr.h b/include/wx/wxexpr.h index 89a29f9f93..304aeb09c9 100644 --- a/include/wx/wxexpr.h +++ b/include/wx/wxexpr.h @@ -6,32 +6,28 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_WXEXPRH__ #define _WX_WXEXPRH__ -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(__APPLE__) #pragma interface "wxexpr.h" #endif -#include +#if wxUSE_PROLOGIO #include "wx/defs.h" #include "wx/string.h" -#if USE_IOSTREAMH -#include -#else -#include -#endif - #include "wx/list.h" #include "wx/hash.h" #include "wx/expr.h" +#include + // Compatibility #define PrologExpr wxExpr #define PrologDatabase wxExprDatabase @@ -56,9 +52,6 @@ typedef bool (*wxExprErrorHandler) (int errorType, char *msg); WXDLLEXPORT_DATA(extern wxExprErrorHandler) currentwxExprErrorHandler; -WXDLLEXPORT_DATA(extern "C" FILE*) yyin; - -extern "C" int WXDLLEXPORT yyparse(void); typedef enum { wxExprNull, @@ -78,20 +71,20 @@ class WXDLLEXPORT wxExpr wxExprType type; union { long integer; - char *word; - char *string; - float real; + wxChar *word; + wxChar *string; + double real; wxExpr *first; // If is a list expr, points to the first node } value; wxExpr *next; // If this is a node in a list, points to the next node wxExpr *last; // If is a list expr, points to the last node - wxExpr(wxExprType the_type, char *word_or_string, bool allocate); + wxExpr(wxExprType the_type, wxChar *word_or_string, bool allocate); wxExpr(const wxString& functor); // Assume this is a new clause - pass functor - wxExpr(wxExprType the_type, const wxString& word_or_string = ""); + wxExpr(wxExprType the_type, const wxString& word_or_string = wxT("")); wxExpr(long the_integer); - wxExpr(float the_real); + wxExpr(double the_real); wxExpr(wxList *the_list); ~wxExpr(void); @@ -105,12 +98,12 @@ class WXDLLEXPORT wxExpr else return 0; } - inline float RealValue(void) const { + inline double RealValue(void) const { if (type == wxExprReal) return value.real; else if (type == wxExprInteger) - return (float)value.integer; - else return (float)0.0; + return (double)value.integer; + else return (double)0.0; } inline wxString WordValue(void) const { @@ -118,7 +111,7 @@ class WXDLLEXPORT wxExpr return value.word; else if (type == wxExprString) return wxString(value.string); - else return wxString(""); + else return wxString(wxT("")); } inline wxString StringValue(void) const { @@ -126,7 +119,7 @@ class WXDLLEXPORT wxExpr return wxString(value.string); else if (type == wxExprWord) return wxString(value.word); - else return wxString(""); + else return wxString(wxT("")); } // Get nth arg of clause (starting from 1) @@ -145,9 +138,8 @@ class WXDLLEXPORT wxExpr wxExpr *AttributeValue(const wxString& word) const; // Use only for a clause wxString Functor(void) const; // Only for a clause bool IsFunctor(const wxString& s) const; // Only for a clause - void WriteClause(ostream& stream); // Write this expression as a top-level clause - void WriteExpr(ostream& stream); // Write as any other subexpression - void WriteLispExpr(ostream& stream); + void WriteClause(FILE* stream); // Write this expression as a top-level clause + void WriteExpr(FILE* stream); // Write as any other subexpression // Append an expression to a list void Append(wxExpr *expr); @@ -166,7 +158,7 @@ class WXDLLEXPORT wxExpr // This should really be called SetAttributeValue since any existing // attribute-value is deleted first. void AddAttributeValue(const wxString& attribute, long value); - void AddAttributeValue(const wxString& attribute, float value); + void AddAttributeValue(const wxString& attribute, double value); void AddAttributeValueWord(const wxString& attribute, const wxString& value); void AddAttributeValueString(const wxString& attribute, const wxString& value); void AddAttributeValue(const wxString& attribute, wxList *value); @@ -178,15 +170,17 @@ class WXDLLEXPORT wxExpr bool GetAttributeValue(const wxString& att, int& var) const; bool GetAttributeValue(const wxString& att, long& var) const; bool GetAttributeValue(const wxString& att, float& var) const; + bool GetAttributeValue(const wxString& att, double& var) const; bool GetAttributeValue(const wxString& att, wxString& var) const; // Word OR string -> string bool GetAttributeValue(const wxString& att, wxExpr **var) const; // Compatibility with old PrologIO - inline void AssignAttributeValue(char *att, int *var) const { GetAttributeValue(att, *var); } - inline void AssignAttributeValue(char *att, long *var) const { GetAttributeValue(att, *var); } - inline void AssignAttributeValue(char *att, float *var) const { GetAttributeValue(att, *var); } - inline void AssignAttributeValue(char *att, wxExpr **var) const { GetAttributeValue(att, var); } - void AssignAttributeValue(char *att, char **var) const ; // Word OR string -> string + inline void AssignAttributeValue(wxChar *att, int *var) const { GetAttributeValue(att, *var); } + inline void AssignAttributeValue(wxChar *att, long *var) const { GetAttributeValue(att, *var); } + inline void AssignAttributeValue(wxChar *att, float *var) const { GetAttributeValue(att, *var); } + inline void AssignAttributeValue(wxChar *att, double *var) const { GetAttributeValue(att, *var); } + inline void AssignAttributeValue(wxChar *att, wxExpr **var) const { GetAttributeValue(att, var); } + void AssignAttributeValue(wxChar *att, wxChar **var) const ; // Word OR string -> string // Add string items to list if the list attribute exists bool GetAttributeValueStringList(const wxString& att, wxList *var) const; @@ -196,84 +190,94 @@ class WXDLLEXPORT wxExpr // so we can index into the wxExpr database and fish out the pointer. inline void SetClientData(wxObject *data) { client_data = data; } inline wxObject *GetClientData(void) const { return client_data; } + + DECLARE_NO_COPY_CLASS(wxExpr) }; class WXDLLEXPORT wxExprDatabase: public wxList { - DECLARE_DYNAMIC_CLASS(wxExprDatabase) - private: - wxNode *position; // Where we are in a search - wxHashTable *hash_table; - wxString attribute_to_hash; - public: - int noErrors; - - wxExprDatabase(wxExprErrorHandler handler = 0); - - // Use hashing on both the functor, and the attribute of - // specified type (wxExprString or wxExprInteger) and name. - // So to find node 45 - // (i.e. match the clause node(id=45, ...)) - // it usually requires 1 look-up: the keys for functor and attribute - // are added together. - // Obviously if the attribute was missing in a clause, it would - // fail to be found by this method, but could be retrieved by a - // linear search using BeginFind and FindClauseByFunctor, - // or just searching through the list as per usual. - - wxExprDatabase(wxExprType type, const wxString& attribute, int size = 500, - wxExprErrorHandler handler = 0); - - ~wxExprDatabase(void); - - void BeginFind(void) ; // Initialise a search - wxExpr *FindClause(long id) ; // Find a term based on an integer id attribute - // e.g. node(id=23, type=rectangle, ....). - - // Find on basis of attribute/value pairs, e.g. type=rectangle - // This doesn't use hashing; it's a linear search. - wxExpr *FindClause(const wxString& word, const wxString& value); - wxExpr *FindClause(const wxString& word, long value); - wxExpr *FindClause(const wxString& word, float value); - wxExpr *FindClauseByFunctor(const wxString& functor); - - wxExpr *HashFind(const wxString& functor, const wxString& value) const; - wxExpr *HashFind(const wxString& functor, long value) const; - - void Append(wxExpr *expr); // Does cleverer things if hashing is on - void ClearDatabase(void); - inline int GetErrorCount() const { return noErrors; } - bool Read(const wxString& filename); - bool ReadFromString(const wxString& buffer); - bool Write(const wxString& fileName); - bool Write(ostream& stream); - void WriteLisp(ostream& stream); - - // Compatibility - inline bool ReadProlog(char *filename) { return Read(wxString(filename)); } - inline bool ReadPrologFromString(char *buffer) { return ReadFromString(wxString(buffer)); } - inline void WriteProlog(ostream& stream) { Write(stream); } +private: + wxNode *position; // Where we are in a search + wxHashTable *hash_table; + wxString attribute_to_hash; + +public: + int noErrors; + + wxExprDatabase(wxExprErrorHandler handler = 0); + + // Use hashing on both the functor, and the attribute of + // specified type (wxExprString or wxExprInteger) and name. + // So to find node 45 + // (i.e. match the clause node(id=45, ...)) + // it usually requires 1 look-up: the keys for functor and attribute + // are added together. + // Obviously if the attribute was missing in a clause, it would + // fail to be found by this method, but could be retrieved by a + // linear search using BeginFind and FindClauseByFunctor, + // or just searching through the list as per usual. + + wxExprDatabase(wxExprType type, const wxString& attribute, int size = 500, + wxExprErrorHandler handler = 0); + + ~wxExprDatabase(void); + + void BeginFind(void) ; // Initialise a search + wxExpr *FindClause(long id) ; // Find a term based on an integer id attribute + // e.g. node(id=23, type=rectangle, ....). + + // Find on basis of attribute/value pairs, e.g. type=rectangle + // This doesn't use hashing; it's a linear search. + wxExpr *FindClause(const wxString& word, const wxString& value); + wxExpr *FindClause(const wxString& word, long value); + wxExpr *FindClause(const wxString& word, double value); + wxExpr *FindClauseByFunctor(const wxString& functor); + + wxExpr *HashFind(const wxString& functor, const wxString& value) const; + wxExpr *HashFind(const wxString& functor, long value) const; + + void Append(wxExpr *expr); // Does cleverer things if hashing is on + void ClearDatabase(void); + inline int GetErrorCount() const { return noErrors; } + bool Read(const wxString& filename); + bool ReadFromString(const wxString& buffer); + bool Write(const wxString& fileName); + bool Write(FILE* stream); + + // Compatibility + inline bool ReadProlog(wxChar *filename) { return Read(wxString(filename)); } + inline bool ReadPrologFromString(char *buffer) + { + return ReadFromString(wxString(buffer, wxConvLibc)); + } + inline void WriteProlog(FILE* stream) { Write(stream); } + +private: + DECLARE_DYNAMIC_CLASS(wxExprDatabase) + DECLARE_NO_COPY_CLASS(wxExprDatabase) }; // Function call-style interface - some more convenience wrappers/unwrappers // Make a call -wxExpr* WXDLLEXPORT wxExprMakeCall(const wxString& functor ...); +WXDLLEXPORT wxExpr* wxExprMakeCall(const wxString& functor ...); #define wxExprMakeInteger(x) (new wxExpr((long)x)) -#define wxExprMakeReal(x) (new wxExpr((float)x)) +#define wxExprMakeReal(x) (new wxExpr((double)x)) #define wxExprMakeString(x) (new wxExpr(wxExprString, x)) #define wxExprMakeWord(x) (new wxExpr(wxExprWord, x)) #define wxExprMake(x) (new wxExpr(x)) // Checks functor -bool WXDLLEXPORT wxExprIsFunctor(wxExpr *expr, const wxString& functor); +WXDLLEXPORT bool wxExprIsFunctor(wxExpr *expr, const wxString& functor); // Temporary variable for communicating between wxexpr.cpp and YACC/LEX WXDLLEXPORT_DATA(extern wxExprDatabase*) thewxExprDatabase; // YACC/LEX can leave memory lying around... -extern "C" WXDLLEXPORT wxExprCleanUp(); +extern "C" WXDLLEXPORT int wxExprCleanUp(); -#endif +#endif // wxUSE_PROLOGIO + +#endif // _WX_WXEXPRH__