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