1 /****************************************************************************
3 * wxWindows HTML Applet Package
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
8 * ========================================================================
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
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.
20 * ========================================================================
25 * Description: Header file for wxEchoVariable Class, Dynamically constructed
26 * objects representing variables in SSI #echo directive
28 ****************************************************************************/
30 #ifndef __WX_ECHOVAR_H
31 #define __WX_ECHOVAR_H
33 #include "wx/object.h"
36 /*--------------------------- Class Definitions ---------------------------*/
38 /****************************************************************************
40 The string value of the variable
43 parms - Optional parameter string passed from parm= field in HTML
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
52 wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE
53 ****************************************************************************/
54 typedef wxString (*wxEchoVariableGetValueFn
)(const char *parms
);
56 /****************************************************************************
58 wxEchoVariable class Definition
59 ****************************************************************************/
60 class wxEchoVariable
: public wxObject
{
62 const wxChar
*m_varName
;
63 wxEchoVariableGetValueFn m_getValueFn
;
64 static wxEchoVariable
*sm_first
;
65 wxEchoVariable
*m_next
;
66 static wxHashTable
*sm_varTable
;
68 static inline wxEchoVariable
*wxEchoVariable::FindVariable(const wxChar
*varName
);
71 // Constructor to create the echo variable and register the class
74 wxEchoVariableGetValueFn getValueFn
);
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
; }
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
);
86 // Initializes parent pointers and hash table for fast searching.
87 static void Initialize();
89 // Cleans up hash table used for fast searching.
90 static void CleanUp();
93 /****************************************************************************
95 class - Name of class for echo variable to find
98 Pointer to the echo variable class
101 Inline helper function to find the echo variable from it's class name.
102 ****************************************************************************/
103 inline wxEchoVariable
*wxEchoVariable::FindVariable(
104 const wxChar
*varName
)
107 return (wxEchoVariable
*)sm_varTable
->Get(varName
);
109 wxEchoVariable
*info
= sm_first
;
111 if (info
->m_varName
&& wxStrcmp(info
->m_varName
, varName
) == 0)
119 /*--------------------------------- MACROS --------------------------------*/
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);
127 #define END_ECHO_VARIABLE(returnval) \
131 #define STRING_ECHO_VARIABLE(name, string) \
132 BEGIN_ECHO_VARIABLE(##name##); \
133 END_ECHO_VARIABLE(wxString(##string##))
135 #endif // __WX_ECHOVAR_H