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