class Poco::Net::NameValueCollection

Overview

A collection of name-value pairs that are used in various internet protocols like HTTP and SMTP. Moreā€¦

#include <NameValueCollection.h>

class NameValueCollection
{
public:
    // typedefs

    typedef Poco::ListMap<std::string, std::string> HeaderMap;
    typedef HeaderMap::Iterator Iterator;
    typedef HeaderMap::ConstIterator ConstIterator;

    // construction

    NameValueCollection();
    NameValueCollection(const NameValueCollection& nvc);

    // methods

    NameValueCollection&
    operator=(const NameValueCollection& nvc);

    void
    swap(NameValueCollection& nvc);

    const std::string&
    operator[](const std::string& name) const;

    void
    set(
        const std::string& name,
        const std::string& value
        );

    void
    add(
        const std::string& name,
        const std::string& value
        );

    const std::string&
    get(const std::string& name) const;

    const std::string&
    get(
        const std::string& name,
        const std::string& defaultValue
        ) const;

    bool
    has(const std::string& name) const;

    ConstIterator
    find(const std::string& name) const;

    ConstIterator
    begin() const;

    ConstIterator
    end() const;

    bool
    empty() const;

    std::size_t
    size() const;

    void
    erase(const std::string& name);

    void
    clear();
};

// direct descendants

class HTMLForm;
class HTTPAuthenticationParams;
class MessageHeader;

Detailed Documentation

A collection of name-value pairs that are used in various internet protocols like HTTP and SMTP.

The name is case-insensitive.

There can be more than one name-value pair with the same name.

Construction

NameValueCollection()

Creates an empty NameValueCollection.

NameValueCollection(const NameValueCollection& nvc)

Creates a NameValueCollection by copying another one.

Methods

NameValueCollection&
operator=(const NameValueCollection& nvc)

Assigns the name-value pairs of another NameValueCollection to this one.

void
swap(NameValueCollection& nvc)

Swaps the NameValueCollection with another one.

const std::string&
operator[](const std::string& name) const

Returns the value of the (first) name-value pair with the given name.

Throws a NotFoundException if the name-value pair does not exist.

void
set(
    const std::string& name,
    const std::string& value
    )

Sets the value of the (first) name-value pair with the given name.

void
add(
    const std::string& name,
    const std::string& value
    )

Adds a new name-value pair with the given name and value.

const std::string&
get(const std::string& name) const

Returns the value of the first name-value pair with the given name.

Throws a NotFoundException if the name-value pair does not exist.

const std::string&
get(
    const std::string& name,
    const std::string& defaultValue
    ) const

Returns the value of the first name-value pair with the given name.

If no value with the given name has been found, the defaultValue is returned.

bool
has(const std::string& name) const

Returns true if there is at least one name-value pair with the given name.

ConstIterator
find(const std::string& name) const

Returns an iterator pointing to the first name-value pair with the given name.

ConstIterator
begin() const

Returns an iterator pointing to the begin of the name-value pair collection.

ConstIterator
end() const

Returns an iterator pointing to the end of the name-value pair collection.

bool
empty() const

Returns true iff the header does not have any content.

std::size_t
size() const

Returns the number of name-value pairs in the collection.

void
erase(const std::string& name)

Removes all name-value pairs with the given name.

void
clear()

Removes all name-value pairs and their values.