File: GenericEventHandler.h

package info (click to toggle)
jade 1.2.1-43
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 8,808 kB
  • ctags: 16,989
  • sloc: cpp: 120,657; sh: 10,452; ansic: 8,228; perl: 378; makefile: 296; sed: 5
file content (127 lines) | stat: -rw-r--r-- 3,861 bytes parent folder | download | duplicates (22)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright (c) 1995, 1996 James Clark
// See the file COPYING for copying permission.

#ifndef GenericEventHandler_INCLUDED
#define GenericEventHandler_INCLUDED 1

#ifdef __GNUG__
#pragma interface
#endif

// Must include Boolean.h before SGMLApplication.h.

#include "Boolean.h"
#include "SGMLApplication.h"
#include "Event.h"
#include "MessageReporter.h"
#include "ErrorCountEventHandler.h"

#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif

class SP_API GenericEventHandler : public ErrorCountEventHandler {
public:
  GenericEventHandler(SGMLApplication &, bool generalEntities);
  ~GenericEventHandler();
  void message(MessageEvent *);
  void appinfo(AppinfoEvent *);
  void startDtd(StartDtdEvent *);
  void endDtd(EndDtdEvent *);
  void endProlog(EndPrologEvent *);
  void entityDefaulted(EntityDefaultedEvent *);
  void startElement(StartElementEvent *);
  void endElement(EndElementEvent *);
  void data(DataEvent *);
  void pi(PiEvent *);
  void sdataEntity(SdataEntityEvent *);
  void externalDataEntity(ExternalDataEntityEvent *);
  void subdocEntity(SubdocEntityEvent *);
  void nonSgmlChar(NonSgmlCharEvent *);
  void commentDecl(CommentDeclEvent *);
  void ignoredChars(IgnoredCharsEvent *);
  void markedSectionStart(MarkedSectionStartEvent *);
  void markedSectionEnd(MarkedSectionEndEvent *);
  void *allocate(size_t);
  void freeAll();
  void freeAll1();

  struct Block {
    Block *next;
    char *mem;
    size_t size;
  };
  static void setString(SGMLApplication::CharString &, const StringC &);
  static void clearString(SGMLApplication::CharString &);
  virtual void reportMessage(const Message &msg, StringC &) = 0;
private:
  GenericEventHandler(const GenericEventHandler &); // undefined
  void operator=(const GenericEventHandler &);  // undefined
  void setLocation(SGMLApplication::Position &, const Location &);
  void setLocation1(SGMLApplication::Position &, const Location &);
  void setAttributes(const SGMLApplication::Attribute *&attributes,
		     const AttributeList &attributeList);
  void setExternalId(SGMLApplication::ExternalId &to,
		     const ExternalId &from);
  void setEntity(SGMLApplication::Entity &to, const Entity &from);
  void setNotation(SGMLApplication::Notation &, const Notation &notation);
  static void clearNotation(SGMLApplication::Notation &);
  static void clearExternalId(SGMLApplication::ExternalId &);
  ConstPtr<Origin> lastOrigin_;
  SGMLApplication::OpenEntityPtr openEntityPtr_;
  size_t firstBlockUsed_;
  size_t firstBlockSpare_;
  Block *freeBlocks_;
  Block *allocBlocks_;
  bool generalEntities_;
  SGMLApplication *app_;
};

class SP_API MsgGenericEventHandler : public GenericEventHandler {
public:
  MsgGenericEventHandler(SGMLApplication &, 
			 bool generalEntities,
			 MessageReporter &reporter,
			 const bool *messagesInhibitedPtr);
  void reportMessage(const Message &msg, StringC &);
private:
  MsgGenericEventHandler(const MsgGenericEventHandler &); // undefined
  void operator=(const MsgGenericEventHandler &);  // undefined
  struct WrapReporter {
    WrapReporter(MessageReporter *r) : reporter(r), origStream(0) {
      origStream = reporter->releaseMessageStream();
      reporter->setMessageStream(&strStream);
    }
    ~WrapReporter() {
      if (origStream) {
	reporter->releaseMessageStream();
	reporter->setMessageStream(origStream);
      }
    }
    MessageReporter *reporter;
    OutputCharStream *origStream;
    StrOutputCharStream strStream;
  };
  const bool *messagesInhibitedPtr_;
  MessageReporter *reporter_;
};

inline void
GenericEventHandler::setString(SGMLApplication::CharString &to,
			   const StringC &from)
{
  to.ptr = from.data();
  to.len = from.size();
}

inline
void GenericEventHandler::clearString(SGMLApplication::CharString &to)
{
  to.len = 0;
}

#ifdef SP_NAMESPACE
}
#endif

#endif /* not GenericEventHandler_INCLUDED */