Initial check-in
[shibboleth/cpp-xmltooling.git] / xmltooling / Namespace.cpp
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 /* Namespace.cpp\r
18  * \r
19  * Data structure for representing XML namespace attributes \r
20  * \r
21  * $Id:$\r
22  */\r
23 \r
24 #include "internal.h"\r
25 #include "unicode.h"\r
26 #include "Namespace.h"\r
27 \r
28 using namespace std;\r
29 using namespace xmltooling;\r
30 \r
31 Namespace::Namespace()\r
32 {\r
33 #ifndef HAVE_GOOD_STL\r
34     m_uri=m_prefix=NULL;\r
35 #endif\r
36 }\r
37 \r
38 Namespace::Namespace(const XMLCh* uri, const XMLCh* prefix)\r
39 {\r
40     setNamespaceURI(uri);\r
41     setNamespacePrefix(prefix);\r
42 }\r
43 \r
44 Namespace::~Namespace()\r
45 {\r
46 #ifndef HAVE_GOOD_STL\r
47     XMLString::release(&m_uri);\r
48     XMLString::release(&m_prefix);\r
49 #endif\r
50 }\r
51 \r
52 void Namespace::setNamespacePrefix(const XMLCh* prefix)\r
53 {\r
54 #ifdef HAVE_GOOD_STL\r
55     if (prefix)\r
56         m_prefix=prefix;\r
57     else\r
58         m_prefix.erase();\r
59 #else\r
60     if (m_prefix)\r
61         XMLString::release(&m_prefix);\r
62     m_prefix=XMLString::replicate(prefix);\r
63 #endif\r
64 }\r
65 \r
66 void Namespace::setNamespaceURI(const XMLCh* uri)\r
67 {\r
68 #ifdef HAVE_GOOD_STL\r
69     if (uri)\r
70         m_uri=uri;\r
71     else\r
72         m_uri.erase();\r
73 #else\r
74     if (m_uri)\r
75         XMLString::release(&m_uri);\r
76     m_uri=XMLString::replicate(uri);\r
77 #endif\r
78 }\r
79 \r
80 #ifndef HAVE_GOOD_STL\r
81 Namespace::Namespace(const Namespace& src)\r
82 {\r
83     m_uri=XMLString::replicate(src.getNamespaceURI());\r
84     m_prefix=XMLString::replicate(src.getNamespacePrefix());\r
85 }\r
86 \r
87 Namespace& Namespace::operator=(const Namespace& src)\r
88 {\r
89     m_uri=XMLString::replicate(src.getNamespaceURI());\r
90     m_prefix=XMLString::replicate(src.getNamespacePrefix());\r
91     return *this;\r
92 }\r
93 \r
94 bool xmltooling::operator==(const Namespace& op1, const Namespace& op2)\r
95 {\r
96     return (!XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI()) &&\r
97             !XMLString::compareString(op1.getNamespacePrefix(),op2.getNamespacePrefix()));\r
98 }\r
99 #endif\r
100 \r
101 bool xmltooling::operator<(const Namespace& op1, const Namespace& op2)\r
102 {\r
103     int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());\r
104     if (i<0)\r
105         return true;\r
106     else if (i==0)\r
107         return (XMLString::compareString(op1.getNamespacePrefix(),op2.getNamespacePrefix())<0);\r
108     else\r
109         return false;\r
110 }\r