2
// NameValueCollection.h
4
// $Id: //poco/1.2/Net/include/Poco/Net/NameValueCollection.h#1 $
8
// Module: NameValueCollection
10
// Definition of the NameValueCollection class.
12
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
15
// Permission is hereby granted, free of charge, to any person or organization
16
// obtaining a copy of the software and accompanying documentation covered by
17
// this license (the "Software") to use, reproduce, display, distribute,
18
// execute, and transmit the Software, and to prepare derivative works of the
19
// Software, and to permit third-parties to whom the Software is furnished to
20
// do so, all subject to the following:
22
// The copyright notices in the Software and this entire statement, including
23
// the above license grant, this restriction and the following disclaimer,
24
// must be included in all copies of the Software, in whole or in part, and
25
// all derivative works of the Software, unless such copies or derivative
26
// works are solely in the form of machine-executable object code generated by
27
// a source language processor.
29
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35
// DEALINGS IN THE SOFTWARE.
39
#ifndef Net_NameValueCollection_INCLUDED
40
#define Net_NameValueCollection_INCLUDED
43
#include "Poco/Net/Net.h"
44
#include "Poco/String.h"
52
class Net_API NameValueCollection
53
/// A collection of name-value pairs that are used in
54
/// various internet protocols like HTTP and SMTP.
56
/// The name is case-insensitive.
58
/// There can be more than one name-value pair with the
64
bool operator() (const std::string& s1, const std::string& s2) const
66
return Poco::icompare(s1, s2) < 0;
70
typedef std::multimap<std::string, std::string, ILT> HeaderMap;
71
typedef HeaderMap::iterator Iterator;
72
typedef HeaderMap::const_iterator ConstIterator;
74
NameValueCollection();
75
/// Creates an empty NameValueCollection.
77
NameValueCollection(const NameValueCollection& nvc);
78
/// Creates a NameValueCollection by copying another one.
80
virtual ~NameValueCollection();
81
/// Destroys the NameValueCollection.
83
NameValueCollection& operator = (const NameValueCollection& nvc);
84
/// Assigns the name-value pairs of another NameValueCollection to this one.
86
void swap(NameValueCollection& nvc);
87
/// Swaps the NameValueCollection with another one.
89
const std::string& operator [] (const std::string& name) const;
90
/// Returns the value of the (first) name-value pair with the given name.
92
/// Throws a NotFoundException if the name-value pair does not exist.
94
void set(const std::string& name, const std::string& value);
95
/// Sets the value of the (first) name-value pair with the given name.
97
void add(const std::string& name, const std::string& value);
98
/// Adds a new name-value pair with the given name and value.
100
const std::string& get(const std::string& name) const;
101
/// Returns the value of the first name-value pair with the given name.
103
/// Throws a NotFoundException if the name-value pair does not exist.
105
const std::string& get(const std::string& name, const std::string& defaultValue) const;
106
/// Returns the value of the first name-value pair with the given name.
107
/// If no value with the given name has been found, the defaultValue is returned.
109
bool has(const std::string& name) const;
110
/// Returns true if there is at least one name-value pair
111
/// with the given name.
113
ConstIterator find(const std::string& name) const;
114
/// Returns an iterator pointing to the first name-value pair
115
/// with the given name.
117
ConstIterator begin() const;
118
/// Returns an iterator pointing to the begin of
119
/// the name-value pair collection.
121
ConstIterator end() const;
122
/// Returns an iterator pointing to the end of
123
/// the name-value pair collection.
126
/// Returns true iff the header does not have any content.
129
/// Returns the number of name-value pairs in the
132
void erase(const std::string& name);
133
/// Removes all name-value pairs with the given name.
136
/// Removes all name-value pairs and their values.
146
inline void swap(NameValueCollection& nvc1, NameValueCollection& nvc2)
152
} } // namespace Poco::Net
155
#endif // Net_NameValueCollection_INCLUDED