3e9bfc8b3d3a472cda15a7b408a92428f69df111
[shibboleth/cpp-xmltooling.git] / xmltooling / Namespace.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /**\r
18  * @file Namespace.h\r
19  * \r
20  * Representing XML namespace attributes \r
21  */\r
22 \r
23 #if !defined(__xmltooling_namespace_h__)\r
24 #define __xmltooling_namespace_h__\r
25 \r
26 #include <xmltooling/unicode.h>\r
27 \r
28 namespace xmltooling {\r
29     \r
30     /**\r
31      * A data structure for encapsulating XML Namespace attributes\r
32      */\r
33     class XMLTOOL_API Namespace\r
34     {\r
35     public:\r
36         /**\r
37          * Constructor\r
38          * @param uri               namespace URI\r
39          * @param prefix            namespace prefix (without the colon)\r
40          * @param alwaysDeclare     true iff the namespace should always be declared regardless of in-scope declarations\r
41          */\r
42         Namespace(const XMLCh* uri=NULL, const XMLCh* prefix=NULL, bool alwaysDeclare=false);\r
43         \r
44         ~Namespace();\r
45 #ifndef HAVE_GOOD_STL\r
46         /**\r
47          * Deep copy constructor\r
48          */\r
49         Namespace(const Namespace& src);\r
50 \r
51         /**\r
52          * Deep assignment operator\r
53          */\r
54         Namespace& operator=(const Namespace& src);\r
55 #endif\r
56         \r
57 #ifdef HAVE_GOOD_STL\r
58         /**\r
59          * Returns the namespace prefix\r
60          * @return  Null-terminated Unicode string containing the prefix, without the colon\r
61          */\r
62         const XMLCh* getNamespacePrefix() const { return m_prefix.c_str(); }\r
63 \r
64         /**\r
65          * Returns the namespace URI\r
66          * @return  Null-terminated Unicode string containing the URI\r
67          */\r
68         const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }\r
69 #else\r
70         /**\r
71          * Returns the namespace prefix\r
72          * @return  Null-terminated Unicode string containing the prefix, without the colon\r
73          */\r
74         const XMLCh* getNamespacePrefix() const { return m_prefix; }\r
75 \r
76         /**\r
77          * Returns the namespace URI\r
78          * @return  Null-terminated Unicode string containing the URI\r
79          */\r
80         const XMLCh* getNamespaceURI() const { return m_uri; }\r
81 #endif\r
82 \r
83         /**\r
84          * Returns true iff the namespace should always be declared regardless of in-scope declarations\r
85          * @return the alwaysDeclared setting\r
86          */\r
87         const bool alwaysDeclare() const { return m_pinned; } \r
88 \r
89         /**\r
90          * Sets the namespace prefix\r
91          * @param prefix    Null-terminated Unicode string containing the prefix, without the colon\r
92          */\r
93         void setNamespacePrefix(const XMLCh* prefix);\r
94 \r
95         /**\r
96          * Sets the namespace URI\r
97          * @param uri  Null-terminated Unicode string containing the URI\r
98          */\r
99         void setNamespaceURI(const XMLCh* uri);\r
100 \r
101         /**\r
102          * Sets the alwaysDeclared property\r
103          * @param alwaysDeclare     true iff the namespace should always be declared regardless of in-scope declarations\r
104          */\r
105         void setAlwaysDeclare(bool alwaysDeclare) { m_pinned = alwaysDeclare; } \r
106         \r
107     private:\r
108         bool m_pinned;\r
109 #ifdef HAVE_GOOD_STL\r
110         xstring m_uri;\r
111         xstring m_prefix;\r
112 #else\r
113         XMLCh* m_uri;\r
114         XMLCh* m_prefix;\r
115 #endif\r
116     };\r
117 \r
118     /**\r
119      * Returns true iff op1's namespace lexically compares less than op2's namespace,\r
120      * or if equal, iff op1's prefix lexically compares less than op2's prefix.\r
121      * \r
122      * Needed for use with sorted STL containers.\r
123      * \r
124      * @param op1   First namspace to compare\r
125      * @param op2   Second namespace to compare\r
126      */\r
127     extern XMLTOOL_API bool operator<(const Namespace& op1, const Namespace& op2);\r
128 \r
129 #ifndef HAVE_GOOD_STL\r
130     /**\r
131      * Returns true iff op1's namespace and prefix are equal to op2's namespace and prefix.\r
132      * @param op1   First namspace to compare\r
133      * @param op2   Second namespace to compare\r
134      */\r
135     extern XMLTOOL_API bool operator==(const Namespace& op1, const Namespace& op2);\r
136 #endif\r
137 \r
138 };\r
139 \r
140 #endif /* __xmltooling_namespace_h__ */\r