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

Last change on this file since 146 was 146, checked in by rjmcnab, 25 years ago

Developed the idea of an "action" and having them define the cgi arguments
which they need and how those cgi arguments function.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/**********************************************************************
2 *
3 * action.h --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: action.h 146 1999-02-04 10:00:57Z rjmcnab $
9 *
10 *********************************************************************/
11
12
13#ifndef ACTION_H
14#define ACTION_H
15
16#include "gsdlconf.h"
17#include "text_t.h"
18#include "cgiargs.h"
19
20#if defined(GSDL_USE_OBJECTSPACE)
21# include <ospace\std\iostream>
22#elif defined(GSDL_USE_IOS_H)
23# include <iostream.h>
24#else
25# include <iostream>
26#endif
27
28
29class action {
30protected:
31 cgiargsinfoclass argsinfo;
32
33public:
34 action ();
35 virtual ~action ();
36
37 // returns the "a" argument value that will specify this action
38 // this name should be short but does not have to be one character
39 // long
40 virtual text_t get_action_name ();
41
42 // response_t is used to inform the calling code what type of
43 // cgi header it should produce
44 // eventually this should reside in cgiutils.h
45 enum response_t {location, content};
46
47 // get_cgihead_info determines the cgi header information for
48 // a set of cgi arguments. If response contains location then
49 // response_data contains the redirect address. If reponse
50 // contains content then reponse_data contains the content-type.
51 // Note that images can now be produced by the receptionist.
52 virtual void get_cgihead_info (cgiargsclass &args, response_t &response,
53 text_t &response_data, ostream &logout);
54
55 // returns false if there was an error which prevented the action
56 // from outputing anything.
57 virtual bool do_action (cgiargsclass &args, outconvertclass &outconvert,
58 ostream &textout, ostream &logout);
59
60 // configure should be called once for each configuration line
61 virtual void configure (const text_tarray &cfgline);
62
63 // getargsinfo should be called after all configuration files
64 // have been read
65 cgiargsinfoclass getargsinfo () {return argsinfo;};
66};
67
68
69// actionptr is used to keep track of pointers to actions
70// sub classes of action might not be the same size so
71// you probably don't want to treat a sub class as a standard
72// "action" class when it comes to copying etc -- anyone got
73// a better way to do this ????
74class actionptr {
75public:
76 action *a;
77
78 actionptr () {a=NULL;}
79 ~actionptr () {if (a!=NULL) delete a; a=NULL;}
80};
81
82typedef map<text_t, actionptr, lttext_t> actionptrmap;
83
84// contains a list of actions indexed by their name
85class actionmapclass {
86protected:
87 actionptrmap actionptrs;
88
89public:
90 // type support for actionptrmap
91 typedef actionptrmap::iterator iterator;
92 typedef actionptrmap::const_iterator const_iterator;
93 typedef actionptrmap::reference reference;
94 typedef actionptrmap::const_reference const_reference;
95 typedef actionptrmap::size_type size_type;
96
97 typedef actionptrmap::difference_type difference_type;
98 typedef actionptrmap::const_reverse_iterator const_reverse_iterator;
99 typedef actionptrmap::reverse_iterator reverse_iterator;
100
101 // constructors
102 actionmapclass ();
103
104 // basic container support
105 iterator begin () {return actionptrs.begin();}
106 const_iterator begin () const {return actionptrs.begin();}
107 iterator end () {return actionptrs.end();}
108 const_iterator end () const {return actionptrs.end();}
109
110 void erase(iterator pos) {actionptrs.erase(pos);}
111 void erase(iterator first, iterator last) {actionptrs.erase(first, last);}
112 actionmapclass &operator=(const actionmapclass &x) {actionptrs=x.actionptrs;return *this;}
113
114 bool empty () const {return actionptrs.empty();}
115 size_type size() const {return actionptrs.size();}
116
117
118 // added functionality
119 void clear () {actionptrs.erase(actionptrs.begin(),actionptrs.end());}
120
121 // theaction becomes the property of this class after addaction
122 // therefore theaction should always be created using new but
123 // not deleted after the call to addaction.
124 void addaction (action *theaction);
125
126 // getaction will return NULL if the action could not be found
127 action *getaction (const text_t &key);
128};
129
130
131#endif
Note: See TracBrowser for help on using the repository browser.