1 // Copyright (c) 1994, 1996 James Clark 2 // See the file COPYING for copying permission. 3 #pragma ident "%Z%%M% %I% %E% SMI" 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 ¤tElement(); 33 const OpenElement ¤tElement() 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 ElementType *lookupCreateUndefinedElement(const StringC &, 44 const Location &, 45 Dtd &); 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 currentElement()62OpenElement &ContentState::currentElement() 63 { 64 return *openElements_.head(); 65 } 66 67 inline currentElement()68const OpenElement &ContentState::currentElement() const 69 { 70 return *openElements_.head(); 71 } 72 73 inline elementIsOpen(const ElementType * e)74Boolean ContentState::elementIsOpen(const ElementType *e) const 75 { 76 return openElementCount_[e->index()] != 0; 77 } 78 79 inline elementIsIncluded(const ElementType * e)80Boolean ContentState::elementIsIncluded(const ElementType *e) const 81 { 82 return includeCount_[e->index()] != 0 && excludeCount_[e->index()] == 0; 83 } 84 85 inline elementIsExcluded(const ElementType * e)86Boolean ContentState::elementIsExcluded(const ElementType *e) const 87 { 88 return excludeCount_[e->index()] != 0; 89 } 90 91 inline lastEndedElementType()92const ElementType *ContentState::lastEndedElementType() const 93 { 94 return lastEndedElementType_; 95 } 96 97 inline tagLevel()98unsigned ContentState::tagLevel() const 99 { 100 return tagLevel_; 101 } 102 103 inline afterDocumentElement()104Boolean ContentState::afterDocumentElement() const 105 { 106 return tagLevel() == 0 && currentElement().isFinished(); 107 } 108 109 inline contentMode()110Mode 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 */ 120