Some root interfaces and configuration machinery
[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          */\r
41         Namespace(const XMLCh* uri=NULL, const XMLCh* prefix=NULL);\r
42         \r
43         ~Namespace();\r
44 #ifndef HAVE_GOOD_STL\r
45         /**\r
46          * Deep copy constructor\r
47          */\r
48         Namespace(const Namespace& src);\r
49 \r
50         /**\r
51          * Deep assignment operator\r
52          */\r
53         Namespace& operator=(const Namespace& src);\r
54 #endif\r
55         \r
56 #ifdef HAVE_GOOD_STL\r
57         /**\r
58          * Returns the namespace prefix\r
59          * @return  Null-terminated Unicode string containing the prefix, without the colon\r
60          */\r
61         const XMLCh* getNamespacePrefix() const { return m_prefix.c_str(); }\r
62 \r
63         /**\r
64          * Returns the namespace URI\r
65          * @return  Null-terminated Unicode string containing the URI\r
66          */\r
67         const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }\r
68 #else\r
69         /**\r
70          * Returns the namespace prefix\r
71          * @return  Null-terminated Unicode string containing the prefix, without the colon\r
72          */\r
73         const XMLCh* getNamespacePrefix() const { return m_prefix; }\r
74 \r
75         /**\r
76          * Returns the namespace URI\r
77          * @return  Null-terminated Unicode string containing the URI\r
78          */\r
79         const XMLCh* getNamespaceURI() const { return m_uri; }\r
80 #endif\r
81 \r
82         /**\r
83          * Sets the namespace prefix\r
84          * @param prefix    Null-terminated Unicode string containing the prefix, without the colon\r
85          */\r
86         void setNamespacePrefix(const XMLCh* prefix);\r
87 \r
88         /**\r
89          * Sets the namespace URI\r
90          * @param uri  Null-terminated Unicode string containing the URI\r
91          */\r
92         void setNamespaceURI(const XMLCh* uri);\r
93         \r
94     private:\r
95 #ifdef HAVE_GOOD_STL\r
96         xstring m_uri;\r
97         xstring m_prefix;\r
98 #else\r
99         XMLCh* m_uri;\r
100         XMLCh* m_prefix;\r
101 #endif\r
102     };\r
103 \r
104     /**\r
105      * Returns true iff op1's namespace lexically compares less than op2's namespace,\r
106      * or if equal, iff op1's prefix lexically compares less than op2's prefix.\r
107      * \r
108      * Needed for use with sorted STL containers.\r
109      * \r
110      * @param op1   First namspace to compare\r
111      * @param op2   Second namespace to compare\r
112      */\r
113     extern XMLTOOL_API bool operator<(const Namespace& op1, const Namespace& op2);\r
114 \r
115 #ifndef HAVE_GOOD_STL\r
116     /**\r
117      * Returns true iff op1's namespace and prefix are equal to op2's namespace and prefix.\r
118      * @param op1   First namspace to compare\r
119      * @param op2   Second namespace to compare\r
120      */\r
121     extern XMLTOOL_API bool operator==(const Namespace& op1, const Namespace& op2);\r
122 #endif\r
123 \r
124 };\r
125 \r
126 #endif /* __xmltooling_namespace_h__ */\r