Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / nsgmls / ContentState.h
1 /* $XConsortium: ContentState.h /main/1 1996/07/29 16:48:27 cde-hp $ */
2 // Copyright (c) 1994, 1996 James Clark
3 // See the file COPYING for copying permission.
4
5 #ifndef ContentState_INCLUDED
6 #define ContentState_INCLUDED 1
7
8 #ifdef __GNUG__
9 #pragma interface
10 #endif
11
12 #include <stddef.h>
13 #include "OpenElement.h"
14 #include "IList.h"
15 #include "Vector.h"
16 #include "Message.h"
17 #include "Dtd.h"
18 #include "Mode.h"
19 #include "Boolean.h"
20
21 #ifdef SP_NAMESPACE
22 namespace SP_NAMESPACE {
23 #endif
24
25 class SP_API ContentState {
26 public:
27   ContentState();
28   void startContent(const Dtd &);
29   void pushElement(OpenElement *);
30   OpenElement *popSaveElement();
31   void popElement();
32   OpenElement &currentElement();
33   const OpenElement &currentElement() const;
34   void getOpenElementInfo(Vector<OpenElementInfo> &,
35                           const StringC &rniPcdata) const;
36   unsigned tagLevel() const;
37   Boolean elementIsIncluded(const ElementType *) const;
38   Boolean elementIsExcluded(const ElementType *) const;
39   Boolean elementIsOpen(const ElementType *) const;
40   Boolean afterDocumentElement() const;
41   const ElementType *lastEndedElementType() const;
42   Mode contentMode() const;
43   const ElementType *lookupCreateUndefinedElement(const StringC &,
44                                                   const Location &);
45   Boolean checkImplyLoop(unsigned);
46   static const ShortReferenceMap theEmptyMap;
47 private:
48   IList<OpenElement> openElements_;
49   Vector<unsigned> openElementCount_;
50   Vector<unsigned> includeCount_;
51   Vector<unsigned> excludeCount_;
52   unsigned totalExcludeCount_;
53   unsigned tagLevel_;
54   unsigned netEnablingCount_;
55   const ElementType *lastEndedElementType_;
56   NamedTable<ElementType> undefinedElementTypeTable_;
57   ElementType documentElementContainer_;
58 };
59
60 inline
61 OpenElement &ContentState::currentElement()
62 {
63   return *openElements_.head();
64 }
65
66 inline
67 const OpenElement &ContentState::currentElement() const
68 {
69   return *openElements_.head();
70 }
71
72 inline
73 Boolean ContentState::elementIsOpen(const ElementType *e) const
74 {
75   return openElementCount_[e->index()] != 0;
76 }
77
78 inline
79 Boolean ContentState::elementIsIncluded(const ElementType *e) const
80 {
81   return includeCount_[e->index()] != 0 && excludeCount_[e->index()] == 0;
82 }
83
84 inline
85 Boolean ContentState::elementIsExcluded(const ElementType *e) const
86 {
87   return excludeCount_[e->index()] != 0;
88 }
89
90 inline
91 const ElementType *ContentState::lastEndedElementType() const
92 {
93   return lastEndedElementType_;
94 }
95
96 inline
97 unsigned ContentState::tagLevel() const
98 {
99   return tagLevel_;
100 }
101
102 inline
103 Boolean ContentState::afterDocumentElement() const
104 {
105   return tagLevel() == 0 && currentElement().isFinished();
106 }
107
108 inline
109 Mode ContentState::contentMode() const
110 {
111   return openElements_.head()->mode(netEnablingCount_ > 0);
112 }
113
114 #ifdef SP_NAMESPACE
115 }
116 #endif
117
118 #endif /* not ContentState_INCLUDED */