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 | |
20 | using Poco::NotFoundException; |
21 | |
22 | |
23 | namespace Poco { |
24 | namespace Net { |
25 | |
26 | |
27 | NameValueCollection::NameValueCollection() |
28 | { |
29 | } |
30 | |
31 | |
32 | NameValueCollection::NameValueCollection(const NameValueCollection& nvc): |
33 | _map(nvc._map) |
34 | { |
35 | } |
36 | |
37 | |
38 | NameValueCollection::~NameValueCollection() |
39 | { |
40 | } |
41 | |
42 | |
43 | NameValueCollection& NameValueCollection::operator = (const NameValueCollection& nvc) |
44 | { |
45 | if (&nvc != this) |
46 | { |
47 | _map = nvc._map; |
48 | } |
49 | return *this; |
50 | } |
51 | |
52 | |
53 | void NameValueCollection::swap(NameValueCollection& nvc) |
54 | { |
55 | std::swap(_map, nvc._map); |
56 | } |
57 | |
58 | |
59 | const 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 | |
69 | void 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 | |
79 | void NameValueCollection::add(const std::string& name, const std::string& value) |
80 | { |
81 | _map.insert(HeaderMap::ValueType(name, value)); |
82 | } |
83 | |
84 | |
85 | const 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 | |
95 | const 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 | |
105 | bool NameValueCollection::has(const std::string& name) const |
106 | { |
107 | return _map.find(name) != _map.end(); |
108 | } |
109 | |
110 | |
111 | NameValueCollection::ConstIterator NameValueCollection::find(const std::string& name) const |
112 | { |
113 | return _map.find(name); |
114 | } |
115 | |
116 | |
117 | NameValueCollection::ConstIterator NameValueCollection::begin() const |
118 | { |
119 | return _map.begin(); |
120 | } |
121 | |
122 | |
123 | NameValueCollection::ConstIterator NameValueCollection::end() const |
124 | { |
125 | return _map.end(); |
126 | } |
127 | |
128 | |
129 | bool NameValueCollection::empty() const |
130 | { |
131 | return _map.empty(); |
132 | } |
133 | |
134 | |
135 | std::size_t NameValueCollection::size() const |
136 | { |
137 | return _map.size(); |
138 | } |
139 | |
140 | |
141 | void NameValueCollection::erase(const std::string& name) |
142 | { |
143 | _map.erase(name); |
144 | } |
145 | |
146 | |
147 | void NameValueCollection::clear() |
148 | { |
149 | _map.clear(); |
150 | } |
151 | |
152 | |
153 | } } // namespace Poco::Net |
154 |