source: NonGTP/Xerces/xerces/include/xercesc/dom/DOMRange.hpp @ 358

Revision 358, 21.4 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1#ifndef DOMRange_HEADER_GUARD_
2#define DOMRange_HEADER_GUARD_
3
4/*
5 * Copyright 2001-2002,2004 The Apache Software Foundation.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20/*
21 * $Id: DOMRange.hpp,v 1.9 2004/09/08 13:55:39 peiyongz Exp $
22 */
23
24#include <xercesc/util/XercesDefs.hpp>
25
26XERCES_CPP_NAMESPACE_BEGIN
27
28class DOMNode;
29class DOMDocumentFragment;
30
31/**
32 * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>Document Object Model (DOM) Level 2 Traversal and Range Specification</a>.
33 * @since DOM Level 2
34 */
35class CDOM_EXPORT DOMRange {
36protected:
37    // -----------------------------------------------------------------------
38    //  Hidden constructors
39    // -----------------------------------------------------------------------
40    /** @name Hidden constructors */
41    //@{   
42    DOMRange() {};
43    //@}
44
45private:
46    // -----------------------------------------------------------------------
47    // Unimplemented constructors and operators
48    // -----------------------------------------------------------------------
49    /** @name Unimplemented constructors and operators */
50    //@{
51    DOMRange(const DOMRange &);
52    DOMRange & operator = (const DOMRange &);
53    //@}
54
55public:
56    // -----------------------------------------------------------------------
57    //  All constructors are hidden, just the destructor is available
58    // -----------------------------------------------------------------------
59    /** @name Destructor */
60    //@{
61    /**
62     * Destructor
63     *
64     */
65    virtual ~DOMRange() {};
66    //@}
67
68    // -----------------------------------------------------------------------
69    //  Class Types
70    // -----------------------------------------------------------------------
71    /** @name Public Contants */
72    //@{
73    /**
74     * Constants CompareHow.
75     *
76     * <p><code>START_TO_START:</code>
77     * Compare start boundary-point of <code>sourceRange</code> to start
78     * boundary-point of Range on which <code>compareBoundaryPoints</code>
79     * is invoked.</p>
80     *
81     * <p><code>START_TO_END:</code>
82     * Compare start boundary-point of <code>sourceRange</code> to end
83     * boundary-point of Range on which <code>compareBoundaryPoints</code>
84     * is invoked.</p>
85     *
86     * <p><code>END_TO_END:</code>
87     * Compare end boundary-point of <code>sourceRange</code> to end
88     * boundary-point of Range on which <code>compareBoundaryPoints</code>
89     * is invoked.</p>
90     *
91     * <p><code>END_TO_START:</code>
92     * Compare end boundary-point of <code>sourceRange</code> to start
93     * boundary-point of Range on which <code>compareBoundaryPoints</code>
94     * is invoked.</p>
95     *
96     * @since DOM Level 2
97     */
98    enum CompareHow {
99        START_TO_START  = 0,
100        START_TO_END    = 1,
101        END_TO_END      = 2,
102        END_TO_START    = 3
103    };
104
105    //@}
106
107    // -----------------------------------------------------------------------
108    //  Virtual DOMRange interface
109    // -----------------------------------------------------------------------
110    /** @name Functions introduced in DOM Level 2 */
111    //@{
112    // -----------------------------------------------------------------------
113    //  Getter methods
114    // -----------------------------------------------------------------------
115    /**
116     * DOMNode within which the Range begins
117     * @exception DOMException
118     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
119     *   invoked on this object.
120     *
121     * @since DOM Level 2
122     */
123    virtual DOMNode* getStartContainer() const = 0;
124
125    /**
126     * Offset within the starting node of the Range.
127     * @exception DOMException
128     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
129     *   invoked on this object.
130     *
131     * @since DOM Level 2
132     */
133    virtual XMLSize_t getStartOffset() const = 0;
134
135    /**
136     * DOMNode within which the Range ends
137     * @exception DOMException
138     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
139     *   invoked on this object.
140     *
141     * @since DOM Level 2
142     */
143    virtual DOMNode* getEndContainer() const = 0;
144
145    /**
146     * Offset within the ending node of the Range.
147     * @exception DOMException
148     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
149     *   invoked on this object.
150     *
151     * @since DOM Level 2
152     */
153    virtual XMLSize_t getEndOffset() const = 0;
154
155    /**
156     * TRUE if the Range is collapsed
157     * @exception DOMException
158     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
159     *   invoked on this object.
160     *
161     * @since DOM Level 2
162     */
163    virtual bool getCollapsed() const = 0;
164
165    /**
166     * The deepest common ancestor container of the Range's two
167     * boundary-points.
168     * @exception DOMException
169     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
170     *   invoked on this object.
171     *
172     * @since DOM Level 2
173     */
174    virtual const DOMNode* getCommonAncestorContainer() const = 0;
175
176    // -----------------------------------------------------------------------
177    //  Setter methods
178    // -----------------------------------------------------------------------
179    /**
180     * Sets the attributes describing the start of the Range.
181     * @param refNode The <code>refNode</code> value. This parameter must be
182     *   different from <code>null</code>.
183     * @param offset The <code>startOffset</code> value.
184     * @exception DOMRangeException
185     *   INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> or an ancestor
186     *   of <code>refNode</code> is an DOMEntity, DOMNotation, or DOMDocumentType
187     *   node.
188     * @exception DOMException
189     *   INDEX_SIZE_ERR: Raised if <code>offset</code> is negative or greater
190     *   than the number of child units in <code>refNode</code>. Child units
191     *   are 16-bit units if <code>refNode</code> is a type of DOMCharacterData
192     *   node (e.g., a DOMText or DOMComment node) or a DOMProcessingInstruction
193     *   node. Child units are Nodes in all other cases.
194     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
195     *   been invoked on this object.
196     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
197     *   from a different document than the one that created this range.
198     *
199     * @since DOM Level 2
200     */
201    virtual void setStart(const DOMNode *refNode, XMLSize_t offset) = 0;
202
203    /**
204     * Sets the attributes describing the end of a Range.
205     * @param refNode The <code>refNode</code> value. This parameter must be
206     *   different from <code>null</code>.
207     * @param offset The <code>endOffset</code> value.
208     * @exception DOMRangeException
209     *   INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> or an ancestor
210     *   of <code>refNode</code> is an DOMEntity, DOMNotation, or DOMDocumentType
211     *   node.
212     * @exception DOMException
213     *   INDEX_SIZE_ERR: Raised if <code>offset</code> is negative or greater
214     *   than the number of child units in <code>refNode</code>. Child units
215     *   are 16-bit units if <code>refNode</code> is a type of DOMCharacterData
216     *   node (e.g., a DOMText or DOMComment node) or a DOMProcessingInstruction
217     *   node. Child units are Nodes in all other cases.
218     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
219     *   been invoked on this object.
220     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
221     *   from a different document than the one that created this range.
222     *
223     * @since DOM Level 2
224     */
225    virtual void setEnd(const DOMNode *refNode, XMLSize_t offset) = 0;
226
227    /**
228     * Sets the start position to be before a node
229     * @param refNode Range starts before <code>refNode</code>
230     * @exception DOMRangeException
231     *   INVALID_NODE_TYPE_ERR: Raised if the root container of
232     *   <code>refNode</code> is not an DOMAttr, DOMDocument, or DOMDocumentFragment
233     *   node or if <code>refNode</code> is a DOMDocument, DOMDocumentFragment,
234     *   DOMAttr, DOMEntity, or DOMNotation node.
235     * @exception DOMException
236     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
237     *   invoked on this object.
238     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
239     *   from a different document than the one that created this range.
240     *
241     * @since DOM Level 2
242     */
243    virtual void setStartBefore(const DOMNode *refNode) = 0;
244
245    /**
246     * Sets the start position to be after a node
247     * @param refNode Range starts after <code>refNode</code>
248     * @exception DOMRangeException
249     *   INVALID_NODE_TYPE_ERR: Raised if the root container of
250     *   <code>refNode</code> is not an DOMAttr, DOMDocument, or DOMDocumentFragment
251     *   node or if <code>refNode</code> is a DOMDocument, DOMDocumentFragment,
252     *   DOMAttr, DOMEntity, or DOMNotation node.
253     * @exception DOMException
254     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
255     *   invoked on this object.
256     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
257     *   from a different document than the one that created this range.
258     *
259     * @since DOM Level 2
260     */
261    virtual void setStartAfter(const DOMNode *refNode) = 0;
262
263    /**
264     * Sets the end position to be before a node.
265     * @param refNode Range ends before <code>refNode</code>
266     * @exception DOMRangeException
267     *   INVALID_NODE_TYPE_ERR: Raised if the root container of
268     *   <code>refNode</code> is not an DOMAttr, DOMDocument, or DOMDocumentFragment
269     *   node or if <code>refNode</code> is a DOMDocument, DOMDocumentFragment,
270     *   DOMAttr, DOMEntity, or DOMNotation node.
271     * @exception DOMException
272     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
273     *   invoked on this object.
274     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
275     *   from a different document than the one that created this range.
276     *
277     * @since DOM Level 2
278     */
279    virtual void setEndBefore(const DOMNode *refNode) = 0;
280
281    /**
282     * Sets the end of a Range to be after a node
283     * @param refNode Range ends after <code>refNode</code>.
284     * @exception DOMRangeException
285     *   INVALID_NODE_TYPE_ERR: Raised if the root container of
286     *   <code>refNode</code> is not a DOMAttr, DOMDocument or DOMDocumentFragment
287     *   node or if <code>refNode</code> is a DOMDocument, DOMDocumentFragment,
288     *   DOMAttr, DOMEntity, or DOMNotation node.
289     * @exception DOMException
290     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
291     *   invoked on this object.
292     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
293     *   from a different document than the one that created this range.
294     *
295     * @since DOM Level 2
296     */
297    virtual void setEndAfter(const DOMNode *refNode) = 0;
298
299    // -----------------------------------------------------------------------
300    //  Misc methods
301    // -----------------------------------------------------------------------
302    /**
303     * Collapse a Range onto one of its boundary-points
304     * @param toStart If TRUE, collapses the Range onto its start; if FALSE,
305     *   collapses it onto its end.
306     * @exception DOMException
307     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
308     *   invoked on this object.
309     *
310     * @since DOM Level 2
311     */
312    virtual void collapse(bool toStart) = 0;
313
314    /**
315     * Select a node and its contents
316     * @param refNode The node to select.
317     * @exception DOMRangeException
318     *   INVALID_NODE_TYPE_ERR: Raised if an ancestor of <code>refNode</code>
319     *   is an DOMEntity, DOMNotation or DOMDocumentType node or if
320     *   <code>refNode</code> is a DOMDocument, DOMDocumentFragment, DOMAttr, DOMEntity,
321     *   or DOMNotation node.
322     * @exception DOMException
323     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
324     *   invoked on this object.
325     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
326     *   from a different document than the one that created this range.
327     *
328     * @since DOM Level 2
329     */
330    virtual void selectNode(const DOMNode *refNode) = 0;
331
332    /**
333     * Select the contents within a node
334     * @param refNode DOMNode to select from
335     * @exception DOMRangeException
336     *   INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> or an ancestor
337     *   of <code>refNode</code> is an DOMEntity, DOMNotation or DOMDocumentType node.
338     * @exception DOMException
339     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
340     *   invoked on this object.
341     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>refNode</code> was created
342     *   from a different document than the one that created this range.
343     *
344     * @since DOM Level 2
345     */
346    virtual void selectNodeContents(const DOMNode *refNode) = 0;
347
348    /**
349     * Compare the boundary-points of two Ranges in a document.
350     * @param how A code representing the type of comparison, as defined
351     *   above.
352     * @param sourceRange The <code>Range</code> on which this current
353     *   <code>Range</code> is compared to.
354     * @return  -1, 0 or 1 depending on whether the corresponding
355     *   boundary-point of the Range is respectively before, equal to, or
356     *   after the corresponding boundary-point of <code>sourceRange</code>.
357     * @exception DOMException
358     *   WRONG_DOCUMENT_ERR: Raised if the two Ranges are not in the same
359     *   DOMDocument or DOMDocumentFragment.
360     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
361     *   been invoked on this object.
362     *
363     * @since DOM Level 2
364     */
365    virtual short compareBoundaryPoints(CompareHow how, const DOMRange* sourceRange) const = 0;
366
367    /**
368     * Removes the contents of a Range from the containing document or
369     * document fragment without returning a reference to the removed
370     * content.
371     * @exception DOMException
372     *   NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of
373     *   the Range is read-only or any of the nodes that contain any of the
374     *   content of the Range are read-only.
375     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
376     *   been invoked on this object.
377     *
378     * @since DOM Level 2
379     */
380    virtual void deleteContents() = 0;
381
382    /**
383     * Moves the contents of a Range from the containing document or document
384     * fragment to a new DOMDocumentFragment.
385     * @return A DOMDocumentFragment containing the extracted contents.
386     * @exception DOMException
387     *   NO_MODIFICATION_ALLOWED_ERR: Raised if any portion of the content of
388     *   the Range is read-only or any of the nodes which contain any of the
389     *   content of the Range are read-only.
390     *   <br>HIERARCHY_REQUEST_ERR: Raised if a DOMDocumentType node would be
391     *   extracted into the new DOMDocumentFragment.
392     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
393     *   been invoked on this object.
394     *
395     * @since DOM Level 2
396     */
397    virtual DOMDocumentFragment* extractContents() = 0;
398
399    /**
400     * Duplicates the contents of a Range
401     * @return A DOMDocumentFragment that contains content equivalent to this
402     *   Range.
403     * @exception DOMException
404     *   HIERARCHY_REQUEST_ERR: Raised if a DOMDocumentType node would be
405     *   extracted into the new DOMDocumentFragment.
406     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
407     *   been invoked on this object.
408     *
409     * @since DOM Level 2
410     */
411    virtual DOMDocumentFragment* cloneContents() const = 0;
412
413    /**
414     * Inserts a node into the DOMDocument or DOMDocumentFragment at the start of
415     * the Range. If the container is a DOMText node, this will be split at the
416     * start of the Range (as if the DOMText node's splitText method was
417     * performed at the insertion point) and the insertion will occur
418     * between the two resulting DOMText nodes. Adjacent DOMText nodes will not be
419     * automatically merged. If the node to be inserted is a
420     * DOMDocumentFragment node, the children will be inserted rather than the
421     * DOMDocumentFragment node itself.
422     * @param newNode The node to insert at the start of the Range
423     * @exception DOMException
424     *   NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of the
425     *   start of the Range is read-only.
426     *   <br>WRONG_DOCUMENT_ERR: Raised if <code>newNode</code> and the
427     *   container of the start of the Range were not created from the same
428     *   document.
429     *   <br>HIERARCHY_REQUEST_ERR: Raised if the container of the start of
430     *   the Range is of a type that does not allow children of the type of
431     *   <code>newNode</code> or if <code>newNode</code> is an ancestor of
432     *   the container.
433     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
434     *   been invoked on this object.
435     * @exception DOMRangeException
436     *   INVALID_NODE_TYPE_ERR: Raised if <code>newNode</code> is an DOMAttr,
437     *   DOMEntity, DOMNotation, or DOMDocument node.
438     *
439     * @since DOM Level 2
440     */
441    virtual void insertNode(DOMNode *newNode) = 0;
442
443    /**
444     * Reparents the contents of the Range to the given node and inserts the
445     * node at the position of the start of the Range.
446     * @param newParent The node to surround the contents with.
447     * @exception DOMException
448     *   NO_MODIFICATION_ALLOWED_ERR: Raised if an ancestor container of
449     *   either boundary-point of the Range is read-only.
450     *   <br>WRONG_DOCUMENT_ERR: Raised if <code> newParent</code> and the
451     *   container of the start of the Range were not created from the same
452     *   document.
453     *   <br>HIERARCHY_REQUEST_ERR: Raised if the container of the start of
454     *   the Range is of a type that does not allow children of the type of
455     *   <code>newParent</code> or if <code>newParent</code> is an ancestor
456     *   of the container or if <code>node</code> would end up with a child
457     *   node of a type not allowed by the type of <code>node</code>.
458     *   <br>INVALID_STATE_ERR: Raised if <code>detach()</code> has already
459     *   been invoked on this object.
460     * @exception DOMRangeException
461     *   BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a
462     *   non-text node.
463     *   <br>INVALID_NODE_TYPE_ERR: Raised if <code> node</code> is an DOMAttr,
464     *   DOMEntity, DOMDocumentType, DOMNotation, DOMDocument, or DOMDocumentFragment node.
465     *
466     * @since DOM Level 2
467     */
468    virtual void surroundContents(DOMNode *newParent) = 0;
469
470    /**
471     * Produces a new Range whose boundary-points are equal to the
472     * boundary-points of the Range.
473     * @return The duplicated Range.
474     * @exception DOMException
475     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
476     *   invoked on this object.
477     *
478     * @since DOM Level 2
479     */
480    virtual DOMRange* cloneRange() const = 0;
481
482    /**
483     * Returns the contents of a Range as a string. This string contains only
484     * the data characters, not any markup.
485     * @return The contents of the Range.
486     * @exception DOMException
487     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
488     *   invoked on this object.
489     *
490     * @since DOM Level 2
491     */
492    virtual const XMLCh* toString() const = 0;
493
494    /**
495     * Called to indicate that the Range is no longer in use and that the
496     * implementation may relinquish any resources associated with this
497     * Range. Subsequent calls to any methods or attribute getters on this
498     * Range will result in a <code>DOMException</code> being thrown with an
499     * error code of <code>INVALID_STATE_ERR</code>.
500     * @exception DOMException
501     *   INVALID_STATE_ERR: Raised if <code>detach()</code> has already been
502     *   invoked on this object.
503     *
504     * @since DOM Level 2
505     */
506    virtual void detach() = 0;
507
508    //@}
509
510    // -----------------------------------------------------------------------
511    //  Non-standard Extension
512    // -----------------------------------------------------------------------
513    /** @name Non-standard Extension */
514    //@{
515    /**
516     * Called to indicate that this Range is no longer in use
517     * and that the implementation may relinquish any resources associated with it.
518     * (release() will call detach() where appropriate)
519     *
520     * Access to a released object will lead to unexpected result.
521     */
522    virtual void release() = 0;
523    //@}
524};
525
526
527XERCES_CPP_NAMESPACE_END
528
529#endif
Note: See TracBrowser for help on using the repository browser.