Imported Upstream version 17.23.5
[platform/upstream/libzypp.git] / zypp / parser / xml / Node.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/xml/Node.h
10  *
11 */
12 #ifndef ZYPP_PARSER_XML_NODE_H
13 #define ZYPP_PARSER_XML_NODE_H
14
15 #include <iosfwd>
16
17 #include <zypp/parser/xml/XmlString.h>
18
19 ///////////////////////////////////////////////////////////////////
20 namespace zypp
21 { /////////////////////////////////////////////////////////////////
22   ///////////////////////////////////////////////////////////////////
23   namespace xml
24   { /////////////////////////////////////////////////////////////////
25
26     ///////////////////////////////////////////////////////////////////
27     //
28     //  CLASS NAME : Node
29     //
30     /** xmlTextReader based interface to \ref Reader's current node.
31      * Node provides xmlTextReader methods that do not change
32      * the readers position in the file. Mostly access to the
33      * nodes attributes.
34      **/
35     class Node
36     {
37     public:
38       /** Default ctor. */
39       Node();
40
41       /** Ctor referencing a \ref Reader. */
42       Node( xmlTextReaderPtr const & reader_r );
43
44       /** Validate Node in a boolean context. */
45       explicit operator bool() const
46       { return _reader; }
47
48     public:
49       /** Provides the number of attributes of the current node. */
50       int attributeCount() const
51       { return xmlTextReaderAttributeCount( _reader ); }
52
53       /** The base URI of the node. */
54       XmlString baseUri() const
55       { return xmlTextReaderConstBaseUri( _reader ); }
56
57       /** Provide the column number of the current parsing point. */
58       int columnNumber() const
59       { return xmlTextReaderGetParserColumnNumber( _reader ); }
60
61       /** The depth of the node in the tree. */
62       int depth() const
63       { return xmlTextReaderDepth( _reader ); }
64
65       /** Determine the encoding of the document being read. */
66       XmlString encoding() const
67       { return xmlTextReaderConstEncoding( _reader ); }
68
69       /** Provides a copy of the attribute value with the specified
70        * qualified name. */
71       XmlString getAttribute( const char * name_r ) const
72       { return XmlString( xmlTextReaderGetAttribute( _reader, reinterpret_cast<const xmlChar *>(name_r) ),
73                           XmlString::FREE ); }
74       /** \overload */
75       XmlString getAttribute( const std::string & name_r ) const
76       { return getAttribute( name_r.c_str() ); }
77
78       /** Provides a copy of the attribute value  with the specified
79        * index relative to the containing element. */
80       XmlString getAttributeNo( int no_r ) const
81       { return XmlString( xmlTextReaderGetAttributeNo( _reader, no_r ), XmlString::FREE ); }
82
83       /** Whether the node has attributes. */
84       int hasAttributes() const
85       { return xmlTextReaderHasAttributes( _reader ); }
86
87       /** Whether the node can have a text value. */
88       int hasValue() const
89       { return xmlTextReaderHasValue( _reader ); }
90
91       /** Whether this is an Attribute node. */
92       bool isAttribute() const
93       { return( nodeType() == XML_READER_TYPE_ATTRIBUTE ); }
94
95       /** Whether an Attribute node was generated from the default value
96        *  defined in the DTD or schema. */
97       int isDefault() const
98       { return xmlTextReaderIsDefault( _reader ); }
99
100       /** Check if the current node is empty. */
101       int isEmptyElement() const
102       { return xmlTextReaderIsEmptyElement( _reader ); }
103
104       /** Determine whether the current node is a namespace declaration
105        *  rather than a regular attribute.*/
106       int isNamespaceDecl() const
107       { return xmlTextReaderIsNamespaceDecl( _reader ); }
108
109       /** Provide the line number of the current parsing point. */
110       int lineNumber() const
111       { return xmlTextReaderGetParserLineNumber( _reader ); }
112
113       /** The local name of the node. */
114       XmlString localName() const
115       { return xmlTextReaderConstLocalName( _reader ); }
116
117       /** The qualified name of the node, equal to Prefix :LocalName. */
118       XmlString name() const
119       { return xmlTextReaderConstName( _reader ); }
120
121       /** The URI defining the namespace associated with the node. */
122       XmlString namespaceUri() const
123       { return xmlTextReaderConstNamespaceUri( _reader ); }
124
125       /** Get the node type of the current node. */
126       NodeType nodeType() const
127       { return (NodeType)xmlTextReaderNodeType( _reader ); }
128
129       /** A shorthand reference to the namespace associated with the node. */
130       XmlString prefix() const
131       { return xmlTextReaderConstPrefix( _reader ); }
132
133       /** The quotation mark character used to enclose the value of an attribute.
134        * \return \c " or \c ' or -1 in case of error. */
135       int quoteChar() const
136       { return xmlTextReaderQuoteChar( _reader ); }
137
138       /** Gets the read state of the reader. */
139       ReadState readState() const
140       { return (ReadState)xmlTextReaderReadState( _reader ); }
141
142       /** Provides the text value of the node if present. */
143       XmlString value() const
144       { return xmlTextReaderConstValue( _reader ); }
145
146       /** Provides a copy of the text value of the node if present. */
147       XmlString getValue() const
148       { return XmlString( xmlTextReaderValue( _reader ), XmlString::FREE ); }
149
150       /** The xml:lang scope within which the node resides. */
151       XmlString xmlLang() const
152       { return xmlTextReaderConstXmlLang( _reader ); }
153
154       /** Determine the XML version of the document being read. */
155       XmlString xmlVersion() const
156       { return xmlTextReaderConstXmlVersion( _reader ); }
157
158     private:
159       /** NULL Reader referenced by default ctor. */
160       static xmlTextReaderPtr const _no_reader;
161       /** Reference to the \ref Reader. */
162       xmlTextReaderPtr const & _reader;
163     };
164     ///////////////////////////////////////////////////////////////////
165
166     /** \relates Node Stream output. */
167     std::ostream & operator<<( std::ostream & str, const Node & obj );
168
169     /////////////////////////////////////////////////////////////////
170   } // namespace xml
171   ///////////////////////////////////////////////////////////////////
172   /////////////////////////////////////////////////////////////////
173 } // namespace zypp
174 ///////////////////////////////////////////////////////////////////
175 #endif // ZYPP_PARSER_XML_NODE_H