Update copyright.
[shibboleth/cpp-xmltooling.git] / xmltooling / Namespace.cpp
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * Namespace.cpp
19  * 
20  * Representing XML namespace attributes 
21  */
22
23 #include "internal.h"
24 #include "Namespace.h"
25
26 using namespace xmltooling;
27
28 Namespace::Namespace(const XMLCh* uri, const XMLCh* prefix, bool alwaysDeclare) : m_pinned(alwaysDeclare)
29 {
30 #ifndef HAVE_GOOD_STL
31     m_uri=m_prefix=NULL;
32 #endif
33     setNamespaceURI(uri);
34     setNamespacePrefix(prefix);
35 }
36
37 Namespace::~Namespace()
38 {
39 #ifndef HAVE_GOOD_STL
40     XMLString::release(&m_uri);
41     XMLString::release(&m_prefix);
42 #endif
43 }
44
45 void Namespace::setNamespacePrefix(const XMLCh* prefix)
46 {
47 #ifdef HAVE_GOOD_STL
48     if (prefix)
49         m_prefix=prefix;
50     else
51         m_prefix.erase();
52 #else
53     if (m_prefix)
54         XMLString::release(&m_prefix);
55     m_prefix=XMLString::replicate(prefix);
56 #endif
57 }
58
59 void Namespace::setNamespaceURI(const XMLCh* uri)
60 {
61 #ifdef HAVE_GOOD_STL
62     if (uri)
63         m_uri=uri;
64     else
65         m_uri.erase();
66 #else
67     if (m_uri)
68         XMLString::release(&m_uri);
69     m_uri=XMLString::replicate(uri);
70 #endif
71 }
72
73 #ifndef HAVE_GOOD_STL
74 Namespace::Namespace(const Namespace& src)
75 {
76     m_uri=XMLString::replicate(src.getNamespaceURI());
77     m_prefix=XMLString::replicate(src.getNamespacePrefix());
78     m_pinned=src.alwaysDeclare();
79 }
80
81 Namespace& Namespace::operator=(const Namespace& src)
82 {
83     m_uri=XMLString::replicate(src.getNamespaceURI());
84     m_prefix=XMLString::replicate(src.getNamespacePrefix());
85     m_pinned=src.alwaysDeclare();
86     return *this;
87 }
88
89 bool xmltooling::operator==(const Namespace& op1, const Namespace& op2)
90 {
91     return (XMLString::equals(op1.getNamespaceURI(),op2.getNamespaceURI()) &&
92             XMLString::equals(op1.getNamespacePrefix(),op2.getNamespacePrefix()));
93 }
94 #endif
95
96 bool xmltooling::operator<(const Namespace& op1, const Namespace& op2)
97 {
98     int i=XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI());
99     if (i<0)
100         return true;
101     else if (i==0)
102         return (XMLString::compareString(op1.getNamespacePrefix(),op2.getNamespacePrefix())<0);
103     else
104         return false;
105 }