4df23ba2d8a631fac2a9983a4aa226047167faf5
[shibboleth/cpp-xmltooling.git] / xmltooling / QName.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 QName.h\r
19  * \r
20  * Representing XML QNames \r
21  */\r
22 \r
23 #if !defined(__xmltooling_qname_h__)\r
24 #define __xmltooling_qname_h__\r
25 \r
26 #include <algorithm>\r
27 #include <xmltooling/unicode.h>\r
28 \r
29 namespace xmltooling {\r
30     \r
31     /**\r
32      * A data structure for encapsulating XML QNames.\r
33      * The Xerces class is too limited to use at the moment.\r
34      */\r
35     class XMLTOOL_API QName\r
36     {\r
37     public:\r
38         /**\r
39          * Constructor\r
40          * @param uri       namespace URI\r
41          * @param localPart local name\r
42          * @param prefix    namespace prefix (without the colon)\r
43          */\r
44         QName(const XMLCh* uri=NULL, const XMLCh* localPart=NULL, const XMLCh* prefix=NULL);\r
45         \r
46         ~QName();\r
47 #ifndef HAVE_GOOD_STL\r
48         /**\r
49          * Deep copy constructor\r
50          */\r
51         QName(const QName& src);\r
52 \r
53         /**\r
54          * Deep assignment operator\r
55          */\r
56         QName& operator=(const QName& src);\r
57 #endif\r
58         \r
59 #ifdef HAVE_GOOD_STL\r
60         /**\r
61          * Returns the namespace prefix\r
62          * @return  Null-terminated Unicode string containing the prefix, without the colon\r
63          */\r
64         const XMLCh* getPrefix() const { return m_prefix.c_str(); }\r
65 \r
66         /**\r
67          * Returns the namespace URI\r
68          * @return  Null-terminated Unicode string containing the URI\r
69          */\r
70         const XMLCh* getNamespaceURI() const { return m_uri.c_str(); }\r
71 \r
72         /**\r
73          * Returns the local part of the name\r
74          * @return  Null-terminated Unicode string containing the local name\r
75          */\r
76         const XMLCh* getLocalPart() const { return m_local.c_str(); }\r
77 #else\r
78         /**\r
79          * Returns the namespace prefix\r
80          * @return  Null-terminated Unicode string containing the prefix, without the colon\r
81          */\r
82         const XMLCh* getPrefix() const { return m_prefix; }\r
83 \r
84         /**\r
85          * Returns the namespace URI\r
86          * @return  Null-terminated Unicode string containing the URI\r
87          */\r
88         const XMLCh* getNamespaceURI() const { return m_uri; }\r
89 \r
90         /**\r
91          * Returns the local part of the name\r
92          * @return  Null-terminated Unicode string containing the local name\r
93          */\r
94         const XMLCh* getLocalPart() const { return m_local; }\r
95 #endif\r
96 \r
97         /**\r
98          * Sets the namespace prefix\r
99          * @param prefix    Null-terminated Unicode string containing the prefix, without the colon\r
100          */\r
101         void setPrefix(const XMLCh* prefix);\r
102 \r
103         /**\r
104          * Sets the namespace URI\r
105          * @param uri  Null-terminated Unicode string containing the URI\r
106          */\r
107         void setNamespaceURI(const XMLCh* uri);\r
108         \r
109         /**\r
110          * Sets the local part of the name\r
111          * @param localPart  Null-terminated Unicode string containing the local name\r
112          */\r
113         void setLocalPart(const XMLCh* localPart);\r
114         \r
115         /**\r
116          * Gets a string representation of the QName for logging, etc.\r
117          * Format is prefix:localPart or {namespaceURI}localPart if no prefix.\r
118          * \r
119          * @return the string representation\r
120          */\r
121         std::string toString() const;\r
122         \r
123     private:\r
124 #ifdef HAVE_GOOD_STL\r
125         xstring m_uri;\r
126         xstring m_local;\r
127         xstring m_prefix;\r
128 #else\r
129         XMLCh* m_uri;\r
130         XMLCh* m_local;\r
131         XMLCh* m_prefix;\r
132 #endif\r
133     };\r
134 \r
135     /**\r
136      * Returns true iff op1's namespace lexically compares less than op2's namespace,\r
137      * or if equal, iff op1's prefix lexically compares less than op2's prefix.\r
138      * \r
139      * Needed for use with sorted STL containers.\r
140      * \r
141      * @param op1   First qname to compare\r
142      * @param op2   Second qname to compare\r
143      */\r
144     extern XMLTOOL_API bool operator<(const QName& op1, const QName& op2);\r
145 \r
146     /**\r
147      * Returns true iff op1's components are equal to op2's components, excluding prefix.\r
148      * @param op1   First qname to compare\r
149      * @param op2   Second qname to compare\r
150      */\r
151     extern XMLTOOL_API bool operator==(const QName& op1, const QName& op2);\r
152 \r
153 };\r
154 \r
155 #endif /* __xmltooling_qname_h__ */\r