Initial commit
[profile/ivi/openjade.git] / style / SosofoObj.h
1 // Copyright (c) 1996 James Clark
2 // See the file copying.txt for copying permission.
3
4 #ifndef SosofoObj_INCLUDED
5 #define SosofoObj_INCLUDED 1
6
7 #include "ELObj.h"
8 #include "Location.h"
9 #include "FOTBuilder.h"
10 #include "Owner.h"
11 #include "CopyOwner.h"
12 #include "Insn.h"
13
14 #ifdef DSSSL_NAMESPACE
15 namespace DSSSL_NAMESPACE {
16 #endif
17
18 class ProcessContext;
19 class Interpreter;
20
21 class SosofoObj : public ELObj {
22 public:
23   virtual void process(ProcessContext &) = 0;
24   SosofoObj *asSosofo();
25   virtual bool tableBorderStyle(StyleObj *&);
26   virtual bool ruleStyle(ProcessContext &, StyleObj *&);
27   virtual bool isRule();
28   virtual bool characterStyle(ProcessContext &, StyleObj *&, FOTBuilder::CharacterNIC &);
29   virtual bool isCharacter();
30 };
31
32 class NextMatchSosofoObj : public SosofoObj {
33 public:
34   NextMatchSosofoObj(StyleObj *);
35   void process(ProcessContext &);
36 private:
37   StyleObj *style_;
38 };
39
40 class EmptySosofoObj : public SosofoObj {
41 public:
42   void process(ProcessContext &);
43 };
44
45 class ProcessingMode;
46
47 class ProcessNodeSosofoObj : public SosofoObj {
48 public:
49   void *operator new(size_t, Collector &c) {
50     return c.allocateObject(1);
51   }
52   ProcessNodeSosofoObj(const NodePtr &node, const ProcessingMode *mode);
53   void process(ProcessContext &);
54 private:
55   NodePtr node_;
56   const ProcessingMode *mode_;
57 };
58
59 class ProcessNodeListSosofoObj : public SosofoObj {
60 public:
61   ProcessNodeListSosofoObj(NodeListObj *, const ProcessingMode *);
62   void process(ProcessContext &);
63   void traceSubObjects(Collector &) const;
64 private:
65   NodeListObj *nodeList_;
66   const ProcessingMode *mode_;
67 };
68
69 class AppendSosofoObj : public SosofoObj {
70 public:
71   void *operator new(size_t, Collector &c) {
72     return c.allocateObject(1);
73   }
74   AppendSosofoObj() { hasSubObjects_ = 1; }
75   AppendSosofoObj *asAppendSosofo();
76   void process(ProcessContext &);
77   void append(SosofoObj *);
78   void traceSubObjects(Collector &) const;
79 private:
80   Vector<SosofoObj *> v_;
81 };
82
83 class LiteralSosofoObj : public SosofoObj {
84 public:
85   LiteralSosofoObj(ELObj *str) : str_(str) { hasSubObjects_ = 1; }
86   void process(ProcessContext &);
87   void traceSubObjects(Collector &) const;
88 private:
89   ELObj *str_;
90 };
91
92 class CurrentNodePageNumberSosofoObj : public SosofoObj {
93 public:
94   void *operator new(size_t, Collector &c) {
95     return c.allocateObject(1);
96   }
97   CurrentNodePageNumberSosofoObj(const NodePtr &node) : node_(node) { }
98   void process(ProcessContext &);
99 private:
100   NodePtr node_;
101 };
102
103 class PageNumberSosofoObj : public SosofoObj {
104 public:
105   PageNumberSosofoObj() { }
106   void process(ProcessContext &);
107 };
108
109 class CompoundFlowObj;
110
111 class FlowObj : public SosofoObj {
112 public:
113   FlowObj();
114   virtual FlowObj *copy(Collector &) const = 0;
115   virtual CompoundFlowObj *asCompoundFlowObj();
116   virtual bool hasNonInheritedC(const Identifier *) const;
117   virtual bool hasPseudoNonInheritedC(const Identifier *) const;
118   virtual void setNonInheritedC(const Identifier *, ELObj *, const Location &, Interpreter &);
119   virtual bool setImplicitChar(ELObj *, const Location &, Interpreter &);
120   void traceSubObjects(Collector &) const;
121   void setStyle(StyleObj *);
122   void process(ProcessContext &);
123   virtual void pushStyle(ProcessContext &, unsigned &);
124   virtual void popStyle(ProcessContext &, unsigned);
125   virtual void processInner(ProcessContext &) = 0;
126 protected:
127   static
128     bool setDisplayNIC(FOTBuilder::DisplayNIC &,
129                        const Identifier *, ELObj *,
130                        const Location &, Interpreter &);
131   static bool isDisplayNIC(const Identifier *);
132   StyleObj *style_;
133 };
134
135 class CompoundFlowObj : public FlowObj {
136 public:
137   CompoundFlowObj() : content_(0) { }
138   void processInner(ProcessContext &);
139   void traceSubObjects(Collector &) const;
140   void setContent(SosofoObj *content) { content_ = content; }
141   CompoundFlowObj *asCompoundFlowObj();
142 protected:
143   SosofoObj *content() const;
144 private:
145   SosofoObj *content_;
146 };
147
148 class SequenceFlowObj : public CompoundFlowObj {
149 public:
150   SequenceFlowObj() { }
151   void processInner(ProcessContext &);
152   FlowObj *copy(Collector &) const;
153 };
154
155 class ProcessingMode;
156
157 class ProcessChildrenSosofoObj : public SosofoObj {
158 public:
159   ProcessChildrenSosofoObj(const ProcessingMode *mode) : mode_(mode) { }
160   void process(ProcessContext &);
161 private:
162   const ProcessingMode *mode_;
163 };
164
165 class ProcessChildrenTrimSosofoObj : public SosofoObj {
166 public:
167   ProcessChildrenTrimSosofoObj(const ProcessingMode *mode) : mode_(mode) { }
168   void process(ProcessContext &);
169 private:
170   const ProcessingMode *mode_;
171 };
172
173 class SetNonInheritedCsSosofoObj : public SosofoObj {
174 public:
175   void *operator new(size_t, Collector &c) {
176     return c.allocateObject(1);
177   }
178   SetNonInheritedCsSosofoObj(FlowObj *, const InsnPtr &, ELObj **, const NodePtr &);
179   ~SetNonInheritedCsSosofoObj();
180   void process(ProcessContext &);
181   void traceSubObjects(Collector &) const;
182   bool characterStyle(ProcessContext &, StyleObj *&, FOTBuilder::CharacterNIC &);
183   bool isCharacter();
184   bool ruleStyle(ProcessContext &, StyleObj *&);
185   bool isRule();
186 private:
187   ELObj *resolve(ProcessContext &);
188
189   FlowObj *flowObj_;
190   ELObj **display_;
191   InsnPtr code_;
192   NodePtr node_;
193 };
194
195 class Expression;
196
197 // This wraps a flow object that has a label:.
198 class LabelSosofoObj : public SosofoObj {
199 public:
200   void *operator new(size_t, Collector &c) {
201     return c.allocateObject(1);
202   }
203   LabelSosofoObj(SymbolObj *, const Location &, SosofoObj *content);
204   void process(ProcessContext &);
205   void traceSubObjects(Collector &) const;
206 private:
207   SymbolObj *label_;
208   Owner<Location> locp_;
209   SosofoObj *content_;
210 };
211
212 // This wraps the content of a sosofo with a content-map:.
213
214 class ContentMapSosofoObj : public SosofoObj {
215 public:
216   ContentMapSosofoObj(ELObj *, const Location *, SosofoObj *content);
217   void process(ProcessContext &);
218   void traceSubObjects(Collector &) const;
219 private:
220   ELObj *contentMap_;
221   const Location *locp_;
222   SosofoObj *content_; 
223 };
224
225 class DiscardLabeledSosofoObj : public SosofoObj {
226 public:
227   DiscardLabeledSosofoObj(SymbolObj *, SosofoObj *);
228   void process(ProcessContext &);
229   void traceSubObjects(Collector &) const;
230 private:
231   SymbolObj *label_;
232   SosofoObj *content_; 
233 };
234
235 class PageTypeSosofoObj : public SosofoObj {
236 public:
237   PageTypeSosofoObj(unsigned, SosofoObj *, SosofoObj *);
238   void process(ProcessContext &);
239   void traceSubObjects(Collector &) const;
240 private:
241   unsigned pageTypeFlag_;
242   SosofoObj *match_;
243   SosofoObj *noMatch_;
244 };
245
246 inline
247 void FlowObj::setStyle(StyleObj *style)
248 {
249   style_ = style;
250 }
251
252 inline
253 void AppendSosofoObj::append(SosofoObj *obj)
254 {
255   v_.push_back(obj);
256 }
257
258 inline
259 SosofoObj *CompoundFlowObj::content() const
260 {
261   return content_;
262 }
263
264 #ifdef DSSSL_NAMESPACE
265 }
266 #endif
267
268 #endif /* not SosofoObj_INCLUDED */
269