21bf4b2462b6c2819a13d6e5cc39e34639d6c22f
[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, bool alwaysDeclare) : m_pinned(alwaysDeclare)\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     m_pinned=src.getAlwaysDeclare();\r
79 }\r
80 \r
81 Namespace& Namespace::operator=(const Namespace& src)\r
82 {\r
83     m_uri=XMLString::replicate(src.getNamespaceURI());\r
84     m_prefix=XMLString::replicate(src.getNamespacePrefix());\r
85     m_pinned=src.getAlwaysDeclare();\r
86     return *this;\r
87 }\r
88 \r
89 bool xmltooling::operator==(const Namespace& op1, const Namespace& op2)\r
90 {\r
91     return (XMLString::equals(op1.getNamespaceURI(),op2.getNamespaceURI()) &&\r
92             XMLString::equals(op1.getNamespacePrefix(),op2.getNamespacePrefix()));\r
93 }\r
94 #endif\r
95 \r
96 bool xmltooling::operator<(const Namespace& op1, const Namespace& op2)\r
97 {\r
98     int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());\r
99     if (i<0)\r
100         return true;\r
101     else if (i==0)\r
102         return (XMLString::compareString(op1.getNamespacePrefix(),op2.getNamespacePrefix())<0);\r
103     else\r
104         return false;\r
105 }\r