]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/applet/echovar.h
Merges from Scitech Branch (George Davison):
[wxWidgets.git] / contrib / include / wx / applet / echovar.h
1 /****************************************************************************
2 *
3 * wxWindows HTML Applet Package
4 *
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
6 * All rights reserved.
7 *
8 * ========================================================================
9 *
10 * The contents of this file are subject to the wxWindows License
11 * Version 3.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.wxwindows.org/licence3.txt
14 *
15 * Software distributed under the License is distributed on an
16 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
19 *
20 * ========================================================================
21 *
22 * Language: ANSI C++
23 * Environment: Any
24 *
25 * Description: Header file for wxEchoVariable Class, Dynamically constructed
26 * objects representing variables in SSI #echo directive
27 *
28 ****************************************************************************/
29
30 #ifndef __WX_ECHOVAR_H
31 #define __WX_ECHOVAR_H
32
33 #include "wx/object.h"
34 #include "wx/hash.h"
35
36 /*--------------------------- Class Definitions ---------------------------*/
37
38 /****************************************************************************
39 RETURNS:
40 The string value of the variable
41
42 PARAMETERS:
43 parms - Optional parameter string passed from parm= field in HTML
44
45 REMARKS:
46 To create new variables for the #echo HTML preprocessing directives
47 you need to derive classes from wxEchoVariable and override the
48 pure virtual GetValue function. However this should not be done directly
49 but by using the BEGIN_ECHO_VARIABLE and END_ECHO_VARIABLE macros
50
51 SEE ALSO:
52 wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE
53 ****************************************************************************/
54 typedef wxString (*wxEchoVariableGetValueFn)(const char *parms);
55
56 /****************************************************************************
57 REMARKS:
58 wxEchoVariable class Definition
59 ****************************************************************************/
60 class wxEchoVariable : public wxObject {
61 protected:
62 const wxChar *m_varName;
63 wxEchoVariableGetValueFn m_getValueFn;
64 static wxEchoVariable *sm_first;
65 wxEchoVariable *m_next;
66 static wxHashTable *sm_varTable;
67
68 static inline wxEchoVariable *wxEchoVariable::FindVariable(const wxChar *varName);
69
70 public:
71 // Constructor to create the echo variable and register the class
72 wxEchoVariable(
73 const char *varName,
74 wxEchoVariableGetValueFn getValueFn);
75
76 // Member variable access functions
77 const wxChar *GetClassName() const { return m_varName; }
78 wxEchoVariableGetValueFn GetValueFn() const { return m_getValueFn; }
79 static const wxEchoVariable* GetFirst() { return sm_first; }
80 const wxEchoVariable* GetNext() const { return m_next; }
81
82 // Static functions to retrieve any variable avaliable
83 static wxString GetValue(const wxChar *varName,const wxChar *parms = NULL);
84 static bool Exists(const wxChar *varName);
85
86 // Initializes parent pointers and hash table for fast searching.
87 static void Initialize();
88
89 // Cleans up hash table used for fast searching.
90 static void CleanUp();
91 };
92
93 /****************************************************************************
94 PARAMETERS:
95 class - Name of class for echo variable to find
96
97 RETURNS:
98 Pointer to the echo variable class
99
100 REMARKS:
101 Inline helper function to find the echo variable from it's class name.
102 ****************************************************************************/
103 inline wxEchoVariable *wxEchoVariable::FindVariable(
104 const wxChar *varName)
105 {
106 if (sm_varTable)
107 return (wxEchoVariable*)sm_varTable->Get(varName);
108 else {
109 wxEchoVariable *info = sm_first;
110 while (info) {
111 if (info->m_varName && wxStrcmp(info->m_varName, varName) == 0)
112 return info;
113 info = info->m_next;
114 }
115 return NULL;
116 }
117 }
118
119 /*--------------------------------- MACROS --------------------------------*/
120
121 #define BEGIN_ECHO_VARIABLE(name) \
122 wxString wxEchoVariableFn##name(const char *parms); \
123 wxEchoVariable wxEchoVariable##name(#name,wxEchoVariableFn##name); \
124 wxString wxEchoVariableFn##name(const char *parms) { \
125 wxString _BEV_parm = wxString(parms);
126
127 #define END_ECHO_VARIABLE(returnval) \
128 return returnval; \
129 }
130
131 #define STRING_ECHO_VARIABLE(name, string) \
132 BEGIN_ECHO_VARIABLE(##name##); \
133 END_ECHO_VARIABLE(wxString(##string##))
134
135 #endif // __WX_ECHOVAR_H
136