2
2
* Copyright (C) 2004 William Lachance (wrlach@gmail.com)
3
3
* Copyright (C) 2005 Net Integration Technologies (http://www.net-itech.com)
4
* Copyright (C) 2006 Fridrich Strba (fridrich.strba@bluewin.ch)
5
6
* This library is free software; you can redistribute it and/or
6
7
* modify it under the terms of the GNU Library General Public
30
class WPXStdMapImpl : public WPXMapImpl
34
virtual ~WPXStdMapImpl();
35
virtual void insert(const char *name, WPXProperty *property);
36
virtual const WPXProperty * operator[](const char *name) const;
37
virtual void remove(const char *name);
36
void insert(const char *name, WPXProperty *property);
37
const WPXProperty * operator[](const char *name) const;
38
void remove(const char *name);
41
42
mutable std::map<std::string, WPXProperty *> m_map;
43
friend class WPXStdMapIterImpl;
44
friend class WPXMapIterImpl;
46
WPXStdMapImpl::~WPXStdMapImpl()
47
WPXMapImpl::~WPXMapImpl()
48
49
for (std::map<std::string, WPXProperty *>::iterator iter = m_map.begin();
49
50
iter != m_map.end();
50
51
iter++) { delete iter->second; }
53
const WPXProperty * WPXStdMapImpl::operator[](const char *name) const
54
const WPXProperty * WPXMapImpl::operator[](const char *name) const
55
std::map<std::string, WPXProperty *>::iterator i;
56
const std::string s(name);
56
std::map<std::string, WPXProperty *>::iterator i = m_map.find(name);
58
57
if (i != m_map.end()) {
65
void WPXStdMapImpl::insert(const char *name, WPXProperty *prop)
70
void WPXStdMapImpl::remove(const char *name)
72
// FIXME: delete element?
76
void WPXStdMapImpl::clear()
64
void WPXMapImpl::insert(const char *name, WPXProperty *prop)
66
std::map<std::string, WPXProperty *>::iterator i = m_map.lower_bound(name);
67
if (i != m_map.end() && !(m_map.key_comp()(name, i->first))) {
68
WPXProperty *tmpProp = i->second;
73
m_map.insert(i, std::map<std::string, WPXProperty *>::value_type(name, prop));
76
void WPXMapImpl::remove(const char *name)
78
std::map<std::string, WPXProperty *>::iterator i = m_map.find(name);
79
if (i != m_map.end()) {
80
if (i->second) delete (i->second);
85
void WPXMapImpl::clear()
78
87
for (std::map<std::string, WPXProperty *>::iterator iter = m_map.begin();
79
88
iter != m_map.end();
85
94
WPXPropertyList::WPXPropertyList() :
86
m_mapImpl(new WPXStdMapImpl())
95
m_mapImpl(new WPXMapImpl())
90
99
WPXPropertyList::WPXPropertyList(const WPXPropertyList &propList) :
91
m_mapImpl(new WPXStdMapImpl())
100
m_mapImpl(new WPXMapImpl())
93
102
WPXPropertyList::Iter i(propList);
94
103
for (i.rewind(); i.next(); )
154
163
m_mapImpl->clear();
157
class WPXStdMapIterImpl : public WPXMapIterImpl
160
WPXStdMapIterImpl(const WPXStdMapImpl *impl);
161
virtual void rewind();
164
virtual const WPXProperty * operator()() const;
165
virtual const char * key();
169
WPXMapIterImpl(const WPXMapImpl *impl);
173
const WPXProperty * operator()() const;
168
177
bool m_imaginaryFirst;
174
WPXStdMapIterImpl::WPXStdMapIterImpl(const WPXStdMapImpl *impl)
183
WPXMapIterImpl::WPXMapIterImpl(const WPXMapImpl *impl)
176
185
m_map = &(impl->m_map);
177
186
m_iter = impl->m_map.begin();
178
187
m_imaginaryFirst = false;
181
void WPXStdMapIterImpl::rewind()
190
void WPXMapIterImpl::rewind()
183
192
// rewind to an imaginary element that preceeds the first one
184
193
m_imaginaryFirst = true;
185
194
m_iter = m_map->begin();
188
bool WPXStdMapIterImpl::next()
197
bool WPXMapIterImpl::next()
190
199
if (!m_imaginaryFirst)
207
const WPXProperty * WPXStdMapIterImpl::operator()() const
216
const WPXProperty * WPXMapIterImpl::operator()() const
209
218
return m_iter->second;
212
const char * WPXStdMapIterImpl::key()
221
const char * WPXMapIterImpl::key()
214
223
return m_iter->first.c_str();
217
226
WPXPropertyList::Iter::Iter(const WPXPropertyList &propList)
219
228
WPXMapImpl *impl = propList.m_mapImpl;
220
m_iterImpl = new WPXStdMapIterImpl(static_cast<WPXStdMapImpl *>(impl));
229
m_iterImpl = new WPXMapIterImpl(static_cast<WPXMapImpl *>(impl));
223
232
WPXPropertyList::Iter::~Iter()