1//
2// NameValueCollection.cpp
3//
4// Library: Net
5// Package: Messages
6// Module: NameValueCollection
7//
8// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/Net/NameValueCollection.h"
16#include "Poco/Exception.h"
17#include <algorithm>
18
19
20using Poco::NotFoundException;
21
22
23namespace Poco {
24namespace Net {
25
26
27NameValueCollection::NameValueCollection()
28{
29}
30
31
32NameValueCollection::NameValueCollection(const NameValueCollection& nvc):
33 _map(nvc._map)
34{
35}
36
37
38NameValueCollection::~NameValueCollection()
39{
40}
41
42
43NameValueCollection& NameValueCollection::operator = (const NameValueCollection& nvc)
44{
45 if (&nvc != this)
46 {
47 _map = nvc._map;
48 }
49 return *this;
50}
51
52
53void NameValueCollection::swap(NameValueCollection& nvc)
54{
55 std::swap(_map, nvc._map);
56}
57
58
59const std::string& NameValueCollection::operator [] (const std::string& name) const
60{
61 ConstIterator it = _map.find(name);
62 if (it != _map.end())
63 return it->second;
64 else
65 throw NotFoundException(name);
66}
67
68
69void NameValueCollection::set(const std::string& name, const std::string& value)
70{
71 Iterator it = _map.find(name);
72 if (it != _map.end())
73 it->second = value;
74 else
75 _map.insert(HeaderMap::ValueType(name, value));
76}
77
78
79void NameValueCollection::add(const std::string& name, const std::string& value)
80{
81 _map.insert(HeaderMap::ValueType(name, value));
82}
83
84
85const std::string& NameValueCollection::get(const std::string& name) const
86{
87 ConstIterator it = _map.find(name);
88 if (it != _map.end())
89 return it->second;
90 else
91 throw NotFoundException(name);
92}
93
94
95const std::string& NameValueCollection::get(const std::string& name, const std::string& defaultValue) const
96{
97 ConstIterator it = _map.find(name);
98 if (it != _map.end())
99 return it->second;
100 else
101 return defaultValue;
102}
103
104
105bool NameValueCollection::has(const std::string& name) const
106{
107 return _map.find(name) != _map.end();
108}
109
110
111NameValueCollection::ConstIterator NameValueCollection::find(const std::string& name) const
112{
113 return _map.find(name);
114}
115
116
117NameValueCollection::ConstIterator NameValueCollection::begin() const
118{
119 return _map.begin();
120}
121
122
123NameValueCollection::ConstIterator NameValueCollection::end() const
124{
125 return _map.end();
126}
127
128
129bool NameValueCollection::empty() const
130{
131 return _map.empty();
132}
133
134
135std::size_t NameValueCollection::size() const
136{
137 return _map.size();
138}
139
140
141void NameValueCollection::erase(const std::string& name)
142{
143 _map.erase(name);
144}
145
146
147void NameValueCollection::clear()
148{
149 _map.clear();
150}
151
152
153} } // namespace Poco::Net
154