source: branches/New_Config_Format-branch/gsdl/lib/display.h@ 1279

Last change on this file since 1279 was 1279, checked in by sjboddie, 24 years ago

merged changes to trunk into New_Config_Format branch

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/**********************************************************************
2 *
3 * display.h -- Context sensitive macro language
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * $Id: display.h 1279 2000-07-12 22:21:53Z sjboddie $
25 *
26 *********************************************************************/
27
28
29#ifndef DISPLAY_H
30#define DISPLAY_H
31
32#include "gsdlconf.h"
33#include "text_t.h"
34
35
36#if defined(GSDL_USE_OBJECTSPACE)
37# include <ospace\std\vector>
38# include <ospace\std\list>
39# include <ospace\std\set>
40# include <ospace\std\map>
41# include <ospace\std\algorithm>
42#elif defined(GSDL_USE_STL_H)
43# include <vector.h>
44# include <list.h>
45# include <set.h>
46# include <map.h>
47# if defined(GSDL_USE_ALGO_H)
48# include <algo.h>
49# else
50# include <algorithm.h>
51# endif
52#else
53# include <vector>
54# include <list>
55# include <set>
56# include <map>
57# include <algorithm>
58#endif
59
60#if defined(GSDL_USE_OBJECTSPACE)
61# include <ospace\std\iostream>
62# include <ospace\std\fstream>
63#elif defined(GSDL_USE_IOS_H)
64# include <iostream.h>
65# include <fstream.h>
66
67#define unistream ifstream
68
69#else
70# include <iostream>
71# include <fstream>
72
73typedef std::basic_ifstream<unsigned char> unistream;
74
75#endif
76
77
78// use the standard namespace
79#if defined(GSDL_USE_OBJECTSPACE)
80using namespace ospace::std;
81#elif !defined(GSDL_NAMESPACE_BROKEN)
82using namespace std;
83#endif
84
85
86
87// MAXRECURSIONDEPTH is a cutoff to catch
88// cyclic macros (a includes b and b includes a)
89#define MAXRECURSIONDEPTH 30
90
91// class prototypes
92class defaultmacros_t;
93class currentmacros_t;
94
95// a few supporting types
96// fileelement isn't finished yet, I have to find out
97// more about getting information about files
98struct fileinfoelement
99{
100 int otherinfo;
101};
102
103inline bool operator==(const fileinfoelement &x, const fileinfoelement &y) {
104 return (x.otherinfo==y.otherinfo);
105}
106
107inline bool operator<(const fileinfoelement &x, const fileinfoelement &y) {
108 return (x.otherinfo<y.otherinfo);
109}
110
111typedef map<text_t, fileinfoelement, lttext_t> fileinfomap;
112
113
114typedef map<text_t, text_t, lttext_t> paramhashtype;
115
116
117struct paramspec
118{
119 double spec;
120 text_t param;
121};
122
123inline bool operator==(const paramspec& x, const paramspec& y)
124{
125 return ((x.spec == y.spec) && (x.param == y.param));
126}
127
128inline bool operator!=(const paramspec& x, const paramspec& y)
129{
130 return ((x.spec != y.spec) || (x.param != y.param));
131}
132
133// note: paramspec is sorted by reverse spec and then param
134
135inline bool operator<(const paramspec& x, const paramspec& y)
136{
137 return ((x.spec > y.spec) ||
138 ((x.spec == y.spec) && (x.param < y.param)));
139}
140
141inline bool operator>(const paramspec& x, const paramspec& y)
142{
143 return ((x.spec < y.spec) ||
144 ((x.spec == y.spec) && (x.param > y.param)));
145}
146
147typedef vector<paramspec> paramspeclist;
148
149
150// NOTE: when macros are used within text they should have
151// underscores '_' on both sides, however, in calls to
152// setdefaultmacro and setmacro they should not have the
153// underscores. So you might have
154//
155// setmacro ("aname", "query", " some text ");
156// expandstring ("_aname_", expandedtext);
157//
158// because the input to expandstring is a block of text, not
159// a macroname
160
161class displayclass
162{
163public:
164 displayclass ();
165 ~displayclass ();
166
167 // isdefaultmacro sees if there is an entry in the list of
168 // default macros with the given package and macro name
169 // returns 0 if no macros in the package or in the global package
170 // were found
171 // 1 if no macros in the package were found but a macro
172 // in the global package was found
173 // 2 if a macro in the given package was found
174 int isdefaultmacro (text_t package, const text_t &macroname);
175
176 // setdefaultmacro adds an entry to the list of default macros
177 // returns 0 if there was no error,
178 // -1 if it redefined a macro
179 // -2 if it hid a Global macro
180 // -3 if it redefined a macro and hid a Global macro
181 // -4 if no macroname was supplied
182 int setdefaultmacro (text_t package, const text_t &macroname,
183 text_t params, const text_t &macrovalue);
184
185 // loads a default macro file (if it isn't already loaded)
186 // returns 0 if didn't need to load the file (it was already loaded)
187 // 1 if was (re)loaded
188 // -1 an error occurred while trying to load the file
189 int loaddefaultmacros (text_t thisfilename);
190
191 // prepares to create a page: deletes all macros set with
192 // 'setmacro', checks all the default macro files to see
193 // if any need reloading, and sets the page parameters.
194 void openpage (const text_t &thispageparams,
195 const text_t &thisprecedence);
196
197 // changes the parameters for the current page.
198 void setpageparams (text_t thispageparams,
199 text_t thisprecedence);
200
201 // overrides (or sets) a macro for the current page.
202 // returns 0 if there was no error,
203 // -1 if it redefined a macro
204 // -4 if no macroname was supplied
205 int setmacro (const text_t &macroname,
206 text_t package,
207 const text_t &macrovalue);
208
209 void expandstring (const text_t &inputtext, text_t &outputtext);
210 void expandstring (text_t package, const text_t &inputtext,
211 text_t &outputtext, int recursiondepth = 0);
212
213 // these functions are not ment to be used directly, they are used to permit
214 // concise stream output like:
215 // cout << text_t2ascii << display << "_amacro_" << "_anothermacro_";
216 void setconvertclass (outconvertclass *theoutc) {outc = theoutc;}
217 outconvertclass *getconvertclass () {return outc;}
218
219 // say where any error logging goes, this can be NULL
220 // if no error logging is desired - returns previous value
221 ostream *setlogout (ostream *thelogout);
222
223 // debug stuff
224 void printdefaultmacros ();
225 void printallparams ();
226
227protected:
228 // special variables to permit trickly output
229 outconvertclass *outc;
230
231 // general variables
232 text_tset allparams; // possible parameter combinations
233 defaultmacros_t *defaultmacros;
234 fileinfomap *defaultfiles;
235
236 // variables to do with a page expansion
237 text_t params;
238 text_t precedence;
239 paramspeclist *orderparamlist; // ordered by specificness
240 currentmacros_t *currentmacros; // only macros set by setmacro
241
242 // logging variable
243 ostream *logout;
244
245 // reloads any default macro files which have changed
246 // returns 0 no errors occurred
247 // -1 an error occurred while trying to load one of the files
248 int checkdefaultmacrofiles ();
249
250 int setdefaultmacro (text_t package, const text_t &macroname,
251 text_t params, const text_t &filename,
252 const text_t &macrovalue);
253
254 // evaluates a boolean expression
255 bool boolexpr (text_t package, const text_t &expr, int recursiondepth);
256
257 // (recursively) expand out a macro
258 // returns true if the macro was found
259 // false if the macro was not found
260 bool macro (const text_t &macroname, text_t macropackage,
261 const text_t &macroparam, text_t &outputtext,
262 int recursiondepth);
263};
264
265
266displayclass &operator<< (outconvertclass &theoutc, displayclass &display);
267displayclass &operator<< (displayclass &display, const text_t &t);
268
269#endif
270
Note: See TracBrowser for help on using the repository browser.