~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Net/src/NameValueCollection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// NameValueCollection.cpp
 
3
//
 
4
// $Id: //poco/1.2/Net/src/NameValueCollection.cpp#1 $
 
5
//
 
6
// Library: Net
 
7
// Package: Messages
 
8
// Module:  NameValueCollection
 
9
//
 
10
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
 
11
// and Contributors.
 
12
//
 
13
// Permission is hereby granted, free of charge, to any person or organization
 
14
// obtaining a copy of the software and accompanying documentation covered by
 
15
// this license (the "Software") to use, reproduce, display, distribute,
 
16
// execute, and transmit the Software, and to prepare derivative works of the
 
17
// Software, and to permit third-parties to whom the Software is furnished to
 
18
// do so, all subject to the following:
 
19
// 
 
20
// The copyright notices in the Software and this entire statement, including
 
21
// the above license grant, this restriction and the following disclaimer,
 
22
// must be included in all copies of the Software, in whole or in part, and
 
23
// all derivative works of the Software, unless such copies or derivative
 
24
// works are solely in the form of machine-executable object code generated by
 
25
// a source language processor.
 
26
// 
 
27
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
28
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
29
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 
30
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 
31
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 
32
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
33
// DEALINGS IN THE SOFTWARE.
 
34
//
 
35
 
 
36
 
 
37
#include "Poco/Net/NameValueCollection.h"
 
38
#include "Poco/Exception.h"
 
39
#include <algorithm>
 
40
 
 
41
 
 
42
using Poco::NotFoundException;
 
43
 
 
44
 
 
45
namespace Poco {
 
46
namespace Net {
 
47
 
 
48
 
 
49
NameValueCollection::NameValueCollection()
 
50
{
 
51
}
 
52
 
 
53
 
 
54
NameValueCollection::NameValueCollection(const NameValueCollection& nvc):
 
55
        _map(nvc._map)
 
56
{
 
57
}
 
58
 
 
59
 
 
60
NameValueCollection::~NameValueCollection()
 
61
{
 
62
}
 
63
 
 
64
 
 
65
NameValueCollection& NameValueCollection::operator = (const NameValueCollection& nvc)
 
66
{
 
67
        if (&nvc != this)
 
68
        {
 
69
                _map = nvc._map;
 
70
        }
 
71
        return *this;
 
72
}
 
73
 
 
74
 
 
75
void NameValueCollection::swap(NameValueCollection& nvc)
 
76
{
 
77
        std::swap(_map, nvc._map);
 
78
}
 
79
 
 
80
        
 
81
const std::string& NameValueCollection::operator [] (const std::string& name) const
 
82
{
 
83
        ConstIterator it = _map.find(name);
 
84
        if (it != _map.end())
 
85
                return it->second;
 
86
        else
 
87
                throw NotFoundException(name);
 
88
}
 
89
 
 
90
        
 
91
void NameValueCollection::set(const std::string& name, const std::string& value)        
 
92
{
 
93
        Iterator it = _map.find(name);
 
94
        if (it != _map.end())
 
95
                _map.erase(it);
 
96
        _map.insert(HeaderMap::value_type(name, value));
 
97
}
 
98
 
 
99
        
 
100
void NameValueCollection::add(const std::string& name, const std::string& value)
 
101
{
 
102
        _map.insert(HeaderMap::value_type(name, value));
 
103
}
 
104
 
 
105
        
 
106
const std::string& NameValueCollection::get(const std::string& name) const
 
107
{
 
108
        ConstIterator it = _map.find(name);
 
109
        if (it != _map.end())
 
110
                return it->second;
 
111
        else
 
112
                throw NotFoundException(name);
 
113
}
 
114
 
 
115
 
 
116
const std::string& NameValueCollection::get(const std::string& name, const std::string& defaultValue) const
 
117
{
 
118
        ConstIterator it = _map.find(name);
 
119
        if (it != _map.end())
 
120
                return it->second;
 
121
        else
 
122
                return defaultValue;
 
123
}
 
124
 
 
125
 
 
126
bool NameValueCollection::has(const std::string& name) const
 
127
{
 
128
        return _map.find(name) != _map.end();
 
129
}
 
130
 
 
131
 
 
132
NameValueCollection::ConstIterator NameValueCollection::find(const std::string& name) const
 
133
{
 
134
        return _map.find(name);
 
135
}
 
136
 
 
137
        
 
138
NameValueCollection::ConstIterator NameValueCollection::begin() const
 
139
{
 
140
        return _map.begin();
 
141
}
 
142
 
 
143
        
 
144
NameValueCollection::ConstIterator NameValueCollection::end() const
 
145
{
 
146
        return _map.end();
 
147
}
 
148
 
 
149
        
 
150
bool NameValueCollection::empty() const
 
151
{
 
152
        return _map.empty();
 
153
}
 
154
 
 
155
 
 
156
int NameValueCollection::size() const
 
157
{
 
158
        return (int) _map.size();
 
159
}
 
160
 
 
161
 
 
162
void NameValueCollection::erase(const std::string& name)
 
163
{
 
164
        _map.erase(name);
 
165
}
 
166
 
 
167
 
 
168
void NameValueCollection::clear()
 
169
{
 
170
        _map.clear();
 
171
}
 
172
 
 
173
 
 
174
} } // namespace Poco::Net