1 /* 2 * This library is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU Lesser General Public 4 * License as published by the Free Software Foundation; either 5 * version 2.1 of the License, or (at your option) any later version. 6 * 7 * As a special exception, you may use this file as part of a free 8 * software library without restriction. Specifically, if other files 9 * instantiate templates or use macros or inline functions from this 10 * file, or you compile this file and link it with other files to 11 * produce an executable, this file does not by itself cause the 12 * resulting executable to be covered by the GNU General Public 13 * License. This exception does not however invalidate any other 14 * reasons why the executable file might be covered by the GNU Library 15 * General Public License. 16 * 17 * This library is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 * Lesser General Public License for more details. 21 * 22 * You should have received a copy of the GNU Lesser General Public 23 * License along with this library; if not, write to the Free Software 24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 25 */ 26 #ifndef cxxtools_Xml_Node_h 27 #define cxxtools_Xml_Node_h 28 29 #include <cxxtools/xml/api.h> 30 31 namespace cxxtools { 32 33 namespace xml { 34 35 /** 36 * @brief The super-class for all specific Node type of an XML document. 37 * 38 * A Node may for example be a opening tag, a closing tag, a comment or a doctype declaration. 39 * The supported node types are contained in the enum Type. To determine the type of a Node the 40 * method type() can be used. 41 * 42 * For every supported node type (except "Unknown") a specialized class exists that is derived 43 * from this Node class. Those classes contain more data and access methods to allow the user 44 * to determine the information specific to the node, for example the tag name for a StartElement. 45 * 46 * This class mainly provides the method type() to determine the type of the Node. The user 47 * may use this information to determine to which specialized class that is associated 48 * with the type this object can be cast; for the Node::StartElement type the Node object can be 49 * cast to StartElement, for example. 50 * 51 * @see Type 52 */ 53 class CXXTOOLS_XML_API Node { 54 public: 55 enum Type { 56 //! Unknown Node type (may not currently be supported) 57 Unknown = 0, 58 //! Xml declaration (see class XmlDeclaration) 59 StartDocument = 1, 60 //! Doctype (see class DocType) 61 DocType = 2, 62 //! End of the document (see EndDocument) 63 EndDocument = 3, 64 //! Start element aka opening tag (see StartElement) 65 StartElement = 4, 66 //! End element aka closing tag (see EndElement) 67 EndElement = 5, 68 //! Parsed content of a tag's body (see Characters) 69 Characters = 6, 70 //! Comment (see Comment) 71 Comment, 72 //! Processing instruction (see ProcessingInstruction) 73 ProcessingInstruction 74 }; 75 76 public: 77 /** 78 * @brief Constructs a new Node object with the specified node type 79 * @see Type 80 */ Node(Type type)81 Node(Type type) 82 : _type(type) 83 { } 84 85 //! Empty destructor ~Node()86 virtual ~Node() 87 { } 88 89 /** 90 * @brief Returns the type of this Node that can be used to determine what specific 91 * Node this object is. 92 * 93 * This information may be used to determine to which specialized Node class that is associated 94 * with the type, this Node object can be cast; for the Node::StartElement type the Node object 95 * can be cast to StartElement, for example. 96 * 97 * @return The type of this node. 98 */ type()99 Type type() const 100 {return _type;} 101 102 /** 103 * @brief Compares this Node object with the given node. 104 * 105 * The return value of the generic operator== method is always false. Class which derive 106 * from this class should always override this method and provide a useful comparison, for 107 * example by comparing the node type and contents of the current and given Node object 108 * 109 * @param node In subclasses this Node object is compared to the current Node object. 110 * @return In sub-classes $true is returned if this Node object is the same as the given 111 * Node object. In this generic class $false$ is always returned. 112 */ 113 virtual bool operator==(const Node& node) const 114 { return false; } 115 116 virtual Node* clone() const = 0; 117 118 private: 119 //! The type of this Node. 120 Type _type; 121 }; 122 123 } 124 125 } 126 127 #endif 128