2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
20 * Representing XML QNames
\r
23 #if !defined(__xmltooling_qname_h__)
\r
24 #define __xmltooling_qname_h__
\r
26 #include <algorithm>
\r
27 #include <xmltooling/unicode.h>
\r
29 namespace xmltooling {
\r
32 * A data structure for encapsulating XML QNames.
\r
33 * The Xerces class is too limited to use at the moment.
\r
35 class XMLTOOL_API QName
\r
40 * @param uri namespace URI
\r
41 * @param localPart local name
\r
42 * @param prefix namespace prefix (without the colon)
\r
44 QName(const XMLCh* uri=NULL, const XMLCh* localPart=NULL, const XMLCh* prefix=NULL);
\r
47 #ifndef HAVE_GOOD_STL
\r
49 * Deep copy constructor
\r
51 QName(const QName& src);
\r
54 * Deep assignment operator
\r
56 QName& operator=(const QName& src);
\r
59 #ifdef HAVE_GOOD_STL
\r
61 * Indicates whether the QName has a prefix.
\r
62 * @return true iff the prefix is non-empty
\r
64 bool hasPrefix() const { return !m_prefix.empty(); }
\r
67 * Indicates whether the QName has a non-empty namespace.
\r
68 * @return true iff the namespace is non-empty
\r
70 bool hasNamespaceURI() const { return !m_uri.empty(); }
\r
73 * Indicates whether the QName has a non-empty local name.
\r
74 * @return true iff the local name is non-empty
\r
76 bool hasLocalPart() const { return !m_local.empty(); }
\r
79 * Returns the namespace prefix
\r
80 * @return Null-terminated Unicode string containing the prefix, without the colon
\r
82 const XMLCh* getPrefix() const { return m_prefix.c_str(); }
\r
85 * Returns the namespace URI
\r
86 * @return Null-terminated Unicode string containing the URI
\r
88 const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }
\r
91 * Returns the local part of the name
\r
92 * @return Null-terminated Unicode string containing the local name
\r
94 const XMLCh* getLocalPart() const { return m_local.c_str(); }
\r
97 * Indicates whether the QName has a prefix.
\r
98 * @return true iff the prefix is non-empty
\r
100 bool hasPrefix() const { return m_prefix && *m_prefix; }
\r
103 * Indicates whether the QName has a non-empty namespace.
\r
104 * @return true iff the namespace is non-empty
\r
106 bool hasNamespaceURI() const { return m_uri && *m_uri; }
\r
109 * Indicates whether the QName has a non-empty local name.
\r
110 * @return true iff the local name is non-empty
\r
112 bool hasLocalPart() const { return m_local && *m_local; }
\r
115 * Returns the namespace prefix
\r
116 * @return Null-terminated Unicode string containing the prefix, without the colon
\r
118 const XMLCh* getPrefix() const { return m_prefix; }
\r
121 * Returns the namespace URI
\r
122 * @return Null-terminated Unicode string containing the URI
\r
124 const XMLCh* getNamespaceURI() const { return m_uri; }
\r
127 * Returns the local part of the name
\r
128 * @return Null-terminated Unicode string containing the local name
\r
130 const XMLCh* getLocalPart() const { return m_local; }
\r
134 * Sets the namespace prefix
\r
135 * @param prefix Null-terminated Unicode string containing the prefix, without the colon
\r
137 void setPrefix(const XMLCh* prefix);
\r
140 * Sets the namespace URI
\r
141 * @param uri Null-terminated Unicode string containing the URI
\r
143 void setNamespaceURI(const XMLCh* uri);
\r
146 * Sets the local part of the name
\r
147 * @param localPart Null-terminated Unicode string containing the local name
\r
149 void setLocalPart(const XMLCh* localPart);
\r
152 * Gets a string representation of the QName for logging, etc.
\r
153 * Format is prefix:localPart or {namespaceURI}localPart if no prefix.
\r
155 * @return the string representation
\r
157 std::string toString() const;
\r
160 #ifdef HAVE_GOOD_STL
\r
172 * Returns true iff op1's namespace lexically compares less than op2's namespace,
\r
173 * or if equal, iff op1's prefix lexically compares less than op2's prefix.
\r
175 * Needed for use with sorted STL containers.
\r
177 * @param op1 First qname to compare
\r
178 * @param op2 Second qname to compare
\r
180 extern XMLTOOL_API bool operator<(const QName& op1, const QName& op2);
\r
183 * Returns true iff op1's components are equal to op2's components, excluding prefix.
\r
184 * @param op1 First qname to compare
\r
185 * @param op2 Second qname to compare
\r
187 extern XMLTOOL_API bool operator==(const QName& op1, const QName& op2);
\r
190 * Returns true iff op1's components are not equal to op2's components, excluding prefix.
\r
191 * @param op1 First qname to compare
\r
192 * @param op2 Second qname to compare
\r
194 extern XMLTOOL_API bool operator!=(const QName& op1, const QName& op2);
\r
198 #endif /* __xmltooling_qname_h__ */
\r