source: trunk/gsdl/src/recpt/action.h@ 754

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

chnaged arguments passed to many functions

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/**********************************************************************
2 *
3 * action.h --
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: action.h 754 1999-11-01 21:10:57Z sjboddie $
25 *
26 *********************************************************************/
27
28
29#ifndef ACTION_H
30#define ACTION_H
31
32#include "gsdlconf.h"
33#include "text_t.h"
34#include "cgiargs.h"
35#include "display.h"
36#include "recptproto.h"
37#include "browserclass.h"
38
39#if defined(GSDL_USE_OBJECTSPACE)
40# include <ospace\std\iostream>
41#elif defined(GSDL_USE_IOS_H)
42# include <iostream.h>
43#else
44# include <iostream>
45#endif
46
47
48class action {
49protected:
50 cgiargsinfoclass argsinfo;
51
52
53public:
54 action ();
55 virtual ~action ();
56
57 // configure should be called once for each configuration line
58 virtual void configure (const text_t &key, const text_tarray &cfgline);
59
60 // init should be called after all the configuration is done but
61 // before any other methods are called
62 virtual bool init (ostream &logout);
63
64 // returns the "a" argument value that will specify this action
65 // this name should be short but does not have to be one character
66 // long
67 virtual text_t get_action_name ();
68
69 // check_cgiargs should be called before get_cgihead_info,
70 // define_external_macros, and do_action. If an error is found
71 // a message will be written to logout, if the error is severe
72 // then the function will return false and no page content
73 // should be produced based on the arguments.
74 virtual bool check_cgiargs (cgiargsinfoclass &argsinfo, cgiargsclass &args,
75 ostream &logout);
76
77 // check_external_cgiargs should be called after check_cgiargs
78 // for all actions. It should only be used to override some other
79 // normal behaviour, for example, producing a login page when
80 // the requested page needs authentication.
81 virtual bool check_external_cgiargs (cgiargsinfoclass &argsinfo,
82 cgiargsclass &args,
83 outconvertclass &outconvert,
84 const text_t &saveconf,
85 ostream &logout);
86
87 // get_cgihead_info determines the cgi header information for
88 // a set of cgi arguments. If response contains location then
89 // response_data contains the redirect address. If reponse
90 // contains content then reponse_data contains the content-type.
91 // Note that images can now be produced by the receptionist.
92 virtual void get_cgihead_info (cgiargsclass &args, recptprotolistclass *protos,
93 response_t &response, text_t &response_data,
94 ostream &logout);
95
96 // uses_display should return true if the receptionist should return
97 // true if the display class is needed to output the page content.
98 // The default is to return true.
99 virtual bool uses_display (cgiargsclass &args);
100
101 // define all the macros which are related to pages generated
102 // by this action
103 virtual void define_internal_macros (displayclass &disp, cgiargsclass &args,
104 recptprotolistclass *protos, ostream &logout);
105
106 // define all the macros which might be used by other actions
107 // to produce pages. These macros should be well documented.
108 virtual void define_external_macros (displayclass &disp, cgiargsclass &args,
109 recptprotolistclass *protos, ostream &logout);
110
111 // returns false if there was an error which prevented the action
112 // from outputing anything.
113 virtual bool do_action (cgiargsclass &args, recptprotolistclass *protos,
114 browsermapclass *browsers, displayclass &disp,
115 outconvertclass &outconvert, ostream &textout,
116 ostream &logout);
117
118 // getargsinfo should be called after all configuration files
119 // have been read
120 cgiargsinfoclass getargsinfo () {return argsinfo;};
121};
122
123
124// The actionptr function does not 'own' the action. The
125// action should be deleted by the code which created it.
126class actionptr {
127public:
128 action *a;
129
130 actionptr () {a=NULL;}
131};
132
133bool operator==(const actionptr &x, const actionptr &y);
134bool operator<(const actionptr &x, const actionptr &y);
135
136typedef map<text_t, actionptr, lttext_t> actionptrmap;
137
138// contains a list of actions indexed by their name
139class actionmapclass {
140protected:
141 actionptrmap actionptrs;
142
143public:
144 // type support for actionptrmap
145 typedef actionptrmap::iterator iterator;
146 typedef actionptrmap::const_iterator const_iterator;
147 typedef actionptrmap::reference reference;
148 typedef actionptrmap::const_reference const_reference;
149 typedef actionptrmap::size_type size_type;
150
151 typedef actionptrmap::difference_type difference_type;
152 typedef actionptrmap::const_reverse_iterator const_reverse_iterator;
153 typedef actionptrmap::reverse_iterator reverse_iterator;
154
155 // basic container support
156 iterator begin () {return actionptrs.begin();}
157 const_iterator begin () const {return actionptrs.begin();}
158 iterator end () {return actionptrs.end();}
159 const_iterator end () const {return actionptrs.end();}
160
161 void erase(iterator pos) {actionptrs.erase(pos);}
162 void erase(iterator first, iterator last) {actionptrs.erase(first, last);}
163 actionmapclass &operator=(const actionmapclass &x) {actionptrs=x.actionptrs;return *this;}
164
165 bool empty () const {return actionptrs.empty();}
166 size_type size() const {return actionptrs.size();}
167
168
169 // added functionality
170 void clear () {actionptrs.erase(actionptrs.begin(),actionptrs.end());}
171
172 // theaction remains the property of the calling code but
173 // should not be deleted until it is removed from this list.
174 void addaction (action *theaction);
175
176 // getaction will return NULL if the action could not be found
177 action *getaction (const text_t &key);
178};
179
180
181#endif
Note: See TracBrowser for help on using the repository browser.