KHtml

dom2_traversal.cpp
1 
23 #include "dom/dom_exception.h"
24 #include "dom/dom_string.h"
25 #include "xml/dom_nodeimpl.h"
26 #include "xml/dom2_traversalimpl.h"
27 
28 using namespace DOM;
29 
30 NodeIterator::NodeIterator()
31 {
32  impl = nullptr;
33 }
34 
35 NodeIterator::NodeIterator(const NodeIterator &other)
36 {
37  impl = other.impl;
38  if (impl) {
39  impl->ref();
40  }
41 }
42 
43 NodeIterator::NodeIterator(NodeIteratorImpl *i)
44 {
45  impl = i;
46  if (impl) {
47  impl->ref();
48  }
49 }
50 
51 NodeIterator &NodeIterator::operator = (const NodeIterator &other)
52 {
53  if (impl != other.impl) {
54  if (impl) {
55  impl->deref();
56  }
57  impl = other.impl;
58  if (impl) {
59  impl->ref();
60  }
61  }
62  return *this;
63 }
64 
65 NodeIterator::~NodeIterator()
66 {
67  if (impl) {
68  impl->deref();
69  }
70 }
71 
73 {
74  if (impl) {
75  return impl->root();
76  }
77  return nullptr;
78 }
79 
80 unsigned long NodeIterator::whatToShow()
81 {
82  if (impl) {
83  return impl->whatToShow();
84  }
85  return 0;
86 }
87 
89 {
90  if (impl) {
91  return impl->filter();
92  }
93  return nullptr;
94 }
95 
97 {
98  if (impl) {
99  return impl->expandEntityReferences();
100  }
101  return 0;
102 }
103 
105 {
106  void *dummy;
107  if (!impl) {
108  throw DOMException(DOMException::INVALID_STATE_ERR);
109  }
110 
111  int exceptioncode = 0;
112  SharedPtr<NodeImpl> r = impl->nextNode(exceptioncode, dummy);
113  if (exceptioncode) {
114  throw DOMException(exceptioncode);
115  }
116  return r.get();
117 }
118 
120 {
121  void *dummy; // ### rely on C++ exception propagation --- might not be safe
122  // we could probably proxy the DOM exceptions at the very least
123  if (!impl) {
124  throw DOMException(DOMException::INVALID_STATE_ERR);
125  }
126 
127  int exceptioncode = 0;
128  SharedPtr<NodeImpl> r = impl->previousNode(exceptioncode, dummy);
129  if (exceptioncode) {
130  throw DOMException(exceptioncode);
131  }
132  return r.get();
133 }
134 
136 {
137  if (!impl) {
138  throw DOMException(DOMException::INVALID_STATE_ERR);
139  }
140 
141  int exceptioncode = 0;
142  impl->detach(exceptioncode);
143  if (exceptioncode) {
144  throw DOMException(exceptioncode);
145  }
146 }
147 
148 NodeIteratorImpl *NodeIterator::handle() const
149 {
150  return impl;
151 }
152 
153 bool NodeIterator::isNull() const
154 {
155  return (impl == nullptr);
156 }
157 
158 // -----------------------------------------------------------
159 
160 NodeFilter::NodeFilter()
161 {
162  impl = nullptr;
163 }
164 
165 NodeFilter::NodeFilter(const NodeFilter &other)
166 {
167  impl = other.impl;
168  if (impl) {
169  impl->ref();
170  }
171 }
172 
173 NodeFilter::NodeFilter(NodeFilterImpl *i)
174 {
175  impl = i;
176  if (impl) {
177  impl->ref();
178  }
179 }
180 
181 NodeFilter &NodeFilter::operator = (const NodeFilter &other)
182 {
183  if (impl != other.impl) {
184  if (impl) {
185  impl->deref();
186  }
187  impl = other.impl;
188  if (impl) {
189  impl->ref();
190  }
191  }
192  return *this;
193 }
194 
195 NodeFilter::~NodeFilter()
196 {
197  if (impl) {
198  impl->deref();
199  }
200 }
201 
203 {
204  void *dummy;
205  if (impl) {
206  return impl->acceptNode(n, dummy);
207  }
208  return 0;
209 }
210 
211 void NodeFilter::setCustomNodeFilter(CustomNodeFilter *custom)
212 {
213  if (impl) {
214  impl->setCustomNodeFilter(custom);
215  }
216 }
217 
218 CustomNodeFilter *NodeFilter::customNodeFilter()
219 {
220  if (impl) {
221  return impl->customNodeFilter();
222  }
223  return nullptr;
224 }
225 
226 NodeFilterImpl *NodeFilter::handle() const
227 {
228  return impl;
229 }
230 
231 bool NodeFilter::isNull() const
232 {
233  return (impl == nullptr);
234 }
235 
236 NodeFilter NodeFilter::createCustom(CustomNodeFilter *custom)
237 {
238  NodeFilterImpl *i = new NodeFilterImpl();
239  i->setCustomNodeFilter(custom);
240  return i;
241 }
242 
243 // --------------------------------------------------------------
244 CustomNodeFilter::CustomNodeFilter()
245 {
246  impl = nullptr;
247 }
248 
249 CustomNodeFilter::~CustomNodeFilter()
250 {
251 }
252 
253 short CustomNodeFilter::acceptNode(const Node &/*n*/)
254 {
255  return NodeFilter::FILTER_ACCEPT;
256 }
257 
258 bool CustomNodeFilter::isNull()
259 {
260  return false;
261 }
262 
264 {
265  return "";
266 }
267 
268 // --------------------------------------------------------------
269 
270 TreeWalker::TreeWalker()
271 {
272  impl = nullptr;
273 }
274 
275 TreeWalker::TreeWalker(const TreeWalker &other)
276 {
277  impl = other.impl;
278  if (impl) {
279  impl->ref();
280  }
281 }
282 
283 TreeWalker::TreeWalker(TreeWalkerImpl *i)
284 {
285  impl = i;
286  if (impl) {
287  impl->ref();
288  }
289 }
290 
291 TreeWalker &TreeWalker::operator = (const TreeWalker &other)
292 {
293  if (impl != other.impl) {
294  if (impl) {
295  impl->deref();
296  }
297  impl = other.impl;
298  if (impl) {
299  impl->ref();
300  }
301  }
302 
303  return *this;
304 }
305 
306 TreeWalker::~TreeWalker()
307 {
308  if (impl) {
309  impl->deref();
310  }
311 }
312 
314 {
315  if (impl) {
316  return impl->getRoot();
317  }
318  return nullptr;
319 }
320 
321 unsigned long TreeWalker::whatToShow()
322 {
323  if (impl) {
324  return impl->getWhatToShow();
325  }
326  return 0;
327 }
328 
330 {
331  if (impl) {
332  return impl->getFilter();
333  }
334  return nullptr;
335 }
336 
338 {
339  if (impl) {
340  return impl->getExpandEntityReferences();
341  }
342  return false;
343 }
344 
346 {
347  if (impl) {
348  return impl->getCurrentNode();
349  }
350  return nullptr;
351 }
352 
353 void TreeWalker::setCurrentNode(const Node &_currentNode)
354 {
355  int exceptionCode = 0;
356  if (impl) {
357  impl->setCurrentNode(_currentNode.handle(), exceptionCode);
358  }
359  if (exceptionCode) {
360  throw DOMException(exceptionCode);
361  }
362 }
363 
365 {
366  void *dummy;
367  if (impl) {
368  return impl->parentNode(dummy);
369  }
370  return nullptr;
371 }
372 
374 {
375  void *dummy;
376  if (impl) {
377  return impl->firstChild(dummy);
378  }
379  return nullptr;
380 }
381 
383 {
384  void *dummy;
385  if (impl) {
386  return impl->lastChild(dummy);
387  }
388  return nullptr;
389 }
390 
392 {
393  void *dummy;
394  if (impl) {
395  return impl->previousSibling(dummy);
396  }
397  return nullptr;
398 }
399 
401 {
402  void *dummy;
403  if (impl) {
404  return impl->nextSibling(dummy);
405  }
406  return nullptr;
407 }
408 
410 {
411  void *dummy;
412  if (impl) {
413  return impl->previousNode(dummy);
414  }
415  return nullptr;
416 }
417 
419 {
420  void *dummy;
421  if (impl) {
422  return impl->nextNode(dummy);
423  }
424  return nullptr;
425 }
426 
427 TreeWalkerImpl *TreeWalker::handle() const
428 {
429  return impl;
430 }
431 
432 bool TreeWalker::isNull() const
433 {
434  return (impl == nullptr);
435 }
436 
CustomNodeFilter can be used to define your own NodeFilter for use with NodeIterators and TreeWalkers...
NodeIteratorImpl * handle() const
Node root()
The root node of the TreeWalker, as specified when it was created.
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:278
NodeFilter filter()
The filter used to screen nodes.
Node previousSibling()
Moves the TreeWalker to the previous sibling of the current node, and returns the new node...
Node nextSibling()
Moves the TreeWalker to the next sibling of the current node, and returns the new node...
unsigned long whatToShow()
This attribute determines which node types are presented via the TreeWalker.
virtual DOMString customNodeFilterType()
Node previousNode()
Moves the TreeWalker to the previous node in document order relative to the current node...
DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impos...
Definition: dom_exception.h:58
unsigned long whatToShow()
This attribute determines which node types are presented via the iterator.
Node nextNode()
Returns the next node in the set and advances the position of the Iterator in the set...
TreeWalker objects are used to navigate a document tree or subtree using the view of the document def...
virtual short acceptNode(const Node &n)
Test whether a specified node is visible in the logical view of a TreeWalker or NodeIterator.
NodeFilter filter()
The NodeFilter used to screen nodes.
Node currentNode()
The node at which the TreeWalker is currently positioned.
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
Node firstChild()
Moves the TreeWalker to the first child of the current node, and returns the new node.
Node root()
The root node of the NodeIterator, as specified when it was created.
Node previousNode()
Returns the previous node in the set and moves the position of the Iterator backwards in the set...
Filters are objects that know how to "filter out" nodes.
TreeWalkerImpl * handle() const
void setCurrentNode(const Node &_currentNode)
see currentNode
This library provides a full-featured HTML parser and widget.
bool expandEntityReferences()
The value of this flag determines whether the children of entity reference nodes are visible to the T...
virtual NodeFilterImpl * handle() const
NodeIterators are used to step through a set of nodes, e.g.
Node lastChild()
Moves the TreeWalker to the last child of the current node, and returns the new node.
void detach()
Detaches the NodeIterator from the set which it iterated over, releasing any computational resources ...
bool expandEntityReferences()
The value of this flag determines whether the children of entity reference nodes are visible to the i...
NodeImpl * handle() const
Definition: dom_node.h:936
Node nextNode()
Moves the TreeWalker to the next node in document order relative to the current node, and returns the new node.
Node parentNode()
Moves to and returns the parent node of the current node.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 10 2020 22:49:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.