2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 * @file xmltooling/Namespace.h
24 * Representing XML namespace attributes.
27 #if !defined(__xmltooling_namespace_h__)
28 #define __xmltooling_namespace_h__
30 #include <xmltooling/unicode.h>
32 namespace xmltooling {
34 #if defined (_MSC_VER)
35 #pragma warning( push )
36 #pragma warning( disable : 4251 )
40 * A data structure for encapsulating XML Namespace attributes.
42 class XMLTOOL_API Namespace
46 * Tri-state indicator of namespace usage.
48 enum namespace_usage_t {
56 * @param uri namespace URI
57 * @param prefix namespace prefix (without the colon)
58 * @param alwaysDeclare true iff the namespace should always be declared regardless of in-scope declarations
59 * @param usage indicates usage of namespace in the context of an XMLObject
61 Namespace(const XMLCh* uri=nullptr, const XMLCh* prefix=nullptr, bool alwaysDeclare=false, namespace_usage_t usage=Indeterminate);
66 * Returns the namespace prefix
67 * @return Null-terminated Unicode string containing the prefix, without the colon
69 const XMLCh* getNamespacePrefix() const { return m_prefix.c_str(); }
72 * Returns the namespace URI
73 * @return Null-terminated Unicode string containing the URI
75 const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }
78 * Returns true iff the namespace should always be declared regardless of in-scope declarations
79 * @return the alwaysDeclared setting
81 const bool alwaysDeclare() const { return m_pinned; }
84 * Returns the usage of the namespace by an XMLObject
85 * @return the usage setting
87 const namespace_usage_t usage() const { return m_usage; }
90 * Sets the namespace prefix
91 * @param prefix Null-terminated Unicode string containing the prefix, without the colon
93 void setNamespacePrefix(const XMLCh* prefix);
96 * Sets the namespace URI
97 * @param uri Null-terminated Unicode string containing the URI
99 void setNamespaceURI(const XMLCh* uri);
102 * Sets the alwaysDeclared property
103 * @param alwaysDeclare true iff the namespace should always be declared regardless of in-scope declarations
105 void setAlwaysDeclare(bool alwaysDeclare) { m_pinned = alwaysDeclare; }
108 * Sets the usage property
109 * @param usage usage of the namespace by an XMLObject
111 void setUsage(namespace_usage_t usage) { m_usage = usage; }
115 namespace_usage_t m_usage;
120 #if defined (_MSC_VER)
121 #pragma warning( pop )
125 * Returns true iff op1's namespace lexically compares less than op2's namespace,
126 * or if equal, iff op1's prefix lexically compares less than op2's prefix.
128 * Needed for use with sorted STL containers.
130 * @param op1 First namspace to compare
131 * @param op2 Second namespace to compare
133 extern XMLTOOL_API bool operator<(const Namespace& op1, const Namespace& op2);
136 * Returns true iff op1's namespace and prefix are equal to op2's namespace and prefix.
137 * @param op1 First namspace to compare
138 * @param op2 Second namespace to compare
140 extern XMLTOOL_API bool operator==(const Namespace& op1, const Namespace& op2);
144 #endif /* __xmltooling_namespace_h__ */