1 // Copyright (c) 1994 James Clark 2 // See the file COPYING for copying permission. 3 #pragma ident "%Z%%M% %I% %E% SMI" 4 5 #ifndef OpenElement_INCLUDED 6 #define OpenElement_INCLUDED 1 7 #ifdef __GNUG__ 8 #pragma interface 9 #endif 10 11 #include "Boolean.h" 12 #include "ContentToken.h" 13 #include "ElementType.h" 14 #include "Link.h" 15 #include "Mode.h" 16 #include "Allocator.h" 17 #include "Location.h" 18 19 #ifdef SP_NAMESPACE 20 namespace SP_NAMESPACE { 21 #endif 22 23 class SP_API OpenElement : public Link { 24 public: new(size_t sz,Allocator & alloc)25 void *operator new(size_t sz, Allocator &alloc) { return alloc.alloc(sz); } new(size_t sz)26 void *operator new(size_t sz) { return Allocator::allocSimple(sz); } delete(void * p)27 void operator delete(void *p) { Allocator::free(p); } 28 OpenElement(const ElementType *, Boolean net, Boolean included, 29 const ShortReferenceMap *currentMap, 30 const Location &startLocation); 31 Boolean isFinished() const; 32 Boolean tryTransition(const ElementType *); 33 const LeafContentToken *invalidExclusion(const ElementType *) const; 34 // This doesn't handle declared content of EMPTY. 35 // If this situation can arise must use declaredEmpty(). 36 Boolean tryTransitionPcdata(); 37 const LeafContentToken *impliedStartTag() const; 38 void doRequiredTransition(); 39 const ElementType *type() const; 40 Boolean netEnabling() const; 41 Boolean included() const; 42 const MatchState &matchState() const; 43 void setMatchState(const MatchState &); 44 Mode mode(Boolean netEnabled) const; 45 const ShortReferenceMap *map() const; 46 void setMap(const ShortReferenceMap *); 47 Boolean requiresSpecialParse() const; 48 const Location &startLocation() const; 49 const LeafContentToken *currentPosition() const; 50 Boolean declaredEmpty() const; 51 void setConref(); 52 unsigned long index() const; 53 void setIndex(unsigned long); 54 private: 55 OpenElement(const OpenElement &); // undefined 56 void operator=(const OpenElement &); // undefined 57 const ElementType *elementType_; 58 PackedBoolean netEnabling_; // start-tag was net-enabling 59 PackedBoolean included_; 60 MatchState matchState_; 61 ElementDefinition::DeclaredContent declaredContent_; 62 const ShortReferenceMap *map_; 63 Location startLocation_; 64 unsigned long index_; 65 }; 66 67 inline type()68const ElementType *OpenElement::type() const 69 { 70 return elementType_; 71 } 72 73 inline netEnabling()74Boolean OpenElement::netEnabling() const 75 { 76 return netEnabling_; 77 } 78 79 inline included()80Boolean OpenElement::included() const 81 { 82 return included_; 83 } 84 85 inline matchState()86const MatchState &OpenElement::matchState() const 87 { 88 return matchState_; 89 } 90 91 inline setMatchState(const MatchState & state)92void OpenElement::setMatchState(const MatchState &state) 93 { 94 matchState_ = state; 95 } 96 97 inline isFinished()98Boolean OpenElement::isFinished() const 99 { 100 return (declaredContent_ != ElementDefinition::modelGroup 101 || matchState_.isFinished()); 102 } 103 104 inline tryTransition(const ElementType * e)105Boolean OpenElement::tryTransition(const ElementType *e) 106 { 107 return (declaredContent_ == ElementDefinition::modelGroup 108 ? matchState_.tryTransition(e) 109 : (declaredContent_ == ElementDefinition::any)); 110 } 111 112 inline tryTransitionPcdata()113Boolean OpenElement::tryTransitionPcdata() 114 { 115 return (declaredContent_ == ElementDefinition::modelGroup 116 ? matchState_.tryTransitionPcdata() 117 : 1); // CDATA, RCDATA, ANY all ok 118 } 119 120 inline invalidExclusion(const ElementType * e)121const LeafContentToken *OpenElement::invalidExclusion(const ElementType *e) 122 const 123 { 124 return (declaredContent_ == ElementDefinition::modelGroup 125 ? matchState_.invalidExclusion(e) 126 : 0); 127 } 128 129 inline doRequiredTransition()130void OpenElement::doRequiredTransition() 131 { 132 matchState_.doRequiredTransition(); 133 } 134 135 inline impliedStartTag()136const LeafContentToken *OpenElement::impliedStartTag() const 137 { 138 return (declaredContent_ == ElementDefinition::modelGroup 139 ? matchState_.impliedStartTag() 140 : 0); 141 } 142 143 inline map()144const ShortReferenceMap *OpenElement::map() const 145 { 146 return map_; 147 } 148 149 inline setMap(const ShortReferenceMap * map)150void OpenElement::setMap(const ShortReferenceMap *map) 151 { 152 map_ = map; 153 } 154 155 inline requiresSpecialParse()156Boolean OpenElement::requiresSpecialParse() const 157 { 158 return (declaredContent_ == ElementDefinition::cdata 159 || declaredContent_ == ElementDefinition::rcdata); 160 } 161 162 inline mode(Boolean netEnabled)163Mode OpenElement::mode(Boolean netEnabled) const 164 { 165 return elementType_->definition()->mode(netEnabled); 166 } 167 168 inline startLocation()169const Location &OpenElement::startLocation() const 170 { 171 return startLocation_; 172 } 173 174 inline currentPosition()175const LeafContentToken *OpenElement::currentPosition() const 176 { 177 return (declaredContent_ == ElementDefinition::modelGroup 178 ? matchState_.currentPosition() 179 : 0); 180 } 181 182 inline declaredEmpty()183Boolean OpenElement::declaredEmpty() const 184 { 185 return declaredContent_ == ElementDefinition::empty; 186 } 187 188 inline setConref()189void OpenElement::setConref() 190 { 191 declaredContent_ = ElementDefinition::empty; 192 } 193 194 inline index()195unsigned long OpenElement::index() const 196 { 197 return index_; 198 } 199 200 inline setIndex(unsigned long index)201void OpenElement::setIndex(unsigned long index) 202 { 203 index_ = index; 204 } 205 206 #ifdef SP_NAMESPACE 207 } 208 #endif 209 210 #endif /* not OpenElement_INCLUDED */ 211