Major revamp of credential and trust handling code, PKIX engine still needs work.
[shibboleth/cpp-xmltooling.git] / xmltooling / Namespace.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file Namespace.h
19  * 
20  * Representing XML namespace attributes 
21  */
22
23 #if !defined(__xmltooling_namespace_h__)
24 #define __xmltooling_namespace_h__
25
26 #include <xmltooling/unicode.h>
27
28 namespace xmltooling {
29
30 #if defined (_MSC_VER)
31     #pragma warning( push )
32     #pragma warning( disable : 4251 )
33 #endif
34
35     /**
36      * A data structure for encapsulating XML Namespace attributes
37      */
38     class XMLTOOL_API Namespace
39     {
40     public:
41         /**
42          * Constructor
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          */
47         Namespace(const XMLCh* uri=NULL, const XMLCh* prefix=NULL, bool alwaysDeclare=false);
48         
49         ~Namespace();
50 #ifndef HAVE_GOOD_STL
51         /**
52          * Deep copy constructor
53          */
54         Namespace(const Namespace& src);
55
56         /**
57          * Deep assignment operator
58          */
59         Namespace& operator=(const Namespace& src);
60 #endif
61         
62 #ifdef HAVE_GOOD_STL
63         /**
64          * Returns the namespace prefix
65          * @return  Null-terminated Unicode string containing the prefix, without the colon
66          */
67         const XMLCh* getNamespacePrefix() const { return m_prefix.c_str(); }
68
69         /**
70          * Returns the namespace URI
71          * @return  Null-terminated Unicode string containing the URI
72          */
73         const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }
74 #else
75         /**
76          * Returns the namespace prefix
77          * @return  Null-terminated Unicode string containing the prefix, without the colon
78          */
79         const XMLCh* getNamespacePrefix() const { return m_prefix; }
80
81         /**
82          * Returns the namespace URI
83          * @return  Null-terminated Unicode string containing the URI
84          */
85         const XMLCh* getNamespaceURI() const { return m_uri; }
86 #endif
87
88         /**
89          * Returns true iff the namespace should always be declared regardless of in-scope declarations
90          * @return the alwaysDeclared setting
91          */
92         const bool alwaysDeclare() const { return m_pinned; } 
93
94         /**
95          * Sets the namespace prefix
96          * @param prefix    Null-terminated Unicode string containing the prefix, without the colon
97          */
98         void setNamespacePrefix(const XMLCh* prefix);
99
100         /**
101          * Sets the namespace URI
102          * @param uri  Null-terminated Unicode string containing the URI
103          */
104         void setNamespaceURI(const XMLCh* uri);
105
106         /**
107          * Sets the alwaysDeclared property
108          * @param alwaysDeclare     true iff the namespace should always be declared regardless of in-scope declarations
109          */
110         void setAlwaysDeclare(bool alwaysDeclare) { m_pinned = alwaysDeclare; } 
111         
112     private:
113         bool m_pinned;
114 #ifdef HAVE_GOOD_STL
115         xstring m_uri;
116         xstring m_prefix;
117 #else
118         XMLCh* m_uri;
119         XMLCh* m_prefix;
120 #endif
121     };
122
123 #if defined (_MSC_VER)
124     #pragma warning( pop )
125 #endif
126
127     /**
128      * Returns true iff op1's namespace lexically compares less than op2's namespace,
129      * or if equal, iff op1's prefix lexically compares less than op2's prefix.
130      * 
131      * Needed for use with sorted STL containers.
132      * 
133      * @param op1   First namspace to compare
134      * @param op2   Second namespace to compare
135      */
136     extern XMLTOOL_API bool operator<(const Namespace& op1, const Namespace& op2);
137
138 #ifndef HAVE_GOOD_STL
139     /**
140      * Returns true iff op1's namespace and prefix are equal to op2's namespace and prefix.
141      * @param op1   First namspace to compare
142      * @param op2   Second namespace to compare
143      */
144     extern XMLTOOL_API bool operator==(const Namespace& op1, const Namespace& op2);
145 #endif
146
147 };
148
149 #endif /* __xmltooling_namespace_h__ */