Set fourth file version digit to signify rebuild.
[shibboleth/cpp-xmltooling.git] / xmltooling / Namespace.h
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 /**
22  * @file xmltooling/Namespace.h
23  * 
24  * Representing XML namespace attributes.
25  */
26
27 #if !defined(__xmltooling_namespace_h__)
28 #define __xmltooling_namespace_h__
29
30 #include <xmltooling/unicode.h>
31
32 namespace xmltooling {
33
34 #if defined (_MSC_VER)
35     #pragma warning( push )
36     #pragma warning( disable : 4251 )
37 #endif
38
39     /**
40      * A data structure for encapsulating XML Namespace attributes.
41      */
42     class XMLTOOL_API Namespace
43     {
44     public:
45         /**
46          * Tri-state indicator of namespace usage.
47          */
48         enum namespace_usage_t {
49             Indeterminate,
50             NonVisiblyUsed,
51             VisiblyUsed
52         };
53
54         /**
55          * Constructor
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
60          */
61         Namespace(const XMLCh* uri=nullptr, const XMLCh* prefix=nullptr, bool alwaysDeclare=false, namespace_usage_t usage=Indeterminate);
62         
63         ~Namespace();
64         
65         /**
66          * Returns the namespace prefix
67          * @return  Null-terminated Unicode string containing the prefix, without the colon
68          */
69         const XMLCh* getNamespacePrefix() const { return m_prefix.c_str(); }
70
71         /**
72          * Returns the namespace URI
73          * @return  Null-terminated Unicode string containing the URI
74          */
75         const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }
76
77         /**
78          * Returns true iff the namespace should always be declared regardless of in-scope declarations
79          * @return the alwaysDeclared setting
80          */
81         const bool alwaysDeclare() const { return m_pinned; }
82
83         /**
84          * Returns the usage of the namespace by an XMLObject
85          * @return the usage setting
86          */
87         const namespace_usage_t usage() const { return m_usage; }
88
89         /**
90          * Sets the namespace prefix
91          * @param prefix    Null-terminated Unicode string containing the prefix, without the colon
92          */
93         void setNamespacePrefix(const XMLCh* prefix);
94
95         /**
96          * Sets the namespace URI
97          * @param uri  Null-terminated Unicode string containing the URI
98          */
99         void setNamespaceURI(const XMLCh* uri);
100
101         /**
102          * Sets the alwaysDeclared property
103          * @param alwaysDeclare     true iff the namespace should always be declared regardless of in-scope declarations
104          */
105         void setAlwaysDeclare(bool alwaysDeclare) { m_pinned = alwaysDeclare; } 
106         
107         /**
108          * Sets the usage property
109          * @param usage usage of the namespace by an XMLObject
110          */
111         void setUsage(namespace_usage_t usage) { m_usage = usage; }
112
113     private:
114         bool m_pinned;
115         namespace_usage_t m_usage;
116         xstring m_uri;
117         xstring m_prefix;
118     };
119
120 #if defined (_MSC_VER)
121     #pragma warning( pop )
122 #endif
123
124     /**
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.
127      * 
128      * Needed for use with sorted STL containers.
129      * 
130      * @param op1   First namspace to compare
131      * @param op2   Second namespace to compare
132      */
133     extern XMLTOOL_API bool operator<(const Namespace& op1, const Namespace& op2);
134
135     /**
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
139      */
140     extern XMLTOOL_API bool operator==(const Namespace& op1, const Namespace& op2);
141
142 };
143
144 #endif /* __xmltooling_namespace_h__ */