Update copyright.
[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     /**
31      * A data structure for encapsulating XML Namespace attributes
32      */
33     class XMLTOOL_API Namespace
34     {
35     public:
36         /**
37          * Constructor
38          * @param uri               namespace URI
39          * @param prefix            namespace prefix (without the colon)
40          * @param alwaysDeclare     true iff the namespace should always be declared regardless of in-scope declarations
41          */
42         Namespace(const XMLCh* uri=NULL, const XMLCh* prefix=NULL, bool alwaysDeclare=false);
43         
44         ~Namespace();
45 #ifndef HAVE_GOOD_STL
46         /**
47          * Deep copy constructor
48          */
49         Namespace(const Namespace& src);
50
51         /**
52          * Deep assignment operator
53          */
54         Namespace& operator=(const Namespace& src);
55 #endif
56         
57 #ifdef HAVE_GOOD_STL
58         /**
59          * Returns the namespace prefix
60          * @return  Null-terminated Unicode string containing the prefix, without the colon
61          */
62         const XMLCh* getNamespacePrefix() const { return m_prefix.c_str(); }
63
64         /**
65          * Returns the namespace URI
66          * @return  Null-terminated Unicode string containing the URI
67          */
68         const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }
69 #else
70         /**
71          * Returns the namespace prefix
72          * @return  Null-terminated Unicode string containing the prefix, without the colon
73          */
74         const XMLCh* getNamespacePrefix() const { return m_prefix; }
75
76         /**
77          * Returns the namespace URI
78          * @return  Null-terminated Unicode string containing the URI
79          */
80         const XMLCh* getNamespaceURI() const { return m_uri; }
81 #endif
82
83         /**
84          * Returns true iff the namespace should always be declared regardless of in-scope declarations
85          * @return the alwaysDeclared setting
86          */
87         const bool alwaysDeclare() const { return m_pinned; } 
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     private:
108         bool m_pinned;
109 #ifdef HAVE_GOOD_STL
110         xstring m_uri;
111         xstring m_prefix;
112 #else
113         XMLCh* m_uri;
114         XMLCh* m_prefix;
115 #endif
116     };
117
118     /**
119      * Returns true iff op1's namespace lexically compares less than op2's namespace,
120      * or if equal, iff op1's prefix lexically compares less than op2's prefix.
121      * 
122      * Needed for use with sorted STL containers.
123      * 
124      * @param op1   First namspace to compare
125      * @param op2   Second namespace to compare
126      */
127     extern XMLTOOL_API bool operator<(const Namespace& op1, const Namespace& op2);
128
129 #ifndef HAVE_GOOD_STL
130     /**
131      * Returns true iff op1's namespace and prefix are equal to op2's namespace and prefix.
132      * @param op1   First namspace to compare
133      * @param op2   Second namespace to compare
134      */
135     extern XMLTOOL_API bool operator==(const Namespace& op1, const Namespace& op2);
136 #endif
137
138 };
139
140 #endif /* __xmltooling_namespace_h__ */