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 wxIfElseVariable Class, Dynamically constructed
26 * objects representing variables in SSI #if, #else and #endif directives
28 ****************************************************************************/
30 #ifndef __WX_IFELSEVAR_H
31 #define __WX_IFELSEVAR_H
33 #include "wx/object.h"
36 /*--------------------------- Class Definitions ---------------------------*/
38 /****************************************************************************
40 The boolean value of the variable
43 To create new variables for the #if, #else and #endif HTML preprocessing
44 blocks you need to derive classes from wxIfElseVariable and override the
45 pure virtual GetValue function. However this should not be done directly
46 but by using the BEGIN_IFELSE_VARIABLE and END_IFELSE_VARIABLE macros
49 wxIfElsePrep, BEGIN_IFELSE_VARIABLE, END_IFELSE_VARIABLE
50 ****************************************************************************/
51 typedef bool (*wxIfElseVariableGetValueFn
)();
53 /****************************************************************************
55 wxIfElseVariable class Definition
56 ****************************************************************************/
57 class wxIfElseVariable
: public wxObject
{
59 const wxChar
*m_varName
;
60 wxIfElseVariableGetValueFn m_getValueFn
;
61 static wxIfElseVariable
*sm_first
;
62 wxIfElseVariable
*m_next
;
63 static wxHashTable
*sm_varTable
;
67 static inline wxIfElseVariable
*wxIfElseVariable::FindVariable(const wxChar
*varName
);
70 // Constructor to create the echo variable and register the class
73 wxIfElseVariableGetValueFn getValueFn
);
75 // Member variable access functions
76 const wxChar
*GetClassName() const { return m_varName
; }
77 wxIfElseVariableGetValueFn
GetValueFn() const { return m_getValueFn
; }
78 static const wxIfElseVariable
* GetFirst() { return sm_first
; }
79 const wxIfElseVariable
* GetNext() const { return m_next
; }
81 // Static functions to retrieve any variable avaliable
82 static bool GetValue(const wxChar
*varName
);
83 static bool Exists(const wxChar
*varName
);
84 static void Force(const wxChar
*varName
, bool val
);
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 wxIfElseVariable
*wxIfElseVariable::FindVariable(
104 const wxChar
*varName
)
107 return (wxIfElseVariable
*)sm_varTable
->Get(varName
);
109 wxIfElseVariable
*info
= sm_first
;
111 if (info
->m_varName
&& wxStrcmp(info
->m_varName
, varName
) == 0)
119 /*--------------------------------- MACROS --------------------------------*/
121 #define BEGIN_IFELSE_VARIABLE(name) \
122 bool wxIfElseVariableFn##name(); \
123 wxIfElseVariable wxIfElseVariable##name(#name,wxIfElseVariableFn##name); \
124 bool wxIfElseVariableFn##name() { \
126 #define END_IFELSE_VARIABLE(returnval) \
130 #define IFELSE_VARIABLE(name, state) \
131 BEGIN_IFELSE_VARIABLE(##name##); \
132 END_IFELSE_VARIABLE(bool (state))
134 #endif // __WX_IFELSEVAR_H