~ubuntu-branches/ubuntu/quantal/libwpd/quantal

« back to all changes in this revision

Viewing changes to src/lib/WPXPropertyList.cpp

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2011-11-29 23:31:13 UTC
  • mfrom: (10.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20111129233113-g69767blnzxs6pee
Tags: 0.9.4-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
1
2
/* libwpd
2
3
 * Copyright (C) 2004 William Lachance (wrlach@gmail.com)
3
4
 * Copyright (C) 2005 Net Integration Technologies (http://www.net-itech.com)
34
35
        WPXMapImpl() : m_map() {}
35
36
        ~WPXMapImpl();
36
37
        void insert(const char *name, WPXProperty *property);
37
 
        const WPXProperty * operator[](const char *name) const;
 
38
        const WPXProperty *operator[](const char *name) const;
38
39
        void remove(const char *name);
39
40
        void clear();
40
41
 
47
48
WPXMapImpl::~WPXMapImpl()
48
49
{
49
50
        for (std::map<std::string, WPXProperty *>::iterator iter = m_map.begin();
50
 
             iter != m_map.end();
51
 
             iter++) { delete iter->second; } 
 
51
                iter != m_map.end();
 
52
                iter++)
 
53
        {
 
54
                delete iter->second;
 
55
        }
52
56
}
53
57
 
54
 
const WPXProperty * WPXMapImpl::operator[](const char *name) const
 
58
const WPXProperty *WPXMapImpl::operator[](const char *name) const
55
59
{
56
60
        std::map<std::string, WPXProperty *>::iterator i = m_map.find(name);
57
 
        if (i != m_map.end()) {
 
61
        if (i != m_map.end())
 
62
        {
58
63
                return i->second;
59
64
        }
60
65
 
64
69
void WPXMapImpl::insert(const char *name, WPXProperty *prop)
65
70
{
66
71
        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))) {
 
72
        if (i != m_map.end() && !(m_map.key_comp()(name, i->first)))
 
73
        {
68
74
                WPXProperty *tmpProp = i->second;
69
75
                i->second = prop;
70
76
                delete tmpProp;
76
82
void WPXMapImpl::remove(const char *name)
77
83
{
78
84
        std::map<std::string, WPXProperty *>::iterator i = m_map.find(name);
79
 
        if (i != m_map.end()) {
 
85
        if (i != m_map.end())
 
86
        {
80
87
                if (i->second) delete (i->second);
81
88
                m_map.erase(i);
82
89
        }
85
92
void WPXMapImpl::clear()
86
93
{
87
94
        for (std::map<std::string, WPXProperty *>::iterator iter = m_map.begin();
88
 
             iter != m_map.end();
89
 
             iter++) { delete iter->second; } 
 
95
                iter != m_map.end();
 
96
                iter++)
 
97
        {
 
98
                delete iter->second;
 
99
        }
90
100
 
91
101
        m_map.clear();
92
102
}
107
117
}
108
118
 
109
119
WPXPropertyList::~WPXPropertyList()
110
 
 
120
{
111
121
        delete m_mapImpl;
112
122
}
113
123
 
114
 
void WPXPropertyList::insert(const char * name, WPXProperty *prop)
115
 
116
 
        m_mapImpl->insert(name, prop); 
 
124
void WPXPropertyList::insert(const char *name, WPXProperty *prop)
 
125
{
 
126
        m_mapImpl->insert(name, prop);
117
127
}
118
128
 
119
 
void WPXPropertyList::insert(const char * name, const int val)
120
 
 
129
void WPXPropertyList::insert(const char *name, const int val)
 
130
{
121
131
        m_mapImpl->insert(name, WPXPropertyFactory::newIntProp(val));
122
132
}
123
133
 
124
 
void WPXPropertyList::insert(const char * name, const bool val)
125
 
 
134
void WPXPropertyList::insert(const char *name, const bool val)
 
135
{
126
136
        m_mapImpl->insert(name, WPXPropertyFactory::newBoolProp(val));
127
137
}
128
138
 
129
 
void WPXPropertyList::insert(const char * name, const char *val)
130
 
131
 
        m_mapImpl->insert(name, WPXPropertyFactory::newStringProp(val));
132
 
}
133
 
 
134
 
void WPXPropertyList::insert(const char * name, const WPXString &val)
135
 
136
 
        m_mapImpl->insert(name, WPXPropertyFactory::newStringProp(val));
137
 
}
138
 
 
139
 
void WPXPropertyList::insert(const char * name, const double val, const WPXUnit units)
140
 
 
139
void WPXPropertyList::insert(const char *name, const char *val)
 
140
{
 
141
        m_mapImpl->insert(name, WPXPropertyFactory::newStringProp(val));
 
142
}
 
143
 
 
144
void WPXPropertyList::insert(const char *name, const WPXString &val)
 
145
{
 
146
        m_mapImpl->insert(name, WPXPropertyFactory::newStringProp(val));
 
147
}
 
148
 
 
149
void WPXPropertyList::insert(const char *name, const double val, const WPXUnit units)
 
150
{
141
151
        if (units == WPX_INCH)
142
152
                m_mapImpl->insert(name, WPXPropertyFactory::newInchProp(val));
143
153
        else if (units == WPX_PERCENT)
144
154
                m_mapImpl->insert(name, WPXPropertyFactory::newPercentProp(val));
145
 
        else if (units == WPX_POINT)            
 
155
        else if (units == WPX_POINT)
146
156
                m_mapImpl->insert(name, WPXPropertyFactory::newPointProp(val));
147
157
        else if (units == WPX_TWIP)
148
158
                m_mapImpl->insert(name, WPXPropertyFactory::newTwipProp(val));
150
160
                m_mapImpl->insert(name, WPXPropertyFactory::newDoubleProp(val));
151
161
}
152
162
 
153
 
void WPXPropertyList::remove(const char * name)
 
163
void WPXPropertyList::remove(const char *name)
154
164
{
155
165
        m_mapImpl->remove(name);
156
166
}
157
167
 
158
 
const WPXPropertyList& WPXPropertyList::operator=(const WPXPropertyList& propList)
 
168
const WPXPropertyList &WPXPropertyList::operator=(const WPXPropertyList &propList)
159
169
{
160
 
    clear();    
 
170
        clear();
161
171
        WPXPropertyList::Iter i(propList);
162
172
        for (i.rewind(); i.next(); )
163
173
        {
166
176
        return *this;
167
177
}
168
178
 
169
 
const WPXProperty * WPXPropertyList::operator[](const char *name) const
 
179
const WPXProperty *WPXPropertyList::operator[](const char *name) const
170
180
{
171
181
        return (*m_mapImpl)[name];
172
182
}
183
193
        void rewind();
184
194
        bool next();
185
195
        bool last();
186
 
        const WPXProperty * operator()() const;
187
 
        const char * key();
 
196
        const WPXProperty *operator()() const;
 
197
        const char *key();
188
198
 
189
199
private:
190
200
        bool m_imaginaryFirst;
202
212
 
203
213
void WPXMapIterImpl::rewind()
204
214
{
205
 
    // rewind to an imaginary element that preceeds the first one
206
 
    m_imaginaryFirst = true;
207
 
    m_iter = m_map->begin(); 
 
215
        // rewind to an imaginary element that preceeds the first one
 
216
        m_imaginaryFirst = true;
 
217
        m_iter = m_map->begin();
208
218
}
209
219
 
210
220
bool WPXMapIterImpl::next()
211
221
{
212
 
    if (!m_imaginaryFirst) 
213
 
        m_iter++; 
214
 
    if (m_iter==m_map->end()) 
215
 
        return false; 
216
 
    m_imaginaryFirst = false;
 
222
        if (!m_imaginaryFirst)
 
223
                m_iter++;
 
224
        if (m_iter==m_map->end())
 
225
                return false;
 
226
        m_imaginaryFirst = false;
217
227
 
218
 
    return true; 
 
228
        return true;
219
229
}
220
230
 
221
231
bool WPXMapIterImpl::last()
222
232
{
223
 
        if (m_iter == m_map->end()) 
 
233
        if (m_iter == m_map->end())
224
234
                return true;
225
 
        
 
235
 
226
236
        return false;
227
237
}
228
238
 
229
 
const WPXProperty * WPXMapIterImpl::operator()() const
 
239
const WPXProperty *WPXMapIterImpl::operator()() const
230
240
{
231
241
        return m_iter->second;
232
242
}
233
243
 
234
 
const char * WPXMapIterImpl::key()
 
244
const char *WPXMapIterImpl::key()
235
245
{
236
246
        return m_iter->first.c_str();
237
247
}
241
251
{
242
252
}
243
253
 
244
 
WPXPropertyList::Iter::~Iter() 
 
254
WPXPropertyList::Iter::~Iter()
245
255
{
246
256
        delete m_iterImpl;
247
257
}
248
258
 
249
259
void WPXPropertyList::Iter::rewind()
250
 
 
260
{
251
261
        // rewind to an imaginary element that preceeds the first one
252
262
        m_iterImpl->rewind();
253
263
}
254
264
 
255
265
bool WPXPropertyList::Iter::next()
256
 
 
266
{
257
267
        return m_iterImpl->next();
258
268
}
259
269
 
262
272
        return m_iterImpl->last();
263
273
}
264
274
 
265
 
const WPXProperty * WPXPropertyList::Iter::operator()() const
 
275
const WPXProperty *WPXPropertyList::Iter::operator()() const
266
276
{
267
277
        return (*m_iterImpl)();
268
278
}
269
279
 
270
 
const char * WPXPropertyList::Iter::key()
 
280
const char *WPXPropertyList::Iter::key()
271
281
{
272
282
        return m_iterImpl->key();
273
283
}
 
284
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */