| 1 |
// Copyright (c) 1996 James Clark |
| 2 |
// See the file copying.txt for copying permission. |
| 3 |
|
| 4 |
#ifndef ProcessContext_INCLUDED |
| 5 |
#define ProcessContext_INCLUDED 1 |
| 6 |
|
| 7 |
#include <OpenSP/Resource.h> |
| 8 |
#include <OpenSP/Ptr.h> |
| 9 |
#include <OpenSP/Vector.h> |
| 10 |
#include <OpenSP/NCVector.h> |
| 11 |
#include <OpenSP/Owner.h> |
| 12 |
#include "Collector.h" |
| 13 |
#include "Style.h" |
| 14 |
#include "FOTBuilder.h" |
| 15 |
#include "ELObj.h" |
| 16 |
#include "SosofoObj.h" |
| 17 |
#include "VM.h" |
| 18 |
#include "ProcessingMode.h" |
| 19 |
#include <OpenSP/Link.h> |
| 20 |
#include <OpenSP/IList.h> |
| 21 |
#include <OpenSP/IQueue.h> |
| 22 |
|
| 23 |
#ifdef DSSSL_NAMESPACE |
| 24 |
namespace DSSSL_NAMESPACE { |
| 25 |
#endif |
| 26 |
|
| 27 |
class Expression; |
| 28 |
|
| 29 |
class ProcessContext : public Collector::DynamicRoot { |
| 30 |
public: |
| 31 |
ProcessContext(Interpreter &, FOTBuilder &); |
| 32 |
~ProcessContext(); |
| 33 |
FOTBuilder ¤tFOTBuilder(); |
| 34 |
StyleStack ¤tStyleStack(); |
| 35 |
void process(const NodePtr &); |
| 36 |
void processNode(const NodePtr &, const ProcessingMode *, |
| 37 |
const Location &, bool chunk = 1); |
| 38 |
void processNodeSafe(const NodePtr &, const ProcessingMode *, |
| 39 |
const Location &, bool chunk = 1); |
| 40 |
void nextMatch(StyleObj *, const Location &loc); |
| 41 |
void processChildren(const ProcessingMode *, const Location &); |
| 42 |
void processChildrenTrim(const ProcessingMode *, const Location &); |
| 43 |
void characters(const Char *, size_t, const Location &); |
| 44 |
void charactersFromNode(const NodePtr &, const Char *, size_t, |
| 45 |
const Location &); |
| 46 |
void trace(Collector &) const; |
| 47 |
void startFlowObj(); |
| 48 |
void endFlowObj(); |
| 49 |
// Uses of label: do this |
| 50 |
void startConnection(SymbolObj *, const Location &); |
| 51 |
void endConnection(); |
| 52 |
|
| 53 |
// Contains information about which flow object classes a port shall accept |
| 54 |
// and can validate flow objects according to this information. |
| 55 |
class Validator : public Resource { |
| 56 |
public: |
| 57 |
// If the flow object specified by the argument is valid in the current |
| 58 |
// position in this stream, this function returns true and updates |
| 59 |
// state information as if the flow object was added to the stream. |
| 60 |
// If the FO isn't valid, this method reports it with a message. |
| 61 |
// Default implementation returns true. |
| 62 |
virtual bool isValid(const FlowObj &, ProcessContext &); |
| 63 |
virtual bool charsValid(size_t, const Location &, ProcessContext &); |
| 64 |
}; |
| 65 |
|
| 66 |
void validate(const FlowObj &); |
| 67 |
void endValidate(); |
| 68 |
// happens only for object with a non-principal port |
| 69 |
void pushPorts(bool hasPrincipalPort, |
| 70 |
const Vector<SymbolObj *> &ports, |
| 71 |
const Vector<FOTBuilder *> &fotbs, |
| 72 |
const Vector<Validator *> validators, |
| 73 |
Validator *principalPortValidator = 0); |
| 74 |
void popPorts(); |
| 75 |
void pushPrincipalPort(Validator *); |
| 76 |
void popPrincipalPort(); |
| 77 |
// Used by SpS headers and footers. |
| 78 |
void pushPseudoPort(FOTBuilder *principalPort, |
| 79 |
Validator *); |
| 80 |
void popPseudoPort(); |
| 81 |
// happens inside pushPorts() (if any) |
| 82 |
void startMapContent(ELObj *, const Location &); |
| 83 |
void endMapContent(); |
| 84 |
void startDiscardLabeled(SymbolObj *); |
| 85 |
void endDiscardLabeled(); |
| 86 |
// table support |
| 87 |
void startTable(); |
| 88 |
void endTable(); |
| 89 |
void startTablePart(); |
| 90 |
void endTablePart(); |
| 91 |
void addTableColumn(unsigned columnIndex, unsigned span, StyleObj *); |
| 92 |
unsigned currentTableColumn(); |
| 93 |
void noteTableCell(unsigned colIndex, unsigned colSpan, unsigned rowSpan); |
| 94 |
StyleObj *tableColumnStyle(unsigned columnIndex, unsigned span); |
| 95 |
StyleObj *tableRowStyle(); |
| 96 |
void startTableRow(StyleObj *); |
| 97 |
bool inTable() const; |
| 98 |
bool inTableRow(); |
| 99 |
void endTableRow(); |
| 100 |
void clearPageType(); |
| 101 |
void setPageType(unsigned); |
| 102 |
bool getPageType(unsigned &) const; |
| 103 |
void startParagraph(); |
| 104 |
void endParagraph(); |
| 105 |
bool paragraphAncestor() const; |
| 106 |
|
| 107 |
VM &vm(); |
| 108 |
private: |
| 109 |
ProcessContext(const ProcessContext &); // undefined |
| 110 |
void operator=(const ProcessContext &); // undefined |
| 111 |
void badContentMap(bool &, const Location &); |
| 112 |
void coverSpannedRows(); |
| 113 |
void restoreConnection(unsigned connectableLevel, size_t portIndex); |
| 114 |
struct Port { |
| 115 |
Port(); |
| 116 |
FOTBuilder *fotb; |
| 117 |
IQueue<NodeSaveFOTBuilder> saveQueue; |
| 118 |
Vector<SymbolObj *> labels; |
| 119 |
Ptr<Validator> validator; |
| 120 |
unsigned connected; |
| 121 |
}; |
| 122 |
// A flow object with a port that can be connected to. |
| 123 |
struct Connectable; |
| 124 |
friend struct Connectable; |
| 125 |
struct Connectable : public Link { |
| 126 |
Connectable(int nPorts, const StyleStack &, unsigned); |
| 127 |
NCVector<Port> ports; |
| 128 |
StyleStack styleStack; |
| 129 |
unsigned flowObjLevel; |
| 130 |
Vector<SymbolObj *> principalPortLabels; |
| 131 |
Ptr<Validator> principalPortValidator; |
| 132 |
}; |
| 133 |
// A connection between a flow object and its flow parent |
| 134 |
// made with label:. |
| 135 |
struct Connection; |
| 136 |
friend struct Connection; |
| 137 |
struct Connection : public Link { |
| 138 |
Connection(FOTBuilder *, const StyleStack & = StyleStack()); |
| 139 |
Connection(const StyleStack &, Port *, unsigned connectableLevel); |
| 140 |
FOTBuilder *fotb; |
| 141 |
StyleStack styleStack; |
| 142 |
Port *port; |
| 143 |
unsigned connectableLevel; |
| 144 |
unsigned nBadFollow; |
| 145 |
}; |
| 146 |
struct Table : public Link { |
| 147 |
Table(); |
| 148 |
unsigned currentColumn; |
| 149 |
// first index is column (zero-based) |
| 150 |
// second is span - 1. |
| 151 |
Vector<Vector<StyleObj *> > columnStyles; |
| 152 |
// for each column, how many rows are covered |
| 153 |
// starting with the current row |
| 154 |
Vector<unsigned> covered; |
| 155 |
unsigned nColumns; |
| 156 |
StyleObj *rowStyle; |
| 157 |
bool inTableRow; |
| 158 |
unsigned rowConnectableLevel; |
| 159 |
}; |
| 160 |
struct NodeStackEntry { |
| 161 |
unsigned long elementIndex; |
| 162 |
unsigned groveIndex; |
| 163 |
const ProcessingMode *processingMode; |
| 164 |
}; |
| 165 |
FOTBuilder ignoreFotb_; |
| 166 |
IList<Connection> connectionStack_; |
| 167 |
IList<Connectable> connectableStack_; |
| 168 |
unsigned connectableStackLevel_; |
| 169 |
IList<Table> tableStack_; |
| 170 |
NCVector<IQueue<NodeSaveFOTBuilder> > principalPortSaveQueues_; |
| 171 |
VM vm_; |
| 172 |
ProcessingMode::Specificity matchSpecificity_; |
| 173 |
unsigned flowObjLevel_; |
| 174 |
bool havePageType_; |
| 175 |
unsigned pageType_; |
| 176 |
unsigned paragraphLevel_; |
| 177 |
Vector<NodeStackEntry> nodeStack_; |
| 178 |
Vector<unsigned> invalidLevels_; |
| 179 |
Vector<Ptr<Validator> > validatorStack_; |
| 180 |
friend class CurrentNodeSetter; |
| 181 |
friend struct Table; |
| 182 |
}; |
| 183 |
|
| 184 |
inline |
| 185 |
FOTBuilder &ProcessContext::currentFOTBuilder() |
| 186 |
{ |
| 187 |
return *connectionStack_.head()->fotb; |
| 188 |
} |
| 189 |
|
| 190 |
inline |
| 191 |
StyleStack &ProcessContext::currentStyleStack() |
| 192 |
{ |
| 193 |
return connectionStack_.head()->styleStack; |
| 194 |
} |
| 195 |
|
| 196 |
inline |
| 197 |
VM &ProcessContext::vm() |
| 198 |
{ |
| 199 |
return vm_; |
| 200 |
} |
| 201 |
|
| 202 |
inline |
| 203 |
void ProcessContext::startFlowObj() |
| 204 |
{ |
| 205 |
flowObjLevel_++; |
| 206 |
} |
| 207 |
|
| 208 |
inline |
| 209 |
void ProcessContext::setPageType(unsigned n) |
| 210 |
{ |
| 211 |
havePageType_ = 1; |
| 212 |
pageType_ = n; |
| 213 |
} |
| 214 |
|
| 215 |
inline |
| 216 |
void ProcessContext::clearPageType() |
| 217 |
{ |
| 218 |
havePageType_ = 0; |
| 219 |
} |
| 220 |
|
| 221 |
inline |
| 222 |
bool ProcessContext::getPageType(unsigned &n) const |
| 223 |
{ |
| 224 |
if (!havePageType_) |
| 225 |
return 0; |
| 226 |
n = pageType_; |
| 227 |
return 1; |
| 228 |
} |
| 229 |
|
| 230 |
inline |
| 231 |
bool ProcessContext::inTable() const |
| 232 |
{ |
| 233 |
return !tableStack_.empty(); |
| 234 |
} |
| 235 |
|
| 236 |
inline |
| 237 |
void ProcessContext::startParagraph() |
| 238 |
{ |
| 239 |
paragraphLevel_++; |
| 240 |
} |
| 241 |
|
| 242 |
inline |
| 243 |
void ProcessContext::endParagraph() |
| 244 |
{ |
| 245 |
paragraphLevel_--; |
| 246 |
} |
| 247 |
|
| 248 |
inline |
| 249 |
bool ProcessContext::paragraphAncestor() const |
| 250 |
{ |
| 251 |
return paragraphLevel_ > 0; |
| 252 |
} |
| 253 |
|
| 254 |
#ifdef DSSSL_NAMESPACE |
| 255 |
} |
| 256 |
#endif |
| 257 |
|
| 258 |
#endif /* not ProcessContext_INCLUDED */ |
| 259 |
|