]> git.saurik.com Git - wxWidgets.git/blame - contrib/include/wx/applet/echovar.h
[ 1176516 ] argv datatype has changed (char in docs but really wxChar)
[wxWidgets.git] / contrib / include / wx / applet / echovar.h
CommitLineData
716cd410
KB
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
574c939e
KB
33#include "wx/object.h"
34#include "wx/hash.h"
35
716cd410
KB
36/*--------------------------- Class Definitions ---------------------------*/
37
574c939e
KB
38/****************************************************************************
39RETURNS:
40The string value of the variable
41
42PARAMETERS:
43parms - Optional parameter string passed from parm= field in HTML
44
45REMARKS:
46To create new variables for the #echo HTML preprocessing directives
47you need to derive classes from wxEchoVariable and override the
48pure virtual GetValue function. However this should not be done directly
49but by using the BEGIN_ECHO_VARIABLE and END_ECHO_VARIABLE macros
50
51SEE ALSO:
52wxEchoPrep, BEGIN_ECHO_VARIABLE, END_ECHO_VARIABLE
53****************************************************************************/
54typedef wxString (*wxEchoVariableGetValueFn)(const char *parms);
55
716cd410
KB
56/****************************************************************************
57REMARKS:
58wxEchoVariable class Definition
59****************************************************************************/
60class wxEchoVariable : public wxObject {
574c939e
KB
61protected:
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);
716cd410
KB
69
70public:
574c939e
KB
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; }
716cd410 81
574c939e
KB
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);
716cd410 85
574c939e
KB
86 // Initializes parent pointers and hash table for fast searching.
87 static void Initialize();
716cd410 88
574c939e
KB
89 // Cleans up hash table used for fast searching.
90 static void CleanUp();
91 };
92
93/****************************************************************************
94PARAMETERS:
95class - Name of class for echo variable to find
716cd410 96
574c939e
KB
97RETURNS:
98Pointer to the echo variable class
716cd410 99
574c939e
KB
100REMARKS:
101Inline helper function to find the echo variable from it's class name.
102****************************************************************************/
103inline 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}
716cd410 118
716cd410
KB
119/*--------------------------------- MACROS --------------------------------*/
120
716cd410 121#define BEGIN_ECHO_VARIABLE(name) \
574c939e
KB
122wxString wxEchoVariableFn##name(const char *parms); \
123wxEchoVariable wxEchoVariable##name(#name,wxEchoVariableFn##name); \
124wxString wxEchoVariableFn##name(const char *parms) { \
716cd410
KB
125 wxString _BEV_parm = wxString(parms);
126
d699f48b 127#define END_ECHO_VARIABLE(returnval) \
716cd410
KB
128 return returnval; \
129 }
130
131#define STRING_ECHO_VARIABLE(name, string) \
132 BEGIN_ECHO_VARIABLE(##name##); \
d699f48b 133 END_ECHO_VARIABLE(wxString(##string##))
716cd410
KB
134
135#endif // __WX_ECHOVAR_H
136