~ubuntu-branches/ubuntu/trusty/openjade1.3/trusty

« back to all changes in this revision

Viewing changes to spgrove/GroveBuilder.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2002-04-09 00:01:50 UTC
  • Revision ID: james.westby@ubuntu.com-20020409000150-r9rkyalxlhvf9ba3
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 1996, 1997 James Clark
 
2
// See the file COPYING for copying permission.
 
3
 
 
4
// FIXME location for SgmlDocument node.
 
5
 
 
6
#include "config.h"
 
7
#include "Boolean.h"
 
8
#include "Node.h"
 
9
#include "Resource.h"
 
10
#include "Ptr.h"
 
11
#include "xnew.h"
 
12
#include "Event.h"
 
13
#include "GroveBuilder.h"
 
14
#include "ErrorCountEventHandler.h"
 
15
#include "OutputCharStream.h"
 
16
#include "MessageFormatter.h"
 
17
#include "Dtd.h"
 
18
#include "Syntax.h"
 
19
#include "Attribute.h"
 
20
#include "Vector.h"
 
21
#include "LocNode.h"
 
22
#include "SdNode.h"
 
23
#include "threads.h"
 
24
#include "macros.h"
 
25
#include <assert.h>
 
26
#include <stdio.h>
 
27
 
 
28
#ifdef _MSC_VER
 
29
#pragma warning ( disable : 4250 ) // inherits via dominance
 
30
#endif
 
31
 
 
32
#include <stddef.h>
 
33
#include <string.h>
 
34
 
 
35
#ifdef SP_NAMESPACE
 
36
namespace SP_NAMESPACE {
 
37
#endif
 
38
 
 
39
#ifdef GROVE_NAMESPACE
 
40
using namespace GROVE_NAMESPACE;
 
41
#endif
 
42
 
 
43
static bool blockingAccess = 1;
 
44
 
 
45
size_t initialBlockSize = 8192;
 
46
unsigned maxBlocksPerSize = 20;
 
47
 
 
48
struct Chunk;
 
49
struct ParentChunk;
 
50
class ElementChunk;
 
51
struct SgmlDocumentChunk;
 
52
class DataChunk;
 
53
class GroveImpl;
 
54
class BaseNode;
 
55
class ChunkNode;
 
56
class ElementNode;
 
57
class DataNode;
 
58
class CdataAttributeValueNode;
 
59
class AttributeValueTokenNode;
 
60
class AttributeAsgnNode;
 
61
class AttributeDefNode;
 
62
class EntityNode;
 
63
class NotationNode;
 
64
class ExternalIdNode;
 
65
class DocumentTypeNode;
 
66
class SgmlConstantsNode;
 
67
class MessageNode;
 
68
class ElementTypeNode;
 
69
class ModelGroupNode;
 
70
class ElementTokenNode;
 
71
class PcdataTokenNode;
 
72
class DefaultEntityNode;
 
73
 
 
74
struct Chunk {
 
75
  // second arg never null
 
76
  // Set ptr to a node pointing to first Node in this.
 
77
  virtual AccessResult setNodePtrFirst(NodePtr &ptr,
 
78
                                       const BaseNode *) const = 0;
 
79
  virtual AccessResult setNodePtrFirst(NodePtr &ptr,
 
80
                                       const ElementNode *node) const;
 
81
  virtual AccessResult setNodePtrFirst(NodePtr &ptr,
 
82
                                       const DataNode *node) const;
 
83
  virtual const Chunk *after() const = 0;
 
84
  virtual AccessResult getFollowing(const GroveImpl *,
 
85
                                    const Chunk *&, unsigned long &nNodes)
 
86
    const;
 
87
  virtual AccessResult getFirstSibling(const GroveImpl *, const Chunk *&) const;
 
88
  virtual const StringC *id() const;
 
89
  virtual Boolean getLocOrigin(const Origin *&) const;
 
90
  ParentChunk *origin;
 
91
};
 
92
 
 
93
struct LocChunk : public Chunk {
 
94
  Index locIndex;
 
95
};
 
96
 
 
97
struct ParentChunk : public LocChunk {
 
98
  ParentChunk() : nextSibling(0) { }
 
99
  Chunk *nextSibling;
 
100
};
 
101
 
 
102
class ElementChunk : public ParentChunk {
 
103
public:
 
104
  virtual const AttributeValue *
 
105
    attributeValue(size_t attIndex, const GroveImpl &grove) const;
 
106
  virtual Boolean mustOmitEndTag() const;
 
107
  virtual Boolean included() const;
 
108
  const AttributeDefinitionList *attDefList() const;
 
109
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
110
  AccessResult setNodePtrFirst(NodePtr &ptr, const DataNode *node) const;
 
111
  AccessResult setNodePtrFirst(NodePtr &ptr, const ElementNode *node) const;
 
112
  static const StringC &key(const ElementChunk &chunk) { return *chunk.id(); }
 
113
  const Chunk *after() const;
 
114
  AccessResult getFollowing(const GroveImpl *, const Chunk *&, unsigned long &nNodes)
 
115
    const;
 
116
  const ElementType *elementType() const { return type; }
 
117
private:
 
118
  friend class ElementNode;
 
119
  const ElementType *type;
 
120
public:
 
121
  unsigned long elementIndex;
 
122
};
 
123
 
 
124
inline
 
125
const AttributeDefinitionList *ElementChunk::attDefList() const
 
126
{
 
127
  return type->attributeDefTemp();
 
128
}
 
129
 
 
130
class LocOriginChunk : public Chunk {
 
131
public:
 
132
  LocOriginChunk(const Origin *lo) : locOrigin(lo) { }
 
133
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *) const;
 
134
  AccessResult setNodePtrFirst(NodePtr &ptr, const ElementNode *node) const;
 
135
  AccessResult setNodePtrFirst(NodePtr &ptr, const DataNode *node) const;
 
136
  const Chunk *after() const;
 
137
  AccessResult getFollowing(const GroveImpl *,
 
138
                            const Chunk *&, unsigned long &nNodes)
 
139
    const;
 
140
  Boolean getLocOrigin(const Origin *&) const;
 
141
private:
 
142
  const Origin *locOrigin;
 
143
};
 
144
 
 
145
class MessageItem {
 
146
public:
 
147
  MessageItem(Node::Severity severity, const StringC &text, const Location &loc)
 
148
    : severity_(severity), text_(text), loc_(loc), next_(0) { }
 
149
  Node::Severity severity() const { return severity_; }
 
150
  const Location &loc() const { return loc_; }
 
151
  const StringC &text() const { return text_; }
 
152
  const MessageItem *next() const { return next_; }
 
153
  MessageItem **nextP() { return &next_; }
 
154
private:
 
155
  Node::Severity severity_;
 
156
  StringC text_;
 
157
  Location loc_;
 
158
  MessageItem *next_;
 
159
};
 
160
 
 
161
// multiple threads using const interface.
 
162
 
 
163
class GroveImpl {
 
164
public:
 
165
  GroveImpl(unsigned groveIndex);
 
166
 
 
167
  // Const interface
 
168
  void addRef() const { ++(((GroveImpl *)this)->refCount_); }
 
169
  void release() const {
 
170
    if (!--(((GroveImpl *)this)->refCount_))
 
171
      delete (GroveImpl *)this;
 
172
  }
 
173
  unsigned groveIndex() const { return groveIndex_; }
 
174
  const SgmlDocumentChunk *root() const { return root_; }
 
175
  const AttributeValue *impliedAttributeValue() const {
 
176
    return impliedAttributeValue_.pointer();
 
177
  }
 
178
  // Return 0 if not yet available.
 
179
  Boolean getAppinfo(const StringC *&) const;
 
180
  const SubstTable<Char> *generalSubstTable() const {
 
181
    return instanceSyntax_.isNull() ? 0 : instanceSyntax_->generalSubstTable();
 
182
  }
 
183
  const SubstTable<Char> *entitySubstTable() const {
 
184
    return instanceSyntax_.isNull() ? 0 : instanceSyntax_->entitySubstTable();
 
185
  }
 
186
  // Be careful not to change ref counts while accessing DTD.
 
187
  const Dtd *governingDtd() const { return dtd_.pointer(); }
 
188
  // must not be called till grove is complete
 
189
  Dtd::ConstEntityIter defaultedEntityIter() const;
 
190
  const Entity *lookupDefaultedEntity(const StringC &) const;
 
191
  const ElementChunk *lookupElement(const StringC &) const;
 
192
  typedef PointerTableIter<ElementChunk *,StringC,Hash,ElementChunk> ElementIter;
 
193
  // must not be called till grove is complete
 
194
  ElementIter elementIter() const;
 
195
  Boolean complete() const { return complete_; }
 
196
  const void *completeLimit() const { return completeLimit_; }
 
197
  const void *completeLimitWithLocChunkAfter() const {
 
198
    return completeLimitWithLocChunkAfter_;
 
199
  }
 
200
  const Origin *currentLocOrigin() const { return currentLocOrigin_; }
 
201
  Boolean hasDefaultEntity() const { return hasDefaultEntity_; }
 
202
  Boolean maybeMoreSiblings(const ParentChunk *chunk) const;
 
203
  // return zero for timeout
 
204
  Boolean waitForMoreNodes() const;
 
205
  AccessResult proxifyLocation(const Location &, Location &) const;
 
206
  const MessageItem *messageList() const { return messageList_; }
 
207
  // must not be called till grove is complete
 
208
  void getSd(ConstPtr<Sd> &, ConstPtr<Syntax> &, ConstPtr<Syntax> &) const;
 
209
  // non-const interface
 
210
  void *allocChunk(size_t);
 
211
  void appendSibling(Chunk *);
 
212
  void appendSibling(DataChunk *);
 
213
  Boolean tryExtend(size_t n) {
 
214
    if (n <= nFree_) {
 
215
      nFree_ -= n;
 
216
      freePtr_ += n;
 
217
      return 1;
 
218
    }
 
219
    else
 
220
      return 0;
 
221
  }
 
222
  DataChunk *pendingData() { return pendingData_; }
 
223
  void push(ElementChunk *, Boolean hasId);
 
224
  void pop();
 
225
  void setAppinfo(const StringC &);
 
226
  void setDtd(const ConstPtr<Dtd> &dtd);
 
227
  void setSd(const ConstPtr<Sd> &, const ConstPtr<Syntax> &, const ConstPtr<Syntax> &);
 
228
  void storeAttributeValue(const ConstPtr<AttributeValue> &value) {
 
229
    values_.push_back(value);
 
230
  }
 
231
  void addDefaultedEntity(const ConstPtr<Entity> &);
 
232
  void setComplete();
 
233
  Boolean haveRootOrigin();
 
234
  void setLocOrigin(const ConstPtr<Origin> &);
 
235
  void appendMessage(MessageItem *);
 
236
private:
 
237
  GroveImpl(const GroveImpl &);
 
238
  void operator=(const GroveImpl &);
 
239
  ~GroveImpl();
 
240
 
 
241
  Boolean maybeMoreSiblings1(const ParentChunk *) const;
 
242
  void *allocFinish(size_t);
 
243
  void pulse();
 
244
  void maybePulse();
 
245
  void finishDocumentElement();
 
246
  void finishProlog();
 
247
  void addBarrier();
 
248
  void storeLocOrigin(const ConstPtr<Origin> &);
 
249
 
 
250
  struct BlockHeader {
 
251
    BlockHeader() : next(0) { }
 
252
    BlockHeader *next;
 
253
  };
 
254
  unsigned groveIndex_;
 
255
  SgmlDocumentChunk *root_;
 
256
  ParentChunk *origin_;
 
257
  DataChunk *pendingData_;
 
258
  Chunk **tailPtr_;
 
259
  ConstPtr<Dtd> dtd_;
 
260
  ConstPtr<Sd> sd_;
 
261
  ConstPtr<Syntax> prologSyntax_;
 
262
  ConstPtr<Syntax> instanceSyntax_;
 
263
  ConstPtr<AttributeValue> impliedAttributeValue_;
 
264
  Vector<ConstPtr<AttributeValue> > values_;
 
265
  Vector<ConstPtr<Origin> > origins_;
 
266
  NamedResourceTable<Entity> defaultedEntityTable_;
 
267
  PointerTable<ElementChunk *,StringC,Hash,ElementChunk> idTable_;
 
268
  Boolean hasDefaultEntity_;
 
269
  Boolean haveAppinfo_;
 
270
  StringC appinfo_;
 
271
  const Origin *currentLocOrigin_;
 
272
 
 
273
  Boolean complete_;
 
274
  const void *completeLimit_;
 
275
  const void *completeLimitWithLocChunkAfter_;
 
276
  // pointer to first free byte in current block
 
277
  char *freePtr_;
 
278
  // free bytes in current block
 
279
  // there's space for a forwarding chunk after this if freePtr_ != 0
 
280
  size_t nFree_;
 
281
  // the head of the list of blocks
 
282
  BlockHeader *blocks_;
 
283
  // where to store pointer to next block
 
284
  BlockHeader **blockTailPtr_;
 
285
  // current normal size for a block
 
286
  size_t blockAllocSize_;
 
287
  // number of blocks allocated at this size
 
288
  size_t nBlocksThisSizeAlloced_;
 
289
  RefCount refCount_;
 
290
  mutable Condition moreNodesCondition_;
 
291
  Mutex mutex_;
 
292
  Mutex *mutexPtr_;
 
293
  unsigned pulseStep_;
 
294
  unsigned long nEvents_;
 
295
  unsigned long nElements_;
 
296
  enum { maxChunksWithoutLocOrigin = 100 };
 
297
  unsigned nChunksSinceLocOrigin_;
 
298
  MessageItem *messageList_;
 
299
  MessageItem **messageListTailP_;
 
300
};
 
301
 
 
302
class GroveImplPtr {
 
303
public:
 
304
  GroveImplPtr(const GroveImpl *grove) : grove_(grove) { grove_->addRef(); }
 
305
  ~GroveImplPtr() { grove_->release(); }
 
306
  const GroveImpl *operator->() const { return grove_; }
 
307
  operator const GroveImpl *() const { return grove_; }
 
308
private:
 
309
  GroveImplPtr(const GroveImplPtr &); // undefined
 
310
  void operator=(const GroveImplPtr &); // undefined
 
311
  const GroveImpl *grove_;
 
312
};
 
313
 
 
314
class GroveImplProxyOrigin : public ProxyOrigin {
 
315
public:
 
316
  GroveImplProxyOrigin(const GroveImpl *grove, const Origin *origin)
 
317
    : grove_(grove), ProxyOrigin(origin) { }
 
318
private:
 
319
  GroveImplPtr grove_;
 
320
};
 
321
 
 
322
class GroveBuilderMessageEventHandler : public ErrorCountEventHandler {
 
323
public:
 
324
  GroveBuilderMessageEventHandler(unsigned groveIndex, Messenger *mgr, MessageFormatter *msgFmt_);
 
325
  ~GroveBuilderMessageEventHandler();
 
326
  void message(MessageEvent *);
 
327
  void sgmlDecl(SgmlDeclEvent *);
 
328
  void makeInitialRoot(NodePtr &);
 
329
  void setSd(const ConstPtr<Sd> &, const ConstPtr<Syntax> &, const ConstPtr<Syntax> &);
 
330
protected:
 
331
  GroveImpl *grove_;
 
332
private:
 
333
  Messenger *mgr_;
 
334
  MessageFormatter *msgFmt_;
 
335
};
 
336
 
 
337
class GroveBuilderEventHandler : public GroveBuilderMessageEventHandler {
 
338
public:
 
339
  GroveBuilderEventHandler(unsigned groveIndex, Messenger *mgr, MessageFormatter *msgFmt_);
 
340
  void appinfo(AppinfoEvent *);
 
341
  void startElement(StartElementEvent *);
 
342
  void endElement(EndElementEvent *);
 
343
  void data(DataEvent *);
 
344
  void sdataEntity(SdataEntityEvent *);
 
345
  void nonSgmlChar(NonSgmlCharEvent *);
 
346
  void externalDataEntity(ExternalDataEntityEvent *);
 
347
  void subdocEntity(SubdocEntityEvent *);
 
348
  void pi(PiEvent *);
 
349
  void endProlog(EndPrologEvent *);
 
350
  void entityDefaulted(EntityDefaultedEvent *);
 
351
};
 
352
 
 
353
inline
 
354
void setString(GroveString &to, const StringC &from)
 
355
{
 
356
  to.assign(from.data(), from.size());
 
357
}
 
358
 
 
359
inline
 
360
bool operator==(const StringC &str1, const GroveString &str2)
 
361
{
 
362
  return (str1.size() == str2.size()
 
363
          && memcmp(str1.data(), str2.data(), str1.size()*sizeof(Char)) == 0);
 
364
}
 
365
 
 
366
inline
 
367
bool operator!=(const StringC &str1, const GroveString &str2)
 
368
{
 
369
  return !(str1 == str2);
 
370
}
 
371
 
 
372
inline
 
373
size_t roundUp(size_t n)
 
374
{
 
375
  return (n + (sizeof(void *) - 1)) & ~(sizeof(void *) - 1);
 
376
}
 
377
 
 
378
// All nodes in this grove must be derived from BaseNode.
 
379
 
 
380
class BaseNode : public Node, public LocNode {
 
381
public:
 
382
  BaseNode(const GroveImpl *grove);
 
383
  virtual ~BaseNode();
 
384
  void addRef();
 
385
  void release();
 
386
  bool canReuse(NodePtr &ptr) const;
 
387
  unsigned groveIndex() const;
 
388
  bool operator==(const Node &node) const;
 
389
  // Implemented with double dispatching.
 
390
  virtual bool same(const BaseNode &) const = 0;
 
391
  // The second half of the dispatch.
 
392
  virtual bool same2(const ChunkNode *) const;
 
393
  virtual bool same2(const DataNode *) const;
 
394
  virtual bool same2(const AttributeAsgnNode *) const;
 
395
  virtual bool same2(const AttributeValueTokenNode *) const;
 
396
  virtual bool same2(const CdataAttributeValueNode *) const;
 
397
  virtual bool same2(const EntityNode *) const;
 
398
  virtual bool same2(const NotationNode *) const;
 
399
  virtual bool same2(const ExternalIdNode *) const;
 
400
  virtual bool same2(const DocumentTypeNode *) const;
 
401
  virtual bool same2(const SgmlConstantsNode *) const;
 
402
  virtual bool same2(const MessageNode *) const;
 
403
  virtual bool same2(const ElementTypeNode *) const;
 
404
  virtual bool same2(const ModelGroupNode *) const;
 
405
  virtual bool same2(const ElementTokenNode *) const;
 
406
  virtual bool same2(const PcdataTokenNode *) const;
 
407
  virtual bool same2(const AttributeDefNode *) const;
 
408
  virtual bool same2(const DefaultEntityNode *) const;
 
409
  const GroveImpl *grove() const { return grove_; }
 
410
  AccessResult nextSibling(NodePtr &ptr) const;
 
411
  AccessResult follow(NodeListPtr &ptr) const;
 
412
  AccessResult children(NodeListPtr &) const;
 
413
  AccessResult getOrigin(NodePtr &ptr) const;
 
414
  AccessResult getGroveRoot(NodePtr &ptr) const;
 
415
  AccessResult getLocation(Location &) const;
 
416
  bool queryInterface(IID, const void *&) const;
 
417
  bool chunkContains(const Node &) const;
 
418
  bool inChunk(const DataNode *node) const;
 
419
  bool inChunk(const CdataAttributeValueNode *) const;
 
420
protected:
 
421
  static unsigned long secondHash(unsigned long n) {
 
422
    return n * 1001;
 
423
  }
 
424
private:
 
425
  unsigned refCount_;
 
426
  GroveImplPtr grove_;
 
427
};
 
428
 
 
429
inline
 
430
BaseNode::BaseNode(const GroveImpl *grove)
 
431
: grove_(grove), refCount_(0)
 
432
{
 
433
}
 
434
 
 
435
inline
 
436
bool BaseNode::canReuse(NodePtr &ptr) const
 
437
{
 
438
  const Node *tem = &*ptr;
 
439
  return tem == this && refCount_ == 1;
 
440
}
 
441
 
 
442
struct ForwardingChunk : Chunk {
 
443
  ForwardingChunk(const Chunk *to, ParentChunk *p)
 
444
    : forwardTo(to) { origin = p; }
 
445
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
446
  AccessResult getFollowing(const GroveImpl *,
 
447
                            const Chunk *&, unsigned long &nNodes)
 
448
    const;
 
449
  const Chunk *after() const { return forwardTo; }
 
450
  const Chunk *forwardTo;
 
451
};
 
452
 
 
453
class ChunkNode : public BaseNode {
 
454
public:
 
455
  ChunkNode(const GroveImpl *grove, const LocChunk *chunk);
 
456
  const LocChunk *chunk() const { return chunk_; }
 
457
  bool same(const BaseNode &node) const;
 
458
  bool same2(const ChunkNode *node) const;
 
459
  unsigned long hash() const;
 
460
  AccessResult getParent(NodePtr &ptr) const;
 
461
  AccessResult getTreeRoot(NodePtr &ptr) const;
 
462
  AccessResult getOrigin(NodePtr &) const;
 
463
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &) const;
 
464
  AccessResult nextChunkSibling(NodePtr &) const;
 
465
  AccessResult nextChunkAfter(NodePtr &) const;
 
466
  AccessResult firstSibling(NodePtr &) const;
 
467
  AccessResult siblingsIndex(unsigned long &) const;
 
468
  AccessResult followSiblingRef(unsigned long, NodePtr &) const;
 
469
  AccessResult getLocation(Location &) const;
 
470
protected:
 
471
  const LocChunk *chunk_;               // never null
 
472
};
 
473
 
 
474
inline
 
475
ChunkNode::ChunkNode(const GroveImpl *grove, const LocChunk *chunk)
 
476
: BaseNode(grove), chunk_(chunk)
 
477
{
 
478
}
 
479
 
 
480
class SgmlDocumentNode;
 
481
 
 
482
struct SgmlDocumentChunk : public ParentChunk {
 
483
  SgmlDocumentChunk() : prolog(0), documentElement(0), epilog(0) { }
 
484
  Chunk *prolog;
 
485
  Chunk *documentElement;
 
486
  Chunk *epilog;
 
487
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
488
  const Chunk *after() const { return this + 1; }
 
489
};
 
490
 
 
491
class SgmlDocumentNode : public ChunkNode, public SdNode {
 
492
public:
 
493
  SgmlDocumentNode(const GroveImpl *grove,
 
494
                   const SgmlDocumentChunk *chunk);
 
495
  void accept(NodeVisitor &visitor);
 
496
  const ClassDef &classDef() const { return ClassDef::sgmlDocument; }
 
497
  AccessResult getDocumentElement(NodePtr &ptr) const;
 
498
  AccessResult getElements(NamedNodeListPtr &ptr) const;
 
499
  AccessResult getEntities(NamedNodeListPtr &ptr) const;
 
500
  AccessResult getDefaultedEntities(NamedNodeListPtr &ptr) const;
 
501
  AccessResult getGoverningDoctype(NodePtr &ptr) const;
 
502
  AccessResult getDoctypesAndLinktypes(NamedNodeListPtr &ptr) const;
 
503
  AccessResult getProlog(NodeListPtr &ptr) const;
 
504
  AccessResult getEpilog(NodeListPtr &ptr) const;
 
505
  AccessResult getSgmlConstants(NodePtr &) const;
 
506
  AccessResult getApplicationInfo(GroveString &str) const;
 
507
  AccessResult getMessages(NodeListPtr &ptr) const;
 
508
  AccessResult nextChunkSibling(NodePtr &) const { return accessNotInClass; }
 
509
  AccessResult firstSibling(NodePtr &) const { return accessNotInClass; }
 
510
  AccessResult siblingsIndex(unsigned long &) const { return accessNotInClass; }
 
511
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &) const { return accessNull; }
 
512
  AccessResult getSd(ConstPtr<Sd> &sd,
 
513
                     ConstPtr<Syntax> &prologSyntax,
 
514
                     ConstPtr<Syntax> &instanceSyntax) const;
 
515
private:
 
516
  const SgmlDocumentChunk *chunk() const {
 
517
    return (const SgmlDocumentChunk *)ChunkNode::chunk();
 
518
  }
 
519
};
 
520
 
 
521
inline
 
522
SgmlDocumentNode::SgmlDocumentNode(const GroveImpl *grove,
 
523
                                   const SgmlDocumentChunk *chunk)
 
524
: ChunkNode(grove, chunk)
 
525
{
 
526
}
 
527
 
 
528
// array of pointers to attribute values stored after chunk
 
529
 
 
530
class AttElementChunk : private ElementChunk {
 
531
protected:
 
532
  AttElementChunk(size_t n) : nAtts(n) { }
 
533
  friend class ElementNode;
 
534
private:
 
535
  const AttributeValue *
 
536
    attributeValue(size_t attIndex, const GroveImpl &) const;
 
537
  Boolean mustOmitEndTag() const;
 
538
  const Chunk *after() const;
 
539
  const StringC *id() const;
 
540
  size_t nAtts;
 
541
};
 
542
 
 
543
class IncludedElementChunk : public ElementChunk {
 
544
  friend class ElementNode;
 
545
  Boolean included() const;
 
546
};
 
547
 
 
548
class IncludedAttElementChunk : public AttElementChunk {
 
549
  IncludedAttElementChunk(size_t n) : AttElementChunk(n) { }
 
550
  friend class ElementNode;
 
551
  Boolean included() const;
 
552
};
 
553
 
 
554
class ElementNode : public ChunkNode {
 
555
public:
 
556
  friend class ElementChunk;
 
557
  ElementNode(const GroveImpl *grove, const ElementChunk *chunk)
 
558
    : ChunkNode(grove, chunk) { }
 
559
  AccessResult attributeRef(unsigned long i, NodePtr &ptr) const;
 
560
  AccessResult nextChunkSibling(NodePtr &ptr) const;
 
561
  AccessResult nextChunkAfter(NodePtr &) const;
 
562
  AccessResult firstChild(NodePtr &ptr) const;
 
563
  AccessResult getAttributes(NamedNodeListPtr &ptr) const;
 
564
  AccessResult getGi(GroveString &str) const;
 
565
  bool hasGi(GroveString) const;
 
566
  AccessResult getId(GroveString &str) const;
 
567
  AccessResult getContent(NodeListPtr &ptr) const;
 
568
  AccessResult getMustOmitEndTag(bool &) const;
 
569
  AccessResult getIncluded(bool &) const;
 
570
  AccessResult elementIndex(unsigned long &) const;
 
571
  AccessResult getElementType(NodePtr &) const;
 
572
  void accept(NodeVisitor &visitor);
 
573
  const ClassDef &classDef() const { return ClassDef::element; }
 
574
  static void add(GroveImpl &grove, const StartElementEvent &event);
 
575
private:
 
576
  static
 
577
    ElementChunk *makeAttElementChunk(GroveImpl &grove,
 
578
                                      const StartElementEvent &,
 
579
                                      Boolean &hasId);
 
580
  const ElementChunk *chunk() const {
 
581
    return (const ElementChunk *)ChunkNode::chunk();
 
582
  }
 
583
  void reuseFor(const ElementChunk *chunk) { chunk_ = chunk; }
 
584
};
 
585
 
 
586
class CharsChunk : public LocChunk {
 
587
public:
 
588
  const Chunk *after() const {
 
589
    return (const Chunk *)((char *)this + allocSize(size));
 
590
  }
 
591
  const Char *data() const { return (const Char *)(this + 1); }
 
592
  size_t size;
 
593
  static size_t allocSize(size_t nChars) {
 
594
    return roundUp(sizeof(CharsChunk) + nChars*sizeof(Char));
 
595
  }
 
596
};
 
597
// The characters immediately follow the chunk
 
598
 
 
599
class DataChunk : public CharsChunk {
 
600
private:
 
601
  friend class DataNode;
 
602
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
603
  AccessResult setNodePtrFirst(NodePtr &ptr, const ElementNode *node) const;
 
604
  AccessResult setNodePtrFirst(NodePtr &ptr, const DataNode *node) const;
 
605
  AccessResult getFollowing(const GroveImpl *, const Chunk *&, unsigned long &) const;
 
606
};
 
607
 
 
608
class DataNode : public ChunkNode {
 
609
public:
 
610
  friend class DataChunk;
 
611
  DataNode(const GroveImpl *, const DataChunk *chunk, size_t index);
 
612
  bool same(const BaseNode &node) const;
 
613
  bool same2(const DataNode *node) const;
 
614
  AccessResult nextSibling(NodePtr &ptr) const;
 
615
  AccessResult nextChunkSibling(NodePtr &ptr) const;
 
616
  AccessResult nextChunkAfter(NodePtr &) const;
 
617
  AccessResult siblingsIndex(unsigned long &) const;
 
618
  AccessResult followSiblingRef(unsigned long, NodePtr &) const;
 
619
  AccessResult charChunk(const SdataMapper &, GroveString &) const;
 
620
  bool chunkContains(const Node &) const;
 
621
  bool inChunk(const DataNode *node) const;
 
622
  AccessResult getNonSgml(unsigned long &) const;
 
623
  AccessResult getLocation(Location &) const;
 
624
  void accept(NodeVisitor &visitor);
 
625
  const ClassDef &classDef() const { return ClassDef::dataChar; }
 
626
  unsigned long hash() const;
 
627
  static void add(GroveImpl &grove, const DataEvent &event);
 
628
private:
 
629
  const DataChunk *chunk() const {
 
630
    return (const DataChunk *)ChunkNode::chunk();
 
631
  }
 
632
  void reuseFor(const DataChunk *chunk, size_t index);
 
633
  size_t index_;
 
634
};
 
635
 
 
636
inline
 
637
DataNode::DataNode(const GroveImpl *grove,
 
638
                   const DataChunk *chunk, size_t index)
 
639
: ChunkNode(grove, chunk), index_(index)
 
640
{
 
641
}
 
642
 
 
643
class PiChunk : protected CharsChunk {
 
644
  friend class PiNode;
 
645
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
646
};
 
647
 
 
648
class PrologPiChunk : public PiChunk {
 
649
  AccessResult getFirstSibling(const GroveImpl *, const struct Chunk *&) const;
 
650
};
 
651
 
 
652
class EpilogPiChunk : public PiChunk {
 
653
  AccessResult getFirstSibling(const GroveImpl *, const struct Chunk *&) const;
 
654
};
 
655
 
 
656
class PiNode : public ChunkNode {
 
657
public:
 
658
  PiNode(const GroveImpl *grove, const PiChunk *chunk)
 
659
    : ChunkNode(grove, chunk) {}
 
660
  AccessResult getSystemData(GroveString &) const;
 
661
  AccessResult getEntityName(GroveString &) const{ return accessNull; }
 
662
  AccessResult getEntity(NodePtr &) const { return accessNull; }
 
663
  void accept(NodeVisitor &visitor) { visitor.pi(*this); }
 
664
  const ClassDef &classDef() const { return ClassDef::pi; }
 
665
  static void add(GroveImpl &grove, const PiEvent &);
 
666
private:
 
667
  const PiChunk *chunk() const {
 
668
    return (const PiChunk *)ChunkNode::chunk();
 
669
  }
 
670
};
 
671
 
 
672
class EntityRefChunk : public LocChunk {
 
673
public:
 
674
  const Entity *entity;
 
675
  const Chunk *after() const { return this + 1; }
 
676
};
 
677
 
 
678
class EntityRefNode : public ChunkNode {
 
679
public:
 
680
  EntityRefNode(const GroveImpl *grove, const EntityRefChunk *chunk)
 
681
    : ChunkNode(grove, chunk) { }
 
682
  AccessResult getEntity(NodePtr &) const;
 
683
  AccessResult getEntityName(GroveString &) const;
 
684
protected:
 
685
  const EntityRefChunk *chunk() const {
 
686
    return (const EntityRefChunk *)ChunkNode::chunk();
 
687
  }
 
688
};
 
689
 
 
690
class SdataNode;
 
691
 
 
692
class SdataChunk : private EntityRefChunk {
 
693
  friend class SdataNode;
 
694
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
695
};
 
696
 
 
697
class SdataNode : public EntityRefNode {
 
698
public:
 
699
  SdataNode(const GroveImpl *grove, const SdataChunk *chunk)
 
700
    : EntityRefNode(grove, chunk) { }
 
701
  AccessResult charChunk(const SdataMapper &, GroveString &) const;
 
702
  AccessResult getSystemData(GroveString &str) const;
 
703
  void accept(NodeVisitor &visitor) { visitor.sdata(*this); }
 
704
  const ClassDef &classDef() const { return ClassDef::sdata; }
 
705
  static void add(GroveImpl &grove, const SdataEntityEvent &event);
 
706
private:
 
707
  Char c_;
 
708
};
 
709
 
 
710
class NonSgmlNode;
 
711
 
 
712
class NonSgmlChunk : public LocChunk {
 
713
public:
 
714
  Char c;
 
715
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
716
  const Chunk *after() const { return this + 1; }
 
717
};
 
718
 
 
719
class NonSgmlNode : public ChunkNode {
 
720
public:
 
721
  NonSgmlNode(const GroveImpl *grove, const NonSgmlChunk *chunk)
 
722
    : ChunkNode(grove, chunk) { }
 
723
  AccessResult charChunk(const SdataMapper &, GroveString &) const;
 
724
  AccessResult getNonSgml(unsigned long &) const;
 
725
  void accept(NodeVisitor &visitor) { visitor.nonSgml(*this); }
 
726
  const ClassDef &classDef() const { return ClassDef::nonSgml; }
 
727
  static void add(GroveImpl &grove, const NonSgmlCharEvent &event);
 
728
protected:
 
729
  const NonSgmlChunk *chunk() const {
 
730
    return (const NonSgmlChunk *)ChunkNode::chunk();
 
731
  }
 
732
};
 
733
 
 
734
class ExternalDataNode;
 
735
 
 
736
class ExternalDataChunk : private EntityRefChunk {
 
737
  friend class ExternalDataNode;
 
738
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
739
};
 
740
 
 
741
class ExternalDataNode : public EntityRefNode {
 
742
public:
 
743
  ExternalDataNode(const GroveImpl *grove, const ExternalDataChunk *chunk)
 
744
    : EntityRefNode(grove, chunk) { }
 
745
  void accept(NodeVisitor &visitor) { visitor.externalData(*this); }
 
746
  const ClassDef &classDef() const { return ClassDef::externalData; }
 
747
  static void add(GroveImpl &grove, const ExternalDataEntityEvent &event);
 
748
};
 
749
 
 
750
class SubdocChunk : private EntityRefChunk {
 
751
  friend class SubdocNode;
 
752
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
753
};
 
754
 
 
755
class SubdocNode : public EntityRefNode {
 
756
public:
 
757
  SubdocNode(const GroveImpl *grove, const SubdocChunk *chunk)
 
758
    : EntityRefNode(grove, chunk) { }
 
759
  void accept(NodeVisitor &visitor) { visitor.subdocument(*this); }
 
760
  const ClassDef &classDef() const { return ClassDef::subdocument; }
 
761
  static void add(GroveImpl &grove, const SubdocEntityEvent &event);
 
762
};
 
763
 
 
764
class PiEntityChunk : private EntityRefChunk {
 
765
  friend class PiEntityNode;
 
766
  AccessResult setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const;
 
767
};
 
768
 
 
769
class PiEntityNode : public EntityRefNode {
 
770
public:
 
771
  PiEntityNode(const GroveImpl *grove, const PiEntityChunk *chunk)
 
772
    : EntityRefNode(grove, chunk) { }
 
773
  AccessResult getSystemData(GroveString &) const;
 
774
  void accept(NodeVisitor &visitor) { visitor.pi(*this); }
 
775
  const ClassDef &classDef() const { return ClassDef::pi; }
 
776
  static void add(GroveImpl &grove,  const Entity *, const Location &);
 
777
};
 
778
 
 
779
struct AttributeDefOrigin {
 
780
  AttributeDefOrigin(size_t attIndex = 0) : attIndex_(attIndex) { }
 
781
  virtual const AttributeDefinitionList *attDefList() const = 0;
 
782
  virtual Node *makeCdataAttributeValueNode(const GroveImpl *grove,
 
783
                                            const AttributeValue *value,
 
784
                                            size_t attIndex,
 
785
                                            const TextIter &iter,
 
786
                                            size_t charIndex = 0) const = 0;
 
787
  virtual Node *makeAttributeValueTokenNode(const GroveImpl *grove,
 
788
                                            const TokenizedAttributeValue *value,
 
789
                                            size_t attIndex,
 
790
                                            size_t tokenIndex) const = 0;
 
791
  virtual Node *makeOriginNode(const GroveImpl *grove, size_t attIndex) const = 0;
 
792
  virtual AccessResult makeAttributeValueNode(const GroveImpl *grove,
 
793
                                              NodePtr &ptr,
 
794
                                              const AttributeValue *value) const;
 
795
  virtual AccessResult makeAttributeValueNodeList(const GroveImpl *grove,
 
796
                                                  NodeListPtr &ptr,
 
797
                                                  const AttributeValue *value) const;
 
798
  virtual AccessResult makeAttributeDefNode(const GroveImpl *grove,
 
799
                                            NodePtr &ptr,
 
800
                                            size_t attributeDefIdx) const = 0;
 
801
  virtual AccessResult makeAttributeDefList(const GroveImpl *,
 
802
                                            NodeListPtr &,
 
803
                                            size_t) const {
 
804
    return accessNull;
 
805
  } 
 
806
  AccessResult makeAttributeDefNode(const GroveImpl *grove,
 
807
                                    NodePtr &ptr,
 
808
                                    const StringC &name) const;
 
809
  virtual const void *attributeOriginId() const = 0;
 
810
  const size_t attIndex() const { return attIndex_; }
 
811
protected:
 
812
  size_t attIndex_;
 
813
};
 
814
 
 
815
struct AttributeOrigin : public virtual AttributeDefOrigin {
 
816
  virtual const AttributeValue *
 
817
    attributeValue(size_t attIndex, const GroveImpl &grove) const = 0;
 
818
  virtual AccessResult
 
819
    setNodePtrAttributeOrigin(NodePtr &, const BaseNode *) const = 0;
 
820
  virtual Node *makeAttributeAsgnNode(const GroveImpl *grove,
 
821
                                      size_t attIndex) const = 0;
 
822
};
 
823
 
 
824
class ElementAttributeOrigin : public virtual AttributeOrigin {
 
825
public:
 
826
  ElementAttributeOrigin(const ElementChunk *);
 
827
  const AttributeDefinitionList *attDefList() const;
 
828
  const AttributeValue *
 
829
    attributeValue(size_t attIndex, const GroveImpl &grove) const;
 
830
  AccessResult setNodePtrAttributeOrigin(NodePtr &, const BaseNode *) const;
 
831
  Node *makeCdataAttributeValueNode(const GroveImpl *grove,
 
832
                                    const AttributeValue *value,
 
833
                                    size_t attIndex,
 
834
                                    const TextIter &iter,
 
835
                                    size_t charIndex) const;
 
836
  Node *makeAttributeValueTokenNode(const GroveImpl *grove,
 
837
                                    const TokenizedAttributeValue *value,
 
838
                                    size_t attIndex,
 
839
                                    size_t tokenIndex) const;
 
840
  Node *makeAttributeAsgnNode(const GroveImpl *grove,
 
841
                              size_t attIndex) const;
 
842
  virtual Node *makeOriginNode(const GroveImpl *grove, size_t attIndex) const;
 
843
  virtual AccessResult makeAttributeDefNode(const GroveImpl *grove,
 
844
                                            NodePtr &ptr,
 
845
                                            size_t attributeDefIdx) const;
 
846
  const void *attributeOriginId() const;
 
847
private:
 
848
  const ElementChunk *chunk_;
 
849
};
 
850
 
 
851
class EntityAttributeOrigin : public virtual AttributeOrigin {
 
852
public:
 
853
  EntityAttributeOrigin(const ExternalDataEntity *);
 
854
  const AttributeDefinitionList *attDefList() const;
 
855
  const AttributeValue *
 
856
    attributeValue(size_t attIndex, const GroveImpl &grove) const;
 
857
  AccessResult setNodePtrAttributeOrigin(NodePtr &, const BaseNode *) const;
 
858
  Node *makeCdataAttributeValueNode(const GroveImpl *grove,
 
859
                                    const AttributeValue *value,
 
860
                                    size_t attIndex,
 
861
                                    const TextIter &iter,
 
862
                                    size_t charIndex) const;
 
863
  Node *makeAttributeValueTokenNode(const GroveImpl *grove,
 
864
                                    const TokenizedAttributeValue *value,
 
865
                                    size_t attIndex,
 
866
                                    size_t tokenIndex) const;
 
867
  Node *makeAttributeAsgnNode(const GroveImpl *grove,
 
868
                              size_t attIndex) const;
 
869
  virtual AccessResult makeAttributeDefNode(const GroveImpl *grove,
 
870
                                            NodePtr &ptr,
 
871
                                            size_t attributeDefIdx) const;
 
872
  virtual Node *makeOriginNode(const GroveImpl *grove, size_t attIndex) const;
 
873
  const void *attributeOriginId() const;
 
874
private:
 
875
  const ExternalDataEntity *entity_;
 
876
};
 
877
 
 
878
// CLASS DEF: ElementTypeAttributeDefOrigin
 
879
class ElementTypeAttributeDefOrigin : public virtual AttributeDefOrigin {
 
880
public:
 
881
  ElementTypeAttributeDefOrigin(const ElementType *);
 
882
  const AttributeDefinitionList *attDefList() const;
 
883
  Node *makeCdataAttributeValueNode(const GroveImpl *grove,
 
884
                                    const AttributeValue *value,
 
885
                                    size_t attIndex,
 
886
                                    const TextIter &iter,
 
887
                                    size_t charIndex) const;
 
888
  Node *makeAttributeValueTokenNode(const GroveImpl *grove,
 
889
                                    const TokenizedAttributeValue *value,
 
890
                                    size_t attIndex,
 
891
                                    size_t tokenIndex) const;
 
892
  virtual AccessResult makeAttributeDefNode(const GroveImpl *grove,
 
893
                                            NodePtr &ptr,
 
894
                                            size_t attributeDefIdx) const;
 
895
  virtual AccessResult makeAttributeDefList(const GroveImpl *grove,
 
896
                                            NodeListPtr &ptr,
 
897
                                            size_t firstAttDefIdx) const;
 
898
  virtual Node *makeOriginNode(const GroveImpl *grove, size_t attIndex) const;
 
899
  virtual const void *attributeOriginId() const;
 
900
protected:
 
901
  const ElementType *elementType_;
 
902
};
 
903
 
 
904
// CLASS DEF: NotationAttributeDefOrigin
 
905
class NotationAttributeDefOrigin : public virtual AttributeDefOrigin {
 
906
public:
 
907
  NotationAttributeDefOrigin(const Notation *);
 
908
  virtual const AttributeDefinitionList *attDefList() const;
 
909
  Node *makeCdataAttributeValueNode(const GroveImpl *grove,
 
910
                                    const AttributeValue *value,
 
911
                                    size_t attIndex,
 
912
                                    const TextIter &iter,
 
913
                                    size_t charIndex) const;
 
914
  Node *makeAttributeValueTokenNode(const GroveImpl *grove,
 
915
                                    const TokenizedAttributeValue *value,
 
916
                                    size_t attIndex,
 
917
                                    size_t tokenIndex) const;
 
918
  virtual AccessResult makeAttributeDefNode(const GroveImpl *grove,
 
919
                                            NodePtr &ptr,
 
920
                                            size_t attributeDefIdx) const;
 
921
  virtual AccessResult makeAttributeDefList(const GroveImpl *grove,
 
922
                                            NodeListPtr &ptr,
 
923
                                            size_t firstAttDefIdx) const;
 
924
  virtual Node *makeOriginNode(const GroveImpl *grove, size_t attIndex) const;
 
925
  virtual const void *attributeOriginId() const;
 
926
protected:
 
927
  const Notation *notation_;
 
928
};
 
929
 
 
930
class AttributeAsgnNode : public BaseNode, public virtual AttributeOrigin {
 
931
public:
 
932
  AttributeAsgnNode(const GroveImpl *grove, size_t attIndex);
 
933
  AccessResult getOrigin(NodePtr &ptr) const;
 
934
  AccessResult getName(GroveString &str) const;
 
935
  AccessResult getImplied(bool &implied) const;
 
936
  AccessResult getValue(NodeListPtr &ptr) const;
 
937
  AccessResult children(NodeListPtr &ptr) const;
 
938
  AccessResult firstChild(NodePtr &ptr) const;
 
939
  AccessResult nextChunkSibling(NodePtr &ptr) const;
 
940
  AccessResult followSiblingRef(unsigned long, NodePtr &) const;
 
941
  AccessResult firstSibling(NodePtr &) const;
 
942
  AccessResult siblingsIndex(unsigned long &) const;
 
943
  AccessResult getTokenSep(Char &) const;
 
944
  AccessResult tokens(GroveString &) const;
 
945
  AccessResult getAttributeDef(NodePtr &) const;
 
946
  void accept(NodeVisitor &visitor);
 
947
  const ClassDef &classDef() const { return ClassDef::attributeAssignment; }
 
948
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
949
    name = ComponentName::idAttributes;
 
950
    return accessOK;
 
951
  }
 
952
  bool same(const BaseNode &node) const;
 
953
  bool same2(const AttributeAsgnNode *node) const;
 
954
  unsigned long hash() const;
 
955
};
 
956
 
 
957
class ElementAttributeAsgnNode
 
958
: public AttributeAsgnNode, public ElementAttributeOrigin {
 
959
public:
 
960
  ElementAttributeAsgnNode(const GroveImpl *grove, size_t attIndex,
 
961
                           const ElementChunk *);
 
962
};
 
963
 
 
964
class EntityAttributeAsgnNode
 
965
: public AttributeAsgnNode, public EntityAttributeOrigin {
 
966
public:
 
967
  EntityAttributeAsgnNode(const GroveImpl *grove, size_t attIndex,
 
968
                           const ExternalDataEntity *);
 
969
};
 
970
 
 
971
class AttributeValueTokenNode
 
972
: public BaseNode, public virtual AttributeDefOrigin {
 
973
public:
 
974
  AttributeValueTokenNode(const GroveImpl *grove,
 
975
                          const TokenizedAttributeValue *value,
 
976
                          size_t attIndex,
 
977
                          size_t tokenIndex);
 
978
  AccessResult getParent(NodePtr &ptr) const;
 
979
  AccessResult nextChunkSibling(NodePtr &ptr) const;
 
980
  AccessResult followSiblingRef(unsigned long, NodePtr &ptr) const;
 
981
  AccessResult firstSibling(NodePtr &) const;
 
982
  AccessResult siblingsIndex(unsigned long &) const;
 
983
  AccessResult getToken(GroveString &str) const;
 
984
  AccessResult getEntity(NodePtr &ptr) const;
 
985
  AccessResult getNotation(NodePtr &ptr) const;
 
986
  AccessResult getReferent(NodePtr &ptr) const;
 
987
  AccessResult getLocation(Location &) const;
 
988
  void accept(NodeVisitor &visitor);
 
989
  const ClassDef &classDef() const { return ClassDef::attributeValueToken; }
 
990
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
991
    name = ComponentName::idValue;
 
992
    return accessOK;
 
993
  }
 
994
  bool same(const BaseNode &node) const;
 
995
  bool same2(const AttributeValueTokenNode *node) const;
 
996
  unsigned long hash() const;
 
997
private:
 
998
  const TokenizedAttributeValue *value_;
 
999
  size_t tokenIndex_;
 
1000
};
 
1001
 
 
1002
class ElementAttributeValueTokenNode
 
1003
: public AttributeValueTokenNode, public ElementAttributeOrigin {
 
1004
public:
 
1005
  ElementAttributeValueTokenNode(const GroveImpl *grove,
 
1006
                                 const TokenizedAttributeValue *value,
 
1007
                                 size_t attIndex,
 
1008
                                 size_t tokenIndex,
 
1009
                                 const ElementChunk *);
 
1010
};
 
1011
 
 
1012
class EntityAttributeValueTokenNode
 
1013
: public AttributeValueTokenNode, public EntityAttributeOrigin {
 
1014
public:
 
1015
  EntityAttributeValueTokenNode(const GroveImpl *grove,
 
1016
                                const TokenizedAttributeValue *value,
 
1017
                                size_t attIndex,
 
1018
                                size_t tokenIndex,
 
1019
                                const ExternalDataEntity *);
 
1020
};
 
1021
 
 
1022
class ElementTypeAttributeValueTokenNode
 
1023
: public AttributeValueTokenNode, public ElementTypeAttributeDefOrigin {
 
1024
public:
 
1025
  ElementTypeAttributeValueTokenNode(const GroveImpl *grove,
 
1026
                                     const TokenizedAttributeValue *value,
 
1027
                                     size_t attIndex,
 
1028
                                     size_t tokenIndex,
 
1029
                                     const ElementType *);
 
1030
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1031
    name = ComponentName::idDefaultValue;
 
1032
    return accessOK;
 
1033
  }
 
1034
};
 
1035
 
 
1036
class NotationAttributeValueTokenNode
 
1037
: public AttributeValueTokenNode, public NotationAttributeDefOrigin {
 
1038
public:
 
1039
  NotationAttributeValueTokenNode(const GroveImpl *grove,
 
1040
                                  const TokenizedAttributeValue *value,
 
1041
                                  size_t attIndex,
 
1042
                                  size_t tokenIndex,
 
1043
                                  const Notation *);
 
1044
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1045
    name = ComponentName::idDefaultValue;
 
1046
    return accessOK;
 
1047
  }
 
1048
};
 
1049
 
 
1050
class CdataAttributeValueNode
 
1051
: public BaseNode, public virtual AttributeDefOrigin {
 
1052
public:
 
1053
  static bool skipBoring(TextIter &iter);
 
1054
  CdataAttributeValueNode(const GroveImpl *grove,
 
1055
                          const AttributeValue *value,
 
1056
                          size_t attIndex,
 
1057
                          const TextIter &iter,
 
1058
                          size_t charIndex);
 
1059
  AccessResult getParent(NodePtr &ptr) const;
 
1060
  AccessResult charChunk(const SdataMapper &, GroveString &) const;
 
1061
  bool chunkContains(const Node &) const;
 
1062
  bool inChunk(const CdataAttributeValueNode *) const;
 
1063
  AccessResult getEntity(NodePtr &) const;
 
1064
  AccessResult getEntityName(GroveString &) const;
 
1065
  AccessResult getSystemData(GroveString &str) const;
 
1066
  AccessResult nextSibling(NodePtr &ptr) const;
 
1067
  AccessResult nextChunkSibling(NodePtr &ptr) const;
 
1068
  AccessResult firstSibling(NodePtr &) const;
 
1069
  AccessResult siblingsIndex(unsigned long &) const;
 
1070
  AccessResult getLocation(Location &) const;
 
1071
  void accept(NodeVisitor &visitor);
 
1072
  const ClassDef &classDef() const;
 
1073
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1074
    name = ComponentName::idValue;
 
1075
    return accessOK;
 
1076
  }
 
1077
  bool same(const BaseNode &node) const;
 
1078
  bool same2(const CdataAttributeValueNode *node) const;
 
1079
  unsigned long hash() const;
 
1080
private:
 
1081
  const AttributeValue *value_;
 
1082
  TextIter iter_; // must be valid
 
1083
  size_t charIndex_;
 
1084
  Char c_;
 
1085
};
 
1086
 
 
1087
class ElementCdataAttributeValueNode
 
1088
: public CdataAttributeValueNode, public ElementAttributeOrigin {
 
1089
public:
 
1090
  ElementCdataAttributeValueNode(const GroveImpl *grove,
 
1091
                                 const AttributeValue *value,
 
1092
                                 size_t attIndex,
 
1093
                                 const TextIter &iter,
 
1094
                                 size_t charIndex,
 
1095
                                 const ElementChunk *);
 
1096
};
 
1097
 
 
1098
class EntityCdataAttributeValueNode
 
1099
: public CdataAttributeValueNode, public EntityAttributeOrigin {
 
1100
public:
 
1101
  EntityCdataAttributeValueNode(const GroveImpl *grove,
 
1102
                                const AttributeValue *value,
 
1103
                                size_t attIndex,
 
1104
                                const TextIter &iter,
 
1105
                                size_t charIndex,
 
1106
                                const ExternalDataEntity *);
 
1107
};
 
1108
 
 
1109
class ElementTypeCdataAttributeValueNode
 
1110
: public CdataAttributeValueNode, public ElementTypeAttributeDefOrigin {
 
1111
public:
 
1112
  ElementTypeCdataAttributeValueNode(const GroveImpl *grove,
 
1113
                                     const AttributeValue *value,
 
1114
                                     size_t attIndex,
 
1115
                                     const TextIter &iter,
 
1116
                                     size_t charIndex,
 
1117
                                     const ElementType *);
 
1118
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1119
    name = ComponentName::idDefaultValue;
 
1120
    return accessOK;
 
1121
  }
 
1122
};
 
1123
 
 
1124
class NotationCdataAttributeValueNode
 
1125
: public CdataAttributeValueNode, public NotationAttributeDefOrigin {
 
1126
public:
 
1127
  NotationCdataAttributeValueNode(const GroveImpl *grove,
 
1128
                                  const AttributeValue *value,
 
1129
                                  size_t attIndex,
 
1130
                                  const TextIter &iter,
 
1131
                                  size_t charIndex,
 
1132
                                  const Notation *);
 
1133
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1134
    name = ComponentName::idDefaultValue;
 
1135
    return accessOK;
 
1136
  }
 
1137
};
 
1138
 
 
1139
class EntityNodeBase : public BaseNode {
 
1140
public:
 
1141
  EntityNodeBase(const GroveImpl *grove, const Entity *entity)
 
1142
   : BaseNode(grove), entity_(entity) {}
 
1143
  AccessResult getName(GroveString &str) const;
 
1144
  AccessResult getExternalId(NodePtr &ptr) const;
 
1145
  AccessResult getNotation(NodePtr &) const;
 
1146
  AccessResult getNotationName(GroveString &) const;
 
1147
  AccessResult getText(GroveString &) const;
 
1148
  AccessResult getEntityType(Node::EntityType::Enum &) const;
 
1149
  AccessResult getAttributes(NamedNodeListPtr &) const;
 
1150
  AccessResult attributeRef(unsigned long i, NodePtr &ptr) const;
 
1151
  AccessResult getLocation(Location &) const;
 
1152
  unsigned long hash() const;
 
1153
protected:
 
1154
  const Entity *entity_;
 
1155
};
 
1156
 
 
1157
class EntityNode : public EntityNodeBase {
 
1158
public:
 
1159
  EntityNode(const GroveImpl *grove, const Entity *entity);
 
1160
  AccessResult getOrigin(NodePtr &ptr) const;
 
1161
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &) const;
 
1162
  AccessResult getDefaulted(bool &) const;
 
1163
  bool same(const BaseNode &) const;
 
1164
  bool same2(const EntityNode *) const;
 
1165
  void accept(NodeVisitor &);
 
1166
  const ClassDef &classDef() const { return ClassDef::entity; }
 
1167
};
 
1168
 
 
1169
class DefaultEntityNode : public EntityNodeBase {
 
1170
public:
 
1171
  DefaultEntityNode(const GroveImpl *grove, const Entity *entity);
 
1172
  AccessResult getOrigin(NodePtr &ptr) const;
 
1173
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &) const;
 
1174
  bool same(const BaseNode &) const;
 
1175
  bool same2(const DefaultEntityNode *) const;
 
1176
  void accept(NodeVisitor &);
 
1177
  const ClassDef &classDef() const { return ClassDef::defaultEntity; }
 
1178
};
 
1179
 
 
1180
class NotationNode : public BaseNode {
 
1181
public:
 
1182
  NotationNode(const GroveImpl *grove, const Notation *notation);
 
1183
  AccessResult getOrigin(NodePtr &ptr) const;
 
1184
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1185
    name = ComponentName::idNotations;
 
1186
    return accessOK;
 
1187
  }
 
1188
  AccessResult getName(GroveString &str) const;
 
1189
  AccessResult getExternalId(NodePtr &ptr) const;
 
1190
  AccessResult getAttributeDefs(NamedNodeListPtr &) const;
 
1191
  bool same(const BaseNode &) const;
 
1192
  bool same2(const NotationNode *) const;
 
1193
  AccessResult getLocation(Location &) const;
 
1194
  void accept(NodeVisitor &);
 
1195
  const ClassDef &classDef() const { return ClassDef::notation; }
 
1196
  unsigned long hash() const;
 
1197
private:
 
1198
  const Notation *notation_;
 
1199
};
 
1200
 
 
1201
class ExternalIdNode : public BaseNode {
 
1202
public:
 
1203
  ExternalIdNode(const GroveImpl *grove);
 
1204
  virtual const ExternalId &externalId() const = 0;
 
1205
  AccessResult getPublicId(GroveString &) const;
 
1206
  AccessResult getSystemId(GroveString &) const;
 
1207
  AccessResult getGeneratedSystemId(GroveString &) const;
 
1208
  void accept(NodeVisitor &);
 
1209
  const ClassDef &classDef() const { return ClassDef::externalId; }
 
1210
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1211
    name = ComponentName::idExternalId;
 
1212
    return accessOK;
 
1213
  }
 
1214
  bool same(const BaseNode &) const;
 
1215
  bool same2(const ExternalIdNode *) const;
 
1216
};
 
1217
 
 
1218
class EntityExternalIdNode : public ExternalIdNode {
 
1219
public:
 
1220
  EntityExternalIdNode(const GroveImpl *grove,
 
1221
                       const ExternalEntity *entity);
 
1222
  const ExternalId &externalId() const;
 
1223
  AccessResult getOrigin(NodePtr &ptr) const;
 
1224
  unsigned long hash() const;
 
1225
private:
 
1226
  const ExternalEntity *entity_;
 
1227
};
 
1228
 
 
1229
class NotationExternalIdNode : public ExternalIdNode {
 
1230
public:
 
1231
  NotationExternalIdNode(const GroveImpl *grove,
 
1232
                         const Notation *notation);
 
1233
  const ExternalId &externalId() const;
 
1234
  AccessResult getOrigin(NodePtr &ptr) const;
 
1235
  unsigned long hash() const;
 
1236
private:
 
1237
  const Notation *notation_;
 
1238
};
 
1239
 
 
1240
class DocumentTypeNode : public BaseNode {
 
1241
public:
 
1242
  DocumentTypeNode(const GroveImpl *grove, const Dtd *);
 
1243
  AccessResult getName(GroveString &) const;
 
1244
  AccessResult getGoverning(bool &) const;
 
1245
  AccessResult getGeneralEntities(NamedNodeListPtr &) const;
 
1246
  AccessResult getNotations(NamedNodeListPtr &) const;
 
1247
  AccessResult getElementTypes(NamedNodeListPtr &) const;
 
1248
  AccessResult getDefaultEntity(NodePtr &) const;
 
1249
  AccessResult getParameterEntities(NamedNodeListPtr &) const;
 
1250
  AccessResult getOrigin(NodePtr &) const;
 
1251
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1252
    name = ComponentName::idDoctypesAndLinktypes;
 
1253
    return accessOK;
 
1254
  }
 
1255
  AccessResult nextChunkSibling(NodePtr &) const;
 
1256
  void accept(NodeVisitor &);
 
1257
  const ClassDef &classDef() const { return ClassDef::documentType; }
 
1258
  bool same(const BaseNode &) const;
 
1259
  bool same2(const DocumentTypeNode *) const;
 
1260
private:
 
1261
  const Dtd *dtd_;
 
1262
};
 
1263
 
 
1264
class SgmlConstantsNode : public BaseNode {
 
1265
public:
 
1266
  SgmlConstantsNode(const GroveImpl *);
 
1267
  AccessResult getOrigin(NodePtr &) const;
 
1268
  void accept(NodeVisitor &);
 
1269
  const ClassDef &classDef() const { return ClassDef::sgmlConstants; }
 
1270
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1271
    name = ComponentName::idSgmlConstants;
 
1272
    return accessOK;
 
1273
  }
 
1274
  bool same(const BaseNode &) const;
 
1275
  bool same2(const SgmlConstantsNode *) const;
 
1276
};
 
1277
 
 
1278
class MessageNode : public BaseNode {
 
1279
public:
 
1280
  MessageNode(const GroveImpl *, const MessageItem *);
 
1281
  AccessResult getOrigin(NodePtr &) const;
 
1282
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1283
    name = ComponentName::noId;
 
1284
    return accessOK;
 
1285
  }
 
1286
  AccessResult nextChunkSibling(NodePtr &) const;
 
1287
  AccessResult firstSibling(NodePtr &) const;
 
1288
  AccessResult siblingsIndex(unsigned long &) const;
 
1289
  void accept(NodeVisitor &);
 
1290
  const ClassDef &classDef() const { return ClassDef::message; }
 
1291
  bool same(const BaseNode &) const;
 
1292
  bool same2(const MessageNode *) const;
 
1293
  AccessResult getLocation(Location &) const;
 
1294
  AccessResult getText(GroveString &) const;
 
1295
  AccessResult getSeverity(Severity &) const;
 
1296
private:
 
1297
  const MessageItem *item_;
 
1298
};
 
1299
 
 
1300
// CLASS DEF: ElementTypeNode
 
1301
class ElementTypeNode : public BaseNode {
 
1302
public:
 
1303
  ElementTypeNode(const GroveImpl *grove, const ElementType &elementType)
 
1304
    : BaseNode(grove), elementType_(elementType) {};
 
1305
  AccessResult getOrigin(NodePtr &) const;
 
1306
  const ClassDef &classDef() const { return ClassDef::elementType; }
 
1307
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1308
    name = ComponentName::idElementTypes;
 
1309
    return accessOK;
 
1310
  }
 
1311
  AccessResult getGi(GroveString &str) const;
 
1312
  AccessResult getAttributeDefs(NamedNodeListPtr &) const;
 
1313
  AccessResult getContentType(Node::ContentType::Enum &) const;
 
1314
  AccessResult getExclusions(GroveStringListPtr &) const;
 
1315
  AccessResult getInclusions(GroveStringListPtr &) const;
 
1316
  AccessResult getModelGroup(NodePtr &) const;
 
1317
  AccessResult getOmitEndTag(bool &) const;
 
1318
  AccessResult getOmitStartTag(bool &) const;
 
1319
  AccessResult getLocation(Location &) const;
 
1320
  bool same(const BaseNode &) const;
 
1321
  bool same2(const ElementTypeNode *) const;
 
1322
  void accept(NodeVisitor &);
 
1323
  unsigned long hash() const;
 
1324
  const ElementType &elementType() const { return elementType_; }
 
1325
protected:
 
1326
  const ElementType &elementType_;
 
1327
};
 
1328
 
 
1329
// CLASS DEF: ContentTokenNodeBase
 
1330
class ModelGroupNode;
 
1331
class ContentTokenNodeBase : public BaseNode {
 
1332
public:
 
1333
  ContentTokenNodeBase(const GroveImpl *grove,
 
1334
                       const ElementType &elementType,
 
1335
                       ModelGroupNode *parentModelGroupNode = 0);
 
1336
  ~ContentTokenNodeBase();
 
1337
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1338
    name = ComponentName::idContentTokens;
 
1339
    return accessOK;
 
1340
  }
 
1341
  AccessResult getOrigin(NodePtr &) const;
 
1342
  AccessResult getLocation(Location &) const;
 
1343
  const ElementType &elementType() const { return elementType_; }
 
1344
protected:
 
1345
  ModelGroupNode *parentModelGroupNode_;
 
1346
  const ElementType &elementType_;
 
1347
};
 
1348
 
 
1349
// CLASS DEF: ElementTokenNode
 
1350
class ElementTokenNode : public ContentTokenNodeBase {
 
1351
public:
 
1352
  ElementTokenNode(const GroveImpl *grove,
 
1353
                   const ElementType &elementType,
 
1354
                   const ElementToken &elementToken,
 
1355
                   ModelGroupNode *parentModelGroupNode)
 
1356
   : ContentTokenNodeBase(grove, elementType, parentModelGroupNode),
 
1357
     elementToken_(elementToken) {}
 
1358
  const ClassDef &classDef() const { return ClassDef::elementToken; }
 
1359
  AccessResult getGi(GroveString &str) const;
 
1360
  AccessResult getOccurIndicator(Node::OccurIndicator::Enum &) const;
 
1361
  bool same(const BaseNode &) const;
 
1362
  bool same2(const ElementTokenNode *) const;
 
1363
  void accept(NodeVisitor &);
 
1364
  unsigned long hash() const;
 
1365
  const ElementToken &elementToken() const { return elementToken_; }
 
1366
protected:
 
1367
  const ElementToken &elementToken_;
 
1368
};
 
1369
 
 
1370
// CLASS DEF: PcdataTokenNode
 
1371
class PcdataTokenNode : public ContentTokenNodeBase {
 
1372
public:
 
1373
  PcdataTokenNode(const GroveImpl *grove,
 
1374
                  const ElementType &elementType,
 
1375
                  const PcdataToken &pcdataToken,
 
1376
                  ModelGroupNode *parentModelGroupNode)
 
1377
   : ContentTokenNodeBase(grove, elementType, parentModelGroupNode),
 
1378
     pcdataToken_(pcdataToken) {}
 
1379
  const ClassDef &classDef() const { return ClassDef::pcdataToken; }
 
1380
  bool same(const BaseNode &) const;
 
1381
  bool same2(const PcdataTokenNode *) const;
 
1382
  void accept(NodeVisitor &);
 
1383
  unsigned long hash() const;
 
1384
  const PcdataToken &pcdataToken() const { return pcdataToken_; }
 
1385
protected:
 
1386
  const PcdataToken &pcdataToken_;
 
1387
};
 
1388
 
 
1389
// CLASS DEF: ModelGroupNode
 
1390
class ModelGroupNode : public ContentTokenNodeBase {
 
1391
public:
 
1392
  ModelGroupNode(const GroveImpl *grove,
 
1393
                 const ElementType &elementType,
 
1394
                 const ModelGroup &modelGroup,
 
1395
                 ModelGroupNode *parentModelGroupNode = 0)
 
1396
   : ContentTokenNodeBase(grove, elementType, parentModelGroupNode),
 
1397
     modelGroup_(modelGroup) {}
 
1398
  const ClassDef &classDef() const { return ClassDef::modelGroup; }
 
1399
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const;
 
1400
  AccessResult getConnector(Node::Connector::Enum &con) const;
 
1401
  AccessResult getOccurIndicator(Node::OccurIndicator::Enum &occur) const;
 
1402
  AccessResult getContentTokens(NodeListPtr &) const;
 
1403
  bool same(const BaseNode &) const;
 
1404
  bool same2(const ModelGroupNode *) const;
 
1405
  void accept(NodeVisitor &);
 
1406
  unsigned long hash() const;
 
1407
  void makeNode(NodePtr &ptr, unsigned contentTokenIdx);
 
1408
  const ModelGroup &modelGroup() const { return modelGroup_; }
 
1409
private:
 
1410
  const ModelGroup &modelGroup_;
 
1411
};
 
1412
 
 
1413
// class DEF: AttributeDefNode
 
1414
class AttributeDefNode : public BaseNode, public virtual AttributeDefOrigin {
 
1415
public:
 
1416
  AttributeDefNode(const GroveImpl *grove, size_t attIndex)
 
1417
   : BaseNode(grove), AttributeDefOrigin(attIndex) {}
 
1418
  const ClassDef &classDef() const { return ClassDef::attributeDef; }
 
1419
  AccessResult getOrigin(NodePtr &ptr) const;
 
1420
  AccessResult getName(GroveString &) const;
 
1421
  AccessResult getDeclValueType(Node::DeclValueType::Enum &) const;
 
1422
  AccessResult getDefaultValueType(Node::DefaultValueType::Enum &) const;
 
1423
  AccessResult getTokens(GroveStringListPtr &) const;
 
1424
  AccessResult getCurrentAttributeIndex(long &) const;
 
1425
  void accept(NodeVisitor &visitor);
 
1426
  bool same(const BaseNode &node) const;
 
1427
  bool same2(const AttributeDefNode *node) const;
 
1428
  unsigned long hash() const;
 
1429
protected:
 
1430
};
 
1431
 
 
1432
// class DEF: ElementTypeAttributeDefNode
 
1433
class ElementTypeAttributeDefNode
 
1434
: public AttributeDefNode, public ElementTypeAttributeDefOrigin {
 
1435
public:
 
1436
  ElementTypeAttributeDefNode(const GroveImpl *grove,
 
1437
                              const ElementType &elementType,
 
1438
                              size_t attributeDefIdx)
 
1439
   : AttributeDefNode(grove, attributeDefIdx),
 
1440
     ElementTypeAttributeDefOrigin(&elementType),
 
1441
     AttributeDefOrigin(attributeDefIdx) {}
 
1442
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1443
    name = ComponentName::idAttributeDefs;
 
1444
    return accessOK;
 
1445
  }
 
1446
  AccessResult getCurrentGroup(NodeListPtr &) const;
 
1447
  AccessResult getLocation(Location &) const;
 
1448
  AccessResult getDefaultValue(NodeListPtr &) const;
 
1449
};
 
1450
 
 
1451
// class DEF: NotationAttributeDefNode
 
1452
class NotationAttributeDefNode
 
1453
: public AttributeDefNode, public NotationAttributeDefOrigin {
 
1454
public:
 
1455
  NotationAttributeDefNode(const GroveImpl *grove,
 
1456
                           const Notation &notation,
 
1457
                           size_t attributeDefIdx)
 
1458
   : AttributeDefNode(grove, attributeDefIdx),
 
1459
     NotationAttributeDefOrigin(&notation),
 
1460
     AttributeDefOrigin(attributeDefIdx)  {};
 
1461
  AccessResult getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const {
 
1462
    name = ComponentName::idAttributeDefs;
 
1463
    return accessOK;
 
1464
  }
 
1465
  AccessResult getCurrentGroup(NodeListPtr &) const;
 
1466
  AccessResult getLocation(Location &) const;
 
1467
  //AccessResult getDefaultValue(NodeListPtr &) const;
 
1468
};
 
1469
 
 
1470
class BaseNodeList : public NodeList {
 
1471
public:
 
1472
  BaseNodeList() : refCount_(0) { }
 
1473
  virtual ~BaseNodeList() { }
 
1474
  void addRef() { ++refCount_; }
 
1475
  bool canReuse(NodeListPtr &ptr) const {
 
1476
    const NodeList *tem = &*ptr;
 
1477
    return tem == this && refCount_ == 1;
 
1478
  }
 
1479
  void release() {
 
1480
    ASSERT(refCount_ != 0);
 
1481
    if (--refCount_ == 0) delete this;
 
1482
  }
 
1483
  AccessResult first(NodePtr &) const { return accessNull; }
 
1484
  AccessResult rest(NodeListPtr &ptr) const { return chunkRest(ptr); }
 
1485
  AccessResult chunkRest(NodeListPtr &) const { return accessNull; }
 
1486
private:
 
1487
  unsigned refCount_;
 
1488
};
 
1489
 
 
1490
class SiblingNodeList : public BaseNodeList {
 
1491
public:
 
1492
  SiblingNodeList(const NodePtr &first) : first_(first) { }
 
1493
  AccessResult first(NodePtr &ptr) const {
 
1494
    ptr = first_;
 
1495
    return accessOK;
 
1496
  }
 
1497
  AccessResult rest(NodeListPtr &ptr) const {
 
1498
    AccessResult ret;
 
1499
    if (canReuse(ptr)) {
 
1500
      ret = ((SiblingNodeList *)this)->first_.assignNextSibling();
 
1501
      if (ret == accessOK)
 
1502
        return ret;
 
1503
    }
 
1504
    else {
 
1505
      NodePtr next;
 
1506
      ret = first_->nextSibling(next);
 
1507
      if (ret == accessOK) {
 
1508
        ptr.assign(new SiblingNodeList(next));
 
1509
        return ret;
 
1510
      }
 
1511
    }
 
1512
    if (ret == accessNull) {
 
1513
      ptr.assign(new BaseNodeList);
 
1514
      return accessOK;
 
1515
    }
 
1516
    return ret;
 
1517
  }
 
1518
  AccessResult chunkRest(NodeListPtr &ptr) const {
 
1519
    AccessResult ret;
 
1520
    if (canReuse(ptr)) {
 
1521
      ret = ((SiblingNodeList *)this)->first_.assignNextChunkSibling();
 
1522
      if (ret == accessOK)
 
1523
        return ret;
 
1524
    }
 
1525
    else {
 
1526
      NodePtr next;
 
1527
      ret = first_->nextChunkSibling(next);
 
1528
      if (ret == accessOK) {
 
1529
        ptr.assign(new SiblingNodeList(next));
 
1530
        return ret;
 
1531
      }
 
1532
    }
 
1533
    if (ret == accessNull) {
 
1534
      ptr.assign(new BaseNodeList);
 
1535
      return accessOK;
 
1536
    }
 
1537
    return ret;
 
1538
  }
 
1539
  AccessResult ref(unsigned long i, NodePtr &ptr) const {
 
1540
    if (i == 0) {
 
1541
      ptr = first_;
 
1542
      return accessOK;
 
1543
    }
 
1544
    return first_->followSiblingRef(i - 1, ptr);
 
1545
  }
 
1546
private:
 
1547
  NodePtr first_; // never null
 
1548
};
 
1549
 
 
1550
class BaseNamedNodeList : public NamedNodeList {
 
1551
public:
 
1552
  BaseNamedNodeList(const GroveImpl *grove,
 
1553
                    const SubstTable<Char> *substTable)
 
1554
  : grove_(grove), substTable_(substTable), refCount_(0) { }
 
1555
  virtual ~BaseNamedNodeList() { }
 
1556
  void addRef() { ++refCount_; }
 
1557
  bool canReuse(NamedNodeListPtr &ptr) const {
 
1558
    const NamedNodeList *tem = &*ptr;
 
1559
    return tem == this && refCount_ == 1;
 
1560
  }
 
1561
  void release() {
 
1562
    ASSERT(refCount_ != 0);
 
1563
    if (--refCount_ == 0) delete this;
 
1564
  }
 
1565
  size_t normalize(Char *s, size_t n) const {
 
1566
    if (substTable_) {
 
1567
      for (size_t i = 0; i < n; i++)
 
1568
        substTable_->subst(s[i]);
 
1569
    }
 
1570
    return n;
 
1571
  }
 
1572
  const GroveImpl *grove() const { return grove_; }
 
1573
  AccessResult namedNode(GroveString str, NodePtr &node) const {
 
1574
    StringC tem(str.data(), str.size());
 
1575
    normalize(&tem[0], tem.size());
 
1576
    return namedNodeU(tem, node);
 
1577
  }
 
1578
  virtual AccessResult namedNodeU(const StringC &, NodePtr &) const = 0;
 
1579
private:
 
1580
  GroveImplPtr grove_;
 
1581
  const SubstTable<Char> *substTable_;
 
1582
  unsigned refCount_;
 
1583
};
 
1584
 
 
1585
class AttributesNamedNodeList
 
1586
: public BaseNamedNodeList, public virtual AttributeOrigin {
 
1587
public:
 
1588
  AttributesNamedNodeList(const GroveImpl *grove)
 
1589
   : BaseNamedNodeList(grove, grove->generalSubstTable()) { }
 
1590
  NodeListPtr nodeList() const;
 
1591
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1592
  Type type() const { return attributes; }
 
1593
};
 
1594
 
 
1595
class ElementAttributesNamedNodeList
 
1596
: public AttributesNamedNodeList, public ElementAttributeOrigin {
 
1597
public:
 
1598
  ElementAttributesNamedNodeList(const GroveImpl *grove,
 
1599
                                 const ElementChunk *chunk)
 
1600
   : AttributesNamedNodeList(grove), ElementAttributeOrigin(chunk) { }
 
1601
};
 
1602
 
 
1603
class EntityAttributesNamedNodeList
 
1604
: public AttributesNamedNodeList, public EntityAttributeOrigin {
 
1605
public:
 
1606
  EntityAttributesNamedNodeList(const GroveImpl *grove,
 
1607
                                const ExternalDataEntity *entity)
 
1608
   : AttributesNamedNodeList(grove), EntityAttributeOrigin(entity) { }
 
1609
};
 
1610
 
 
1611
class ElementsNamedNodeList : public BaseNamedNodeList {
 
1612
public:
 
1613
  ElementsNamedNodeList(const GroveImpl *grove)
 
1614
    : BaseNamedNodeList(grove, grove->generalSubstTable()) { }
 
1615
  NodeListPtr nodeList() const;
 
1616
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1617
  Type type() const { return elements; }
 
1618
};
 
1619
 
 
1620
class DocEntitiesNamedNodeList : public BaseNamedNodeList {
 
1621
public:
 
1622
  DocEntitiesNamedNodeList(const GroveImpl *grove)
 
1623
   : BaseNamedNodeList(grove, grove->entitySubstTable()) { }
 
1624
  NodeListPtr nodeList() const;
 
1625
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1626
  Type type() const { return entities; }
 
1627
};
 
1628
 
 
1629
class DefaultedEntitiesNamedNodeList : public BaseNamedNodeList {
 
1630
public:
 
1631
  DefaultedEntitiesNamedNodeList(const GroveImpl *grove)
 
1632
   : BaseNamedNodeList(grove, grove->entitySubstTable()) { }
 
1633
  NodeListPtr nodeList() const;
 
1634
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1635
  Type type() const { return entities; }
 
1636
};
 
1637
 
 
1638
class GeneralEntitiesNamedNodeList : public BaseNamedNodeList {
 
1639
public:
 
1640
  GeneralEntitiesNamedNodeList(const GroveImpl *, const Dtd *);
 
1641
  NodeListPtr nodeList() const;
 
1642
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1643
  Type type() const { return entities; }
 
1644
private:
 
1645
  const Dtd *dtd_;
 
1646
};
 
1647
 
 
1648
class ParameterEntitiesNamedNodeList : public BaseNamedNodeList {
 
1649
public:
 
1650
  ParameterEntitiesNamedNodeList(const GroveImpl *, const Dtd *);
 
1651
  NodeListPtr nodeList() const;
 
1652
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1653
  Type type() const { return entities; }
 
1654
private:
 
1655
  const Dtd *dtd_;
 
1656
};
 
1657
 
 
1658
class NotationsNamedNodeList : public BaseNamedNodeList {
 
1659
public:
 
1660
  NotationsNamedNodeList(const GroveImpl *, const Dtd *);
 
1661
  NodeListPtr nodeList() const;
 
1662
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1663
  Type type() const { return notations; }
 
1664
private:
 
1665
  const Dtd *dtd_;
 
1666
};
 
1667
 
 
1668
class DoctypesAndLinktypesNamedNodeList : public BaseNamedNodeList {
 
1669
public:
 
1670
  DoctypesAndLinktypesNamedNodeList(const GroveImpl *);
 
1671
  NodeListPtr nodeList() const;
 
1672
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1673
  Type type() const { return doctypesAndLinktypes; }
 
1674
};
 
1675
 
 
1676
class ElementsNodeList : public BaseNodeList {
 
1677
public:
 
1678
  ElementsNodeList(const GroveImpl *grove,
 
1679
                   const Chunk *head);
 
1680
  AccessResult first(NodePtr &) const;
 
1681
  AccessResult chunkRest(NodeListPtr &) const;
 
1682
public:
 
1683
  GroveImplPtr grove_;
 
1684
  const Chunk *first_;
 
1685
};
 
1686
 
 
1687
class EntitiesNodeList : public BaseNodeList {
 
1688
public:
 
1689
  EntitiesNodeList(const GroveImpl *grove,
 
1690
                   const Dtd::ConstEntityIter &iter);
 
1691
  AccessResult first(NodePtr &) const;
 
1692
  AccessResult chunkRest(NodeListPtr &) const;
 
1693
protected:
 
1694
  const GroveImpl *grove() const { return grove_; }
 
1695
public:
 
1696
  GroveImplPtr grove_;
 
1697
  Dtd::ConstEntityIter iter_;
 
1698
};
 
1699
 
 
1700
class DocEntitiesNodeList : public EntitiesNodeList {
 
1701
public:
 
1702
  DocEntitiesNodeList(const GroveImpl *grove);
 
1703
  AccessResult first(NodePtr &) const;
 
1704
  AccessResult chunkRest(NodeListPtr &) const;
 
1705
};
 
1706
 
 
1707
class NotationsNodeList : public BaseNodeList {
 
1708
public:
 
1709
  NotationsNodeList(const GroveImpl *grove,
 
1710
                    const Dtd::ConstNotationIter &iter);
 
1711
  AccessResult first(NodePtr &) const;
 
1712
  AccessResult chunkRest(NodeListPtr &) const;
 
1713
public:
 
1714
  GroveImplPtr grove_;
 
1715
  Dtd::ConstNotationIter iter_;
 
1716
};
 
1717
 
 
1718
// -- CLASS DEF: ElementTypesNodeList
 
1719
class ElementTypesNodeList : public BaseNodeList {
 
1720
public:
 
1721
  ElementTypesNodeList( const GroveImpl *grove,
 
1722
                        const Dtd::ConstElementTypeIter &iter);
 
1723
  AccessResult first(NodePtr &) const;
 
1724
  AccessResult chunkRest(NodeListPtr &) const;
 
1725
public:
 
1726
  GroveImplPtr grove_;
 
1727
  Dtd::ConstElementTypeIter iter_;
 
1728
};
 
1729
 
 
1730
// -- CLASS DEF: ElementTypesNamedNodeList
 
1731
class ElementTypesNamedNodeList : public BaseNamedNodeList {
 
1732
public:
 
1733
  ElementTypesNamedNodeList(const GroveImpl *, const Dtd *);
 
1734
  NodeListPtr nodeList() const;
 
1735
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1736
  Type type() const { return elementTypes; }
 
1737
protected:
 
1738
  const Dtd *dtd_;
 
1739
};
 
1740
 
 
1741
// -- CLASS DEF: ContentTokenNodeList
 
1742
class ContentTokenNodeList : public BaseNodeList {
 
1743
public:
 
1744
  ContentTokenNodeList(const GroveImpl *grove,
 
1745
                       ModelGroupNode &modelGroupNode,
 
1746
                       unsigned firstTokenIdx = 0);
 
1747
  AccessResult first(NodePtr &) const;
 
1748
  AccessResult chunkRest(NodeListPtr &) const;
 
1749
  unsigned firstTokenIdx() const { return firstTokenIdx_; }
 
1750
  AccessResult next();
 
1751
protected:
 
1752
  GroveImplPtr grove_;
 
1753
  ModelGroupNode &modelGroupNode_;
 
1754
  unsigned firstTokenIdx_;
 
1755
};
 
1756
 
 
1757
// -- CLASS DEF: ModelGroupNodeList
 
1758
class ModelGroupNodeList : public BaseNodeList {
 
1759
public:
 
1760
  ModelGroupNodeList(const GroveImpl *grove,
 
1761
                     const ModelGroup &modelGroupNode,
 
1762
                     size_t firstTokenIdx);
 
1763
  AccessResult first(NodePtr &) const;
 
1764
  AccessResult chunkRest(NodeListPtr &) const;
 
1765
protected:
 
1766
  GroveImplPtr grove_;
 
1767
  ModelGroup &modelGroup_;
 
1768
  size_t firstTokenIdx_;
 
1769
};
 
1770
 
 
1771
// -- CLASS DEF: AttributeDefsNodeList
 
1772
class AttributeDefsNodeList
 
1773
 : public BaseNodeList, public virtual AttributeDefOrigin {
 
1774
public:
 
1775
  AttributeDefsNodeList(const GroveImpl *grove,
 
1776
                        size_t firstAttIndex)
 
1777
   : grove_(grove), AttributeDefOrigin(firstAttIndex) {}
 
1778
  AccessResult first(NodePtr &) const;
 
1779
  AccessResult chunkRest(NodeListPtr &) const;
 
1780
  bool inList(size_t attIndex) const;
 
1781
protected:
 
1782
  GroveImplPtr grove_;
 
1783
};
 
1784
 
 
1785
// -- CLASS DEF: ElementTypeAttributeDefsNodeList
 
1786
class ElementTypeAttributeDefsNodeList
 
1787
 : public AttributeDefsNodeList, public ElementTypeAttributeDefOrigin {
 
1788
public:
 
1789
  ElementTypeAttributeDefsNodeList(const GroveImpl *grove,
 
1790
                                   const ElementType &elementType,
 
1791
                                   size_t firstAttIndex)
 
1792
   : AttributeDefsNodeList(grove, firstAttIndex),
 
1793
     ElementTypeAttributeDefOrigin(&elementType),
 
1794
     AttributeDefOrigin(firstAttIndex) {}
 
1795
};
 
1796
 
 
1797
// -- CLASS DEF: NotationAttributeDefsNodeList
 
1798
class NotationAttributeDefsNodeList
 
1799
 : public AttributeDefsNodeList, public NotationAttributeDefOrigin {
 
1800
public:
 
1801
  NotationAttributeDefsNodeList(const GroveImpl *grove,
 
1802
                                const Notation &notation,
 
1803
                                size_t firstAttIndex)
 
1804
   : AttributeDefsNodeList(grove, firstAttIndex),
 
1805
     NotationAttributeDefOrigin(&notation),
 
1806
     AttributeDefOrigin(firstAttIndex) {}
 
1807
};
 
1808
 
 
1809
// -- CLASS DEF: AttributeDefsNamedNodeList
 
1810
class AttributeDefsNamedNodeList
 
1811
 : public BaseNamedNodeList, public virtual AttributeDefOrigin {
 
1812
public:
 
1813
  AttributeDefsNamedNodeList(const GroveImpl *grove)
 
1814
   : BaseNamedNodeList(grove, grove->generalSubstTable()) { }
 
1815
  NodeListPtr nodeList() const;
 
1816
  AccessResult namedNodeU(const StringC &, NodePtr &) const;
 
1817
  Type type() const { return attributeDefs; }
 
1818
};
 
1819
 
 
1820
// -- CLASS DEF: ElementTypeAttributeDefsNamedNodeList
 
1821
class ElementTypeAttributeDefsNamedNodeList
 
1822
 : public AttributeDefsNamedNodeList, public ElementTypeAttributeDefOrigin {
 
1823
public:
 
1824
  ElementTypeAttributeDefsNamedNodeList(const GroveImpl *grove,
 
1825
                                        const ElementType &elementType)
 
1826
   : AttributeDefsNamedNodeList(grove), ElementTypeAttributeDefOrigin(&elementType) { }
 
1827
};
 
1828
 
 
1829
// -- CLASS DEF: NotationAttributeDefsNamedNodeList
 
1830
class NotationAttributeDefsNamedNodeList
 
1831
 : public AttributeDefsNamedNodeList, public NotationAttributeDefOrigin {
 
1832
public:
 
1833
  NotationAttributeDefsNamedNodeList(const GroveImpl *grove,
 
1834
                                     const Notation &notation)
 
1835
   : AttributeDefsNamedNodeList(grove), NotationAttributeDefOrigin(&notation) { }
 
1836
};
 
1837
 
 
1838
// -- CLASS DEF: ElementTypeCurrentGroupAttributeDefsNodeList
 
1839
// elementType_ is first list element, iter.next() represents rest
 
1840
class ElementTypeCurrentGroupAttributeDefsNodeList 
 
1841
: public BaseNodeList {
 
1842
public:
 
1843
  ElementTypeCurrentGroupAttributeDefsNodeList(const GroveImpl *grove,
 
1844
                                               const Dtd::ConstElementTypeIter &iter,
 
1845
                                               size_t currentGroupIndex);
 
1846
  ElementTypeCurrentGroupAttributeDefsNodeList(const GroveImpl *grove,
 
1847
                                               const Dtd::ConstElementTypeIter &iter,
 
1848
                                               const ElementType *elementType,
 
1849
                                               size_t firstAttIndex,
 
1850
                                               size_t currentGroupIndex)
 
1851
   : grove_(grove), iter_(iter), elementType_(elementType), attIndex_(firstAttIndex),
 
1852
     currentGroupIndex_(currentGroupIndex) {}
 
1853
  AccessResult first(NodePtr &) const;
 
1854
  AccessResult chunkRest(NodeListPtr &) const;
 
1855
  bool next(Dtd::ConstElementTypeIter &iter,
 
1856
            const ElementType *&elementType,
 
1857
            size_t &attIndex,
 
1858
            bool incrementFirst = true) const;
 
1859
  bool next(bool incrementFirst = true) {
 
1860
    return next(iter_, elementType_, attIndex_, incrementFirst); }
 
1861
protected:
 
1862
  GroveImplPtr grove_;
 
1863
  Dtd::ConstElementTypeIter iter_;
 
1864
  const ElementType *elementType_;
 
1865
  size_t currentGroupIndex_;
 
1866
  size_t attIndex_;
 
1867
};
 
1868
 
 
1869
inline
 
1870
Boolean GroveImpl::waitForMoreNodes() const
 
1871
{
 
1872
  if (blockingAccess)
 
1873
    return moreNodesCondition_.wait();
 
1874
  else
 
1875
    return 0;
 
1876
}
 
1877
 
 
1878
inline
 
1879
void GroveImpl::pulse()
 
1880
{
 
1881
  moreNodesCondition_.pulse();
 
1882
}
 
1883
 
 
1884
inline
 
1885
void GroveImpl::maybePulse()
 
1886
{
 
1887
  // Once we've had (2^n)*(2^10) events, only pulse every (2^n)th event.
 
1888
  // Up to a limit of n == 8.
 
1889
  // This reduces the overhead of pulsing to negligible levels on WinNT.
 
1890
  if ((++nEvents_ & ~(~unsigned(0) << pulseStep_)) == 0) {
 
1891
    pulse();
 
1892
    if (pulseStep_ < 8 && nEvents_ > (1 << (pulseStep_ + 10)))
 
1893
      pulseStep_++;
 
1894
  }
 
1895
}
 
1896
 
 
1897
inline
 
1898
void GroveImpl::appendSibling(Chunk *chunk)
 
1899
{
 
1900
  if (pendingData_) {
 
1901
    if (tailPtr_) {
 
1902
      // Must set completeLimit_ before setting tailPtr_.
 
1903
      completeLimit_ = pendingData_->after();
 
1904
      *tailPtr_ = pendingData_;
 
1905
      tailPtr_ = 0;
 
1906
    }
 
1907
    pendingData_ = 0;
 
1908
  }
 
1909
  // Must set origin before advancing completeLimit_.
 
1910
  chunk->origin = origin_;
 
1911
  // Must advance completeLimit_ before setting tailPtr_.
 
1912
  completeLimit_ = freePtr_;
 
1913
  if (tailPtr_) {
 
1914
    *tailPtr_ = chunk;
 
1915
    tailPtr_ = 0;
 
1916
  }
 
1917
  pendingData_ = 0;
 
1918
  maybePulse();
 
1919
}
 
1920
 
 
1921
inline
 
1922
void GroveImpl::appendSibling(DataChunk *chunk)
 
1923
{
 
1924
  // Since we might extend this DataChunk, it's
 
1925
  // not safe to set completeLimit_ to after this chunk yet.
 
1926
  // This means we can't yet set tailPtr_.
 
1927
  if (pendingData_) {
 
1928
    // Must set completeLimit_ before setting tailPtr_.
 
1929
    completeLimit_ = pendingData_->after();
 
1930
    if (tailPtr_) {
 
1931
      *tailPtr_ = pendingData_;
 
1932
      tailPtr_ = 0;
 
1933
    }
 
1934
  }
 
1935
  chunk->origin = origin_;
 
1936
  pendingData_ = chunk;
 
1937
  maybePulse();
 
1938
}
 
1939
 
 
1940
inline
 
1941
void GroveImpl::push(ElementChunk *chunk, Boolean hasId)
 
1942
{
 
1943
  if (pendingData_) {
 
1944
    if (tailPtr_) {
 
1945
      // Must set completeLimit_ before setting tailPtr_.
 
1946
      completeLimit_ = pendingData_->after();
 
1947
      *tailPtr_ = pendingData_;
 
1948
      tailPtr_ = 0;
 
1949
    }
 
1950
    pendingData_ = 0;
 
1951
  }
 
1952
  chunk->elementIndex = nElements_++;
 
1953
  chunk->origin = origin_;
 
1954
  // Must set origin_ to chunk before advancing completeLimit_
 
1955
  // otherwise thread would look at element and
 
1956
  // maybeMoreSiblings() would return false.
 
1957
  // Must advance completeLimit_ before setting tailPtr_,
 
1958
  // otherwise tailPtr_ would be beyond completeLimit_.
 
1959
  origin_ = chunk;
 
1960
  completeLimit_ = freePtr_;
 
1961
  // Allow for the possibility of invalid documents with elements
 
1962
  // after the document element.
 
1963
  if ((const Chunk *)chunk->origin == root_ && root_->documentElement == 0)
 
1964
    root_->documentElement = chunk;
 
1965
  else if (tailPtr_) {
 
1966
    *tailPtr_ = chunk;
 
1967
    tailPtr_ = 0;
 
1968
  }
 
1969
  if (hasId) {
 
1970
    Mutex::Lock lock(mutexPtr_);
 
1971
    idTable_.insert(chunk);
 
1972
  }
 
1973
  maybePulse();
 
1974
}
 
1975
 
 
1976
inline
 
1977
void GroveImpl::pop()
 
1978
{
 
1979
  if (pendingData_) {
 
1980
    // Must set completeLimit_ before setting tailPtr_.
 
1981
    completeLimit_ = pendingData_->after();
 
1982
    if (tailPtr_) {
 
1983
      *tailPtr_ = pendingData_;
 
1984
      tailPtr_ = 0;
 
1985
    }
 
1986
    pendingData_ = 0;
 
1987
  }
 
1988
  tailPtr_ = &origin_->nextSibling;
 
1989
  origin_ = origin_->origin;
 
1990
  if ((const Chunk *)origin_ == root_)
 
1991
    finishDocumentElement();
 
1992
  maybePulse();
 
1993
}
 
1994
 
 
1995
inline
 
1996
Boolean GroveImpl::haveRootOrigin()
 
1997
{
 
1998
  return (const Chunk *)origin_ == root_;
 
1999
}
 
2000
 
 
2001
inline
 
2002
void GroveImpl::setDtd(const ConstPtr<Dtd> &dtd)
 
2003
{
 
2004
  dtd_ = dtd;
 
2005
  hasDefaultEntity_ = !dtd_->defaultEntity().isNull();
 
2006
  finishProlog();
 
2007
  pulse();
 
2008
}
 
2009
 
 
2010
inline
 
2011
const ElementChunk *GroveImpl::lookupElement(const StringC &id) const
 
2012
{
 
2013
  Mutex::Lock lock(mutexPtr_);
 
2014
  return idTable_.lookup(id);
 
2015
}
 
2016
 
 
2017
inline
 
2018
GroveImpl::ElementIter GroveImpl::elementIter() const
 
2019
{
 
2020
  ASSERT(complete());
 
2021
  return ElementIter(idTable_);
 
2022
}
 
2023
 
 
2024
inline
 
2025
Boolean GroveImpl::maybeMoreSiblings(const ParentChunk *chunk) const
 
2026
{
 
2027
  return (complete_
 
2028
          ? chunk->nextSibling != 0
 
2029
          : (origin_ == chunk 
 
2030
              || &chunk->nextSibling == tailPtr_
 
2031
              || maybeMoreSiblings1(chunk)));
 
2032
 
2033
 
 
2034
inline
 
2035
void *GroveImpl::allocChunk(size_t n)
 
2036
{
 
2037
  nChunksSinceLocOrigin_++;
 
2038
  if (n <= nFree_) {
 
2039
    void *p = freePtr_;
 
2040
    freePtr_ += n;
 
2041
    nFree_ -= n;
 
2042
    return p;
 
2043
  }
 
2044
  else
 
2045
    return allocFinish(n);
 
2046
}
 
2047
 
 
2048
inline
 
2049
void GroveImpl::setLocOrigin(const ConstPtr<Origin> &locOrigin)
 
2050
{
 
2051
  if (locOrigin.pointer() != currentLocOrigin_
 
2052
      || nChunksSinceLocOrigin_ >= maxChunksWithoutLocOrigin)
 
2053
    storeLocOrigin(locOrigin);
 
2054
}
 
2055
 
 
2056
inline
 
2057
void GroveImpl::appendMessage(MessageItem *item)
 
2058
{
 
2059
  *messageListTailP_ = item;
 
2060
  messageListTailP_ = item->nextP();
 
2061
  pulse();
 
2062
}
 
2063
 
 
2064
inline
 
2065
void ElementNode::add(GroveImpl &grove, const StartElementEvent &event)
 
2066
{
 
2067
  grove.setLocOrigin(event.location().origin());
 
2068
  ElementChunk *chunk;
 
2069
  const AttributeList &atts = event.attributes();
 
2070
  Boolean hasId;
 
2071
  if (atts.nSpec() == 0 && !atts.anyCurrent()) {
 
2072
    void *mem = grove.allocChunk(sizeof(ElementChunk));
 
2073
    if (event.included())
 
2074
      chunk = new (mem) IncludedElementChunk;
 
2075
    else
 
2076
      chunk = new (mem) ElementChunk;
 
2077
    hasId = 0;
 
2078
  }
 
2079
  else
 
2080
    chunk = makeAttElementChunk(grove, event, hasId);
 
2081
  chunk->type = event.elementType();
 
2082
  chunk->locIndex = event.location().index();
 
2083
  grove.push(chunk, hasId);
 
2084
}
 
2085
 
 
2086
// We duplicate ChunkNode::nextChunkSibling to take advantage
 
2087
// of Node reuse (via setNodePtrFirst(NodePtr &, const DataNode *).
 
2088
inline
 
2089
AccessResult DataNode::nextChunkSibling(NodePtr &ptr) const
 
2090
{
 
2091
  // The forwarding chunk has origin = 0, so it will stop
 
2092
  // the iteration before after() can return 0.
 
2093
  const Chunk *p = chunk_->after();
 
2094
  while (p == grove()->completeLimit())
 
2095
    if (!grove()->waitForMoreNodes())
 
2096
      return accessTimeout;
 
2097
  if (p->origin != chunk_->origin)
 
2098
    return accessNull;
 
2099
  return p->setNodePtrFirst(ptr, this);
 
2100
}
 
2101
 
 
2102
inline
 
2103
void DataNode::reuseFor(const DataChunk *chunk, size_t index)
 
2104
{
 
2105
  chunk_ = chunk;
 
2106
  index_ = index;
 
2107
}
 
2108
 
 
2109
inline
 
2110
void DataNode::add(GroveImpl &grove, const DataEvent &event)
 
2111
{
 
2112
  size_t dataLen = event.dataLength();
 
2113
  if (dataLen) {
 
2114
   DataChunk *chunk = grove.pendingData();
 
2115
   if (chunk
 
2116
       && event.location().origin().pointer() == grove.currentLocOrigin()
 
2117
       && event.location().index() == chunk->locIndex + chunk->size
 
2118
       && grove.tryExtend(CharsChunk::allocSize(chunk->size + dataLen)
 
2119
                          - CharsChunk::allocSize(chunk->size))) {
 
2120
     memcpy((Char *)(chunk + 1) + chunk->size,
 
2121
            event.data(),
 
2122
            dataLen * sizeof(Char));
 
2123
     chunk->size += dataLen;
 
2124
   }
 
2125
   else {
 
2126
     grove.setLocOrigin(event.location().origin());
 
2127
     chunk = new (grove.allocChunk(CharsChunk::allocSize(dataLen))) DataChunk;
 
2128
     chunk->size = dataLen;
 
2129
     chunk->locIndex = event.location().index();
 
2130
     memcpy(chunk + 1, event.data(), dataLen * sizeof(Char));
 
2131
     grove.appendSibling(chunk);
 
2132
   }
 
2133
 }
 
2134
}
 
2135
 
 
2136
GroveBuilderMessageEventHandler::GroveBuilderMessageEventHandler(unsigned groveIndex,
 
2137
                                                                 Messenger *mgr,
 
2138
                                                                 MessageFormatter *msgFmt)
 
2139
: mgr_(mgr), grove_(new GroveImpl(groveIndex)), msgFmt_(msgFmt)
 
2140
{
 
2141
  grove_->addRef();
 
2142
}
 
2143
 
 
2144
GroveBuilderMessageEventHandler::~GroveBuilderMessageEventHandler()
 
2145
{
 
2146
  grove_->setComplete();
 
2147
  grove_->release();
 
2148
}
 
2149
 
 
2150
void GroveBuilderMessageEventHandler::makeInitialRoot(NodePtr &root)
 
2151
{
 
2152
  root.assign(new SgmlDocumentNode(grove_, grove_->root()));
 
2153
}
 
2154
 
 
2155
void GroveBuilderMessageEventHandler::message(MessageEvent *event)
 
2156
{
 
2157
  mgr_->dispatchMessage(event->message());
 
2158
  const Message &msg = event->message();
 
2159
  StrOutputCharStream os;
 
2160
  msgFmt_->formatMessage(*msg.type, msg.args, os);
 
2161
  StringC tem;
 
2162
  os.extractString(tem);
 
2163
  Node::Severity severity;
 
2164
  switch (msg.type->severity()) {
 
2165
  case MessageType::info:
 
2166
    severity = Node::info;
 
2167
    break;
 
2168
  case MessageType::warning:
 
2169
    severity = Node::warning;
 
2170
    break;
 
2171
  default:
 
2172
    severity = Node::error;
 
2173
    break;
 
2174
  }
 
2175
  grove_->appendMessage(new MessageItem(severity, tem, msg.loc));
 
2176
  if (!msg.auxLoc.origin().isNull()) {
 
2177
    msgFmt_->formatMessage(msg.type->auxFragment(), msg.args, os);
 
2178
    os.extractString(tem);
 
2179
    grove_->appendMessage(new MessageItem(Node::info, tem, msg.auxLoc));
 
2180
  }
 
2181
  ErrorCountEventHandler::message(event);
 
2182
}
 
2183
 
 
2184
void GroveBuilderMessageEventHandler::sgmlDecl(SgmlDeclEvent *event)
 
2185
{
 
2186
  grove_->setSd(event->sdPointer(), event->prologSyntaxPointer(), event->instanceSyntaxPointer());
 
2187
  delete event;
 
2188
}
 
2189
 
 
2190
void GroveBuilderMessageEventHandler::setSd(const ConstPtr<Sd> &sd, const ConstPtr<Syntax> &prologSyntax, const ConstPtr<Syntax> &instanceSyntax)
 
2191
{
 
2192
  grove_->setSd(sd, prologSyntax, instanceSyntax);
 
2193
}
 
2194
 
 
2195
GroveBuilderEventHandler::GroveBuilderEventHandler(unsigned groveIndex,
 
2196
                                                   Messenger *mgr,
 
2197
                                                   MessageFormatter *msgFmt)
 
2198
: GroveBuilderMessageEventHandler(groveIndex, mgr, msgFmt)
 
2199
{
 
2200
}
 
2201
 
 
2202
void GroveBuilderEventHandler::appinfo(AppinfoEvent *event)
 
2203
{
 
2204
  const StringC *appinfo;
 
2205
  if (event->literal(appinfo))
 
2206
    grove_->setAppinfo(*appinfo);
 
2207
  delete event;
 
2208
}
 
2209
 
 
2210
void GroveBuilderEventHandler::endProlog(EndPrologEvent *event)
 
2211
{
 
2212
  grove_->setDtd(event->dtdPointer());
 
2213
  delete event;
 
2214
}
 
2215
 
 
2216
void GroveBuilderEventHandler::startElement(StartElementEvent *event)
 
2217
{
 
2218
  ElementNode::add(*grove_, *event);
 
2219
  delete event;
 
2220
}
 
2221
 
 
2222
void GroveBuilderEventHandler::endElement(EndElementEvent *event)
 
2223
{
 
2224
  grove_->pop();
 
2225
  delete event;
 
2226
}
 
2227
 
 
2228
void GroveBuilderEventHandler::data(DataEvent *event)
 
2229
{
 
2230
  DataNode::add(*grove_, *event);
 
2231
  delete event;
 
2232
}
 
2233
 
 
2234
void GroveBuilderEventHandler::sdataEntity(SdataEntityEvent *event)
 
2235
{
 
2236
  SdataNode::add(*grove_, *event);
 
2237
  delete event;
 
2238
}
 
2239
 
 
2240
void GroveBuilderEventHandler::nonSgmlChar(NonSgmlCharEvent *event)
 
2241
{
 
2242
  NonSgmlNode::add(*grove_, *event);
 
2243
  delete event;
 
2244
}
 
2245
 
 
2246
void GroveBuilderEventHandler::externalDataEntity(ExternalDataEntityEvent *event)
 
2247
{
 
2248
  ExternalDataNode::add(*grove_, *event);
 
2249
  delete event;
 
2250
}
 
2251
 
 
2252
void GroveBuilderEventHandler::subdocEntity(SubdocEntityEvent *event)
 
2253
{
 
2254
  SubdocNode::add(*grove_, *event);
 
2255
  delete event;
 
2256
}
 
2257
 
 
2258
void GroveBuilderEventHandler::pi(PiEvent *event)
 
2259
{
 
2260
  PiNode::add(*grove_, *event);
 
2261
  delete event;
 
2262
}
 
2263
 
 
2264
void GroveBuilderEventHandler::entityDefaulted(EntityDefaultedEvent *event)
 
2265
{
 
2266
  grove_->addDefaultedEntity(event->entityPointer());
 
2267
  delete event;
 
2268
}
 
2269
 
 
2270
ErrorCountEventHandler *GroveBuilder::make(unsigned index,
 
2271
                                           Messenger *mgr,
 
2272
                                           MessageFormatter *msgFmt,
 
2273
                                           bool validateOnly,
 
2274
                                           NodePtr &root)
 
2275
{
 
2276
  GroveBuilderMessageEventHandler *eh;
 
2277
  if (validateOnly)
 
2278
    eh = new GroveBuilderMessageEventHandler(index, mgr, msgFmt);
 
2279
  else
 
2280
    eh = new GroveBuilderEventHandler(index, mgr, msgFmt);
 
2281
  eh->makeInitialRoot(root);
 
2282
  return eh;
 
2283
}
 
2284
 
 
2285
ErrorCountEventHandler *GroveBuilder::make(unsigned index,
 
2286
                                           Messenger *mgr,
 
2287
                                           MessageFormatter *msgFmt,
 
2288
                                           bool validateOnly,
 
2289
                                           const ConstPtr<Sd> &sd,
 
2290
                                           const ConstPtr<Syntax> &prologSyntax,
 
2291
                                           const ConstPtr<Syntax> &instanceSyntax,
 
2292
                                           NodePtr &root)
 
2293
{
 
2294
  GroveBuilderMessageEventHandler *eh;
 
2295
  if (validateOnly)
 
2296
    eh = new GroveBuilderMessageEventHandler(index, mgr, msgFmt);
 
2297
  else
 
2298
    eh = new GroveBuilderEventHandler(index, mgr, msgFmt);
 
2299
  eh->makeInitialRoot(root);
 
2300
  eh->setSd(sd, prologSyntax, instanceSyntax);
 
2301
  return eh;
 
2302
}
 
2303
 
 
2304
bool GroveBuilder::setBlocking(bool b)
 
2305
{
 
2306
  bool prev = blockingAccess;
 
2307
  blockingAccess = b;
 
2308
  return prev;
 
2309
}
 
2310
 
 
2311
GroveImpl::GroveImpl(unsigned groveIndex)
 
2312
: groveIndex_(groveIndex),
 
2313
  root_(0),
 
2314
  impliedAttributeValue_(new ImpliedAttributeValue),
 
2315
  tailPtr_(0),
 
2316
  freePtr_(0),
 
2317
  nFree_(0),
 
2318
  blocks_(0),
 
2319
  blockTailPtr_(&blocks_),
 
2320
  blockAllocSize_(initialBlockSize),
 
2321
  nBlocksThisSizeAlloced_(0),
 
2322
  complete_(0),
 
2323
  mutexPtr_(&mutex_),
 
2324
  pulseStep_(0),
 
2325
  nEvents_(0),
 
2326
  haveAppinfo_(0),
 
2327
  pendingData_(0),
 
2328
  nElements_(0),
 
2329
  currentLocOrigin_(0),
 
2330
  completeLimitWithLocChunkAfter_(0),
 
2331
  nChunksSinceLocOrigin_(0),
 
2332
  messageList_(0),
 
2333
  messageListTailP_(&messageList_)
 
2334
{
 
2335
  root_ = new (allocChunk(sizeof(SgmlDocumentChunk))) SgmlDocumentChunk;
 
2336
  root_->origin = 0;
 
2337
  root_->locIndex = 0;
 
2338
  completeLimit_ = freePtr_;
 
2339
  origin_ = root_;
 
2340
  tailPtr_ = &root_->prolog;
 
2341
}
 
2342
 
 
2343
GroveImpl::~GroveImpl()
 
2344
{
 
2345
  while (blocks_) {
 
2346
    BlockHeader *tem = blocks_;
 
2347
    blocks_ = blocks_->next;
 
2348
    ::operator delete(tem);
 
2349
  }
 
2350
  while (messageList_) {
 
2351
    MessageItem *tem = messageList_;
 
2352
    messageList_ = *messageList_->nextP();
 
2353
    delete tem;
 
2354
  }
 
2355
}
 
2356
 
 
2357
void GroveImpl::setAppinfo(const StringC &appinfo)
 
2358
{
 
2359
  appinfo_ = appinfo;
 
2360
  haveAppinfo_ = 1;
 
2361
}
 
2362
 
 
2363
Boolean GroveImpl::getAppinfo(const StringC *&appinfo) const
 
2364
{
 
2365
  if (!haveAppinfo_) {
 
2366
    if (!complete_ && sd_.isNull())
 
2367
      return 0; // not available yet
 
2368
    appinfo = 0;
 
2369
  }
 
2370
  else
 
2371
    appinfo = &appinfo_;
 
2372
  return 1;
 
2373
}
 
2374
 
 
2375
void GroveImpl::setSd(const ConstPtr<Sd> &sd, const ConstPtr<Syntax> &prologSyntax, const ConstPtr<Syntax> &instanceSyntax)
 
2376
{
 
2377
  instanceSyntax_ = instanceSyntax;
 
2378
  prologSyntax_ = prologSyntax;
 
2379
  sd_ = sd;
 
2380
}
 
2381
 
 
2382
void GroveImpl::getSd(ConstPtr<Sd> &sd, ConstPtr<Syntax> &prologSyntax, ConstPtr<Syntax> &instanceSyntax) const
 
2383
{
 
2384
  instanceSyntax = instanceSyntax_;
 
2385
  prologSyntax = prologSyntax_;
 
2386
  sd = sd_;
 
2387
}
 
2388
 
 
2389
void GroveImpl::finishProlog()
 
2390
{
 
2391
  if (root_->prolog)
 
2392
    addBarrier();
 
2393
  tailPtr_ = 0;
 
2394
}
 
2395
 
 
2396
void GroveImpl::finishDocumentElement()
 
2397
{
 
2398
  // Be robust in the case of erroneous documents.
 
2399
  if (root_->epilog == 0) {
 
2400
    addBarrier();
 
2401
    tailPtr_ = &root_->epilog;
 
2402
  }
 
2403
}
 
2404
 
 
2405
void GroveImpl::addBarrier()
 
2406
{
 
2407
  if (freePtr_) {
 
2408
    (void) new (freePtr_) ForwardingChunk(0, 0);
 
2409
    if (nFree_ <= sizeof(ForwardingChunk)) {
 
2410
      nFree_ = 0;
 
2411
      freePtr_ = 0;
 
2412
    }
 
2413
    else {
 
2414
      nFree_ -= sizeof(ForwardingChunk);
 
2415
      freePtr_ += sizeof(ForwardingChunk);
 
2416
    }
 
2417
  }
 
2418
}
 
2419
 
 
2420
void GroveImpl::setComplete()
 
2421
{
 
2422
  addBarrier();
 
2423
  mutexPtr_ = 0;
 
2424
  completeLimit_ = 0;
 
2425
  completeLimitWithLocChunkAfter_ = 0;
 
2426
  if (pendingData_ && tailPtr_)
 
2427
    *tailPtr_ = pendingData_;
 
2428
  tailPtr_ = 0; 
 
2429
  pendingData_ = 0;
 
2430
  complete_ = 1;
 
2431
  moreNodesCondition_.set();
 
2432
}
 
2433
 
 
2434
void GroveImpl::addDefaultedEntity(const ConstPtr<Entity> &entity)
 
2435
{
 
2436
  Mutex::Lock lock(mutexPtr_);
 
2437
  // We need a table of ConstPtr<Entity> but we don't have one.
 
2438
  defaultedEntityTable_.insert((Entity *)entity.pointer());
 
2439
}
 
2440
 
 
2441
const Entity *GroveImpl::lookupDefaultedEntity(const StringC &name) const
 
2442
{
 
2443
  Mutex::Lock lock(mutexPtr_);
 
2444
  return defaultedEntityTable_.lookupTemp(name);
 
2445
}
 
2446
 
 
2447
Dtd::ConstEntityIter GroveImpl::defaultedEntityIter() const
 
2448
{
 
2449
  ASSERT(complete());
 
2450
  return Dtd::ConstEntityIter(defaultedEntityTable_);
 
2451
}
 
2452
 
 
2453
Boolean GroveImpl::maybeMoreSiblings1(const ParentChunk *chunk) const
 
2454
{
 
2455
  for (const ParentChunk *open = origin_; open; open = open->origin)
 
2456
    if (open == chunk)
 
2457
      return 1;
 
2458
  // for multi-thread case
 
2459
  return tailPtr_ == &chunk->nextSibling || chunk->nextSibling != 0;
 
2460
}
 
2461
 
 
2462
void *GroveImpl::allocFinish(size_t n)
 
2463
{
 
2464
  if (++nBlocksThisSizeAlloced_ >= maxBlocksPerSize) {
 
2465
     blockAllocSize_ *= 2;
 
2466
     nBlocksThisSizeAlloced_ = 0;
 
2467
  }
 
2468
  size_t allocSize = n + (sizeof(ForwardingChunk) + sizeof(BlockHeader));
 
2469
  if (allocSize < blockAllocSize_) {
 
2470
    nFree_ = blockAllocSize_ - allocSize;
 
2471
    allocSize = blockAllocSize_;
 
2472
  }
 
2473
  else
 
2474
    nFree_ = 0;
 
2475
  *blockTailPtr_ = new (::operator new(allocSize)) BlockHeader;
 
2476
  char *chunkStart = (char *)(*blockTailPtr_ + 1);
 
2477
  blockTailPtr_ = &(*blockTailPtr_)->next;
 
2478
  if (freePtr_)
 
2479
    (void)new (freePtr_) ForwardingChunk((const Chunk *)chunkStart, origin_);
 
2480
  freePtr_ = chunkStart + n;
 
2481
  return chunkStart;
 
2482
}
 
2483
 
 
2484
AccessResult ChunkNode::getLocation(Location &loc) const
 
2485
{
 
2486
  const Origin *origin = grove()->currentLocOrigin();
 
2487
  for (const Chunk *p = chunk_->after(); p; p = p->after()) {
 
2488
    if (p == grove()->completeLimitWithLocChunkAfter()) {
 
2489
      while (!p->getLocOrigin(origin)) {
 
2490
        p = p->after();
 
2491
        ASSERT(p != 0);
 
2492
      }
 
2493
      break;
 
2494
    }
 
2495
    if (p == grove()->completeLimit() || p->getLocOrigin(origin))
 
2496
      break;
 
2497
  }
 
2498
  if (!origin)
 
2499
    return accessNull;
 
2500
  loc = Location(new GroveImplProxyOrigin(grove(), origin), chunk_->locIndex);
 
2501
  return accessOK;
 
2502
}
 
2503
 
 
2504
void GroveImpl::storeLocOrigin(const ConstPtr<Origin> &locOrigin)
 
2505
{
 
2506
  LocOriginChunk *chunk
 
2507
    = new (allocChunk(sizeof(LocOriginChunk)))
 
2508
          LocOriginChunk(currentLocOrigin_);
 
2509
  chunk->origin = origin_;
 
2510
  completeLimitWithLocChunkAfter_ = completeLimit_;
 
2511
  nChunksSinceLocOrigin_ = 0;
 
2512
  if (locOrigin.pointer() == currentLocOrigin_)
 
2513
    return;
 
2514
  if (currentLocOrigin_
 
2515
      && locOrigin == currentLocOrigin_->parent().origin()) {
 
2516
    // Don't need to store it.
 
2517
    currentLocOrigin_ = locOrigin.pointer();
 
2518
    return;
 
2519
  }
 
2520
  currentLocOrigin_ = locOrigin.pointer();
 
2521
  if (locOrigin.isNull())
 
2522
    return;
 
2523
  origins_.push_back(locOrigin);
 
2524
}
 
2525
 
 
2526
AccessResult GroveImpl::proxifyLocation(const Location &loc, Location &ret) const
 
2527
{
 
2528
  if (loc.origin().isNull())
 
2529
    return accessNull;
 
2530
  ret = Location(new GroveImplProxyOrigin(this, loc.origin().pointer()),
 
2531
                 loc.index());
 
2532
  return accessOK;
 
2533
}
 
2534
 
 
2535
NodeListPtr AttributesNamedNodeList::nodeList() const
 
2536
{
 
2537
  const AttributeDefinitionList *defList = attDefList();
 
2538
  if (!defList || defList->size() == 0)
 
2539
    return new BaseNodeList;
 
2540
  else
 
2541
    return new SiblingNodeList(makeAttributeAsgnNode(grove(), 0));
 
2542
}
 
2543
 
 
2544
AccessResult
 
2545
AttributesNamedNodeList::namedNodeU(const StringC &str, NodePtr &ptr) const
 
2546
{
 
2547
  const AttributeDefinitionList *defList = attDefList();
 
2548
  if (defList) {
 
2549
    for (size_t i = 0; i < defList->size(); i++)
 
2550
      if (defList->def(i)->name() == str) {
 
2551
        ptr.assign(makeAttributeAsgnNode(grove(), i));
 
2552
        return accessOK;
 
2553
      }
 
2554
  }
 
2555
  return accessNull;
 
2556
}
 
2557
 
 
2558
void SgmlDocumentNode::accept(NodeVisitor &visitor)
 
2559
{
 
2560
  visitor.sgmlDocument(*this);
 
2561
}
 
2562
 
 
2563
AccessResult SgmlDocumentNode::getSgmlConstants(NodePtr &ptr) const
 
2564
{
 
2565
  ptr.assign(new SgmlConstantsNode(grove()));
 
2566
  return accessOK;
 
2567
}
 
2568
 
 
2569
AccessResult SgmlDocumentNode::getApplicationInfo(GroveString &str) const
 
2570
{
 
2571
  const StringC *appinfo;
 
2572
  while (!grove()->getAppinfo(appinfo))
 
2573
    if (!grove()->waitForMoreNodes())
 
2574
      return accessTimeout;
 
2575
  if (!appinfo)
 
2576
    return accessNull;
 
2577
  setString(str, *appinfo);
 
2578
  return accessOK;
 
2579
}
 
2580
 
 
2581
AccessResult SgmlDocumentNode::getDocumentElement(NodePtr &ptr) const
 
2582
{
 
2583
  while (chunk()->documentElement == 0) {
 
2584
    if (grove()->complete()) {
 
2585
      // Just in case another thread crept 
 
2586
      if (chunk()->documentElement)
 
2587
        break;
 
2588
      return accessNull;
 
2589
    }
 
2590
    if (!grove()->waitForMoreNodes())
 
2591
      return accessTimeout;
 
2592
  }
 
2593
  return chunk()->documentElement->setNodePtrFirst(ptr, this);
 
2594
}
 
2595
 
 
2596
AccessResult SgmlDocumentNode::getProlog(NodeListPtr &ptr) const
 
2597
{
 
2598
  while (chunk()->prolog == 0) {
 
2599
    if (chunk()->documentElement || grove()->complete())
 
2600
      break;
 
2601
    if (!grove()->waitForMoreNodes())
 
2602
      return accessTimeout;
 
2603
  }
 
2604
  if (chunk()->prolog == 0)
 
2605
    ptr.assign(new BaseNodeList);
 
2606
  else {
 
2607
    NodePtr tem;
 
2608
    chunk()->prolog->setNodePtrFirst(tem, this);
 
2609
    ptr.assign(new SiblingNodeList(tem));
 
2610
  }
 
2611
  return accessOK;
 
2612
}
 
2613
 
 
2614
AccessResult SgmlDocumentNode::getEpilog(NodeListPtr &ptr) const
 
2615
{
 
2616
  while (chunk()->epilog == 0) {
 
2617
    if (grove()->complete())
 
2618
      break;
 
2619
    if (!grove()->waitForMoreNodes())
 
2620
      return accessTimeout;
 
2621
  }
 
2622
  if (chunk()->epilog == 0)
 
2623
    ptr.assign(new BaseNodeList);
 
2624
  else {
 
2625
    NodePtr tem;
 
2626
    chunk()->epilog->setNodePtrFirst(tem, this);
 
2627
    ptr.assign(new SiblingNodeList(tem));
 
2628
  }
 
2629
  return accessOK;
 
2630
}
 
2631
 
 
2632
AccessResult SgmlDocumentNode::getElements(NamedNodeListPtr &ptr) const
 
2633
{
 
2634
  while (!grove()->root()->documentElement) {
 
2635
    if (grove()->complete()) {
 
2636
      if (grove()->root()->documentElement)
 
2637
        break;
 
2638
      return accessNull;
 
2639
    }
 
2640
    if (!grove()->waitForMoreNodes())
 
2641
      return accessTimeout;
 
2642
  }
 
2643
  if (!grove()->generalSubstTable())
 
2644
    return accessNull;
 
2645
  ptr.assign(new ElementsNamedNodeList(grove()));
 
2646
  return accessOK;
 
2647
}
 
2648
 
 
2649
AccessResult SgmlDocumentNode::getEntities(NamedNodeListPtr &ptr) const
 
2650
{
 
2651
  while (!grove()->governingDtd()) {
 
2652
    if (grove()->complete()) {
 
2653
      if (grove()->governingDtd())
 
2654
        break;
 
2655
      return accessNull;
 
2656
    }
 
2657
    if (!grove()->waitForMoreNodes())
 
2658
      return accessTimeout;
 
2659
  }
 
2660
  ptr.assign(new DocEntitiesNamedNodeList(grove()));
 
2661
  return accessOK;
 
2662
}
 
2663
 
 
2664
AccessResult SgmlDocumentNode::getDefaultedEntities(NamedNodeListPtr &ptr) const
 
2665
{
 
2666
  while (!grove()->complete())
 
2667
    if (!grove()->waitForMoreNodes())
 
2668
      return accessTimeout;
 
2669
  ptr.assign(new DefaultedEntitiesNamedNodeList(grove()));
 
2670
  return accessOK;
 
2671
}
 
2672
 
 
2673
AccessResult SgmlDocumentNode::getGoverningDoctype(NodePtr &ptr) const
 
2674
{
 
2675
  while (!grove()->governingDtd()) {
 
2676
    if (grove()->complete()) {
 
2677
      if (grove()->governingDtd())
 
2678
        break;
 
2679
      return accessNull;
 
2680
    }
 
2681
    if (!grove()->waitForMoreNodes())
 
2682
      return accessTimeout;
 
2683
  }
 
2684
  ptr.assign(new DocumentTypeNode(grove(), grove()->governingDtd()));
 
2685
  return accessOK;
 
2686
}
 
2687
 
 
2688
AccessResult SgmlDocumentNode::getDoctypesAndLinktypes(NamedNodeListPtr &ptr) const
 
2689
{
 
2690
  while (!grove()->governingDtd()) {
 
2691
    if (grove()->complete()) {
 
2692
      if (grove()->governingDtd())
 
2693
        break;
 
2694
      return accessNull;
 
2695
    }
 
2696
    if (!grove()->waitForMoreNodes())
 
2697
      return accessTimeout;
 
2698
  }
 
2699
  ptr.assign(new DoctypesAndLinktypesNamedNodeList(grove()));
 
2700
  return accessOK;
 
2701
}
 
2702
 
 
2703
AccessResult SgmlDocumentNode::getMessages(NodeListPtr &ptr) const
 
2704
{
 
2705
  while (grove()->messageList() == 0) {
 
2706
    if (grove()->complete())
 
2707
      break;
 
2708
    if (!grove()->waitForMoreNodes())
 
2709
      return accessTimeout;
 
2710
  }
 
2711
  if (grove()->messageList()) {
 
2712
    NodePtr tem(new MessageNode(grove(), grove()->messageList()));
 
2713
    ptr.assign(new SiblingNodeList(tem));
 
2714
  }
 
2715
  else
 
2716
    ptr.assign(new BaseNodeList);
 
2717
  return accessOK;
 
2718
}
 
2719
 
 
2720
AccessResult SgmlDocumentNode::getSd(ConstPtr<Sd> &sd,
 
2721
                                     ConstPtr<Syntax> &prologSyntax,
 
2722
                                     ConstPtr<Syntax> &instanceSyntax) const
 
2723
{
 
2724
  while (!grove()->complete()) {
 
2725
    if (!grove()->waitForMoreNodes())
 
2726
      return accessTimeout;
 
2727
  }
 
2728
  grove()->getSd(sd, prologSyntax, instanceSyntax);
 
2729
  if (!sd.isNull() && !prologSyntax.isNull() && !instanceSyntax.isNull())
 
2730
    return accessOK;
 
2731
  return accessNull;
 
2732
}
 
2733
 
 
2734
AccessResult
 
2735
SgmlDocumentChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const
 
2736
{
 
2737
  ptr.assign(new SgmlDocumentNode(node->grove(), this));
 
2738
  return accessOK;
 
2739
}
 
2740
 
 
2741
DocumentTypeNode::DocumentTypeNode(const GroveImpl *grove, const Dtd *dtd)
 
2742
: BaseNode(grove), dtd_(dtd)
 
2743
{
 
2744
}
 
2745
 
 
2746
AccessResult DocumentTypeNode::nextChunkSibling(NodePtr &) const
 
2747
{
 
2748
  return accessNull;
 
2749
}
 
2750
 
 
2751
AccessResult DocumentTypeNode::getName(GroveString &str) const
 
2752
{
 
2753
  setString(str, dtd_->name());
 
2754
  return accessOK;
 
2755
}
 
2756
 
 
2757
AccessResult DocumentTypeNode::getGoverning(bool &governing) const
 
2758
{
 
2759
  governing = dtd_->isBase();
 
2760
  return accessOK;
 
2761
}
 
2762
 
 
2763
AccessResult DocumentTypeNode::getGeneralEntities(NamedNodeListPtr &ptr) const
 
2764
{
 
2765
  ptr.assign(new GeneralEntitiesNamedNodeList(grove(), dtd_));
 
2766
  return accessOK;
 
2767
}
 
2768
 
 
2769
AccessResult DocumentTypeNode::getParameterEntities(NamedNodeListPtr &ptr) const
 
2770
{
 
2771
  ptr.assign(new ParameterEntitiesNamedNodeList(grove(), dtd_));
 
2772
  return accessOK;
 
2773
}
 
2774
 
 
2775
AccessResult DocumentTypeNode::getNotations(NamedNodeListPtr &ptr) const
 
2776
{
 
2777
  ptr.assign(new NotationsNamedNodeList(grove(), dtd_));
 
2778
  return accessOK;
 
2779
}
 
2780
 
 
2781
AccessResult DocumentTypeNode::getElementTypes(NamedNodeListPtr &ptr) const
 
2782
{
 
2783
  ptr.assign(new ElementTypesNamedNodeList(grove(), dtd_));
 
2784
  return accessOK;
 
2785
}
 
2786
 
 
2787
AccessResult DocumentTypeNode::getDefaultEntity(NodePtr &ptr) const 
 
2788
{
 
2789
  const Entity *entity = dtd_->defaultEntityTemp();
 
2790
  if (entity == 0)
 
2791
    return accessNull;
 
2792
  ptr.assign(new DefaultEntityNode(grove(), entity));
 
2793
  return accessOK;
 
2794
}
 
2795
 
 
2796
AccessResult DocumentTypeNode::getOrigin(NodePtr &ptr) const
 
2797
{
 
2798
  ptr.assign(new SgmlDocumentNode(grove(), grove()->root()));
 
2799
  return accessOK;
 
2800
}
 
2801
 
 
2802
void DocumentTypeNode::accept(NodeVisitor &visitor)
 
2803
{
 
2804
  visitor.documentType(*this);
 
2805
}
 
2806
 
 
2807
bool DocumentTypeNode::same(const BaseNode &node) const
 
2808
{
 
2809
  return node.same2(this);
 
2810
}
 
2811
 
 
2812
bool DocumentTypeNode::same2(const DocumentTypeNode *node) const
 
2813
{
 
2814
  return dtd_ == node->dtd_;
 
2815
}
 
2816
 
 
2817
SgmlConstantsNode::SgmlConstantsNode(const GroveImpl *grove)
 
2818
: BaseNode(grove)
 
2819
{
 
2820
}
 
2821
 
 
2822
AccessResult SgmlConstantsNode::getOrigin(NodePtr &ptr) const
 
2823
{
 
2824
  ptr.assign(new SgmlDocumentNode(grove(), grove()->root()));
 
2825
  return accessOK;
 
2826
}
 
2827
 
 
2828
void SgmlConstantsNode::accept(NodeVisitor &visitor)
 
2829
{
 
2830
  visitor.sgmlConstants(*this);
 
2831
}
 
2832
 
 
2833
bool SgmlConstantsNode::same(const BaseNode &node) const
 
2834
{
 
2835
  return node.same2(this);
 
2836
}
 
2837
 
 
2838
bool SgmlConstantsNode::same2(const SgmlConstantsNode *) const
 
2839
{
 
2840
  return 1;
 
2841
}
 
2842
 
 
2843
MessageNode::MessageNode(const GroveImpl *grove, const MessageItem *item)
 
2844
: BaseNode(grove), item_(item)
 
2845
{
 
2846
}
 
2847
 
 
2848
AccessResult MessageNode::getOrigin(NodePtr &ptr) const
 
2849
{
 
2850
  ptr.assign(new SgmlDocumentNode(grove(), grove()->root()));
 
2851
  return accessOK;
 
2852
}
 
2853
 
 
2854
AccessResult MessageNode::nextChunkSibling(NodePtr &ptr) const
 
2855
{
 
2856
  while (!item_->next()) {
 
2857
    if (grove()->complete()) {
 
2858
      if (item_->next())
 
2859
        break;
 
2860
      return accessNull;
 
2861
    }
 
2862
    if (!grove()->waitForMoreNodes())
 
2863
      return accessTimeout;
 
2864
  }
 
2865
  const MessageItem *p = item_->next();
 
2866
  if (!p)
 
2867
    return accessNull;
 
2868
  ptr.assign(new MessageNode(grove(), p));
 
2869
  return accessOK;
 
2870
}
 
2871
 
 
2872
AccessResult MessageNode::firstSibling(NodePtr &ptr) const
 
2873
{
 
2874
  ptr.assign(new MessageNode(grove(), grove()->messageList()));
 
2875
  return accessOK;
 
2876
}
 
2877
 
 
2878
AccessResult MessageNode::siblingsIndex(unsigned long &n) const
 
2879
{
 
2880
  n = 0;
 
2881
  for (const MessageItem *p = grove()->messageList(); p != item_; p = p->next())
 
2882
    n++;
 
2883
  return accessOK;
 
2884
}
 
2885
 
 
2886
void MessageNode::accept(NodeVisitor &visitor)
 
2887
{
 
2888
  visitor.message(*this);
 
2889
}
 
2890
 
 
2891
bool MessageNode::same(const BaseNode &node) const
 
2892
{
 
2893
  return node.same2(this);
 
2894
}
 
2895
 
 
2896
bool MessageNode::same2(const MessageNode *node) const
 
2897
{
 
2898
  return item_ == node->item_;
 
2899
}
 
2900
 
 
2901
AccessResult MessageNode::getLocation(Location &loc) const
 
2902
{
 
2903
  return grove()->proxifyLocation(item_->loc(), loc);
 
2904
}
 
2905
 
 
2906
AccessResult MessageNode::getText(GroveString &str) const
 
2907
{
 
2908
  setString(str, item_->text());
 
2909
  return accessOK;
 
2910
}
 
2911
 
 
2912
AccessResult MessageNode::getSeverity(Severity &severity) const
 
2913
{
 
2914
  severity = item_->severity();
 
2915
  return accessOK;
 
2916
}
 
2917
 
 
2918
AccessResult ElementNode::nextChunkSibling(NodePtr &ptr) const
 
2919
{
 
2920
  while (!chunk()->nextSibling) {
 
2921
    if (!grove()->maybeMoreSiblings(chunk())) {
 
2922
      // Allow for the possibility of invalid documents with elements in the epilog.
 
2923
      if ((const Chunk *)chunk() == grove()->root()->documentElement)
 
2924
        return accessNotInClass;
 
2925
      else
 
2926
        return accessNull;
 
2927
    }
 
2928
    if (!grove()->waitForMoreNodes())
 
2929
      return accessTimeout;
 
2930
  }
 
2931
  return chunk()->nextSibling->setNodePtrFirst(ptr, this);
 
2932
}
 
2933
 
 
2934
// This is a duplicate of ChunkNode::nextChunkAfter
 
2935
// to take advantage of overloaded setNodePtrFirst.
 
2936
 
 
2937
AccessResult ElementNode::nextChunkAfter(NodePtr &nd) const
 
2938
{
 
2939
  const Chunk *p = chunk_->after();
 
2940
  while (p == grove()->completeLimit())
 
2941
    if (!grove()->waitForMoreNodes())
 
2942
      return accessTimeout;
 
2943
  return p->setNodePtrFirst(nd, this);
 
2944
}
 
2945
 
 
2946
AccessResult ElementChunk::getFollowing(const GroveImpl *grove,
 
2947
                                        const Chunk *&f,
 
2948
                                        unsigned long &n) const
 
2949
{
 
2950
  while (!nextSibling) {
 
2951
    if (!grove->maybeMoreSiblings(this)) {
 
2952
      if ((const Chunk *)origin == grove->root())
 
2953
        return accessNotInClass;
 
2954
      else
 
2955
        return accessNull;
 
2956
    }
 
2957
    if (!grove->waitForMoreNodes())
 
2958
      return accessTimeout;
 
2959
  }
 
2960
  f = nextSibling;
 
2961
  n = 1;
 
2962
  return accessOK;
 
2963
}
 
2964
 
 
2965
AccessResult ElementNode::firstChild(NodePtr &ptr) const
 
2966
{
 
2967
  const Chunk *p = chunk()->after();
 
2968
  while (p == grove()->completeLimit()) {
 
2969
    if (!grove()->waitForMoreNodes())
 
2970
      return accessTimeout;
 
2971
  }
 
2972
  if ((const Chunk *)(p->origin) == chunk())
 
2973
    return p->setNodePtrFirst(ptr, this);
 
2974
  return accessNull;
 
2975
}
 
2976
 
 
2977
AccessResult ElementNode::attributeRef(unsigned long n, NodePtr &ptr) const
 
2978
{
 
2979
  const AttributeDefinitionList *defList = chunk()->attDefList();
 
2980
  if (!defList || n >= defList->size())
 
2981
    return accessNull;
 
2982
  ptr.assign(new ElementAttributeAsgnNode(grove(), size_t(n), chunk()));
 
2983
  return accessOK;
 
2984
}
 
2985
 
 
2986
AccessResult ElementNode::getAttributes(NamedNodeListPtr &ptr) const
 
2987
{
 
2988
  ptr.assign(new ElementAttributesNamedNodeList(grove(), chunk()));
 
2989
  return accessOK;
 
2990
}
 
2991
 
 
2992
AccessResult ElementNode::getGi(GroveString &str) const
 
2993
{
 
2994
  setString(str, chunk()->type->name());
 
2995
  return accessOK;
 
2996
}
 
2997
 
 
2998
bool ElementNode::hasGi(GroveString str) const
 
2999
{
 
3000
  const StringC &gi = chunk()->type->name();
 
3001
  size_t len = gi.size();
 
3002
  if (len != str.size())
 
3003
    return 0;
 
3004
  const SubstTable<Char> *subst = grove()->generalSubstTable();
 
3005
  if (!subst)
 
3006
    return 0;
 
3007
  for (size_t i = 0; i < len; i++)
 
3008
    if ((*subst)[str[i]] != gi[i])
 
3009
      return 0;
 
3010
  return 1;
 
3011
}
 
3012
 
 
3013
AccessResult ElementNode::getId(GroveString &str) const
 
3014
{
 
3015
  const StringC *id = chunk()->id();
 
3016
  if (!id)
 
3017
    return accessNull;
 
3018
  setString(str, *id);
 
3019
  return accessOK;
 
3020
}
 
3021
 
 
3022
AccessResult ElementNode::elementIndex(unsigned long &i) const
 
3023
{
 
3024
  i = chunk()->elementIndex;
 
3025
  return accessOK;
 
3026
}
 
3027
 
 
3028
AccessResult ElementNode::getElementType(NodePtr &ptr) const
 
3029
{
 
3030
  if (chunk()->elementType() == 0)
 
3031
    return accessNull;  
 
3032
  ptr.assign(new ElementTypeNode(grove(), *(chunk()->elementType())));
 
3033
  return accessOK;
 
3034
}
 
3035
 
 
3036
AccessResult ElementNode::getContent(NodeListPtr &ptr) const
 
3037
{
 
3038
  return children(ptr);
 
3039
}
 
3040
 
 
3041
AccessResult ElementNode::getMustOmitEndTag(bool &b) const
 
3042
{
 
3043
  b = chunk()->mustOmitEndTag();
 
3044
  return accessOK;
 
3045
}
 
3046
 
 
3047
AccessResult ElementNode::getIncluded(bool &b) const
 
3048
{
 
3049
  b = chunk()->included();
 
3050
  return accessOK;
 
3051
}
 
3052
 
 
3053
void ElementNode::accept(NodeVisitor &visitor)
 
3054
{
 
3055
  visitor.element(*this);
 
3056
}
 
3057
 
 
3058
ElementChunk *
 
3059
ElementNode::makeAttElementChunk(GroveImpl &grove,
 
3060
                                 const StartElementEvent &event,
 
3061
                                 Boolean &hasId)
 
3062
{
 
3063
  const AttributeList &atts = event.attributes();
 
3064
  size_t nAtts = atts.size();
 
3065
  while (nAtts > 0 && !atts.specified(nAtts - 1) && !atts.current(nAtts - 1))
 
3066
    nAtts--;
 
3067
  ElementChunk *chunk;
 
3068
  void *mem
 
3069
    = grove.allocChunk(sizeof(AttElementChunk) + nAtts * sizeof(AttributeValue *));
 
3070
  if (event.included()) {
 
3071
    // Workaround VC++ 4.1 bug.
 
3072
    AttElementChunk *tem = new (mem) IncludedAttElementChunk(nAtts);
 
3073
    chunk = tem;
 
3074
  }
 
3075
  else
 
3076
    chunk = new (mem) AttElementChunk(nAtts);
 
3077
  const AttributeValue **values
 
3078
    = (const AttributeValue **)(((AttElementChunk *)chunk) + 1);
 
3079
  const AttributeDefinitionList *defList
 
3080
    = event.elementType()->attributeDef().pointer();
 
3081
  unsigned idIndex;
 
3082
  if (atts.idIndex(idIndex) && atts.specified(idIndex) && atts.value(idIndex))
 
3083
    hasId = 1;
 
3084
  else
 
3085
    hasId = 0;
 
3086
  for (size_t i = 0; i < nAtts; i++) {
 
3087
    if (atts.specified(i) || atts.current(i)) {
 
3088
      grove.storeAttributeValue(atts.valuePointer(i));
 
3089
      values[i] = atts.value(i);
 
3090
    }
 
3091
    else {
 
3092
      // If we stored a reference to the implied attribute value in the
 
3093
      // Dtd then it would be safe just to use atts.value(i) here.
 
3094
      // But that would mean we couldn't conveniently tell whether it
 
3095
      // was specified or implied.
 
3096
      values[i] = defList->def(i)->defaultValue(grove.impliedAttributeValue());
 
3097
    }
 
3098
  }
 
3099
  return chunk;
 
3100
}
 
3101
 
 
3102
const Chunk *AttElementChunk::after() const
 
3103
{
 
3104
  return (const Chunk *)((char *)(this + 1)
 
3105
                         + (sizeof(const AttributeValue *) * nAtts));
 
3106
}
 
3107
 
 
3108
const AttributeValue *
 
3109
AttElementChunk::attributeValue(size_t attIndex, const GroveImpl &grove) const
 
3110
{
 
3111
  if (attIndex < nAtts)
 
3112
    return ((const AttributeValue **)(this + 1))[attIndex];
 
3113
  else
 
3114
    return ElementChunk::attributeValue(attIndex, grove);
 
3115
}
 
3116
 
 
3117
const StringC *AttElementChunk::id() const
 
3118
{
 
3119
  size_t i = ElementChunk::attDefList()->idIndex();
 
3120
  if (i == size_t(-1) || i >= nAtts)
 
3121
    return 0;
 
3122
  const AttributeValue *av = ((const AttributeValue **)(this + 1))[i];
 
3123
  if (!av)
 
3124
    return 0;
 
3125
  const Text *t = av->text();
 
3126
  if (!t)
 
3127
    return 0;
 
3128
  return &t->string();
 
3129
}
 
3130
 
 
3131
Boolean AttElementChunk::mustOmitEndTag() const
 
3132
{
 
3133
  if (ElementChunk::mustOmitEndTag())
 
3134
    return 1;
 
3135
  const AttributeDefinitionList *adl = ElementChunk::attDefList();
 
3136
  size_t nAtts = adl->size();
 
3137
  const AttributeValue **atts = (const AttributeValue **)(this + 1);
 
3138
  for (size_t i = 0; i < nAtts; i++)
 
3139
    if (adl->def(i)->isConref() && atts[i] && atts[i]->text())
 
3140
      return 1;
 
3141
  return 0;
 
3142
}
 
3143
 
 
3144
const Chunk *ElementChunk::after() const
 
3145
{
 
3146
  return this + 1;
 
3147
}
 
3148
 
 
3149
const AttributeValue *
 
3150
ElementChunk::attributeValue(size_t attIndex, const GroveImpl &grove) const
 
3151
{
 
3152
  return attDefList()->def(attIndex)->defaultValue(grove.impliedAttributeValue());
 
3153
}
 
3154
 
 
3155
Boolean ElementChunk::mustOmitEndTag() const
 
3156
{
 
3157
  return type->definition()->declaredContent() == ElementDefinition::empty;
 
3158
}
 
3159
 
 
3160
Boolean IncludedElementChunk::included() const
 
3161
{
 
3162
  return 1;
 
3163
}
 
3164
 
 
3165
Boolean IncludedAttElementChunk::included() const
 
3166
{
 
3167
  return 1;
 
3168
}
 
3169
 
 
3170
Boolean ElementChunk::included() const
 
3171
{
 
3172
  return 0;
 
3173
}
 
3174
 
 
3175
AccessResult
 
3176
ElementChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const
 
3177
{
 
3178
  ptr.assign(new ElementNode(node->grove(), this));
 
3179
  return accessOK;
 
3180
}
 
3181
 
 
3182
AccessResult
 
3183
ElementChunk::setNodePtrFirst(NodePtr &ptr, const ElementNode *node) const
 
3184
{
 
3185
  if (node->canReuse(ptr))
 
3186
    ((ElementNode *)node)->reuseFor(this);
 
3187
  else
 
3188
    ptr.assign(new ElementNode(node->grove(), this));
 
3189
  return accessOK;
 
3190
}
 
3191
 
 
3192
AccessResult
 
3193
ElementChunk::setNodePtrFirst(NodePtr &ptr, const DataNode *node) const
 
3194
{
 
3195
  ptr.assign(new ElementNode(node->grove(), this));
 
3196
  return accessOK;
 
3197
}
 
3198
 
 
3199
ElementAttributeOrigin::ElementAttributeOrigin(const ElementChunk *chunk)
 
3200
: chunk_(chunk)
 
3201
{
 
3202
}
 
3203
 
 
3204
const AttributeDefinitionList *ElementAttributeOrigin::attDefList() const
 
3205
{
 
3206
  return chunk_->attDefList();
 
3207
}
 
3208
 
 
3209
 
 
3210
const AttributeValue *
 
3211
ElementAttributeOrigin::attributeValue(size_t attIndex, const GroveImpl &grove) const
 
3212
{
 
3213
  return chunk_->attributeValue(attIndex, grove);
 
3214
}
 
3215
 
 
3216
 
 
3217
AccessResult
 
3218
ElementAttributeOrigin::setNodePtrAttributeOrigin(NodePtr &ptr,
 
3219
                                                  const BaseNode *node) const
 
3220
{
 
3221
  return chunk_->setNodePtrFirst(ptr, node);
 
3222
}
 
3223
  
 
3224
 
 
3225
Node *ElementAttributeOrigin
 
3226
::makeCdataAttributeValueNode(const GroveImpl *grove,
 
3227
                              const AttributeValue *value,
 
3228
                              size_t attIndex,
 
3229
                              const TextIter &iter,
 
3230
                              size_t charIndex) const
 
3231
{
 
3232
  return new ElementCdataAttributeValueNode(grove, value, attIndex, iter,
 
3233
                                            charIndex, chunk_);
 
3234
}
 
3235
 
 
3236
 
 
3237
Node *ElementAttributeOrigin
 
3238
::makeAttributeValueTokenNode(const GroveImpl *grove,
 
3239
                              const TokenizedAttributeValue *value,
 
3240
                              size_t attIndex,
 
3241
                              size_t tokenIndex) const
 
3242
{
 
3243
  return new ElementAttributeValueTokenNode(grove, value, attIndex,
 
3244
                                            tokenIndex, chunk_);
 
3245
}
 
3246
 
 
3247
Node *ElementAttributeOrigin
 
3248
::makeAttributeAsgnNode(const GroveImpl *grove,
 
3249
                        size_t attIndex) const
 
3250
{
 
3251
  return new ElementAttributeAsgnNode(grove, attIndex, chunk_);
 
3252
}
 
3253
 
 
3254
AccessResult ElementAttributeOrigin
 
3255
::makeAttributeDefNode(const GroveImpl *grove,
 
3256
                       NodePtr &ptr,
 
3257
                       size_t attributeDefIdx) const 
 
3258
{
 
3259
  if (chunk_->elementType() == 0)
 
3260
    return accessNull;  
 
3261
  ptr.assign(new ElementTypeAttributeDefNode(grove,
 
3262
                                             *(chunk_->elementType()),
 
3263
                                             attributeDefIdx)); 
 
3264
  return accessOK;
 
3265
}
 
3266
 
 
3267
Node *ElementAttributeOrigin::makeOriginNode(const GroveImpl *grove, size_t attIndex) const 
 
3268
{
 
3269
  return makeAttributeAsgnNode(grove, attIndex);
 
3270
}
 
3271
 
 
3272
const void *ElementAttributeOrigin::attributeOriginId() const
 
3273
{
 
3274
  return chunk_;
 
3275
}
 
3276
 
 
3277
bool DataNode::same(const BaseNode &node) const
 
3278
{
 
3279
  return node.same2(this);
 
3280
}
 
3281
 
 
3282
bool DataNode::same2(const DataNode *node) const
 
3283
{
 
3284
  return chunk_ == node->chunk_ && index_ == node->index_;
 
3285
}
 
3286
 
 
3287
bool DataNode::chunkContains(const Node &node) const
 
3288
{
 
3289
  if (!sameGrove(node))
 
3290
    return 0;
 
3291
  return ((const BaseNode &)node).inChunk(this);
 
3292
}
 
3293
 
 
3294
bool DataNode::inChunk(const DataNode *node) const
 
3295
{
 
3296
  return chunk_ == node->chunk_ && index_ >= node->index_;
 
3297
}
 
3298
 
 
3299
AccessResult DataNode::charChunk(const SdataMapper &, GroveString &str) const
 
3300
{
 
3301
  str.assign(chunk()->data() + index_, chunk()->size - index_);
 
3302
  return accessOK;
 
3303
}
 
3304
 
 
3305
void DataNode::accept(NodeVisitor &visitor)
 
3306
{
 
3307
  visitor.dataChar(*this);
 
3308
}
 
3309
 
 
3310
unsigned long DataNode::hash() const
 
3311
{
 
3312
  return secondHash(ChunkNode::hash() + index_);
 
3313
}
 
3314
 
 
3315
AccessResult DataNode::getNonSgml(unsigned long &) const
 
3316
{
 
3317
  return accessNull;
 
3318
}
 
3319
 
 
3320
AccessResult DataNode::nextSibling(NodePtr &ptr) const
 
3321
{
 
3322
  if (index_ + 1 < chunk()->size) {
 
3323
    if (canReuse(ptr))
 
3324
      ((DataNode *)this)->index_ += 1;
 
3325
    else
 
3326
      ptr.assign(new DataNode(grove(), chunk(), index_ + 1));
 
3327
    return accessOK;
 
3328
  }
 
3329
  return DataNode::nextChunkSibling(ptr);
 
3330
}
 
3331
 
 
3332
AccessResult DataNode::nextChunkAfter(NodePtr &nd) const
 
3333
{
 
3334
  const Chunk *p = chunk_->after();
 
3335
  while (p == grove()->completeLimit())
 
3336
    if (!grove()->waitForMoreNodes())
 
3337
      return accessTimeout;
 
3338
  return p->setNodePtrFirst(nd, this);
 
3339
}
 
3340
 
 
3341
AccessResult DataNode::followSiblingRef(unsigned long i, NodePtr &ptr) const
 
3342
{
 
3343
  if (i < chunk()->size - index_ - 1) {
 
3344
    if (canReuse(ptr))
 
3345
      ((DataNode *)this)->index_ += 1 + size_t(i);
 
3346
    else
 
3347
      ptr.assign(new DataNode(grove(), chunk(), index_ + size_t(i) + 1));
 
3348
    return accessOK;
 
3349
  }
 
3350
  return ChunkNode::followSiblingRef(i - (chunk()->size - index_ - 1), ptr);
 
3351
}
 
3352
 
 
3353
AccessResult DataNode::siblingsIndex(unsigned long &i) const
 
3354
{
 
3355
  AccessResult ret = ChunkNode::siblingsIndex(i);
 
3356
  if (ret == accessOK)
 
3357
    i += index_;
 
3358
  return ret;
 
3359
}
 
3360
 
 
3361
AccessResult DataNode::getLocation(Location &loc) const
 
3362
{
 
3363
  AccessResult ret = ChunkNode::getLocation(loc);
 
3364
  if (ret == accessOK)
 
3365
    loc += index_;
 
3366
  return ret;
 
3367
}
 
3368
 
 
3369
AccessResult DataChunk::getFollowing(const GroveImpl *grove,
 
3370
                                     const Chunk *&f,
 
3371
                                     unsigned long &i) const
 
3372
{
 
3373
  // We could call Chunk::getFollowing to do most of
 
3374
  // the work, but that would cost us a couple of extra
 
3375
  // virtual function calls.
 
3376
  const Chunk *p = CharsChunk::after();
 
3377
  while (p == grove->completeLimit())
 
3378
    if (!grove->waitForMoreNodes())
 
3379
      return accessTimeout;
 
3380
  if (p->origin != origin)
 
3381
    return accessNull;
 
3382
  i = size;
 
3383
  f = p;
 
3384
  return accessOK;
 
3385
}
 
3386
 
 
3387
AccessResult DataChunk::setNodePtrFirst(NodePtr &ptr,
 
3388
                                        const BaseNode *node) const
 
3389
{
 
3390
  ptr.assign(new DataNode(node->grove(), this, 0));
 
3391
  return accessOK;
 
3392
}
 
3393
 
 
3394
// This just saves us a virtual function call in a common case
 
3395
AccessResult DataChunk::setNodePtrFirst(NodePtr &ptr,
 
3396
                                        const ElementNode *node) const
 
3397
{
 
3398
  ptr.assign(new DataNode(node->grove(), this, 0));
 
3399
  return accessOK;
 
3400
}
 
3401
 
 
3402
AccessResult DataChunk::setNodePtrFirst(NodePtr &ptr, const DataNode *node)
 
3403
     const
 
3404
{
 
3405
  if (node->canReuse(ptr))
 
3406
    ((DataNode *)node)->reuseFor(this, 0);
 
3407
  else
 
3408
    ptr.assign(new DataNode(node->grove(), this, 0));
 
3409
  return accessOK;
 
3410
}
 
3411
 
 
3412
AccessResult PiNode::getSystemData(GroveString &str) const
 
3413
{
 
3414
  str.assign(chunk()->data(), chunk()->size);
 
3415
  return accessOK;
 
3416
}
 
3417
 
 
3418
void PiNode::add(GroveImpl &grove, const PiEvent &event)
 
3419
{
 
3420
  const Entity *entity = event.entity();
 
3421
  if (entity)
 
3422
    PiEntityNode::add(grove, entity, event.location());
 
3423
  else {
 
3424
    grove.setLocOrigin(event.location().origin());
 
3425
    size_t dataLen = event.dataLength();
 
3426
    void *mem = grove.allocChunk(CharsChunk::allocSize(dataLen));
 
3427
    PiChunk *chunk;
 
3428
    if (grove.haveRootOrigin()) {
 
3429
      if (grove.root()->documentElement)
 
3430
        chunk = new (mem) EpilogPiChunk;
 
3431
      else
 
3432
        chunk = new (mem) PrologPiChunk;
 
3433
    }
 
3434
    else
 
3435
      chunk = new (mem) PiChunk;
 
3436
    chunk->size = dataLen;
 
3437
    chunk->locIndex = event.location().index();
 
3438
    memcpy(chunk + 1, event.data(), dataLen * sizeof(Char));
 
3439
    grove.appendSibling(chunk);
 
3440
  }
 
3441
}
 
3442
 
 
3443
AccessResult PiChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const
 
3444
{
 
3445
  ptr.assign(new PiNode(node->grove(), this));
 
3446
  return accessOK;
 
3447
}
 
3448
 
 
3449
AccessResult PrologPiChunk::getFirstSibling(const GroveImpl *grove, const struct Chunk *&p) const
 
3450
{
 
3451
  p = grove->root()->prolog;
 
3452
  return accessOK;
 
3453
}
 
3454
 
 
3455
AccessResult EpilogPiChunk::getFirstSibling(const GroveImpl *grove, const struct Chunk *&p) const
 
3456
{
 
3457
  p = grove->root()->epilog;
 
3458
  return accessOK;
 
3459
}
 
3460
 
 
3461
AccessResult SdataNode::charChunk(const SdataMapper &mapper, GroveString &str) const
 
3462
{
 
3463
  const StringC &name = chunk()->entity->name();
 
3464
  const StringC &text = chunk()->entity->asInternalEntity()->string();
 
3465
  Char *cp = (Char *)&c_;
 
3466
  if (mapper.sdataMap(GroveString(name.data(), name.size()), GroveString(text.data(), text.size()), *cp)) {
 
3467
    str.assign(&c_, 1);
 
3468
    return accessOK;
 
3469
  }
 
3470
  else
 
3471
    return accessNull;
 
3472
}
 
3473
 
 
3474
AccessResult SdataNode::getSystemData(GroveString &str) const
 
3475
{
 
3476
  setString(str, chunk()->entity->asInternalEntity()->string());
 
3477
  return accessOK;
 
3478
}
 
3479
 
 
3480
void SdataNode::add(GroveImpl &grove, const SdataEntityEvent &event)
 
3481
{
 
3482
  const Location &loc = event.location().origin()->parent();
 
3483
  grove.setLocOrigin(loc.origin());
 
3484
  SdataChunk *chunk = new (grove.allocChunk(sizeof(SdataChunk))) SdataChunk;
 
3485
  chunk->entity = event.entity();
 
3486
  chunk->locIndex = loc.index();
 
3487
  grove.appendSibling(chunk);
 
3488
}
 
3489
 
 
3490
AccessResult SdataChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node)
 
3491
     const
 
3492
{
 
3493
  ptr.assign(new SdataNode(node->grove(), this));
 
3494
  return accessOK;
 
3495
}
 
3496
 
 
3497
AccessResult NonSgmlChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node)
 
3498
     const
 
3499
{
 
3500
  ptr.assign(new NonSgmlNode(node->grove(), this));
 
3501
  return accessOK;
 
3502
}
 
3503
 
 
3504
AccessResult NonSgmlNode::getNonSgml(unsigned long &n) const
 
3505
{
 
3506
  n = chunk()->c;
 
3507
  return accessOK;
 
3508
}
 
3509
 
 
3510
AccessResult NonSgmlNode::charChunk(const SdataMapper &, GroveString &) const
 
3511
{
 
3512
  return accessNull;
 
3513
}
 
3514
 
 
3515
void NonSgmlNode::add(GroveImpl &grove, const NonSgmlCharEvent &event)
 
3516
{
 
3517
  grove.setLocOrigin(event.location().origin());
 
3518
  NonSgmlChunk *chunk = new (grove.allocChunk(sizeof(NonSgmlChunk))) NonSgmlChunk;
 
3519
  chunk->c = event.character();
 
3520
  chunk->locIndex = event.location().index();
 
3521
  grove.appendSibling(chunk);
 
3522
}
 
3523
 
 
3524
void ExternalDataNode::add(GroveImpl &grove, const ExternalDataEntityEvent &event)
 
3525
{
 
3526
  grove.setLocOrigin(event.location().origin());
 
3527
  ExternalDataChunk *chunk = new (grove.allocChunk(sizeof(ExternalDataChunk))) ExternalDataChunk;
 
3528
  chunk->entity = event.entity();
 
3529
  chunk->locIndex = event.location().index();
 
3530
  grove.appendSibling(chunk);
 
3531
}
 
3532
 
 
3533
AccessResult ExternalDataChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node)
 
3534
     const
 
3535
{
 
3536
  ptr.assign(new ExternalDataNode(node->grove(), this));
 
3537
  return accessOK;
 
3538
}
 
3539
 
 
3540
void SubdocNode::add(GroveImpl &grove, const SubdocEntityEvent &event)
 
3541
{
 
3542
  grove.setLocOrigin(event.location().origin());
 
3543
  SubdocChunk *chunk = new (grove.allocChunk(sizeof(SubdocChunk))) SubdocChunk;
 
3544
  chunk->entity = event.entity();
 
3545
  chunk->locIndex = event.location().index();
 
3546
  grove.appendSibling(chunk);
 
3547
}
 
3548
 
 
3549
AccessResult SubdocChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node)
 
3550
     const
 
3551
{
 
3552
  ptr.assign(new SubdocNode(node->grove(), this));
 
3553
  return accessOK;
 
3554
}
 
3555
 
 
3556
AccessResult PiEntityNode::getSystemData(GroveString &str) const
 
3557
{
 
3558
  setString(str, chunk()->entity->asInternalEntity()->string());
 
3559
  return accessOK;
 
3560
}
 
3561
 
 
3562
void PiEntityNode::add(GroveImpl &grove, const Entity *entity,
 
3563
                       const Location &loc)
 
3564
{
 
3565
  // FIXME use parent?
 
3566
  grove.setLocOrigin(loc.origin());
 
3567
  PiEntityChunk *chunk = new (grove.allocChunk(sizeof(PiEntityChunk))) PiEntityChunk;
 
3568
  chunk->entity = entity;
 
3569
  chunk->locIndex = loc.index();
 
3570
  grove.appendSibling(chunk);
 
3571
}
 
3572
 
 
3573
AccessResult PiEntityChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node)
 
3574
 const
 
3575
{
 
3576
  ptr.assign(new PiEntityNode(node->grove(), this));
 
3577
  return accessOK;
 
3578
}
 
3579
 
 
3580
AccessResult EntityRefNode::getEntity(NodePtr &ptr) const
 
3581
{
 
3582
  ptr.assign(new EntityNode(grove(), chunk()->entity));
 
3583
  return accessOK;
 
3584
}
 
3585
 
 
3586
AccessResult EntityRefNode::getEntityName(GroveString &str) const
 
3587
{
 
3588
  setString(str, chunk()->entity->name());
 
3589
  return accessOK;
 
3590
}
 
3591
 
 
3592
AttributeAsgnNode::AttributeAsgnNode(const GroveImpl *grove,
 
3593
                                     size_t attIndex)
 
3594
: BaseNode(grove), AttributeDefOrigin(attIndex)
 
3595
{
 
3596
}
 
3597
 
 
3598
AccessResult ChunkNode::nextChunkSibling(NodePtr &ptr) const
 
3599
{
 
3600
  // The forwarding chunk has origin = 0, so it will stop
 
3601
  // the iteration before after() can return 0.
 
3602
  const Chunk *p = chunk_->after();
 
3603
  while (p == grove()->completeLimit())
 
3604
    if (!grove()->waitForMoreNodes())
 
3605
      return accessTimeout;
 
3606
  if (p->origin != chunk_->origin)
 
3607
    return accessNull;
 
3608
  return p->setNodePtrFirst(ptr, this);
 
3609
}
 
3610
 
 
3611
AccessResult ChunkNode::nextChunkAfter(NodePtr &nd) const
 
3612
{
 
3613
  const Chunk *p = chunk_->after();
 
3614
  while (p == grove()->completeLimit())
 
3615
    if (!grove()->waitForMoreNodes())
 
3616
      return accessTimeout;
 
3617
  return p->setNodePtrFirst(nd, this);
 
3618
}
 
3619
 
 
3620
AccessResult ChunkNode::firstSibling(NodePtr &ptr) const
 
3621
{
 
3622
  const Chunk *first;
 
3623
  AccessResult ret = chunk_->getFirstSibling(grove(), first);
 
3624
  if (ret != accessOK)
 
3625
    return ret;
 
3626
  return first->setNodePtrFirst(ptr, this);
 
3627
}
 
3628
 
 
3629
AccessResult ChunkNode::siblingsIndex(unsigned long &i) const
 
3630
{
 
3631
  const Chunk *p;
 
3632
  AccessResult ret = chunk_->getFirstSibling(grove(), p);
 
3633
  if (ret != accessOK)
 
3634
    return ret;
 
3635
  i = 0;
 
3636
  while (p != chunk_) {
 
3637
    unsigned long tem;
 
3638
    if (p->getFollowing(grove(), p, tem) != accessOK)
 
3639
      CANNOT_HAPPEN();
 
3640
    i += tem;
 
3641
  }
 
3642
  return accessOK;
 
3643
}
 
3644
 
 
3645
AccessResult ChunkNode::followSiblingRef(unsigned long i, NodePtr &ptr) const
 
3646
{
 
3647
  const Chunk *p;
 
3648
  unsigned long count;
 
3649
  AccessResult ret = chunk()->getFollowing(grove(), p, count);
 
3650
  if (ret != accessOK)
 
3651
    return ret;
 
3652
  while (i > 0) {
 
3653
    const Chunk *lastP = p;
 
3654
    ret = p->getFollowing(grove(), p, count);
 
3655
    if (ret == accessOK && count <= i)
 
3656
      i -= count;
 
3657
    else if (ret == accessOK || ret == accessNull) {
 
3658
      lastP->setNodePtrFirst(ptr, this);
 
3659
      return ptr->followSiblingRef(i - 1, ptr);
 
3660
    }
 
3661
    else
 
3662
      return ret;
 
3663
  }
 
3664
  return p->setNodePtrFirst(ptr, this);
 
3665
}
 
3666
 
 
3667
AccessResult AttributeAsgnNode::getOrigin(NodePtr &ptr) const
 
3668
{
 
3669
  return setNodePtrAttributeOrigin(ptr, this);
 
3670
}
 
3671
 
 
3672
AccessResult AttributeAsgnNode::getName(GroveString &str) const
 
3673
{
 
3674
  setString(str, attDefList()->def(attIndex_)->name());
 
3675
  return accessOK;
 
3676
}
 
3677
 
 
3678
AccessResult AttributeAsgnNode::getImplied(bool &implied) const
 
3679
{
 
3680
  const AttributeValue *value = attributeValue(attIndex_, *grove());
 
3681
  implied = (value != 0 && value->text() == 0);
 
3682
  return accessOK;
 
3683
}
 
3684
 
 
3685
AccessResult AttributeAsgnNode::getValue(NodeListPtr &ptr) const
 
3686
{
 
3687
  return children(ptr);
 
3688
}
 
3689
 
 
3690
AccessResult AttributeAsgnNode::nextChunkSibling(NodePtr &ptr) const
 
3691
{
 
3692
  return followSiblingRef(0, ptr);
 
3693
}
 
3694
 
 
3695
AccessResult AttributeAsgnNode::followSiblingRef(unsigned long i, NodePtr &ptr) const
 
3696
{
 
3697
  // Do it like this to avoid overflow.
 
3698
  if (i >= attDefList()->size() - attIndex_ - 1)
 
3699
    return accessNull;
 
3700
  if (canReuse(ptr))
 
3701
    ((AttributeAsgnNode *)this)->attIndex_ += size_t(i) + 1;
 
3702
  else
 
3703
    ptr.assign(makeAttributeAsgnNode(grove(), attIndex_ + 1 + size_t(i)));
 
3704
  return accessOK;
 
3705
}
 
3706
 
 
3707
AccessResult AttributeAsgnNode::firstSibling(NodePtr &ptr) const
 
3708
{
 
3709
  if (canReuse(ptr))
 
3710
    ((AttributeAsgnNode *)this)->attIndex_ = 0;
 
3711
  else
 
3712
    ptr.assign(makeAttributeAsgnNode(grove(), 0));
 
3713
  return accessOK;
 
3714
}
 
3715
 
 
3716
AccessResult AttributeAsgnNode::siblingsIndex(unsigned long &i) const
 
3717
{
 
3718
  i = attIndex_;
 
3719
  return accessOK;
 
3720
}
 
3721
 
 
3722
void AttributeAsgnNode::accept(NodeVisitor &visitor)
 
3723
{
 
3724
  visitor.attributeAssignment(*this);
 
3725
}
 
3726
 
 
3727
AccessResult AttributeAsgnNode::firstChild(NodePtr &ptr) const
 
3728
{
 
3729
  const AttributeValue *value = attributeValue(attIndex_, *grove());
 
3730
  return makeAttributeValueNode(grove(), ptr, value);
 
3731
}
 
3732
 
 
3733
AccessResult AttributeAsgnNode::children(NodeListPtr &ptr) const
 
3734
{
 
3735
  const AttributeValue *value = attributeValue(attIndex_, *grove());
 
3736
  return makeAttributeValueNodeList(grove(), ptr, value);
 
3737
}
 
3738
 
 
3739
AccessResult AttributeAsgnNode::getTokenSep(Char &ch) const
 
3740
{
 
3741
  const AttributeValue *value = attributeValue(attIndex_, *grove());
 
3742
  if (!value)
 
3743
    return accessNull;
 
3744
  const Text *text;
 
3745
  const StringC *str;
 
3746
  if (value->info(text, str) != AttributeValue::tokenized)
 
3747
    return accessNull;
 
3748
  const TokenizedAttributeValue *tValue =
 
3749
    (const TokenizedAttributeValue *)value;
 
3750
  if (tValue->nTokens() <= 1)
 
3751
    return accessNull;
 
3752
  const Char *ptr;
 
3753
  size_t len;
 
3754
  tValue->token(0, ptr, len);
 
3755
  // the character following the token is a space
 
3756
  ch = ptr[len];
 
3757
  return accessOK;
 
3758
}
 
3759
 
 
3760
AccessResult AttributeAsgnNode::tokens(GroveString &s) const
 
3761
{
 
3762
  const AttributeValue *value = attributeValue(attIndex_, *grove());
 
3763
  if (!value)
 
3764
    return accessNull;
 
3765
  const Text *text;
 
3766
  const StringC *str;
 
3767
  if (value->info(text, str) != AttributeValue::tokenized)
 
3768
    return accessNull;
 
3769
  setString(s, *str);
 
3770
  return accessOK;
 
3771
}
 
3772
 
 
3773
AccessResult AttributeAsgnNode::getAttributeDef(NodePtr &ptr) const
 
3774
{
 
3775
  return makeAttributeDefNode(grove(), ptr, attIndex_);
 
3776
}
 
3777
 
 
3778
bool AttributeAsgnNode::same(const BaseNode &node) const
 
3779
{
 
3780
  return node.same2(this);
 
3781
}
 
3782
 
 
3783
bool AttributeAsgnNode::same2(const AttributeAsgnNode *node)
 
3784
 const
 
3785
{
 
3786
  return (attributeOriginId() == node->attributeOriginId()
 
3787
          && attIndex_ == node->attIndex_);
 
3788
}
 
3789
 
 
3790
unsigned long AttributeAsgnNode::hash() const
 
3791
{
 
3792
  unsigned long n = (unsigned long)attributeOriginId();
 
3793
  return secondHash(n + attIndex_);
 
3794
}
 
3795
 
 
3796
ElementAttributeAsgnNode
 
3797
::ElementAttributeAsgnNode(const GroveImpl *grove, size_t attIndex,
 
3798
                           const ElementChunk *chunk)
 
3799
: AttributeAsgnNode(grove, attIndex),
 
3800
  ElementAttributeOrigin(chunk),
 
3801
  AttributeDefOrigin(attIndex)
 
3802
{
 
3803
}
 
3804
 
 
3805
EntityAttributeAsgnNode
 
3806
::EntityAttributeAsgnNode(const GroveImpl *grove, size_t attIndex,
 
3807
                          const ExternalDataEntity *entity)
 
3808
: AttributeAsgnNode(grove, attIndex),
 
3809
  EntityAttributeOrigin(entity),
 
3810
  AttributeDefOrigin(attIndex)
 
3811
{
 
3812
}
 
3813
 
 
3814
CdataAttributeValueNode
 
3815
::CdataAttributeValueNode(const GroveImpl *grove,
 
3816
                          const AttributeValue *value,
 
3817
                          size_t attIndex,
 
3818
                          const TextIter &iter,
 
3819
                          size_t charIndex)
 
3820
: BaseNode(grove),
 
3821
  AttributeDefOrigin(attIndex),
 
3822
  value_(value),
 
3823
  iter_(iter),
 
3824
  charIndex_(charIndex)
 
3825
{
 
3826
}
 
3827
 
 
3828
bool CdataAttributeValueNode::skipBoring(TextIter &iter)
 
3829
{
 
3830
  while (iter.valid()) {
 
3831
    switch (iter.type()) {
 
3832
    case TextItem::data:
 
3833
    case TextItem::cdata:
 
3834
    case TextItem::sdata:
 
3835
      {
 
3836
        size_t length;
 
3837
        iter.chars(length);
 
3838
        if (length > 0)
 
3839
          return 1;
 
3840
      }
 
3841
      // fall through
 
3842
    default:
 
3843
      iter.advance();
 
3844
      break;
 
3845
    }
 
3846
  }
 
3847
  return 0;
 
3848
}
 
3849
 
 
3850
AccessResult CdataAttributeValueNode::getParent(NodePtr &ptr) const
 
3851
{
 
3852
  ptr.assign(makeOriginNode(grove(), attIndex_));
 
3853
  return accessOK;
 
3854
}
 
3855
 
 
3856
AccessResult CdataAttributeValueNode::charChunk(const SdataMapper &mapper, GroveString &str) const
 
3857
{
 
3858
  if (iter_.type() == TextItem::sdata) {
 
3859
    const Entity *entity = iter_.location().origin()->asEntityOrigin()->entity();
 
3860
    const StringC &name = entity->name();
 
3861
    const StringC &text = entity->asInternalEntity()->string();
 
3862
    Char *cp = (Char *)&c_;
 
3863
    if (mapper.sdataMap(GroveString(name.data(), name.size()), GroveString(text.data(), text.size()), *cp)) {
 
3864
      str.assign(&c_, 1);
 
3865
      return accessOK;
 
3866
    }
 
3867
    else
 
3868
      return accessNull;
 
3869
  }
 
3870
  size_t len;
 
3871
  const Char *s = iter_.chars(len);
 
3872
  str.assign(s + charIndex_, len - charIndex_);
 
3873
  return accessOK;
 
3874
}
 
3875
 
 
3876
AccessResult CdataAttributeValueNode::siblingsIndex(unsigned long &n) const
 
3877
{
 
3878
  TextIter copy(iter_);
 
3879
  size_t tem;
 
3880
  const Char *iterChars = iter_.chars(tem);
 
3881
  copy.rewind();
 
3882
  skipBoring(copy);
 
3883
  n = 0;
 
3884
  while (copy.chars(tem) != iterChars) {
 
3885
    if (copy.type() == TextItem::sdata)
 
3886
      n += 1;
 
3887
    else
 
3888
      n += tem;
 
3889
    copy.advance();
 
3890
    skipBoring(copy);
 
3891
  }
 
3892
  n += charIndex_;
 
3893
  return accessOK;
 
3894
}
 
3895
 
 
3896
AccessResult CdataAttributeValueNode::getEntity(NodePtr &ptr) const
 
3897
{
 
3898
  if (iter_.type() != TextItem::sdata)
 
3899
    return accessNotInClass;
 
3900
  const Entity *entity
 
3901
    = iter_.location().origin()->asEntityOrigin()->entity();
 
3902
  ptr.assign(new EntityNode(grove(), entity));
 
3903
  return accessOK;
 
3904
}
 
3905
 
 
3906
AccessResult CdataAttributeValueNode::getEntityName(GroveString &str) const
 
3907
{
 
3908
  if (iter_.type() != TextItem::sdata)
 
3909
    return accessNotInClass;
 
3910
  const Entity *entity
 
3911
    = iter_.location().origin()->asEntityOrigin()->entity();
 
3912
  setString(str, entity->name());
 
3913
  return accessOK;
 
3914
}
 
3915
 
 
3916
AccessResult CdataAttributeValueNode::getSystemData(GroveString &str) const
 
3917
{
 
3918
  if (iter_.type() != TextItem::sdata)
 
3919
    return accessNotInClass;
 
3920
  size_t len;
 
3921
  const Char *ptr = iter_.chars(len);
 
3922
  str.assign(ptr, len);
 
3923
  return accessOK;
 
3924
}
 
3925
 
 
3926
AccessResult CdataAttributeValueNode::firstSibling(NodePtr &ptr) const
 
3927
{
 
3928
  TextIter copy(iter_);
 
3929
  copy.rewind();
 
3930
  skipBoring(copy);
 
3931
  if (canReuse(ptr)) {
 
3932
    CdataAttributeValueNode *node = (CdataAttributeValueNode *)this;
 
3933
    node->iter_ = copy;
 
3934
    node->charIndex_ = 0;
 
3935
  }
 
3936
  else
 
3937
    ptr.assign(makeCdataAttributeValueNode(grove(), value_, attIndex_, copy));
 
3938
  return accessOK;
 
3939
}
 
3940
 
 
3941
AccessResult CdataAttributeValueNode::nextChunkSibling(NodePtr &ptr) const
 
3942
{
 
3943
  TextIter copy(iter_);
 
3944
  copy.advance();
 
3945
  if (!skipBoring(copy))
 
3946
    return accessNull;
 
3947
  if (canReuse(ptr)) {
 
3948
    CdataAttributeValueNode *node = (CdataAttributeValueNode *)this;
 
3949
    node->iter_ = copy;
 
3950
    node->charIndex_ = 0;
 
3951
  }
 
3952
  else
 
3953
    ptr.assign(makeCdataAttributeValueNode(grove(), value_, attIndex_, copy));
 
3954
  return accessOK;
 
3955
}
 
3956
 
 
3957
AccessResult CdataAttributeValueNode::nextSibling(NodePtr &ptr) const
 
3958
{
 
3959
  if (iter_.type() != TextItem::sdata) {
 
3960
    size_t length;
 
3961
    iter_.chars(length);
 
3962
    if (charIndex_ + 1 < length) {
 
3963
      if (canReuse(ptr))
 
3964
        ((CdataAttributeValueNode *)this)->charIndex_ += 1;
 
3965
      else
 
3966
        ptr.assign(makeCdataAttributeValueNode(grove(), value_,
 
3967
                                               attIndex_, iter_,
 
3968
                                               charIndex_ + 1));
 
3969
      return accessOK;
 
3970
    }
 
3971
  }
 
3972
  return CdataAttributeValueNode::nextChunkSibling(ptr);
 
3973
}
 
3974
 
 
3975
AccessResult CdataAttributeValueNode::getLocation(Location &loc) const
 
3976
{
 
3977
  if (iter_.type() == TextItem::sdata)
 
3978
    return grove()->proxifyLocation(iter_.location().origin()->parent(), loc);
 
3979
  else
 
3980
    return grove()->proxifyLocation(iter_.location(), loc);
 
3981
}
 
3982
 
 
3983
void CdataAttributeValueNode::accept(NodeVisitor &visitor)
 
3984
{
 
3985
  if (iter_.type() == TextItem::sdata)
 
3986
    visitor.sdata(*this);
 
3987
  else
 
3988
    visitor.dataChar(*this);
 
3989
}
 
3990
 
 
3991
unsigned long CdataAttributeValueNode::hash() const
 
3992
{
 
3993
  unsigned long n;
 
3994
  CdataAttributeValueNode::siblingsIndex(n);
 
3995
  return secondHash(secondHash((unsigned long)attributeOriginId() + attIndex_) + n);
 
3996
}
 
3997
 
 
3998
const ClassDef &CdataAttributeValueNode::classDef() const
 
3999
{
 
4000
  if (iter_.type() == TextItem::sdata)
 
4001
    return ClassDef::sdata;
 
4002
  else
 
4003
    return ClassDef::dataChar;
 
4004
}
 
4005
 
 
4006
bool CdataAttributeValueNode::same(const BaseNode &node) const
 
4007
{
 
4008
  return node.same2(this);
 
4009
}
 
4010
 
 
4011
bool CdataAttributeValueNode::same2(const CdataAttributeValueNode *node)
 
4012
     const
 
4013
{
 
4014
  size_t tem;
 
4015
  return (attributeOriginId() == node->attributeOriginId()
 
4016
          && attIndex_ == node->attIndex_
 
4017
          && charIndex_ == node->charIndex_
 
4018
          && iter_.chars(tem) == node->iter_.chars(tem));
 
4019
}
 
4020
 
 
4021
bool CdataAttributeValueNode::chunkContains(const Node &node) const
 
4022
{
 
4023
  if (!sameGrove(node))
 
4024
    return 0;
 
4025
  return ((const BaseNode &)node).inChunk(this);
 
4026
}
 
4027
 
 
4028
bool CdataAttributeValueNode::inChunk(const CdataAttributeValueNode *node) const
 
4029
{
 
4030
  size_t tem;
 
4031
  return (attributeOriginId() == node->attributeOriginId()
 
4032
          && attIndex_ == node->attIndex_
 
4033
          && iter_.chars(tem) == node->iter_.chars(tem)
 
4034
          && charIndex_ >= node->charIndex_);
 
4035
}
 
4036
 
 
4037
ElementCdataAttributeValueNode
 
4038
::ElementCdataAttributeValueNode(const GroveImpl *grove,
 
4039
                                 const AttributeValue *value,
 
4040
                                 size_t attIndex,
 
4041
                                 const TextIter &iter,
 
4042
                                 size_t charIndex,
 
4043
                                 const ElementChunk *chunk)
 
4044
: CdataAttributeValueNode(grove, value, attIndex, iter, charIndex),
 
4045
  ElementAttributeOrigin(chunk), AttributeDefOrigin(attIndex)
 
4046
{
 
4047
}
 
4048
 
 
4049
EntityCdataAttributeValueNode
 
4050
::EntityCdataAttributeValueNode(const GroveImpl *grove,
 
4051
                                const AttributeValue *value,
 
4052
                                size_t attIndex,
 
4053
                                const TextIter &iter,
 
4054
                                size_t charIndex,
 
4055
                                const ExternalDataEntity *entity)
 
4056
: CdataAttributeValueNode(grove, value, attIndex, iter, charIndex),
 
4057
  EntityAttributeOrigin(entity), AttributeDefOrigin(attIndex)
 
4058
{
 
4059
}
 
4060
 
 
4061
ElementTypeCdataAttributeValueNode
 
4062
::ElementTypeCdataAttributeValueNode(const GroveImpl *grove,
 
4063
                                     const AttributeValue *value,
 
4064
                                     size_t attIndex,
 
4065
                                     const TextIter &iter,
 
4066
                                     size_t charIndex,
 
4067
                                     const ElementType *elementType)
 
4068
: CdataAttributeValueNode(grove, value, attIndex, iter, charIndex),
 
4069
  ElementTypeAttributeDefOrigin(elementType), AttributeDefOrigin(attIndex)
 
4070
{
 
4071
}
 
4072
 
 
4073
NotationCdataAttributeValueNode
 
4074
::NotationCdataAttributeValueNode(const GroveImpl *grove,
 
4075
                                  const AttributeValue *value,
 
4076
                                  size_t attIndex,
 
4077
                                  const TextIter &iter,
 
4078
                                  size_t charIndex,
 
4079
                                  const Notation *notation)
 
4080
: CdataAttributeValueNode(grove, value, attIndex, iter, charIndex),
 
4081
  NotationAttributeDefOrigin(notation), AttributeDefOrigin(attIndex)
 
4082
{
 
4083
}
 
4084
 
 
4085
AttributeValueTokenNode
 
4086
::AttributeValueTokenNode(const GroveImpl *grove,
 
4087
                          const TokenizedAttributeValue *value,
 
4088
                          size_t attIndex, size_t tokenIndex)
 
4089
: BaseNode(grove),
 
4090
  AttributeDefOrigin(attIndex),
 
4091
  value_(value),
 
4092
  tokenIndex_(tokenIndex)
 
4093
{
 
4094
}
 
4095
 
 
4096
AccessResult AttributeValueTokenNode::getParent(NodePtr &ptr) const
 
4097
{
 
4098
  ptr.assign(makeOriginNode(grove(), attIndex_));
 
4099
  return accessOK;
 
4100
}
 
4101
 
 
4102
AccessResult AttributeValueTokenNode::nextChunkSibling(NodePtr &ptr) const
 
4103
{
 
4104
  return followSiblingRef(0, ptr);
 
4105
}
 
4106
 
 
4107
AccessResult AttributeValueTokenNode::followSiblingRef(unsigned long i, NodePtr &ptr) const
 
4108
{
 
4109
  // Do it like this to avoid possibility of overflow
 
4110
  if (i >= value_->nTokens() - tokenIndex_ - 1)
 
4111
    return accessNull;
 
4112
  if (canReuse(ptr)) {
 
4113
    AttributeValueTokenNode *node = (AttributeValueTokenNode *)this;
 
4114
    node->tokenIndex_ += size_t(i) + 1;
 
4115
  }
 
4116
  else
 
4117
    ptr.assign(makeAttributeValueTokenNode(grove(), value_, attIndex_,
 
4118
                                           tokenIndex_ + size_t(i) + 1));
 
4119
  return accessOK;
 
4120
}
 
4121
 
 
4122
AccessResult AttributeValueTokenNode::firstSibling(NodePtr &ptr) const
 
4123
{
 
4124
  if (canReuse(ptr))
 
4125
    ((AttributeValueTokenNode *)this)->tokenIndex_ = 0;
 
4126
  else
 
4127
    ptr.assign(makeAttributeValueTokenNode(grove(), value_, attIndex_, 0));
 
4128
  return accessOK;
 
4129
}
 
4130
 
 
4131
AccessResult AttributeValueTokenNode::siblingsIndex(unsigned long &i) const
 
4132
{
 
4133
  i = tokenIndex_;
 
4134
  return accessOK;
 
4135
}
 
4136
 
 
4137
AccessResult AttributeValueTokenNode::getToken(GroveString &str) const
 
4138
{
 
4139
  const Char *ptr;
 
4140
  size_t len;
 
4141
  value_->token(tokenIndex_, ptr, len);
 
4142
  str.assign(ptr, len);
 
4143
  return accessOK;
 
4144
}
 
4145
 
 
4146
AccessResult AttributeValueTokenNode::getEntity(NodePtr &ptr) const
 
4147
{
 
4148
   if (!attDefList()->def(attIndex_)->isEntity())
 
4149
    return accessNull;
 
4150
  StringC token(value_->token(tokenIndex_));
 
4151
  const Entity *entity = grove()->governingDtd()->lookupEntityTemp(0, token);
 
4152
  if (!entity) {
 
4153
    entity = grove()->lookupDefaultedEntity(token);
 
4154
    if (!entity)
 
4155
      return accessNull;
 
4156
  }
 
4157
  ptr.assign(new EntityNode(grove(), entity));
 
4158
  return accessOK;
 
4159
}
 
4160
 
 
4161
AccessResult AttributeValueTokenNode::getNotation(NodePtr &ptr) const
 
4162
{
 
4163
  if (!attDefList()->def(attIndex_)->isNotation())
 
4164
    return accessNull;
 
4165
  StringC token(value_->token(tokenIndex_));
 
4166
  const Notation *notation = grove()->governingDtd()->lookupNotationTemp(token);
 
4167
  if (!notation)
 
4168
    return accessNull;
 
4169
  ptr.assign(new NotationNode(grove(), notation));
 
4170
  return accessOK;
 
4171
}
 
4172
 
 
4173
AccessResult AttributeValueTokenNode::getReferent(NodePtr &ptr) const
 
4174
{
 
4175
  if (!attDefList()->def(attIndex_)->isIdref())
 
4176
    return accessNull;
 
4177
  StringC token(value_->token(tokenIndex_));
 
4178
  for (;;) {
 
4179
    Boolean complete = grove()->complete();
 
4180
    const ElementChunk *element = grove()->lookupElement(token);
 
4181
    if (element) {
 
4182
      ptr.assign(new ElementNode(grove(), element));
 
4183
      break;
 
4184
    }
 
4185
    if (complete)
 
4186
      return accessNull;
 
4187
    if (!grove()->waitForMoreNodes())
 
4188
      return accessTimeout;
 
4189
  }
 
4190
  return accessOK;
 
4191
}
 
4192
 
 
4193
void AttributeValueTokenNode::accept(NodeVisitor &visitor)
 
4194
{
 
4195
  visitor.attributeValueToken(*this);
 
4196
}
 
4197
 
 
4198
unsigned long AttributeValueTokenNode::hash() const
 
4199
{
 
4200
  return secondHash(secondHash((unsigned long)attributeOriginId() + attIndex_) + tokenIndex_);
 
4201
}
 
4202
 
 
4203
bool AttributeValueTokenNode::same(const BaseNode &node) const
 
4204
{
 
4205
  return node.same2(this);
 
4206
}
 
4207
 
 
4208
bool AttributeValueTokenNode::same2(const AttributeValueTokenNode *node) const
 
4209
{
 
4210
  return (attributeOriginId() == node->attributeOriginId()
 
4211
          && attIndex_ == node->attIndex_
 
4212
          && tokenIndex_ == node->tokenIndex_);
 
4213
}
 
4214
 
 
4215
AccessResult AttributeValueTokenNode::getLocation(Location &loc) const
 
4216
{
 
4217
  const ConstPtr<Origin> *originP;
 
4218
  Index index;
 
4219
  if (!value_->tokenLocation(tokenIndex_, originP, index)
 
4220
      && originP->pointer()) {
 
4221
    loc = Location(new GroveImplProxyOrigin(grove(), originP->pointer()), index);
 
4222
    return accessOK;
 
4223
  }
 
4224
  return accessNull;
 
4225
}
 
4226
 
 
4227
ElementAttributeValueTokenNode
 
4228
::ElementAttributeValueTokenNode(const GroveImpl *grove,
 
4229
                                 const TokenizedAttributeValue *value,
 
4230
                                 size_t attIndex,
 
4231
                                 size_t tokenIndex,
 
4232
                                 const ElementChunk *chunk)
 
4233
: AttributeValueTokenNode(grove, value, attIndex, tokenIndex),
 
4234
  ElementAttributeOrigin(chunk), AttributeDefOrigin(attIndex)
 
4235
{
 
4236
}
 
4237
 
 
4238
EntityAttributeValueTokenNode
 
4239
::EntityAttributeValueTokenNode(const GroveImpl *grove,
 
4240
                                const TokenizedAttributeValue *value,
 
4241
                                size_t attIndex,
 
4242
                                size_t tokenIndex,
 
4243
                                const ExternalDataEntity *entity)
 
4244
: AttributeValueTokenNode(grove, value, attIndex, tokenIndex),
 
4245
  EntityAttributeOrigin(entity), AttributeDefOrigin(attIndex)
 
4246
{
 
4247
}
 
4248
 
 
4249
ElementTypeAttributeValueTokenNode
 
4250
::ElementTypeAttributeValueTokenNode(const GroveImpl *grove,
 
4251
                                     const TokenizedAttributeValue *value,
 
4252
                                     size_t attIndex,
 
4253
                                     size_t tokenIndex,
 
4254
                                     const ElementType *elementType)
 
4255
: AttributeValueTokenNode(grove, value, attIndex, tokenIndex),
 
4256
  ElementTypeAttributeDefOrigin(elementType), AttributeDefOrigin(attIndex)
 
4257
{
 
4258
}
 
4259
 
 
4260
NotationAttributeValueTokenNode
 
4261
::NotationAttributeValueTokenNode(const GroveImpl *grove,
 
4262
                                  const TokenizedAttributeValue *value,
 
4263
                                  size_t attIndex,
 
4264
                                  size_t tokenIndex,
 
4265
                                  const Notation *notation)
 
4266
: AttributeValueTokenNode(grove, value, attIndex, tokenIndex),
 
4267
  NotationAttributeDefOrigin(notation), AttributeDefOrigin(attIndex)
 
4268
{
 
4269
}
 
4270
 
 
4271
EntityNode::EntityNode(const GroveImpl *grove, const Entity *entity)
 
4272
: EntityNodeBase(grove, entity)
 
4273
{
 
4274
}
 
4275
 
 
4276
DefaultEntityNode::DefaultEntityNode(const GroveImpl *grove, const Entity *entity)
 
4277
: EntityNodeBase(grove, entity)
 
4278
{
 
4279
}
 
4280
 
 
4281
AccessResult EntityNode::getOrigin(NodePtr &ptr) const
 
4282
{
 
4283
  if (entity_->defaulted() && grove()->lookupDefaultedEntity(entity_->name()))
 
4284
    ptr.assign(new SgmlDocumentNode(grove(), grove()->root()));
 
4285
  else
 
4286
    ptr.assign(new DocumentTypeNode(grove(), grove()->governingDtd()));
 
4287
  return accessOK;
 
4288
}
 
4289
 
 
4290
AccessResult DefaultEntityNode::getOrigin(NodePtr &ptr) const
 
4291
{
 
4292
  ptr.assign(new DocumentTypeNode(grove(), grove()->governingDtd()));
 
4293
  return accessOK;
 
4294
}
 
4295
 
 
4296
AccessResult EntityNode::getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const
 
4297
{
 
4298
  if (entity_->defaulted() && grove()->lookupDefaultedEntity(entity_->name()))
 
4299
    name = ComponentName::idDefaultedEntities;
 
4300
  else
 
4301
    name = ComponentName::idGeneralEntities;
 
4302
  return accessOK;
 
4303
}
 
4304
 
 
4305
AccessResult DefaultEntityNode::getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const
 
4306
{
 
4307
  name = ComponentName::idDefaultEntity;
 
4308
  return accessOK;
 
4309
}
 
4310
 
 
4311
AccessResult EntityNodeBase::getName(GroveString &str) const
 
4312
{
 
4313
  setString(str, entity_->name());
 
4314
  return accessOK;
 
4315
}
 
4316
 
 
4317
AccessResult EntityNodeBase::getExternalId(NodePtr &ptr) const
 
4318
{
 
4319
  const ExternalEntity *x = entity_->asExternalEntity();
 
4320
  if (!x)
 
4321
    return accessNull;
 
4322
  ptr.assign(new EntityExternalIdNode(grove(), x));
 
4323
  return accessOK;
 
4324
}
 
4325
 
 
4326
AccessResult EntityNodeBase::getNotation(NodePtr &ptr) const
 
4327
{
 
4328
  const ExternalDataEntity *x = entity_->asExternalDataEntity();
 
4329
  if (!x || !x->notation())
 
4330
    return accessNull;
 
4331
  ptr.assign(new NotationNode(grove(), x->notation()));
 
4332
  return accessOK;
 
4333
}
 
4334
 
 
4335
AccessResult EntityNodeBase::getNotationName(GroveString &str) const
 
4336
{
 
4337
  const ExternalDataEntity *x = entity_->asExternalDataEntity();
 
4338
  if (!x || !x->notation())
 
4339
    return accessNull;
 
4340
  setString(str, x->notation()->name());
 
4341
  return accessOK;
 
4342
}
 
4343
 
 
4344
AccessResult EntityNodeBase::getText(GroveString &str) const
 
4345
{
 
4346
  const InternalEntity *i = entity_->asInternalEntity();
 
4347
  if (!i)
 
4348
    return accessNull;
 
4349
  setString(str, i->string());
 
4350
  return accessOK;
 
4351
}
 
4352
 
 
4353
AccessResult EntityNodeBase::getEntityType(Node::EntityType::Enum &entityType) const
 
4354
{
 
4355
  switch (entity_->dataType()) {
 
4356
  case EntityDecl::sgmlText:
 
4357
    entityType = EntityType::text;
 
4358
    break;
 
4359
  case EntityDecl::pi:
 
4360
    entityType = EntityType::pi;
 
4361
    break;
 
4362
  case EntityDecl::cdata:
 
4363
    entityType = EntityType::cdata;
 
4364
    break;
 
4365
  case EntityDecl::sdata:
 
4366
    entityType = EntityType::sdata;
 
4367
    break;
 
4368
  case EntityDecl::ndata:
 
4369
    entityType = EntityType::ndata;
 
4370
    break;
 
4371
  case EntityDecl::subdoc:
 
4372
    entityType = EntityType::subdocument;
 
4373
    break;
 
4374
  default:
 
4375
    CANNOT_HAPPEN();
 
4376
  }
 
4377
  return accessOK;
 
4378
}
 
4379
 
 
4380
AccessResult EntityNode::getDefaulted(bool &dflted) const
 
4381
{
 
4382
  dflted = entity_->defaulted();
 
4383
  return accessOK;
 
4384
}
 
4385
 
 
4386
AccessResult EntityNodeBase::getAttributes(NamedNodeListPtr &ptr) const
 
4387
{
 
4388
  const ExternalDataEntity *x = entity_->asExternalDataEntity();
 
4389
  if (!x)
 
4390
    return accessNull;
 
4391
  ptr.assign(new EntityAttributesNamedNodeList(grove(), x));
 
4392
  return accessOK;
 
4393
}
 
4394
 
 
4395
AccessResult EntityNodeBase::attributeRef(unsigned long i, NodePtr &ptr) const
 
4396
{
 
4397
  const ExternalDataEntity *x = entity_->asExternalDataEntity();
 
4398
  if (!x || i >= x->attributes().size())
 
4399
    return accessNull;
 
4400
  ptr.assign(new EntityAttributeAsgnNode(grove(), size_t(i), x));
 
4401
  return accessOK;
 
4402
}
 
4403
 
 
4404
AccessResult EntityNodeBase::getLocation(Location &loc) const
 
4405
{
 
4406
  return grove()->proxifyLocation(entity_->defLocation(), loc);
 
4407
}
 
4408
 
 
4409
bool EntityNode::same(const BaseNode &node) const
 
4410
{
 
4411
  return node.same2(this);
 
4412
}
 
4413
 
 
4414
bool DefaultEntityNode::same(const BaseNode &node) const
 
4415
{
 
4416
  return node.same2(this);
 
4417
}
 
4418
 
 
4419
bool EntityNode::same2(const EntityNode *node) const
 
4420
{
 
4421
  return entity_ == node->entity_;
 
4422
}
 
4423
 
 
4424
bool DefaultEntityNode::same2(const DefaultEntityNode *node) const
 
4425
{
 
4426
  return entity_ == node->entity_;
 
4427
}
 
4428
 
 
4429
void EntityNode::accept(NodeVisitor &visitor)
 
4430
{
 
4431
  visitor.entity(*this);
 
4432
}
 
4433
 
 
4434
void DefaultEntityNode::accept(NodeVisitor &visitor)
 
4435
{
 
4436
  visitor.defaultEntity(*this);
 
4437
}
 
4438
 
 
4439
unsigned long EntityNodeBase::hash() const
 
4440
{
 
4441
  return (unsigned long)entity_;
 
4442
}
 
4443
 
 
4444
EntityAttributeOrigin
 
4445
::EntityAttributeOrigin(const ExternalDataEntity *entity)
 
4446
: entity_(entity)
 
4447
{
 
4448
}
 
4449
 
 
4450
const AttributeDefinitionList *
 
4451
EntityAttributeOrigin::attDefList() const
 
4452
{
 
4453
  return entity_->notation()->attributeDefTemp();
 
4454
}
 
4455
 
 
4456
 
 
4457
const AttributeValue *
 
4458
EntityAttributeOrigin::attributeValue(size_t attIndex, const GroveImpl &) const
 
4459
{
 
4460
  return entity_->attributes().value(attIndex);
 
4461
}
 
4462
 
 
4463
AccessResult
 
4464
EntityAttributeOrigin::setNodePtrAttributeOrigin(NodePtr &ptr,
 
4465
                                                 const BaseNode *node) const
 
4466
{
 
4467
  ptr.assign(new EntityNode(node->grove(), entity_));
 
4468
  return accessOK;
 
4469
}
 
4470
 
 
4471
Node *EntityAttributeOrigin
 
4472
::makeCdataAttributeValueNode(const GroveImpl *grove,
 
4473
                              const AttributeValue *value,
 
4474
                              size_t attIndex,
 
4475
                              const TextIter &iter,
 
4476
                              size_t charIndex) const
 
4477
{
 
4478
  return new EntityCdataAttributeValueNode(grove, value, attIndex, iter,
 
4479
                                           charIndex, entity_);
 
4480
}
 
4481
 
 
4482
 
 
4483
Node *EntityAttributeOrigin
 
4484
::makeAttributeValueTokenNode(const GroveImpl *grove,
 
4485
                              const TokenizedAttributeValue *value,
 
4486
                              size_t attIndex,
 
4487
                              size_t tokenIndex) const
 
4488
{
 
4489
  return new EntityAttributeValueTokenNode(grove, value, attIndex,
 
4490
                                           tokenIndex, entity_);
 
4491
}
 
4492
 
 
4493
Node *EntityAttributeOrigin
 
4494
::makeAttributeAsgnNode(const GroveImpl *grove,
 
4495
                        size_t attIndex) const
 
4496
{
 
4497
  return new EntityAttributeAsgnNode(grove, attIndex, entity_);
 
4498
}
 
4499
 
 
4500
AccessResult EntityAttributeOrigin
 
4501
::makeAttributeDefNode(const GroveImpl *grove,
 
4502
                       NodePtr &ptr,
 
4503
                       size_t attributeDefIdx) const 
 
4504
{
 
4505
  if (entity_->notation() == 0)
 
4506
    return accessNull;  
 
4507
  ptr.assign(new NotationAttributeDefNode(grove,
 
4508
                                          *(entity_->notation()),
 
4509
                                          attributeDefIdx)); 
 
4510
  return accessOK;
 
4511
}
 
4512
 
 
4513
Node *EntityAttributeOrigin::makeOriginNode(const GroveImpl *grove, size_t attIndex) const 
 
4514
{
 
4515
  return makeAttributeAsgnNode(grove, attIndex);
 
4516
}
 
4517
 
 
4518
const void *EntityAttributeOrigin::attributeOriginId() const
 
4519
{
 
4520
  return entity_;
 
4521
}
 
4522
 
 
4523
DoctypesAndLinktypesNamedNodeList
 
4524
::DoctypesAndLinktypesNamedNodeList(const GroveImpl *grove)
 
4525
: BaseNamedNodeList(grove, grove->generalSubstTable())
 
4526
{
 
4527
}
 
4528
 
 
4529
NodeListPtr DoctypesAndLinktypesNamedNodeList::nodeList() const
 
4530
{
 
4531
  NodePtr tem(new DocumentTypeNode(grove(), grove()->governingDtd()));
 
4532
  return new SiblingNodeList(tem);
 
4533
}
 
4534
 
 
4535
AccessResult
 
4536
DoctypesAndLinktypesNamedNodeList
 
4537
::namedNodeU(const StringC &str, NodePtr &ptr) const
 
4538
{
 
4539
  if (grove()->governingDtd()->name() != str)
 
4540
    return accessNull;
 
4541
  ptr.assign(new DocumentTypeNode(grove(), grove()->governingDtd()));
 
4542
  return accessOK;
 
4543
}
 
4544
 
 
4545
GeneralEntitiesNamedNodeList
 
4546
::GeneralEntitiesNamedNodeList(const GroveImpl *grove, const Dtd *dtd)
 
4547
: BaseNamedNodeList(grove, grove->entitySubstTable()), dtd_(dtd)
 
4548
{
 
4549
}
 
4550
 
 
4551
NodeListPtr GeneralEntitiesNamedNodeList::nodeList() const
 
4552
{
 
4553
  return new EntitiesNodeList(grove(),
 
4554
                              dtd_->generalEntityIter());
 
4555
}
 
4556
 
 
4557
AccessResult
 
4558
GeneralEntitiesNamedNodeList::namedNodeU(const StringC &str, NodePtr &ptr) const
 
4559
{
 
4560
  const Entity *entity
 
4561
   = dtd_->lookupEntityTemp(0, str);
 
4562
  if (!entity)
 
4563
    return accessNull;
 
4564
  ptr.assign(new EntityNode(grove(), entity));
 
4565
  return accessOK;
 
4566
}
 
4567
 
 
4568
ParameterEntitiesNamedNodeList
 
4569
::ParameterEntitiesNamedNodeList(const GroveImpl *grove, const Dtd *dtd)
 
4570
: BaseNamedNodeList(grove, grove->entitySubstTable()), dtd_(dtd)
 
4571
{
 
4572
}
 
4573
 
 
4574
NodeListPtr ParameterEntitiesNamedNodeList::nodeList() const
 
4575
{
 
4576
  return new EntitiesNodeList(grove(),
 
4577
                              dtd_->parameterEntityIter());
 
4578
}
 
4579
 
 
4580
AccessResult
 
4581
ParameterEntitiesNamedNodeList::namedNodeU(const StringC &str, NodePtr &ptr) const
 
4582
{
 
4583
  const Entity *entity
 
4584
   = dtd_->lookupEntityTemp(1, str);
 
4585
  if (!entity)
 
4586
    return accessNull;
 
4587
  ptr.assign(new EntityNode(grove(), entity));
 
4588
  return accessOK;
 
4589
}
 
4590
 
 
4591
AccessResult
 
4592
DefaultedEntitiesNamedNodeList::namedNodeU(const StringC &str, NodePtr &ptr) const
 
4593
{
 
4594
  const Entity *entity
 
4595
   = grove()->lookupDefaultedEntity(str);
 
4596
  if (!entity)
 
4597
    return accessNull;
 
4598
  ptr.assign(new EntityNode(grove(), entity));
 
4599
  return accessOK;
 
4600
}
 
4601
 
 
4602
NodeListPtr
 
4603
DefaultedEntitiesNamedNodeList::nodeList() const
 
4604
{
 
4605
  return new EntitiesNodeList(grove(), grove()->defaultedEntityIter());
 
4606
}
 
4607
 
 
4608
NodeListPtr DocEntitiesNamedNodeList::nodeList() const
 
4609
{
 
4610
  return new DocEntitiesNodeList(grove());
 
4611
}
 
4612
 
 
4613
AccessResult
 
4614
DocEntitiesNamedNodeList::namedNodeU(const StringC &str, NodePtr &ptr) const
 
4615
{
 
4616
  const Entity *entity
 
4617
   = grove()->governingDtd()->lookupEntityTemp(0, str);
 
4618
  // How I hate the default entity.
 
4619
  while (!entity) {
 
4620
    if (!grove()->hasDefaultEntity())
 
4621
      return accessNull;
 
4622
    // Make sure that the value of complete
 
4623
    // we look at is that before we looked up
 
4624
    // the entity.
 
4625
    Boolean complete = grove()->complete();
 
4626
    entity = grove()->lookupDefaultedEntity(str);
 
4627
    if (entity)
 
4628
      break;
 
4629
    if (complete)
 
4630
      return accessNull;
 
4631
    if (!grove()->waitForMoreNodes())
 
4632
      return accessTimeout;
 
4633
  }
 
4634
  ptr.assign(new EntityNode(grove(), entity));
 
4635
  return accessOK;
 
4636
}
 
4637
 
 
4638
AccessResult
 
4639
ElementsNamedNodeList::namedNodeU(const StringC &str, NodePtr &ptr) const
 
4640
{
 
4641
  for (;;) {
 
4642
    Boolean complete = grove()->complete();
 
4643
    const ElementChunk *element = grove()->lookupElement(str);
 
4644
    if (element) {
 
4645
      ptr.assign(new ElementNode(grove(), element));
 
4646
      break;
 
4647
    }
 
4648
    if (complete)
 
4649
      return accessNull;
 
4650
    if (!grove()->waitForMoreNodes())
 
4651
      return accessTimeout;
 
4652
  }
 
4653
  return accessOK;
 
4654
}
 
4655
 
 
4656
NodeListPtr ElementsNamedNodeList::nodeList() const
 
4657
{
 
4658
  return new ElementsNodeList(grove(), grove()->root()->documentElement);
 
4659
}
 
4660
 
 
4661
ElementsNodeList::ElementsNodeList(const GroveImpl *grove,
 
4662
                                   const Chunk *first)
 
4663
: grove_(grove), first_(first)
 
4664
{
 
4665
}
 
4666
 
 
4667
AccessResult ElementsNodeList::first(NodePtr &ptr) const
 
4668
{
 
4669
  const Chunk *p = first_;
 
4670
  while (p) {
 
4671
    while (p == grove_->completeLimit()) {
 
4672
      if (!grove_->waitForMoreNodes())
 
4673
        return accessTimeout;
 
4674
    }
 
4675
    if (p->id()) {
 
4676
      ((ElementsNodeList *)this)->first_ = p;
 
4677
      ptr.assign(new ElementNode(grove_, (const ElementChunk *)p));
 
4678
      return accessOK;
 
4679
    }
 
4680
    p = p->after();
 
4681
  }
 
4682
  return accessNull;
 
4683
}
 
4684
 
 
4685
AccessResult ElementsNodeList::chunkRest(NodeListPtr &ptr) const
 
4686
{
 
4687
  const Chunk *p = first_;
 
4688
  while (p) {
 
4689
    while (p == grove_->completeLimit()) {
 
4690
      if (!grove_->waitForMoreNodes())
 
4691
        return accessTimeout;
 
4692
    }
 
4693
    if (p->id()) {
 
4694
      if (canReuse(ptr))
 
4695
        ((ElementsNodeList *)this)->first_ = p->after();
 
4696
      else
 
4697
        ptr.assign(new ElementsNodeList(grove_, p->after()));
 
4698
      return accessOK;
 
4699
    }
 
4700
    p = p->after();
 
4701
 }
 
4702
 return accessNull;
 
4703
}
 
4704
 
 
4705
// iter.next() gives first member of list that this represents
 
4706
 
 
4707
EntitiesNodeList::EntitiesNodeList(const GroveImpl *grove,
 
4708
                                   const Dtd::ConstEntityIter &iter)
 
4709
: grove_(grove), iter_(iter)
 
4710
{
 
4711
}
 
4712
 
 
4713
AccessResult EntitiesNodeList::first(NodePtr &ptr) const
 
4714
{
 
4715
  Dtd::ConstEntityIter tem(iter_);
 
4716
  const Entity *entity = tem.nextTemp();
 
4717
  if (!entity)
 
4718
    return accessNull;
 
4719
  ptr.assign(new EntityNode(grove_, entity));
 
4720
  return accessOK;
 
4721
}
 
4722
 
 
4723
AccessResult EntitiesNodeList::chunkRest(NodeListPtr &ptr) const
 
4724
{
 
4725
  if (canReuse(ptr)) {
 
4726
    EntitiesNodeList *list = (EntitiesNodeList *)this;
 
4727
    if (list->iter_.nextTemp() == 0)
 
4728
      return accessNull;
 
4729
    return accessOK;
 
4730
  }
 
4731
  Dtd::ConstEntityIter tem(iter_);
 
4732
  if (tem.nextTemp() == 0)
 
4733
    return accessNull;
 
4734
  ptr.assign(new EntitiesNodeList(grove_, tem));
 
4735
  return accessOK;
 
4736
}
 
4737
 
 
4738
DocEntitiesNodeList::DocEntitiesNodeList(const GroveImpl *grove)
 
4739
: EntitiesNodeList(grove, grove->governingDtd()->generalEntityIter())
 
4740
{
 
4741
}
 
4742
 
 
4743
AccessResult DocEntitiesNodeList::first(NodePtr &ptr) const
 
4744
{
 
4745
  AccessResult ret = EntitiesNodeList::first(ptr);
 
4746
  if (ret != accessNull || !grove()->hasDefaultEntity())
 
4747
    return ret;
 
4748
  while (!grove()->complete())
 
4749
    if (!grove()->waitForMoreNodes())
 
4750
      return accessTimeout;
 
4751
  Dtd::ConstEntityIter tem(grove()->defaultedEntityIter());
 
4752
  const Entity *entity = tem.nextTemp();
 
4753
  if (!entity)
 
4754
    return accessNull;
 
4755
  ptr.assign(new EntityNode(grove(), entity));
 
4756
  return accessOK;
 
4757
}
 
4758
 
 
4759
AccessResult DocEntitiesNodeList::chunkRest(NodeListPtr &ptr) const
 
4760
{
 
4761
  AccessResult ret = EntitiesNodeList::chunkRest(ptr);
 
4762
  if (ret != accessNull || !grove()->hasDefaultEntity())
 
4763
    return ret;
 
4764
  while (!grove()->complete())
 
4765
    if (!grove()->waitForMoreNodes())
 
4766
      return accessTimeout;
 
4767
  Dtd::ConstEntityIter tem(grove()->defaultedEntityIter());
 
4768
  const Entity *entity = tem.nextTemp();
 
4769
  if (!entity)
 
4770
    return accessNull;
 
4771
  ptr.assign(new EntitiesNodeList(grove(), tem));
 
4772
  return accessOK;
 
4773
}
 
4774
 
 
4775
NotationsNamedNodeList
 
4776
::NotationsNamedNodeList(const GroveImpl *grove, const Dtd *dtd)
 
4777
: BaseNamedNodeList(grove, grove->generalSubstTable()), dtd_(dtd)
 
4778
{
 
4779
}
 
4780
 
 
4781
NodeListPtr NotationsNamedNodeList::nodeList() const
 
4782
{
 
4783
  return new NotationsNodeList(grove(),
 
4784
                               dtd_->notationIter());
 
4785
}
 
4786
 
 
4787
AccessResult
 
4788
NotationsNamedNodeList::namedNodeU(const StringC &str, NodePtr &ptr) const
 
4789
{
 
4790
  const Notation *notation
 
4791
   = dtd_->lookupNotationTemp(str);
 
4792
  if (!notation)
 
4793
    return accessNull;
 
4794
  ptr.assign(new NotationNode(grove(), notation));
 
4795
  return accessOK;
 
4796
}
 
4797
 
 
4798
 
 
4799
// iter.next() gives first member of list that this represents
 
4800
 
 
4801
NotationsNodeList::NotationsNodeList(const GroveImpl *grove,
 
4802
                                     const Dtd::ConstNotationIter &iter)
 
4803
: grove_(grove), iter_(iter)
 
4804
{
 
4805
}
 
4806
 
 
4807
AccessResult NotationsNodeList::first(NodePtr &ptr) const
 
4808
{
 
4809
  Dtd::ConstNotationIter tem(iter_);
 
4810
  const Notation *notation = tem.nextTemp();
 
4811
  if (!notation)
 
4812
    return accessNull;
 
4813
  ptr.assign(new NotationNode(grove_, notation));
 
4814
  return accessOK;
 
4815
}
 
4816
 
 
4817
AccessResult NotationsNodeList::chunkRest(NodeListPtr &ptr) const
 
4818
{
 
4819
  if (canReuse(ptr)) {
 
4820
    NotationsNodeList *list = (NotationsNodeList *)this;
 
4821
    if (list->iter_.next().isNull())
 
4822
      return accessNull;
 
4823
    return accessOK;
 
4824
  }
 
4825
  Dtd::ConstNotationIter tem(iter_);
 
4826
  if (tem.nextTemp() == 0)
 
4827
    return accessNull;
 
4828
  ptr.assign(new NotationsNodeList(grove_, tem));
 
4829
  return accessOK;
 
4830
}
 
4831
 
 
4832
NotationNode::NotationNode(const GroveImpl *grove,
 
4833
                           const Notation *notation)
 
4834
: BaseNode(grove), notation_(notation)
 
4835
{
 
4836
}
 
4837
 
 
4838
AccessResult NotationNode::getOrigin(NodePtr &ptr) const
 
4839
{
 
4840
  ptr.assign(new DocumentTypeNode(grove(), grove()->governingDtd()));
 
4841
  return accessOK;
 
4842
}
 
4843
 
 
4844
AccessResult NotationNode::getName(GroveString &str) const
 
4845
{
 
4846
  setString(str, notation_->name());
 
4847
  return accessOK;
 
4848
}
 
4849
 
 
4850
AccessResult NotationNode::getExternalId(NodePtr &ptr) const
 
4851
{
 
4852
  ptr.assign(new NotationExternalIdNode(grove(), notation_));
 
4853
  return accessOK;
 
4854
}
 
4855
 
 
4856
AccessResult NotationNode::getAttributeDefs(NamedNodeListPtr &ptr) const
 
4857
{
 
4858
  ptr.assign(new NotationAttributeDefsNamedNodeList(grove(), *notation_));
 
4859
  return accessOK;
 
4860
}
 
4861
 
 
4862
AccessResult NotationNode::getLocation(Location &loc) const
 
4863
{
 
4864
  return grove()->proxifyLocation(notation_->defLocation(), loc);
 
4865
}
 
4866
 
 
4867
bool NotationNode::same(const BaseNode &node) const
 
4868
{
 
4869
  return node.same2(this);
 
4870
}
 
4871
 
 
4872
bool NotationNode::same2(const NotationNode *node) const
 
4873
{
 
4874
  return notation_ == node->notation_;
 
4875
}
 
4876
 
 
4877
void NotationNode::accept(NodeVisitor &visitor)
 
4878
{
 
4879
  visitor.notation(*this);
 
4880
}
 
4881
 
 
4882
unsigned long NotationNode::hash() const
 
4883
{
 
4884
  return (unsigned long)notation_;
 
4885
}
 
4886
 
 
4887
ExternalIdNode::ExternalIdNode(const GroveImpl *grove)
 
4888
: BaseNode(grove)
 
4889
{
 
4890
}
 
4891
 
 
4892
AccessResult ExternalIdNode::getPublicId(GroveString &str) const
 
4893
{
 
4894
  const StringC *s = externalId().publicIdString();
 
4895
  if (!s)
 
4896
    return accessNull;
 
4897
  setString(str, *s);
 
4898
  return accessOK;
 
4899
}
 
4900
 
 
4901
AccessResult ExternalIdNode::getSystemId(GroveString &str) const
 
4902
{
 
4903
  const StringC *s = externalId().systemIdString();
 
4904
  if (!s)
 
4905
    return accessNull;
 
4906
  setString(str, *s);
 
4907
  return accessOK;
 
4908
}
 
4909
 
 
4910
AccessResult ExternalIdNode::getGeneratedSystemId(GroveString &str) const
 
4911
{
 
4912
  const StringC &s = externalId().effectiveSystemId();
 
4913
  if (!s.size())
 
4914
    return accessNull;
 
4915
  setString(str, s);
 
4916
  return accessOK;
 
4917
}
 
4918
 
 
4919
void ExternalIdNode::accept(NodeVisitor &visitor)
 
4920
{
 
4921
  visitor.externalId(*this);
 
4922
}
 
4923
 
 
4924
bool ExternalIdNode::same(const BaseNode &node) const
 
4925
{
 
4926
  return node.same2(this);
 
4927
}
 
4928
 
 
4929
bool ExternalIdNode::same2(const ExternalIdNode *node) const
 
4930
{
 
4931
  return &externalId() == &node->externalId();
 
4932
}
 
4933
 
 
4934
EntityExternalIdNode::EntityExternalIdNode(const GroveImpl *grove,
 
4935
                                           const ExternalEntity *entity)
 
4936
: ExternalIdNode(grove), entity_(entity)
 
4937
{
 
4938
}
 
4939
 
 
4940
const ExternalId &EntityExternalIdNode::externalId() const
 
4941
{
 
4942
  return entity_->externalId();
 
4943
}
 
4944
 
 
4945
AccessResult EntityExternalIdNode::getOrigin(NodePtr &ptr) const
 
4946
{
 
4947
  ptr.assign(new EntityNode(grove(), entity_));
 
4948
  return accessOK;
 
4949
}
 
4950
 
 
4951
unsigned long EntityExternalIdNode::hash() const
 
4952
{
 
4953
  return secondHash((unsigned long)entity_);
 
4954
}
 
4955
 
 
4956
NotationExternalIdNode::NotationExternalIdNode(const GroveImpl *grove,
 
4957
                                               const Notation *notation)
 
4958
: ExternalIdNode(grove), notation_(notation)
 
4959
{
 
4960
}
 
4961
 
 
4962
const ExternalId &NotationExternalIdNode::externalId() const
 
4963
{
 
4964
  return notation_->externalId();
 
4965
}
 
4966
 
 
4967
AccessResult NotationExternalIdNode::getOrigin(NodePtr &ptr) const
 
4968
{
 
4969
  ptr.assign(new NotationNode(grove(), notation_));
 
4970
  return accessOK;
 
4971
}
 
4972
 
 
4973
unsigned long NotationExternalIdNode::hash() const
 
4974
{
 
4975
  return secondHash((unsigned long)notation_);
 
4976
}
 
4977
 
 
4978
AccessResult ChunkNode::getParent(NodePtr &ptr) const
 
4979
{
 
4980
  if (!chunk_->origin)
 
4981
    return accessNull;
 
4982
  // This is needed because PiNodes in the prolog and
 
4983
  // epilog don't have a parent but do have an origin.
 
4984
  // Also for the document element.
 
4985
  if ((const Chunk *)chunk()->origin == grove()->root())
 
4986
    return accessNull;
 
4987
  chunk_->origin->setNodePtrFirst(ptr, this);
 
4988
  return accessOK;
 
4989
}
 
4990
 
 
4991
AccessResult ChunkNode::getTreeRoot(NodePtr &ptr) const
 
4992
{
 
4993
  if (chunk()->origin
 
4994
      && (const Chunk *)chunk()->origin != grove()->root()
 
4995
      // With invalid documents we might have elements in the epilog
 
4996
      && !grove()->root()->epilog
 
4997
      && grove()->root()->documentElement)
 
4998
    return grove()->root()->documentElement->setNodePtrFirst(ptr, this);
 
4999
  return Node::getTreeRoot(ptr);
 
5000
}
 
5001
 
 
5002
AccessResult ChunkNode::getOrigin(NodePtr &ptr) const
 
5003
{
 
5004
  if (!chunk_->origin)
 
5005
    return accessNull;
 
5006
  chunk_->origin->setNodePtrFirst(ptr, this);
 
5007
  return accessOK;
 
5008
}
 
5009
 
 
5010
AccessResult ChunkNode::getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const
 
5011
{
 
5012
  if ((const Chunk *)chunk()->origin != grove()->root())
 
5013
    name = ComponentName::idContent;
 
5014
  else if ((const Chunk *)chunk() == grove()->root()->documentElement)
 
5015
    name = ComponentName::idDocumentElement;
 
5016
  else {
 
5017
    const Chunk *tem;
 
5018
    if (chunk()->getFirstSibling(grove(), tem) == accessOK && tem == grove()->root()->prolog)
 
5019
      name = ComponentName::idProlog;
 
5020
    else
 
5021
      name = ComponentName::idEpilog;
 
5022
  }
 
5023
  return accessOK;
 
5024
}
 
5025
 
 
5026
unsigned long ChunkNode::hash() const
 
5027
{
 
5028
  return (unsigned long)chunk_;
 
5029
}
 
5030
 
 
5031
bool ChunkNode::same(const BaseNode &node) const
 
5032
{
 
5033
  return node.same2(this);
 
5034
}
 
5035
 
 
5036
bool ChunkNode::same2(const ChunkNode *node) const
 
5037
{
 
5038
  return chunk_ == node->chunk_;
 
5039
}
 
5040
 
 
5041
BaseNode::~BaseNode()
 
5042
{
 
5043
}
 
5044
 
 
5045
void BaseNode::addRef()
 
5046
{
 
5047
  ++refCount_;
 
5048
}
 
5049
 
 
5050
void BaseNode::release()
 
5051
{
 
5052
  ASSERT(refCount_ != 0);
 
5053
  if (--refCount_ == 0)
 
5054
    delete this;
 
5055
}
 
5056
 
 
5057
unsigned BaseNode::groveIndex() const
 
5058
{
 
5059
  return grove_->groveIndex();
 
5060
}
 
5061
 
 
5062
bool BaseNode::operator==(const Node &node) const
 
5063
{
 
5064
  if (!sameGrove(node))
 
5065
    return 0;
 
5066
  return same((const BaseNode &)node);
 
5067
}
 
5068
 
 
5069
bool BaseNode::chunkContains(const Node &node) const
 
5070
{
 
5071
  if (!sameGrove(node))
 
5072
    return 0;
 
5073
  return same((const BaseNode &)node);
 
5074
}
 
5075
 
 
5076
bool BaseNode::inChunk(const DataNode *) const
 
5077
{
 
5078
  return 0;
 
5079
}
 
5080
 
 
5081
bool BaseNode::inChunk(const CdataAttributeValueNode *) const
 
5082
{
 
5083
  return 0;
 
5084
}
 
5085
 
 
5086
bool BaseNode::same2(const ChunkNode *) const
 
5087
{
 
5088
  return 0;
 
5089
}
 
5090
 
 
5091
bool BaseNode::same2(const DataNode *) const
 
5092
{
 
5093
  return 0;
 
5094
}
 
5095
 
 
5096
bool BaseNode::same2(const AttributeAsgnNode *) const
 
5097
{
 
5098
  return 0;
 
5099
}
 
5100
 
 
5101
bool BaseNode::same2(const AttributeValueTokenNode *) const
 
5102
{
 
5103
  return 0;
 
5104
}
 
5105
 
 
5106
bool BaseNode::same2(const CdataAttributeValueNode *) const
 
5107
{
 
5108
  return 0;
 
5109
}
 
5110
 
 
5111
bool BaseNode::same2(const EntityNode *) const
 
5112
{
 
5113
  return 0;
 
5114
}
 
5115
 
 
5116
bool BaseNode::same2(const NotationNode *) const
 
5117
{
 
5118
  return 0;
 
5119
}
 
5120
 
 
5121
bool BaseNode::same2(const ExternalIdNode *) const
 
5122
{
 
5123
  return 0;
 
5124
}
 
5125
 
 
5126
bool BaseNode::same2(const DocumentTypeNode *) const
 
5127
{
 
5128
  return 0;
 
5129
}
 
5130
 
 
5131
bool BaseNode::same2(const SgmlConstantsNode *) const
 
5132
{
 
5133
  return 0;
 
5134
}
 
5135
 
 
5136
bool BaseNode::same2(const MessageNode *) const
 
5137
{
 
5138
  return 0;
 
5139
}
 
5140
 
 
5141
bool BaseNode::same2(const ElementTypeNode *) const
 
5142
{
 
5143
  return 0;
 
5144
}
 
5145
 
 
5146
bool BaseNode::same2(const ModelGroupNode *) const
 
5147
{
 
5148
  return 0;
 
5149
}
 
5150
 
 
5151
bool BaseNode::same2(const ElementTokenNode *) const
 
5152
{
 
5153
  return 0;
 
5154
}
 
5155
 
 
5156
bool BaseNode::same2(const PcdataTokenNode *) const
 
5157
{
 
5158
  return 0;
 
5159
}
 
5160
 
 
5161
bool BaseNode::same2(const AttributeDefNode *) const
 
5162
{
 
5163
  return 0;
 
5164
}
 
5165
 
 
5166
bool BaseNode::same2(const DefaultEntityNode *) const
 
5167
{
 
5168
  return 0;
 
5169
}
 
5170
 
 
5171
AccessResult BaseNode::nextSibling(NodePtr &ptr) const
 
5172
{
 
5173
  return nextChunkSibling(ptr);
 
5174
}
 
5175
 
 
5176
AccessResult BaseNode::follow(NodeListPtr &ptr) const
 
5177
{
 
5178
  NodePtr nd;
 
5179
  AccessResult ret = nextSibling(nd);
 
5180
  switch (ret) {
 
5181
  case accessOK:
 
5182
    ptr.assign(new SiblingNodeList(nd));
 
5183
    break;
 
5184
  case accessNull:
 
5185
    ptr.assign(new BaseNodeList);
 
5186
    ret = accessOK;
 
5187
    break;
 
5188
  default:
 
5189
    break;
 
5190
  }
 
5191
  return ret;
 
5192
}
 
5193
 
 
5194
AccessResult BaseNode::children(NodeListPtr &ptr) const
 
5195
{
 
5196
  NodePtr head;
 
5197
  AccessResult ret = firstChild(head);
 
5198
  switch (ret) {
 
5199
  case accessOK:
 
5200
    ptr.assign(new SiblingNodeList(head));
 
5201
    break;
 
5202
  case accessNull:
 
5203
    ptr.assign(new BaseNodeList);
 
5204
    ret = accessOK;
 
5205
    break;
 
5206
  default:
 
5207
    break;
 
5208
  }
 
5209
  return ret;
 
5210
}
 
5211
 
 
5212
AccessResult BaseNode::getOrigin(NodePtr &ptr) const
 
5213
{
 
5214
  return getParent(ptr);
 
5215
}
 
5216
 
 
5217
AccessResult BaseNode::getGroveRoot(NodePtr &ptr) const
 
5218
{
 
5219
  ptr.assign(new SgmlDocumentNode(grove(), grove()->root()));
 
5220
  return accessOK;
 
5221
}
 
5222
 
 
5223
AccessResult BaseNode::getLocation(Location &) const
 
5224
{
 
5225
  return accessNull;
 
5226
}
 
5227
 
 
5228
bool BaseNode::queryInterface(IID iid, const void *&p) const
 
5229
{
 
5230
  if (iid == LocNode::iid) {
 
5231
    const LocNode *ip = this;
 
5232
    p = ip;
 
5233
    return 1;
 
5234
  }
 
5235
  return 0;
 
5236
}
 
5237
 
 
5238
AccessResult
 
5239
ForwardingChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const
 
5240
{
 
5241
  if (forwardTo == 0)
 
5242
    return accessNull;
 
5243
  ASSERT(origin == forwardTo->origin);
 
5244
  return forwardTo->setNodePtrFirst(ptr, node);
 
5245
}
 
5246
 
 
5247
AccessResult
 
5248
ForwardingChunk::getFollowing(const GroveImpl *grove,
 
5249
                              const Chunk *&p, unsigned long &nNodes)
 
5250
    const
 
5251
{
 
5252
  AccessResult ret = Chunk::getFollowing(grove, p, nNodes);
 
5253
  if (ret == accessOK)
 
5254
    nNodes = 0;
 
5255
  return ret;
 
5256
}
 
5257
 
 
5258
AccessResult
 
5259
LocOriginChunk::getFollowing(const GroveImpl *grove,
 
5260
                             const Chunk *&p, unsigned long &nNodes)
 
5261
    const
 
5262
{
 
5263
  AccessResult ret = Chunk::getFollowing(grove, p, nNodes);
 
5264
  if (ret == accessOK)
 
5265
    nNodes = 0;
 
5266
  return ret;
 
5267
}
 
5268
 
 
5269
AccessResult LocOriginChunk::setNodePtrFirst(NodePtr &ptr, const BaseNode *node) const
 
5270
{
 
5271
  return ((const Chunk *)(this + 1))->setNodePtrFirst(ptr, node);
 
5272
}
 
5273
 
 
5274
AccessResult LocOriginChunk::setNodePtrFirst(NodePtr &ptr, const ElementNode *node) const
 
5275
{
 
5276
  return ((const Chunk *)(this + 1))->setNodePtrFirst(ptr, node);
 
5277
}
 
5278
 
 
5279
AccessResult LocOriginChunk::setNodePtrFirst(NodePtr &ptr, const DataNode *node) const
 
5280
{
 
5281
  return ((const Chunk *)(this + 1))->setNodePtrFirst(ptr, node);
 
5282
}
 
5283
 
 
5284
const Chunk *LocOriginChunk::after() const
 
5285
{
 
5286
  return this + 1;
 
5287
}
 
5288
 
 
5289
Boolean LocOriginChunk::getLocOrigin(const Origin *&ret) const
 
5290
{
 
5291
  ret = locOrigin;
 
5292
  return 1;
 
5293
}
 
5294
 
 
5295
AccessResult
 
5296
Chunk::setNodePtrFirst(NodePtr &ptr, const ElementNode *node) const
 
5297
{
 
5298
  return setNodePtrFirst(ptr, (const BaseNode *)node);
 
5299
}
 
5300
 
 
5301
AccessResult
 
5302
Chunk::setNodePtrFirst(NodePtr &ptr, const DataNode *node) const
 
5303
{
 
5304
  return setNodePtrFirst(ptr, (const BaseNode *)node);
 
5305
}
 
5306
 
 
5307
const StringC *Chunk::id() const
 
5308
{
 
5309
  return 0;
 
5310
}
 
5311
 
 
5312
AccessResult Chunk::getFollowing(const GroveImpl *grove,
 
5313
                                 const Chunk *&f, unsigned long &n) const
 
5314
{
 
5315
  const Chunk *p = after();
 
5316
  while (p == grove->completeLimit())
 
5317
    if (!grove->waitForMoreNodes())
 
5318
      return accessTimeout;
 
5319
  if (p->origin != origin)
 
5320
    return accessNull;
 
5321
  n = 1;
 
5322
  f = p;
 
5323
  return accessOK;
 
5324
}
 
5325
 
 
5326
AccessResult Chunk::getFirstSibling(const GroveImpl *grove,
 
5327
                                    const Chunk *&p) const
 
5328
{
 
5329
  if ((const Chunk *)origin == grove->root())
 
5330
    return accessNotInClass;
 
5331
  p = origin->after();
 
5332
  return accessOK;
 
5333
}
 
5334
 
 
5335
Boolean Chunk::getLocOrigin(const Origin *&) const
 
5336
{
 
5337
  return 0;
 
5338
}
 
5339
 
 
5340
// ------------------------------ dev --------------------------------
 
5341
 
 
5342
// -- CLASS IMP: ElementTypeNode
 
5343
 
 
5344
AccessResult ElementTypeNode::getOrigin(NodePtr &ptr) const
 
5345
{
 
5346
  ptr.assign(new DocumentTypeNode(grove(), grove()->governingDtd()));
 
5347
  return accessOK;
 
5348
}
 
5349
 
 
5350
AccessResult ElementTypeNode::getLocation(Location &loc) const
 
5351
{
 
5352
  const ElementDefinition *def = elementType_.definition();
 
5353
  if (def == 0)
 
5354
    return accessNull;
 
5355
  return grove()->proxifyLocation(def->location(), loc);
 
5356
}
 
5357
 
 
5358
AccessResult ElementTypeNode::getGi(GroveString &str) const
 
5359
{
 
5360
  setString(str, elementType_.name());
 
5361
  return accessOK;
 
5362
}
 
5363
 
 
5364
AccessResult ElementTypeNode::getModelGroup(NodePtr &ptr) const
 
5365
{
 
5366
  const ElementDefinition *def = elementType_.definition();
 
5367
  if (def == 0 || def->declaredContent() != ElementDefinition::modelGroup)
 
5368
    return accessNull;
 
5369
  ptr.assign(new ModelGroupNode(grove(),
 
5370
                                elementType_, 
 
5371
                                *(def->compiledModelGroup()->modelGroup())));  
 
5372
  return accessOK;
 
5373
}
 
5374
 
 
5375
AccessResult ElementTypeNode::getContentType(Node::ContentType::Enum &enumId) const
 
5376
{
 
5377
  const ElementDefinition *def = elementType_.definition();
 
5378
  if (def == 0)
 
5379
    return accessNull;
 
5380
  switch (def->declaredContent() ) {
 
5381
    case ElementDefinition::modelGroup:
 
5382
      enumId = ContentType::modelgrp;
 
5383
      break;
 
5384
    case ElementDefinition::any:
 
5385
      enumId = ContentType::any;
 
5386
      break;
 
5387
    case ElementDefinition::cdata:
 
5388
      enumId = ContentType::cdata;
 
5389
      break;
 
5390
    case ElementDefinition::rcdata:
 
5391
      enumId = ContentType::rcdata;
 
5392
      break;
 
5393
    case ElementDefinition::empty:
 
5394
      enumId = ContentType::empty;
 
5395
      break;
 
5396
    default:
 
5397
      CANNOT_HAPPEN();
 
5398
  }
 
5399
  return accessOK;
 
5400
}
 
5401
 
 
5402
AccessResult ElementTypeNode::getExclusions(GroveStringListPtr &sl) const
 
5403
{
 
5404
  const ElementDefinition *def = elementType_.definition();
 
5405
  if (def == 0
 
5406
      || (def->declaredContent() != ElementDefinition::modelGroup
 
5407
          && def->declaredContent() != ElementDefinition::any))
 
5408
    return accessNull;
 
5409
  sl.assign(new GroveStringList);
 
5410
  GroveString str;
 
5411
  for (size_t i = 0; i < def->nExclusions(); i++ ) {
 
5412
    setString(str, def->exclusion(i)->name());
 
5413
    sl->append(str);
 
5414
  }
 
5415
  return accessOK;
 
5416
}
 
5417
 
 
5418
AccessResult ElementTypeNode::getInclusions(GroveStringListPtr &sl) const
 
5419
{
 
5420
  const ElementDefinition *def = elementType_.definition();
 
5421
  if (def == 0
 
5422
      || (def->declaredContent() != ElementDefinition::modelGroup
 
5423
          && def->declaredContent() != ElementDefinition::any))
 
5424
    return accessNull;
 
5425
  sl.assign(new GroveStringList);
 
5426
  GroveString str;
 
5427
  for (size_t i = 0; i < def->nInclusions(); i++ ) {
 
5428
    setString(str, def->inclusion(i)->name());
 
5429
    sl->append(str);
 
5430
  }
 
5431
  return accessOK;
 
5432
}
 
5433
 
 
5434
AccessResult ElementTypeNode::getOmitEndTag(bool &f) const
 
5435
{
 
5436
  const ElementDefinition *def = elementType_.definition();
 
5437
  if (def == 0 || !def->omittedTagSpec())
 
5438
    return accessNull;
 
5439
  f = def->canOmitEndTag();
 
5440
  return accessOK;
 
5441
}
 
5442
 
 
5443
AccessResult ElementTypeNode::getOmitStartTag(bool &f) const
 
5444
{
 
5445
  const ElementDefinition *def = elementType_.definition();
 
5446
  if (def == 0  || !def->omittedTagSpec())
 
5447
    return accessNull;
 
5448
  f = def->canOmitStartTag();
 
5449
  return accessOK;
 
5450
}
 
5451
 
 
5452
AccessResult ElementTypeNode::getAttributeDefs(NamedNodeListPtr &ptr) const
 
5453
{
 
5454
  ptr.assign(new ElementTypeAttributeDefsNamedNodeList(grove(), elementType_));
 
5455
  return accessOK;
 
5456
}
 
5457
 
 
5458
bool ElementTypeNode::same(const BaseNode &node) const
 
5459
{
 
5460
  return node.same2(this);
 
5461
}
 
5462
 
 
5463
bool ElementTypeNode::same2(const ElementTypeNode *node) const
 
5464
{
 
5465
  return &elementType_ == &(node->elementType());
 
5466
}
 
5467
 
 
5468
void ElementTypeNode::accept(NodeVisitor &visitor)
 
5469
{
 
5470
  visitor.elementType(*this);
 
5471
}
 
5472
 
 
5473
unsigned long ElementTypeNode::hash() const
 
5474
{
 
5475
  return (unsigned long)&elementType_;
 
5476
}
 
5477
 
 
5478
// -- CLASS IMP: ElementTypesNodeList
 
5479
 
 
5480
ElementTypesNodeList::ElementTypesNodeList( const GroveImpl *grove,
 
5481
                                            const Dtd::ConstElementTypeIter &iter )
 
5482
 : grove_(grove), iter_(iter)
 
5483
{
 
5484
}
 
5485
 
 
5486
AccessResult ElementTypesNodeList::first(NodePtr &ptr) const
 
5487
{
 
5488
  Dtd::ConstElementTypeIter tem(iter_);
 
5489
  const ElementType *elementType = tem.next();
 
5490
  if (!elementType)
 
5491
    return accessNull;
 
5492
  ptr.assign(new ElementTypeNode(grove_, *elementType));
 
5493
  return accessOK;
 
5494
}
 
5495
 
 
5496
AccessResult ElementTypesNodeList::chunkRest(NodeListPtr &ptr) const
 
5497
{
 
5498
  if (canReuse(ptr)) {
 
5499
    ElementTypesNodeList *list = (ElementTypesNodeList *)this;
 
5500
    if (list->iter_.next() == 0)
 
5501
      return accessNull;
 
5502
    return accessOK;
 
5503
  }
 
5504
  Dtd::ConstElementTypeIter tem(iter_);
 
5505
  if (tem.next() == 0)
 
5506
    return accessNull;
 
5507
  ptr.assign(new ElementTypesNodeList(grove_, tem));
 
5508
  return accessOK;
 
5509
}
 
5510
 
 
5511
// -- CLASS IMP: ElementTypesNamedNodeList
 
5512
 
 
5513
ElementTypesNamedNodeList::ElementTypesNamedNodeList(const GroveImpl *grove, const Dtd *dtd)
 
5514
 : BaseNamedNodeList( grove, grove->generalSubstTable() ), dtd_(dtd)
 
5515
{
 
5516
}
 
5517
 
 
5518
NodeListPtr ElementTypesNamedNodeList::nodeList() const
 
5519
{
 
5520
  return new ElementTypesNodeList(grove(), dtd_->elementTypeIter());
 
5521
}
 
5522
 
 
5523
AccessResult ElementTypesNamedNodeList::namedNodeU(const StringC &str, NodePtr &ptr) const
 
5524
{
 
5525
  const ElementType *elementType = dtd_->lookupElementType(str); // ? Temp
 
5526
  if (!elementType)
 
5527
    return accessNull;
 
5528
  ptr.assign(new ElementTypeNode(grove(), *elementType));
 
5529
  return accessOK;
 
5530
}
 
5531
 
 
5532
// -- CLASS IMP: ContentTokenNodeBase
 
5533
 
 
5534
ContentTokenNodeBase::ContentTokenNodeBase(const GroveImpl *grove,
 
5535
                                           const ElementType &elementType,
 
5536
                                           ModelGroupNode *parentModelGroupNode)
 
5537
 : BaseNode(grove), elementType_(elementType), parentModelGroupNode_(parentModelGroupNode)
 
5538
{
 
5539
  if (parentModelGroupNode_ != 0)
 
5540
    parentModelGroupNode_->addRef();
 
5541
}
 
5542
 
 
5543
ContentTokenNodeBase::~ContentTokenNodeBase()
 
5544
{
 
5545
  if (parentModelGroupNode_ != 0)
 
5546
    parentModelGroupNode_->release();
 
5547
}
 
5548
 
 
5549
AccessResult ContentTokenNodeBase::getOrigin(NodePtr &ptr) const
 
5550
{
 
5551
  if (parentModelGroupNode_ != 0)
 
5552
    ptr.assign(parentModelGroupNode_);
 
5553
  else
 
5554
    ptr.assign(new ElementTypeNode(grove(), elementType_));
 
5555
  return accessOK;
 
5556
}
 
5557
 
 
5558
AccessResult ContentTokenNodeBase::getLocation(Location &loc) const
 
5559
{
 
5560
  const ElementDefinition *def = elementType_.definition();
 
5561
  if (def == 0)
 
5562
    return accessNull;
 
5563
  return grove()->proxifyLocation(def->location(), loc);
 
5564
}
 
5565
 
 
5566
// -- CLASS IMP: ElementTokenNode
 
5567
 
 
5568
AccessResult ElementTokenNode::getGi(GroveString &str) const
 
5569
{
 
5570
  assert(elementToken_.elementType() != 0);
 
5571
  setString(str, elementToken_.elementType()->name());
 
5572
  return accessOK;
 
5573
}
 
5574
 
 
5575
AccessResult ElementTokenNode::getOccurIndicator(Node::OccurIndicator::Enum &occur) const
 
5576
{
 
5577
  switch (elementToken_.occurrenceIndicator())
 
5578
  {
 
5579
    case ContentToken::opt:
 
5580
      occur = OccurIndicator::opt;
 
5581
      break;      
 
5582
    case ContentToken::plus:
 
5583
      occur = OccurIndicator::plus;
 
5584
      break;
 
5585
    case ContentToken::rep:
 
5586
      occur = OccurIndicator::rep;
 
5587
      break;
 
5588
    case ContentToken::none:
 
5589
      return accessNull;
 
5590
    default:
 
5591
      CANNOT_HAPPEN();
 
5592
  }
 
5593
  return accessOK;
 
5594
}
 
5595
 
 
5596
bool ElementTokenNode::same(const BaseNode &node) const
 
5597
{
 
5598
  return node.same2(this);
 
5599
}
 
5600
 
 
5601
bool ElementTokenNode::same2(const ElementTokenNode *node) const
 
5602
{
 
5603
  return &elementToken_ == &(node->elementToken());
 
5604
}
 
5605
 
 
5606
void ElementTokenNode::accept(NodeVisitor &visitor)
 
5607
{
 
5608
  visitor.elementToken(*this);
 
5609
}
 
5610
 
 
5611
unsigned long ElementTokenNode::hash() const
 
5612
{
 
5613
  return (unsigned long)&elementToken_;
 
5614
}
 
5615
 
 
5616
// -- CLASS IMP: PcdataTokenNode
 
5617
 
 
5618
bool PcdataTokenNode::same(const BaseNode &node) const
 
5619
{
 
5620
  return node.same2(this);
 
5621
}
 
5622
 
 
5623
bool PcdataTokenNode::same2(const PcdataTokenNode *node) const
 
5624
{
 
5625
  return &pcdataToken_ == &(node->pcdataToken());
 
5626
}
 
5627
 
 
5628
void PcdataTokenNode::accept(NodeVisitor &visitor)
 
5629
{
 
5630
  visitor.pcdataToken(*this);
 
5631
}
 
5632
 
 
5633
unsigned long PcdataTokenNode::hash() const
 
5634
{
 
5635
  return (unsigned long)&pcdataToken_;
 
5636
}
 
5637
 
 
5638
// -- CLASS IMP: ModelGroupNode
 
5639
 
 
5640
AccessResult ModelGroupNode::getOriginToSubnodeRelPropertyName(ComponentName::Id &name) const
 
5641
{
 
5642
  name = parentModelGroupNode_ == 0
 
5643
          ? ComponentName::idModelGroup
 
5644
          : ComponentName::idContentTokens;
 
5645
  return accessOK;
 
5646
}
 
5647
 
 
5648
AccessResult ModelGroupNode::getConnector(Node::Connector::Enum &conn) const
 
5649
{
 
5650
  switch (modelGroup_.connector())
 
5651
  {
 
5652
    case ModelGroup::andConnector:
 
5653
      conn = Connector::and_;
 
5654
      break;      
 
5655
    case ModelGroup::orConnector:
 
5656
      conn = Connector::or_;
 
5657
      break;
 
5658
    case ModelGroup::seqConnector:
 
5659
      conn = Connector::seq;
 
5660
      break;
 
5661
    default:
 
5662
      CANNOT_HAPPEN();
 
5663
  }
 
5664
  return accessOK;
 
5665
}
 
5666
 
 
5667
AccessResult ModelGroupNode::getOccurIndicator(Node::OccurIndicator::Enum &occur) const
 
5668
{
 
5669
  switch (modelGroup_.occurrenceIndicator()) {
 
5670
    case ContentToken::opt:
 
5671
      occur = OccurIndicator::opt;
 
5672
      break;      
 
5673
    case ContentToken::plus:
 
5674
      occur = OccurIndicator::plus;
 
5675
      break;
 
5676
    case ContentToken::rep:
 
5677
      occur = OccurIndicator::rep;
 
5678
      break;
 
5679
    case ContentToken::none:
 
5680
      return accessNull;
 
5681
    default:
 
5682
      CANNOT_HAPPEN();
 
5683
  }
 
5684
  return accessOK;
 
5685
}
 
5686
 
 
5687
AccessResult ModelGroupNode::getContentTokens(NodeListPtr &ptr) const
 
5688
{
 
5689
  ptr.assign(new ContentTokenNodeList(grove(), *(ModelGroupNode *)this));
 
5690
  return accessOK;
 
5691
}
 
5692
 
 
5693
void ModelGroupNode::makeNode(NodePtr &ptr, unsigned contentTokenIdx)
 
5694
{
 
5695
  assert( contentTokenIdx < modelGroup_.nMembers());
 
5696
  const ContentToken &contentToken = modelGroup_.member(contentTokenIdx);
 
5697
  const ModelGroup *asModelGroup = contentToken.asModelGroup();
 
5698
  if (asModelGroup != 0)
 
5699
    ptr.assign(new ModelGroupNode(grove(),
 
5700
                                  elementType_,
 
5701
                                  *asModelGroup,
 
5702
                                  this));
 
5703
  else
 
5704
  {
 
5705
    const LeafContentToken *asLeafContentToken = contentToken.asLeafContentToken();
 
5706
    if (asLeafContentToken != 0)
 
5707
      if (asLeafContentToken->elementType() != 0)
 
5708
        ptr.assign(new ElementTokenNode(grove(),
 
5709
                                        elementType_,
 
5710
                                        *(const ElementToken*)asLeafContentToken,
 
5711
                                        this));
 
5712
      else if (asLeafContentToken->occurrenceIndicator() == ContentToken::rep)
 
5713
        ptr.assign(new PcdataTokenNode(grove(),
 
5714
                                       elementType_,
 
5715
                                       *(const PcdataToken*)asLeafContentToken,
 
5716
                                       this));
 
5717
      else
 
5718
        CANNOT_HAPPEN();
 
5719
  }
 
5720
}
 
5721
 
 
5722
bool ModelGroupNode::same(const BaseNode &node) const
 
5723
{
 
5724
  return node.same2(this);
 
5725
}
 
5726
 
 
5727
bool ModelGroupNode::same2(const ModelGroupNode *node) const
 
5728
{
 
5729
  return &modelGroup_ == &(node->modelGroup());
 
5730
}
 
5731
 
 
5732
void ModelGroupNode::accept(NodeVisitor &visitor)
 
5733
{
 
5734
  visitor.modelGroup(*this);
 
5735
}
 
5736
 
 
5737
unsigned long ModelGroupNode::hash() const
 
5738
{
 
5739
  return (unsigned long)&modelGroup_;
 
5740
}
 
5741
 
 
5742
// -- CLASS IMP: ContentTokenNodeList
 
5743
 
 
5744
ContentTokenNodeList::ContentTokenNodeList(const GroveImpl *grove,
 
5745
                                           ModelGroupNode &modelGroupNode,
 
5746
                                           unsigned firstTokenIdx)
 
5747
 : grove_(grove), modelGroupNode_(modelGroupNode), firstTokenIdx_(firstTokenIdx)
 
5748
{
 
5749
}
 
5750
 
 
5751
AccessResult ContentTokenNodeList::next()
 
5752
{
 
5753
  if (++firstTokenIdx_ >= modelGroupNode_.modelGroup().nMembers())
 
5754
    return accessNull;
 
5755
  return accessOK;
 
5756
}
 
5757
 
 
5758
AccessResult ContentTokenNodeList::first(NodePtr &ptr) const
 
5759
{
 
5760
  if (firstTokenIdx_ < modelGroupNode_.modelGroup().nMembers()) 
 
5761
    modelGroupNode_.makeNode(ptr, firstTokenIdx_);
 
5762
  else
 
5763
    return accessNull;
 
5764
  return accessOK;
 
5765
}
 
5766
 
 
5767
AccessResult ContentTokenNodeList::chunkRest(NodeListPtr &ptr) const
 
5768
{
 
5769
  if (canReuse(ptr)) {
 
5770
    ContentTokenNodeList *list = (ContentTokenNodeList *)this;
 
5771
    return list->next();
 
5772
  }
 
5773
  unsigned firstTokenIdx = firstTokenIdx_;
 
5774
  if (++firstTokenIdx >= modelGroupNode_.modelGroup().nMembers())
 
5775
    return accessNull;
 
5776
  ptr.assign(new ContentTokenNodeList(grove_, modelGroupNode_, firstTokenIdx));
 
5777
  return accessOK;
 
5778
}
 
5779
 
 
5780
// class IMP: AttributeDefOrigin
 
5781
 
 
5782
AccessResult
 
5783
AttributeDefOrigin::makeAttributeValueNode(const GroveImpl *grove,
 
5784
                                           NodePtr &ptr,
 
5785
                                           const AttributeValue *value) const
 
5786
{
 
5787
  if (value) {
 
5788
    const Text *text;
 
5789
    const StringC *str;
 
5790
    switch (value->info(text, str)) {
 
5791
    case AttributeValue::tokenized:
 
5792
        ptr.assign(makeAttributeValueTokenNode(grove,
 
5793
                                               (const TokenizedAttributeValue *)value,
 
5794
                                               attIndex_, 0));
 
5795
      return accessOK;
 
5796
    case AttributeValue::cdata:
 
5797
      {
 
5798
        TextIter iter(*text);
 
5799
        if (!CdataAttributeValueNode::skipBoring(iter)) {
 
5800
          ptr.assign(0);
 
5801
          return accessNull;
 
5802
        }
 
5803
        else {
 
5804
          ptr.assign(makeCdataAttributeValueNode(grove, value,
 
5805
                                                 attIndex_, iter));
 
5806
          return accessOK;
 
5807
        }
 
5808
      }
 
5809
    default:
 
5810
      break;
 
5811
    }
 
5812
  }
 
5813
  return accessNull;
 
5814
}
 
5815
 
 
5816
AccessResult
 
5817
AttributeDefOrigin::makeAttributeValueNodeList(const GroveImpl *grove,
 
5818
                                               NodeListPtr &ptr,
 
5819
                                               const AttributeValue *value = 0) const
 
5820
{
 
5821
  NodePtr nodePtr;
 
5822
  AccessResult result;
 
5823
  result = makeAttributeValueNode(grove, nodePtr, value);
 
5824
  if (result == accessOK)
 
5825
    ptr.assign(nodePtr.operator->() == 0 ? new BaseNodeList : new SiblingNodeList(nodePtr));
 
5826
  return result;
 
5827
}
 
5828
 
 
5829
AccessResult AttributeDefOrigin::makeAttributeDefNode(const GroveImpl *grove,
 
5830
                                                      NodePtr &ptr,
 
5831
                                                      const StringC &name) const
 
5832
{
 
5833
  if (attDefList() == 0)
 
5834
    return accessNull;
 
5835
  for (size_t i = 0; i < attDefList()->size(); i++)
 
5836
    if (attDefList()->def(i)->name() == name)
 
5837
    {
 
5838
      return makeAttributeDefNode(grove, ptr, i);
 
5839
      break;
 
5840
    }
 
5841
  return accessNull;
 
5842
}
 
5843
 
 
5844
// class IMP: ElementTypeAttributeDefOrigin
 
5845
 
 
5846
ElementTypeAttributeDefOrigin::ElementTypeAttributeDefOrigin(const ElementType *elementType)
 
5847
: elementType_(elementType)
 
5848
{
 
5849
}
 
5850
 
 
5851
const AttributeDefinitionList *ElementTypeAttributeDefOrigin::attDefList() const
 
5852
{
 
5853
  return elementType_->attributeDefTemp();
 
5854
}
 
5855
 
 
5856
AccessResult ElementTypeAttributeDefOrigin::makeAttributeDefNode(const GroveImpl *grove,
 
5857
                                                                 NodePtr &ptr,
 
5858
                                                                 size_t attributeDefIdx) const
 
5859
{
 
5860
  ptr.assign(new ElementTypeAttributeDefNode(grove, *elementType_, attributeDefIdx));
 
5861
  return accessOK;
 
5862
}
 
5863
 
 
5864
AccessResult ElementTypeAttributeDefOrigin::makeAttributeDefList(const GroveImpl *grove,
 
5865
                                                                 NodeListPtr &ptr,
 
5866
                                                                 size_t firstAttDefIdx) const
 
5867
{
 
5868
  ptr.assign(new ElementTypeAttributeDefsNodeList(grove,
 
5869
                                                  *elementType_,
 
5870
                                                  firstAttDefIdx));
 
5871
  return accessOK;
 
5872
}
 
5873
 
 
5874
Node *ElementTypeAttributeDefOrigin
 
5875
::makeCdataAttributeValueNode(const GroveImpl *grove,
 
5876
                              const AttributeValue *value,
 
5877
                              size_t attIndex,
 
5878
                              const TextIter &iter,
 
5879
                              size_t charIndex) const
 
5880
{
 
5881
  return new ElementTypeCdataAttributeValueNode(grove, value, attIndex, iter,
 
5882
                                                charIndex, elementType_);
 
5883
}
 
5884
 
 
5885
 
 
5886
Node *ElementTypeAttributeDefOrigin
 
5887
::makeAttributeValueTokenNode(const GroveImpl *grove,
 
5888
                              const TokenizedAttributeValue *value,
 
5889
                              size_t attIndex,
 
5890
                              size_t tokenIndex) const
 
5891
{
 
5892
  return new ElementTypeAttributeValueTokenNode(grove, value, attIndex,
 
5893
                                                tokenIndex, elementType_);
 
5894
}
 
5895
 
 
5896
Node *ElementTypeAttributeDefOrigin::makeOriginNode(const GroveImpl *grove, size_t) const 
 
5897
{
 
5898
  return new ElementTypeAttributeDefNode(grove, *elementType_, attIndex_);
 
5899
}
 
5900
 
 
5901
const void *ElementTypeAttributeDefOrigin::attributeOriginId() const
 
5902
{
 
5903
  return elementType_;
 
5904
}
 
5905
 
 
5906
// class IMP: NotationAttributeDefOrigin
 
5907
 
 
5908
NotationAttributeDefOrigin::NotationAttributeDefOrigin(const Notation *notation)
 
5909
: notation_(notation)
 
5910
{
 
5911
}
 
5912
 
 
5913
const AttributeDefinitionList *NotationAttributeDefOrigin::attDefList() const
 
5914
{
 
5915
  return notation_->attributeDefTemp();
 
5916
}
 
5917
 
 
5918
AccessResult NotationAttributeDefOrigin::makeAttributeDefNode(const GroveImpl *grove, 
 
5919
                                                              NodePtr &ptr,
 
5920
                                                              size_t attributeDefIdx) const
 
5921
{
 
5922
  ptr.assign(new NotationAttributeDefNode(grove, *notation_, attributeDefIdx));
 
5923
  return accessOK;
 
5924
}
 
5925
 
 
5926
AccessResult NotationAttributeDefOrigin::makeAttributeDefList(const GroveImpl *grove,
 
5927
                                                              NodeListPtr &ptr,
 
5928
                                                              size_t firstAttDefIdx) const
 
5929
{
 
5930
  ptr.assign(new NotationAttributeDefsNodeList(grove,
 
5931
                                               *notation_,
 
5932
                                               firstAttDefIdx));
 
5933
  return accessOK;
 
5934
}
 
5935
 
 
5936
Node *NotationAttributeDefOrigin
 
5937
::makeCdataAttributeValueNode(const GroveImpl *grove,
 
5938
                              const AttributeValue *value,
 
5939
                              size_t attIndex,
 
5940
                              const TextIter &iter,
 
5941
                              size_t charIndex) const
 
5942
{
 
5943
  return new NotationCdataAttributeValueNode(grove, value, attIndex, iter,
 
5944
                                             charIndex, notation_);
 
5945
}
 
5946
 
 
5947
 
 
5948
Node *NotationAttributeDefOrigin
 
5949
::makeAttributeValueTokenNode(const GroveImpl *grove,
 
5950
                              const TokenizedAttributeValue *value,
 
5951
                              size_t attIndex,
 
5952
                              size_t tokenIndex) const
 
5953
{
 
5954
  return new NotationAttributeValueTokenNode(grove, value, attIndex,
 
5955
                                             tokenIndex, notation_);
 
5956
}
 
5957
 
 
5958
Node *NotationAttributeDefOrigin::makeOriginNode(const GroveImpl *grove, size_t) const 
 
5959
{
 
5960
  return new NotationAttributeDefNode(grove, *notation_, attIndex_);
 
5961
}
 
5962
 
 
5963
const void *NotationAttributeDefOrigin::attributeOriginId() const
 
5964
{
 
5965
  return notation_;
 
5966
}
 
5967
 
 
5968
// class IMP: AttributeDefNode
 
5969
 
 
5970
AccessResult AttributeDefNode::getOrigin(NodePtr &ptr) const
 
5971
{
 
5972
  ptr.assign(makeOriginNode(grove(), attIndex_));
 
5973
  return accessOK;
 
5974
}
 
5975
 
 
5976
AccessResult AttributeDefNode::getName(GroveString &str) const
 
5977
{
 
5978
  setString(str, attDefList()->def(attIndex_)->name());
 
5979
  return accessOK;
 
5980
}
 
5981
 
 
5982
AccessResult AttributeDefNode::getDeclValueType(Node::DeclValueType::Enum &dvt) const
 
5983
{
 
5984
  AttributeDefinitionDesc desc;
 
5985
  attDefList()->def(attIndex_)->getDesc(desc);
 
5986
  switch (desc.declaredValue)  
 
5987
  {
 
5988
    case AttributeDefinitionDesc::cdata:
 
5989
      dvt = DeclValueType::cdata;
 
5990
      break;
 
5991
    case AttributeDefinitionDesc::name:
 
5992
      dvt = DeclValueType::name;
 
5993
      break;
 
5994
    case AttributeDefinitionDesc::number:
 
5995
      dvt = DeclValueType::number;
 
5996
      break;
 
5997
    case AttributeDefinitionDesc::nmtoken:
 
5998
      dvt = DeclValueType::nmtoken;
 
5999
      break;
 
6000
    case AttributeDefinitionDesc::nutoken:
 
6001
      dvt = DeclValueType::nutoken;
 
6002
      break;
 
6003
    case AttributeDefinitionDesc::entity:
 
6004
      dvt = DeclValueType::entity;
 
6005
      break;
 
6006
    case AttributeDefinitionDesc::idref:
 
6007
      dvt = DeclValueType::idref;
 
6008
      break;
 
6009
    case AttributeDefinitionDesc::names:
 
6010
      dvt = DeclValueType::names;
 
6011
      break;
 
6012
    case AttributeDefinitionDesc::numbers:
 
6013
      dvt = DeclValueType::numbers;
 
6014
      break;
 
6015
    case AttributeDefinitionDesc::nmtokens:
 
6016
      dvt = DeclValueType::nmtokens;
 
6017
      break;
 
6018
    case AttributeDefinitionDesc::nutokens:
 
6019
      dvt = DeclValueType::nutokens;
 
6020
      break;
 
6021
    case AttributeDefinitionDesc::entities:
 
6022
      dvt = DeclValueType::entities;
 
6023
      break;
 
6024
    case AttributeDefinitionDesc::idrefs:
 
6025
      dvt = DeclValueType::idrefs;
 
6026
      break;
 
6027
    case AttributeDefinitionDesc::id:
 
6028
      dvt = DeclValueType::id;
 
6029
      break;
 
6030
    case AttributeDefinitionDesc::notation:
 
6031
      dvt = DeclValueType::notation;
 
6032
      break;
 
6033
    case AttributeDefinitionDesc::nameTokenGroup:
 
6034
      dvt = DeclValueType::nmtkgrp;
 
6035
      break;
 
6036
    default:
 
6037
      CANNOT_HAPPEN();
 
6038
  }
 
6039
  return accessOK;
 
6040
}
 
6041
 
 
6042
AccessResult AttributeDefNode::getDefaultValueType(Node::DefaultValueType::Enum &dvt) const
 
6043
{
 
6044
  AttributeDefinitionDesc desc;
 
6045
  attDefList()->def(attIndex_)->getDesc(desc);
 
6046
  switch (desc.defaultValueType)  
 
6047
  {
 
6048
    case AttributeDefinitionDesc::required:
 
6049
      dvt = DefaultValueType::required;
 
6050
      break;
 
6051
    case AttributeDefinitionDesc::current:
 
6052
      dvt = DefaultValueType::current;
 
6053
      break;
 
6054
    case AttributeDefinitionDesc::implied:
 
6055
      dvt = DefaultValueType::implied;
 
6056
      break;
 
6057
    case AttributeDefinitionDesc::conref:
 
6058
      dvt = DefaultValueType::conref;
 
6059
      break;
 
6060
    case AttributeDefinitionDesc::defaulted:
 
6061
      dvt = DefaultValueType::value;
 
6062
      break;
 
6063
    case AttributeDefinitionDesc::fixed:
 
6064
      dvt = DefaultValueType::fixed;
 
6065
      break;
 
6066
    default:
 
6067
      CANNOT_HAPPEN();
 
6068
  }
 
6069
  return accessOK;
 
6070
}
 
6071
 
 
6072
AccessResult AttributeDefNode::getTokens(GroveStringListPtr &tokens) const
 
6073
{
 
6074
  AttributeDefinitionDesc desc;
 
6075
  attDefList()->def(attIndex_)->getDesc(desc);
 
6076
  if (desc.declaredValue != AttributeDefinitionDesc::notation
 
6077
       && desc.declaredValue != AttributeDefinitionDesc::nameTokenGroup)
 
6078
    return accessNull;
 
6079
  tokens.assign(new GroveStringList);
 
6080
  GroveString str;
 
6081
  for (size_t i = 0; i < desc.allowedValues.size(); i++)
 
6082
  {
 
6083
    setString(str, desc.allowedValues[i]);
 
6084
    tokens->append(str);
 
6085
  }
 
6086
  return accessOK;
 
6087
}
 
6088
 
 
6089
AccessResult AttributeDefNode::getCurrentAttributeIndex(long &index) const 
 
6090
{
 
6091
  AttributeDefinitionDesc desc;
 
6092
  attDefList()->def(attIndex_)->getDesc(desc);
 
6093
  if (desc.defaultValueType != AttributeDefinitionDesc::current)
 
6094
    return accessNull;
 
6095
  index = desc.currentIndex;  
 
6096
  return accessOK;
 
6097
}
 
6098
 
 
6099
void AttributeDefNode::accept(NodeVisitor &visitor)
 
6100
{
 
6101
  visitor.attributeDef(*this);
 
6102
}
 
6103
 
 
6104
bool AttributeDefNode::same(const BaseNode &node) const
 
6105
{
 
6106
  return node.same2(this);
 
6107
}
 
6108
 
 
6109
bool AttributeDefNode::same2(const AttributeDefNode *node) const
 
6110
{
 
6111
  return (attributeOriginId() == node->attributeOriginId()
 
6112
          && attIndex_ == node->attIndex());
 
6113
}
 
6114
 
 
6115
unsigned long AttributeDefNode::hash() const
 
6116
{
 
6117
  unsigned long n = (unsigned long)attributeOriginId();
 
6118
  return secondHash(n + attIndex_);
 
6119
}
 
6120
 
 
6121
// class IMP: ElementTypeAttributeDefNode
 
6122
 
 
6123
AccessResult ElementTypeAttributeDefNode::getCurrentGroup(NodeListPtr &ptr) const 
 
6124
{
 
6125
  AttributeDefinitionDesc desc;
 
6126
  attDefList()->def(attIndex_)->getDesc(desc);
 
6127
  if (desc.defaultValueType != AttributeDefinitionDesc::current)
 
6128
    return accessNull;
 
6129
  ptr.assign(
 
6130
   new ElementTypeCurrentGroupAttributeDefsNodeList(grove(),
 
6131
                                                    grove()->governingDtd()->elementTypeIter(),
 
6132
                                                    desc.currentIndex));
 
6133
  return accessOK;
 
6134
}
 
6135
 
 
6136
AccessResult ElementTypeAttributeDefNode::getLocation(Location &loc) const
 
6137
{
 
6138
  const ElementDefinition *def = elementType_->definition();
 
6139
  if (def == 0)
 
6140
    return accessNull;
 
6141
  return grove()->proxifyLocation(def->location(), loc);
 
6142
}
 
6143
 
 
6144
AccessResult ElementTypeAttributeDefNode::getDefaultValue(NodeListPtr &ptr) const
 
6145
{
 
6146
  AttributeDefinitionDesc desc;
 
6147
  attDefList()->def(attIndex_)->getDesc(desc);
 
6148
  const AttributeValue *value = desc.defaultValue.pointer();
 
6149
  return makeAttributeValueNodeList(grove(), ptr, value);
 
6150
}
 
6151
 
 
6152
// class IMP: NotationAttributeDefNode
 
6153
 
 
6154
AccessResult NotationAttributeDefNode::getCurrentGroup(NodeListPtr &ptr) const 
 
6155
{
 
6156
  AttributeDefinitionDesc desc;
 
6157
  attDefList()->def(attIndex_)->getDesc(desc);
 
6158
  if (desc.defaultValueType != AttributeDefinitionDesc::current)
 
6159
    return accessNull;
 
6160
  NodePtr nodePtr;
 
6161
  nodePtr.assign(new NotationAttributeDefNode(grove(), *notation_, attIndex_));
 
6162
  ptr.assign(new SiblingNodeList(nodePtr));
 
6163
  return accessOK;
 
6164
}
 
6165
 
 
6166
AccessResult NotationAttributeDefNode::getLocation(Location &loc) const
 
6167
{
 
6168
  return grove()->proxifyLocation(notation_->defLocation(), loc);
 
6169
}
 
6170
 
 
6171
// -- CLASS IMP: AttributeDefsNodeList
 
6172
 
 
6173
bool AttributeDefsNodeList::inList(size_t attIndex) const
 
6174
{
 
6175
  if (attDefList() == 0 || attIndex >= attDefList()->size())
 
6176
    return false;
 
6177
  return true;
 
6178
}
 
6179
 
 
6180
AccessResult AttributeDefsNodeList::first(NodePtr &ptr) const
 
6181
{
 
6182
  return inList(attIndex_)
 
6183
          ? makeAttributeDefNode(grove_, ptr, attIndex_)
 
6184
          : accessNull;
 
6185
}
 
6186
 
 
6187
AccessResult AttributeDefsNodeList::chunkRest(NodeListPtr &ptr) const
 
6188
{
 
6189
  if (canReuse(ptr)) {
 
6190
    AttributeDefsNodeList *list = (AttributeDefsNodeList *)this;
 
6191
    if (list->inList(list->attIndex_)) {
 
6192
      ++(list->attIndex_);
 
6193
      return accessOK;
 
6194
    }
 
6195
    return accessNull;
 
6196
  }
 
6197
  return inList(attIndex_)
 
6198
          ? makeAttributeDefList(grove_, ptr, attIndex_+1)
 
6199
          : accessNull;
 
6200
}
 
6201
 
 
6202
// -- CLASS IMP: AttributeDefsNamedNodeList
 
6203
 
 
6204
NodeListPtr AttributeDefsNamedNodeList::nodeList() const
 
6205
{
 
6206
  NodeListPtr ptr;
 
6207
  makeAttributeDefList(grove(), ptr, 0);
 
6208
  return ptr;
 
6209
}
 
6210
 
 
6211
AccessResult AttributeDefsNamedNodeList::namedNodeU(const StringC &str, NodePtr &ptr) const
 
6212
{
 
6213
  return makeAttributeDefNode(grove(), ptr, str);
 
6214
}
 
6215
 
 
6216
// -- CLASS IMP: ElementTypeCurrentGroupAttributeDefsNodeList
 
6217
 
 
6218
ElementTypeCurrentGroupAttributeDefsNodeList
 
6219
 ::ElementTypeCurrentGroupAttributeDefsNodeList(const GroveImpl *grove,
 
6220
                                                const Dtd::ConstElementTypeIter &iter,
 
6221
                                                size_t currentGroupIndex) 
 
6222
   : grove_(grove), iter_(iter), currentGroupIndex_(currentGroupIndex), attIndex_(0)
 
6223
{
 
6224
  elementType_ = iter_.next();
 
6225
  next(false);
 
6226
}
 
6227
 
 
6228
bool ElementTypeCurrentGroupAttributeDefsNodeList::next(Dtd::ConstElementTypeIter &iter,
 
6229
                                                        const ElementType *&elementType,
 
6230
                                                        size_t &attIndex,
 
6231
                                                        bool incrementFirst) const
 
6232
{
 
6233
  if (incrementFirst)
 
6234
    attIndex++;
 
6235
  while (elementType != 0) {
 
6236
    if (attIndex >= elementType->attributeDefTemp()->size() ) {
 
6237
      do {
 
6238
        elementType = iter.next();
 
6239
      } while(elementType != 0 && !elementType->attributeDefTemp()->anyCurrent());
 
6240
      attIndex = 0;
 
6241
    }
 
6242
    else {
 
6243
      if (elementType->attributeDefTemp()->def(attIndex)->isCurrent()) {
 
6244
        AttributeDefinitionDesc desc;
 
6245
        elementType->attributeDefTemp()->def(attIndex)->getDesc(desc);  
 
6246
        if (desc.currentIndex == currentGroupIndex_)
 
6247
          break;
 
6248
      }
 
6249
      attIndex++;
 
6250
    }
 
6251
  }
 
6252
  return elementType != 0 ? true : false;
 
6253
}
 
6254
 
 
6255
AccessResult ElementTypeCurrentGroupAttributeDefsNodeList::first(NodePtr &ptr) const
 
6256
{
 
6257
  if (elementType_ == 0)
 
6258
    return accessNull;
 
6259
  ptr.assign(new ElementTypeAttributeDefNode(grove_,
 
6260
                                             *elementType_,
 
6261
                                             attIndex_));
 
6262
  return accessOK;
 
6263
}
 
6264
 
 
6265
AccessResult ElementTypeCurrentGroupAttributeDefsNodeList::chunkRest(NodeListPtr &ptr) const
 
6266
{
 
6267
  if (elementType_ == 0)
 
6268
    return accessNull;
 
6269
  if (canReuse(ptr)) {
 
6270
    ElementTypeCurrentGroupAttributeDefsNodeList *list
 
6271
     = (ElementTypeCurrentGroupAttributeDefsNodeList *)this;
 
6272
    list->next();
 
6273
    return accessOK;
 
6274
  } else {
 
6275
    Dtd::ConstElementTypeIter iter(iter_);
 
6276
    const ElementType *elementType = elementType_;
 
6277
    size_t attIndex = attIndex_;
 
6278
    next(iter, elementType, attIndex);
 
6279
    ptr.assign(new ElementTypeCurrentGroupAttributeDefsNodeList(grove_,
 
6280
                                                                iter,
 
6281
                                                                elementType,
 
6282
                                                                attIndex,
 
6283
                                                                currentGroupIndex_));
 
6284
  }
 
6285
  return accessOK;
 
6286
}
 
6287
 
 
6288
// ------------------------------ dev end --------------------------------
 
6289
 
 
6290
#ifdef SP_NAMESPACE
 
6291
}
 
6292
#endif
 
6293
 
 
6294
#include "grove_inst.cxx"