]> git.saurik.com Git - wxWidgets.git/blame - contrib/include/wx/applet/ifelsevar.h
added wxStaticCast, moved wxConstCast from wx/object.h to wx/defs.h for consistency
[wxWidgets.git] / contrib / include / wx / applet / ifelsevar.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 wxIfElseVariable Class, Dynamically constructed
26* objects representing variables in SSI #if, #else and #endif directives
27*
28****************************************************************************/
29
30#ifndef __WX_IFELSEVAR_H
31#define __WX_IFELSEVAR_H
32
574c939e
KB
33#include "wx/object.h"
34#include "wx/hash.h"
35
716cd410
KB
36/*--------------------------- Class Definitions ---------------------------*/
37
38/****************************************************************************
574c939e
KB
39RETURNS:
40The boolean value of the variable
41
716cd410 42REMARKS:
574c939e
KB
43To create new variables for the #if, #else and #endif HTML preprocessing
44blocks you need to derive classes from wxIfElseVariable and override the
45pure virtual GetValue function. However this should not be done directly
46but by using the BEGIN_IFELSE_VARIABLE and END_IFELSE_VARIABLE macros
716cd410
KB
47
48SEE ALSO:
574c939e
KB
49wxIfElsePrep, BEGIN_IFELSE_VARIABLE, END_IFELSE_VARIABLE
50****************************************************************************/
51typedef bool (*wxIfElseVariableGetValueFn)();
52
53/****************************************************************************
54REMARKS:
55wxIfElseVariable class Definition
716cd410
KB
56****************************************************************************/
57class wxIfElseVariable : public wxObject {
574c939e
KB
58protected:
59 const wxChar *m_varName;
60 wxIfElseVariableGetValueFn m_getValueFn;
61 static wxIfElseVariable *sm_first;
62 wxIfElseVariable *m_next;
63 static wxHashTable *sm_varTable;
64 bool forced;
65 bool forceVal;
66
67 static inline wxIfElseVariable *wxIfElseVariable::FindVariable(const wxChar *varName);
716cd410
KB
68
69public:
574c939e
KB
70 // Constructor to create the echo variable and register the class
71 wxIfElseVariable(
72 const char *varName,
73 wxIfElseVariableGetValueFn getValueFn);
74
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; }
716cd410 80
574c939e
KB
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);
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 wxIfElseVariable *wxIfElseVariable::FindVariable(
104 const wxChar *varName)
105{
106 if (sm_varTable)
107 return (wxIfElseVariable*)sm_varTable->Get(varName);
108 else {
109 wxIfElseVariable *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
KB
118
119/*--------------------------------- MACROS --------------------------------*/
120
121#define BEGIN_IFELSE_VARIABLE(name) \
574c939e
KB
122bool wxIfElseVariableFn##name(); \
123wxIfElseVariable wxIfElseVariable##name(#name,wxIfElseVariableFn##name); \
124bool wxIfElseVariableFn##name() { \
716cd410 125
d699f48b 126#define END_IFELSE_VARIABLE(returnval) \
716cd410
KB
127 return returnval; \
128 }
129
130#define IFELSE_VARIABLE(name, state) \
131 BEGIN_IFELSE_VARIABLE(##name##); \
d699f48b 132 END_IFELSE_VARIABLE(bool (state))
716cd410
KB
133
134#endif // __WX_IFELSEVAR_H
135