[80] | 1 | // |
---|
| 2 | // Name.h |
---|
| 3 | // |
---|
| 4 | // $Id: //poco/1.3/XML/include/Poco/XML/Name.h#1 $ |
---|
| 5 | // |
---|
| 6 | // Library: XML |
---|
| 7 | // Package: XML |
---|
| 8 | // Module: Name |
---|
| 9 | // |
---|
| 10 | // Definition of the Name class. |
---|
| 11 | // |
---|
| 12 | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
---|
| 13 | // and Contributors. |
---|
| 14 | // |
---|
| 15 | // Permission is hereby granted, free of charge, to any person or organization |
---|
| 16 | // obtaining a copy of the software and accompanying documentation covered by |
---|
| 17 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
| 18 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
| 19 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
| 20 | // do so, all subject to the following: |
---|
| 21 | // |
---|
| 22 | // The copyright notices in the Software and this entire statement, including |
---|
| 23 | // the above license grant, this restriction and the following disclaimer, |
---|
| 24 | // must be included in all copies of the Software, in whole or in part, and |
---|
| 25 | // all derivative works of the Software, unless such copies or derivative |
---|
| 26 | // works are solely in the form of machine-executable object code generated by |
---|
| 27 | // a source language processor. |
---|
| 28 | // |
---|
| 29 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 30 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 31 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
| 32 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
| 33 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
| 34 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
| 35 | // DEALINGS IN THE SOFTWARE. |
---|
| 36 | // |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | #ifndef XML_Name_INCLUDED |
---|
| 40 | #define XML_Name_INCLUDED |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | #include "Poco/XML/XML.h" |
---|
| 44 | #include "Poco/XML/XMLString.h" |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | namespace Poco { |
---|
| 48 | namespace XML { |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | class XML_API Name |
---|
| 52 | /// An XML element or attribute name, consisting of a |
---|
| 53 | /// qualified name, a namespace URI and a local name. |
---|
| 54 | { |
---|
| 55 | public: |
---|
| 56 | Name(); |
---|
| 57 | /// Creates an empty Name. |
---|
| 58 | |
---|
| 59 | Name(const XMLString& qname); |
---|
| 60 | /// Creates a Name from a qualified name only. |
---|
| 61 | |
---|
| 62 | Name(const XMLString& qname, const XMLString& namespaceURI); |
---|
| 63 | /// Creates a Name from a qualified name and a namespace URI. |
---|
| 64 | /// The local name is extracted from the qualified name. |
---|
| 65 | |
---|
| 66 | Name(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); |
---|
| 67 | /// Creates a Name from a qualified name, a namespace URI and a local name. |
---|
| 68 | |
---|
| 69 | Name(const Name& name); |
---|
| 70 | /// Copy constructor. |
---|
| 71 | |
---|
| 72 | ~Name(); |
---|
| 73 | /// Destroys the name. |
---|
| 74 | |
---|
| 75 | Name& operator = (const Name& name); |
---|
| 76 | /// Assignment operator. |
---|
| 77 | |
---|
| 78 | void swap(Name& name); |
---|
| 79 | /// Swaps the name with another one. |
---|
| 80 | |
---|
| 81 | void assign(const XMLString& qname); |
---|
| 82 | /// Assigns a new value to the name. |
---|
| 83 | |
---|
| 84 | void assign(const XMLString& qname, const XMLString& namespaceURI); |
---|
| 85 | /// Assigns new values to the name. |
---|
| 86 | /// The local name is extracted from the qualified name. |
---|
| 87 | |
---|
| 88 | void assign(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName); |
---|
| 89 | /// Assigns new values to the name. |
---|
| 90 | |
---|
| 91 | bool equals(const Name& name) const; |
---|
| 92 | /// Returns true if both names are equal. |
---|
| 93 | |
---|
| 94 | bool equals(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const; |
---|
| 95 | /// Returns true if all the name's components are equal to the given ones. |
---|
| 96 | |
---|
| 97 | bool equalsWeakly(const XMLString& qname, const XMLString& namespaceURI, const XMLString& localName) const; |
---|
| 98 | /// Returns true if either the qnames are identical or the namespaceURIs and the localNames are identical. |
---|
| 99 | |
---|
| 100 | const XMLString& qname() const; |
---|
| 101 | /// Returns the qualified name. |
---|
| 102 | |
---|
| 103 | const XMLString& namespaceURI() const; |
---|
| 104 | /// Returns the namespace URI. |
---|
| 105 | |
---|
| 106 | const XMLString& localName() const; |
---|
| 107 | /// Returns the local name. |
---|
| 108 | |
---|
| 109 | XMLString prefix() const; |
---|
| 110 | /// Returns the namespace prefix. |
---|
| 111 | |
---|
| 112 | static void split(const XMLString& qname, XMLString& prefix, XMLString& localName); |
---|
| 113 | /// Splits the given qualified name into its prefix and localName parts. |
---|
| 114 | |
---|
| 115 | static XMLString localName(const XMLString& qname); |
---|
| 116 | /// Returns the local name part of the given qualified name. |
---|
| 117 | |
---|
| 118 | static XMLString prefix(const XMLString& qname); |
---|
| 119 | /// Returns the prefix part of the given qualified name. |
---|
| 120 | |
---|
| 121 | static const XMLString EMPTY_NAME; |
---|
| 122 | |
---|
| 123 | private: |
---|
| 124 | XMLString _qname; |
---|
| 125 | XMLString _namespaceURI; |
---|
| 126 | XMLString _localName; |
---|
| 127 | }; |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | // |
---|
| 131 | // inlines |
---|
| 132 | // |
---|
| 133 | inline const XMLString& Name::qname() const |
---|
| 134 | { |
---|
| 135 | return _qname; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | inline const XMLString& Name::namespaceURI() const |
---|
| 140 | { |
---|
| 141 | return _namespaceURI; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | inline const XMLString& Name::localName() const |
---|
| 146 | { |
---|
| 147 | return _localName; |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | inline void swap(Name& n1, Name& n2) |
---|
| 152 | { |
---|
| 153 | n1.swap(n2); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | } } // namespace Poco::XML |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | #endif // XML_Name_INCLUDED |
---|