Base class for all XML objects in a document. More...
Public Member Functions | |
virtual | ~Node () override |
Virtual destructor. | |
size_t | childrenCount () const |
Get the number of children. More... | |
virtual void | clear () |
Clear the content of the node. More... | |
virtual Node * | clone () const =0 |
Clone the content of the node in a dynamically allocated object. More... | |
UString | debug () const |
Build a debug string for the node. More... | |
size_t | depth () const |
Get the depth of an XML element. More... | |
Document * | document () |
Get the document into which the node is located. More... | |
const Document * | document () const |
Get the document into which the node is located. More... | |
Node * | firstChild () |
Get the first child of a node. More... | |
const Node * | firstChild () const |
Get the first child of a node. More... | |
Element * | firstChildElement () |
Get the first child Element of a node. More... | |
const Element * | firstChildElement () const |
Get the first child Element of a node. More... | |
bool | hasChildren () const |
Check if the node has children. More... | |
Node * | lastChild () |
Get the last child. More... | |
const Node * | lastChild () const |
Get the last child. More... | |
size_t | lineNumber () const |
Get the line number in input document. More... | |
Node * | nextSibling () |
Get the next sibling node. More... | |
const Node * | nextSibling () const |
Get the next sibling node. More... | |
Element * | nextSiblingElement () |
Find the next sibling element. More... | |
const Element * | nextSiblingElement () const |
Find the next sibling element. More... | |
Node * | parent () |
Get the parent's node. More... | |
const Node * | parent () const |
Get the parent's node. More... | |
Node * | previousSibling () |
Get the previous sibling node. More... | |
const Node * | previousSibling () const |
Get the previous sibling node. More... | |
virtual void | print (TextFormatter &output, bool keepNodeOpen=false) const =0 |
Format the node for an output XML document. More... | |
virtual void | printClose (TextFormatter &output, size_t levels=std::numeric_limits< size_t >::max()) const |
Print the closing tags for the node. More... | |
virtual void | reparent (Node *newParent, bool last=true) |
Attach the node to a new parent. More... | |
Report & | report () const |
Get a reference to the report object for the XML node. More... | |
bool | ringAlone () const |
Check if the node is alone in its own ring. More... | |
void | ringInsertAfter (RingNode *o) |
Insert this object in a ring after the specified node. More... | |
void | ringInsertBefore (RingNode *o) |
Insert this object in a ring before the specified node. More... | |
template<typename T > | |
T * | ringNext () |
Get the next node in the ring. More... | |
template<typename T > | |
const T * | ringNext () const |
Get the next node in the ring. More... | |
template<typename T > | |
T * | ringPrevious () |
Get the previous node in the ring. More... | |
template<typename T > | |
const T * | ringPrevious () const |
Get the previous node in the ring. More... | |
void | ringRemove () |
Remove the node from the ring it belongs to and creates its own ring. | |
size_t | ringSize () const |
Count the number of element in the ring. More... | |
void | ringSwap (RingNode *o) |
Swap this object and another one in their rings. More... | |
void | setValue (const UString &value) |
Set the value of the node. More... | |
virtual bool | stickyOutput () const |
Check if the text shall be stuck to other elements in XML output. More... | |
virtual const Tweaks & | tweaks () const |
Get a constant reference to the current XML parsing and formatting tweaks for this node. More... | |
virtual UString | typeName () const =0 |
Return a node type name, mainly for debug purpose. More... | |
const UString & | value () const |
Get the value of the node. More... | |
Protected Member Functions | |
Node (const Node &other) | |
Copy constructor. More... | |
Node (Node *parent, const UString &value=UString(), bool last=true) | |
Constructor. More... | |
Node (Report &report, size_t line=0) | |
Constructor. More... | |
Node * | identifyNextNode (TextParser &parser) |
Identify the next token in the document. More... | |
virtual bool | parseChildren (TextParser &parser) |
Parse children nodes and add them to the node. More... | |
virtual bool | parseNode (TextParser &parser, const Node *parent)=0 |
Parse the node. More... | |
Base class for all XML objects in a document.
Implementation note on inheritance: Node is a subclass of RingNode. The "ring" is used to link all siblings. This inheritance should be private since it is an internal characteristics of Node. However, if we make this inheritance private, the dynamic_cast operations in RingNode fail. This is a very annoying C++ feature.
|
explicitprotected |
Constructor.
[in,out] | report | Where to report errors. |
[in] | line | Line number in input document. |
|
protected |
Copy constructor.
[in] | other | Other instance to copy. |
|
explicitprotected |
Constructor.
[in,out] | parent | The parent document into which the declaration is added. |
[in] | value | Value of the node. |
[in] | last | If true, the child is added at the end of the list of children. If false, it is added at the beginning. |
|
inline |
Get the line number in input document.
|
virtual |
Clear the content of the node.
The node becomes empty but remains attached to its parent.
Reimplemented in ts::xml::Element.
|
pure virtual |
Clone the content of the node in a dynamically allocated object.
This virtual method must be implemented by subclasses to allocate a object of the right class.
Implemented in ts::xml::Unknown, ts::xml::Text, ts::xml::Element, ts::xml::Document, ts::xml::Declaration, and ts::xml::Comment.
|
virtual |
Attach the node to a new parent.
The node is first detached from its previous parent.
[in,out] | newParent | New parent. If zero, the node becomes orphan. In that case, the node will no longer be freed by its parent and must be explicitly deleted. |
[in] | last | If true, the child is added at the end of the list of children. If false, it is added at the beginning. |
|
inline |
Get the parent's node.
|
inline |
Get the parent's node.
|
inline |
Get the document into which the node is located.
Document* ts::xml::Node::document | ( | ) |
Get the document into which the node is located.
|
virtual |
Get a constant reference to the current XML parsing and formatting tweaks for this node.
Reimplemented in ts::xml::Document.
size_t ts::xml::Node::depth | ( | ) | const |
Get the depth of an XML element.
|
inline |
Check if the node has children.
|
inline |
Get the number of children.
|
inline |
Get the first child of a node.
|
inline |
Get the first child of a node.
|
inline |
Get the last child.
|
inline |
Get the last child.
|
inline |
Get the next sibling node.
Node* ts::xml::Node::nextSibling | ( | ) |
Get the next sibling node.
|
inline |
Get the previous sibling node.
Node* ts::xml::Node::previousSibling | ( | ) |
Get the previous sibling node.
|
inline |
Element* ts::xml::Node::firstChildElement | ( | ) |
|
inline |
Find the next sibling element.
Element* ts::xml::Node::nextSiblingElement | ( | ) |
Find the next sibling element.
|
inline |
Get the value of the node.
The semantic of the value depends on the node subclass:
|
inline |
|
pure virtual |
Return a node type name, mainly for debug purpose.
Implemented in ts::xml::Unknown, ts::xml::Text, ts::xml::Element, ts::xml::Document, ts::xml::Declaration, and ts::xml::Comment.
|
pure virtual |
Format the node for an output XML document.
[in,out] | output | The output object to format the XML document. |
[in] | keepNodeOpen | If true, keep the node open so that children may be printed later. |
Implemented in ts::xml::Unknown, ts::xml::Text, ts::xml::Element, ts::xml::Document, ts::xml::Declaration, and ts::xml::Comment.
|
virtual |
Print the closing tags for the node.
Typically used after print() when keepNodeOpen was true. The default implementation is to do nothing. Subclasses may replace this.
[in,out] | output | The output object to format the XML document. |
[in] | levels | Number of levels to close. By default, close the complete document. If zero, no output is produced. |
Reimplemented in ts::xml::Element, and ts::xml::Document.
|
virtual |
Check if the text shall be stuck to other elements in XML output.
Reimplemented in ts::xml::Text.
UString ts::xml::Node::debug | ( | ) | const |
Build a debug string for the node.
|
inline |
Get a reference to the report object for the XML node.
|
protected |
Identify the next token in the document.
[in,out] | parser | The document parser. |
|
protectedpure virtual |
Parse the node.
[in,out] | parser | The document parser. On input, the current position of the parser after the tag which identified the node ("<?", "<!--", etc.) On output, it must be after the last character of the node. |
[in] | parent | Candidate parent node, for information only, do not modify. Can be null. |
Implemented in ts::xml::Unknown, ts::xml::Text, ts::xml::Element, ts::xml::Document, ts::xml::Declaration, and ts::xml::Comment.
|
protectedvirtual |
Parse children nodes and add them to the node.
Stop either at end of document or before a "</" sequence or on error.
[in,out] | parser | The document parser. |
|
inlineinherited |
Check if the node is alone in its own ring.
|
inherited |
Insert this object in a ring after the specified node.
[in] | o | A node of a ring. This object is inserted after o in the ring. |
|
inherited |
Insert this object in a ring before the specified node.
[in] | o | A node of a ring. This object is inserted before o in the ring. |
|
inherited |
Swap this object and another one in their rings.
If the two objects belong to the same ring, their positions are swapped. If they belong to distinct rings, they also move to each other's ring.
[in] | o | The node to swap with. |
|
inlineinherited |
Get the next node in the ring.
T | A superclass of RingNode, the expected type of the next object in the ring. |
|
inlineinherited |
Get the next node in the ring.
T | A superclass of RingNode, the expected type of the next object in the ring. |
|
inlineinherited |
Get the previous node in the ring.
T | A superclass of RingNode, the expected type of the previous object in the ring. |
|
inlineinherited |
Get the previous node in the ring.
T | A superclass of RingNode, the expected type of the previous object in the ring. |
|
inherited |
Count the number of element in the ring.
Warning: This method has a linear response time, avoid using it when possible.