| 1 |
// Copyright (c) 1996 James Clark |
| 2 |
// See the file copying.txt for copying permission. |
| 3 |
|
| 4 |
#ifndef NumberCache_INCLUDED |
| 5 |
#define NumberCache_INCLUDED 1 |
| 6 |
|
| 7 |
#include <OpenSP/Boolean.h> |
| 8 |
#include "Node.h" |
| 9 |
#include <OpenSP/NamedTable.h> |
| 10 |
#include <OpenSP/StringC.h> |
| 11 |
#include <OpenSP/NCVector.h> |
| 12 |
|
| 13 |
#ifdef DSSSL_NAMESPACE |
| 14 |
namespace DSSSL_NAMESPACE { |
| 15 |
#endif |
| 16 |
|
| 17 |
class NumberCache { |
| 18 |
public: |
| 19 |
NumberCache(); |
| 20 |
// Return 0 if argument is not a node. |
| 21 |
bool childNumber(const NodePtr &node, unsigned long &); |
| 22 |
// Number of elements before or equal to node whose gi is equal to s. |
| 23 |
unsigned long elementNumber(const NodePtr &node, const StringC &s); |
| 24 |
// Number of elements before or equal to node whose gi is equal to s, |
| 25 |
// and that are after the last element before node with gi reset. |
| 26 |
unsigned long elementNumberAfter(const NodePtr &, const StringC &s, |
| 27 |
const StringC &reset); |
| 28 |
private: |
| 29 |
struct Entry : Named { |
| 30 |
Entry(const StringC &); |
| 31 |
NodePtr node; |
| 32 |
unsigned long num; |
| 33 |
}; |
| 34 |
// A separate cache for each level of the tree. |
| 35 |
NCVector<NamedTable<Entry> > childNumbers_; |
| 36 |
struct ElementEntry : Entry { |
| 37 |
ElementEntry(const StringC &); |
| 38 |
NodePtr subNode; |
| 39 |
unsigned long subNum; |
| 40 |
}; |
| 41 |
NamedTable<ElementEntry> elementNumbers_; |
| 42 |
friend struct ElementEntry; |
| 43 |
}; |
| 44 |
|
| 45 |
#ifdef DSSSL_NAMESPACE |
| 46 |
} |
| 47 |
#endif |
| 48 |
|
| 49 |
#endif /* not NumberCache_INCLUDED */ |
| 50 |
|