Initial check-in
[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 <string>\r
27 #include <xmltooling/Namespace.h>\r
28 \r
29 namespace xmltooling {\r
30     \r
31     /**\r
32      * A data structure for encapsulating XML Namespace attributes\r
33      */\r
34     class XMLTOOL_API Namespace\r
35     {\r
36     public:\r
37         /**\r
38          * Default constructor\r
39          */\r
40         Namespace();\r
41         \r
42         /**\r
43          * Constructor that takes an existing declaration\r
44          * @param uri       namespace URI\r
45          * @param prefix    namespace prefix (without the colon)\r
46          */\r
47         Namespace(const XMLCh* uri, const XMLCh* prefix);\r
48         \r
49         ~Namespace();\r
50 #ifndef HAVE_GOOD_STL\r
51         /**\r
52          * Deep copy constructor\r
53          */\r
54         Namespace(const Namespace&);\r
55 \r
56         /**\r
57          * Deep assignment operator\r
58          */\r
59         Namespace& operator=(const Namespace&);\r
60 #endif\r
61         \r
62 #ifdef HAVE_GOOD_STL\r
63         /**\r
64          * Returns the namespace prefix\r
65          * @return  Null-terminated Unicode string containing the prefix, without the colon\r
66          */\r
67         const XMLCh* getNamespacePrefix() const { return m_prefix.c_str(); }\r
68 \r
69         /**\r
70          * Returns the namespace URI\r
71          * @return  Null-terminated Unicode string containing the URI\r
72          */\r
73         const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }\r
74 #else\r
75         /**\r
76          * Returns the namespace prefix\r
77          * @return  Null-terminated Unicode string containing the prefix, without the colon\r
78          */\r
79         const XMLCh* getNamespacePrefix() const { return m_prefix; }\r
80 \r
81         /**\r
82          * Returns the namespace URI\r
83          * @return  Null-terminated Unicode string containing the URI\r
84          */\r
85         const XMLCh* getNamespaceURI() const { return m_uri; }\r
86 #endif\r
87 \r
88         /**\r
89          * Sets the namespace prefix\r
90          * @param prefix    Null-terminated Unicode string containing the prefix, without the colon\r
91          */\r
92         void setNamespacePrefix(const XMLCh* prefix);\r
93 \r
94         /**\r
95          * Sets the namespace URI\r
96          * @param uri  Null-terminated Unicode string containing the URI\r
97          */\r
98         void setNamespaceURI(const XMLCh* uri);\r
99         \r
100     private:\r
101 #ifdef HAVE_GOOD_STL\r
102         xstring m_uri;\r
103         xstring m_prefix;\r
104 #else\r
105         XMLCh* m_uri;\r
106         XMLCh* m_prefix;\r
107 #endif\r
108     };\r
109 \r
110     /**\r
111      * Returns true iff op1's namespace lexically compares less than op2's namespace,\r
112      * or if equal, iff op1's prefix lexically compares less than op2's prefix.\r
113      * \r
114      * Needed for use with sorted STL containers.\r
115      * \r
116      * @param op1   First namspace to compare\r
117      * @param op2   Second namespace to compare\r
118      */\r
119     extern XMLTOOL_API bool operator<(const Namespace& op1, const Namespace& op2);\r
120 \r
121 #ifndef HAVE_GOOD_STL\r
122     /**\r
123      * Returns true iff op1's namespace and prefix are equal to op2's namespace and prefix.\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 #endif\r
129 \r
130 };\r
131 \r
132 #endif /* __xmltooling_namespace_h__ */\r