source: trunk/gsdl/lib/display.h@ 3012

Last change on this file since 3012 was 3012, checked in by jrm21, 22 years ago

istream.get(char&) caused funny problems with gcc3 so they've been replaced
with char=istream.get() instead.

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