2 * Copyright 2001-2010 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file xmltooling/Namespace.h
20 * Representing XML namespace attributes
23 #if !defined(__xmltooling_namespace_h__)
24 #define __xmltooling_namespace_h__
26 #include <xmltooling/unicode.h>
28 namespace xmltooling {
30 #if defined (_MSC_VER)
31 #pragma warning( push )
32 #pragma warning( disable : 4251 )
36 * A data structure for encapsulating XML Namespace attributes
38 class XMLTOOL_API Namespace
43 * @param uri namespace URI
44 * @param prefix namespace prefix (without the colon)
45 * @param alwaysDeclare true iff the namespace should always be declared regardless of in-scope declarations
46 * @param visiblyUsed true iff the namespace is visibly used by an XMLObject its attached to
48 Namespace(const XMLCh* uri=NULL, const XMLCh* prefix=NULL, bool alwaysDeclare=false, bool visiblyUsed=true);
53 * Returns the namespace prefix
54 * @return Null-terminated Unicode string containing the prefix, without the colon
56 const XMLCh* getNamespacePrefix() const { return m_prefix.c_str(); }
59 * Returns the namespace URI
60 * @return Null-terminated Unicode string containing the URI
62 const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }
65 * Returns true iff the namespace should always be declared regardless of in-scope declarations
66 * @return the alwaysDeclared setting
68 const bool alwaysDeclare() const { return m_pinned; }
71 * Returns true iff the namespace is visibly used by an XMLObject its attached to
72 * @return the visiblyUsed setting
74 const bool visiblyUsed() const { return m_visiblyUsed; }
77 * Sets the namespace prefix
78 * @param prefix Null-terminated Unicode string containing the prefix, without the colon
80 void setNamespacePrefix(const XMLCh* prefix);
83 * Sets the namespace URI
84 * @param uri Null-terminated Unicode string containing the URI
86 void setNamespaceURI(const XMLCh* uri);
89 * Sets the alwaysDeclared property
90 * @param alwaysDeclare true iff the namespace should always be declared regardless of in-scope declarations
92 void setAlwaysDeclare(bool alwaysDeclare) { m_pinned = alwaysDeclare; }
95 * Sets the visiblyUsed property
96 * @param visiblyUsed true iff the namespace is visibly used by an XMLObject its attached to
98 void setVisiblyUsed(bool visiblyUsed) { m_visiblyUsed = visiblyUsed; }
101 bool m_pinned,m_visiblyUsed;
106 #if defined (_MSC_VER)
107 #pragma warning( pop )
111 * Returns true iff op1's namespace lexically compares less than op2's namespace,
112 * or if equal, iff op1's prefix lexically compares less than op2's prefix.
114 * Needed for use with sorted STL containers.
116 * @param op1 First namspace to compare
117 * @param op2 Second namespace to compare
119 extern XMLTOOL_API bool operator<(const Namespace& op1, const Namespace& op2);
122 * Returns true iff op1's namespace and prefix are equal to op2's namespace and prefix.
123 * @param op1 First namspace to compare
124 * @param op2 Second namespace to compare
126 extern XMLTOOL_API bool operator==(const Namespace& op1, const Namespace& op2);
130 #endif /* __xmltooling_namespace_h__ */