2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: ContentState.C /main/1 1996/07/29 16:48:21 cde-hp $ */
24 // Copyright (c) 1994, 1996 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
32 #include "ContentState.h"
33 #include "IListIter.h"
38 namespace SP_NAMESPACE {
41 const ShortReferenceMap ContentState::theEmptyMap;
44 typedef IListIter<OpenElement> Dummy_IListIter_OpenElement;
47 ContentState::ContentState()
48 : documentElementContainer_(StringC(), size_t(-1))
52 void ContentState::startContent(const Dtd &dtd)
54 NCVector<Owner<ContentToken> > tokens(1);
55 tokens[0] = new ElementToken(dtd.documentElementType(),
57 Owner<ModelGroup> model(new SeqModelGroup(tokens, ContentToken::none));
58 Owner<CompiledModelGroup> compiledModel(new CompiledModelGroup(model));
59 Vector<ContentModelAmbiguity> ambiguities;
60 Boolean pcdataUnreachable;
61 compiledModel->compile(dtd.nElementTypeIndex(), ambiguities,
63 ASSERT(ambiguities.size() == 0);
64 ConstPtr<ElementDefinition> def
65 = new ElementDefinition(Location(),
68 ElementDefinition::modelGroup,
70 documentElementContainer_.setElementDefinition(def, 0);
72 while (!openElements_.empty())
73 delete openElements_.get();
74 openElements_.insert(new OpenElement(&documentElementContainer_,
79 includeCount_.assign(dtd.nElementTypeIndex(), 0);
80 excludeCount_.assign(dtd.nElementTypeIndex(), 0);
81 openElementCount_.assign(dtd.nElementTypeIndex(), 0);
82 netEnablingCount_ = 0;
83 totalExcludeCount_ = 0;
84 lastEndedElementType_ = 0;
85 undefinedElementTypeTable_.clear();
88 void ContentState::pushElement(OpenElement *e)
91 openElementCount_[e->type()->index()]++;
92 const ElementDefinition *def = e->type()->definition();
95 for (i = 0; i < def->nInclusions(); i++)
96 includeCount_[def->inclusion(i)->index()]++;
97 for (i = 0; i < def->nExclusions(); i++) {
98 excludeCount_[def->exclusion(i)->index()]++;
102 if (e->netEnabling())
104 openElements_.insert(e);
107 OpenElement *ContentState::popSaveElement()
109 ASSERT(tagLevel_ > 0);
110 OpenElement *e = openElements_.get();
112 openElementCount_[e->type()->index()]--;
113 const ElementDefinition *def = e->type()->definition();
116 for (i = 0; i < def->nInclusions(); i++)
117 includeCount_[def->inclusion(i)->index()]--;
118 for (i = 0; i < def->nExclusions(); i++) {
119 excludeCount_[def->exclusion(i)->index()]--;
120 totalExcludeCount_--;
123 if (e->netEnabling())
125 lastEndedElementType_ = e->type();
129 void ContentState::popElement()
131 delete popSaveElement();
134 Boolean ContentState::checkImplyLoop(unsigned count)
136 for (IListIter<OpenElement> iter(openElements_);
138 iter.next(), count--)
139 if (iter.cur()->type() == openElements_.head()->type()
140 // I'm not sure whether this is necessary.
141 && iter.cur()->matchState() == openElements_.head()->matchState())
146 void ContentState::getOpenElementInfo(Vector<OpenElementInfo> &v,
147 const StringC &rniPcdata) const
151 unsigned i = tagLevel_;
152 for (IListIter<OpenElement> iter(openElements_);
153 !iter.done() && i > 0;
155 OpenElementInfo &e = v[--i];
156 e.gi = iter.cur()->type()->name();
157 const LeafContentToken *token = iter.cur()->currentPosition();
158 if (token && !token->isInitial()) {
159 e.matchIndex = token->typeIndex() + 1;
160 const ElementType *type = token->elementType();
161 e.matchType = type ? type->name() : rniPcdata;
163 e.included = iter.cur()->included();
168 ContentState::lookupCreateUndefinedElement(const StringC &name,
171 const ElementType *e = undefinedElementTypeTable_.lookup(name);
174 ElementType *p = new ElementType(name,
175 openElementCount_.size());
176 p->setElementDefinition(new ElementDefinition(loc,
177 ElementDefinition::undefinedIndex,
178 (ElementDefinition::omitStart
179 |ElementDefinition::omitEnd),
180 ElementDefinition::any),
182 undefinedElementTypeTable_.insert(p);
183 includeCount_.push_back(0);
184 excludeCount_.push_back(0);
185 openElementCount_.push_back(0);