Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | List of all members
net_instaweb::StringMultiMap< StringCompare > Class Template Reference

#include "string_multi_map.h"

Public Member Functions

bool empty () const
 
void Clear ()
 
int num_names () const
 Returns the number of distinct names.
 
int num_values () const
 
bool Lookup (const StringPiece &name, ConstStringStarVector *values) const
 
const GoogleStringLookup1 (const StringPiece &name) const
 
bool Has (const StringPiece &name) const
 
bool RemoveAll (const StringPiece &key)
 Remove all variables by name. Returns true if anything was removed.
 
bool RemoveAllFromSortedArray (const StringPiece *names, int names_size)
 
StringPiece name (int index) const
 
const GoogleStringvalue (int index) const
 Note that the value can be NULL.
 
void Add (const StringPiece &key, const StringPiece &value)
 Add a new variable. The value can be null. More...
 
void AddFromNameValuePairs (const StringPiece &name_value_list, const StringPiece &separators, char value_separator, bool omit_if_no_value)
 
void CopyFrom (const StringMultiMap &string_multi_map)
 

Detailed Description

template<class StringCompare>
class net_instaweb::StringMultiMap< StringCompare >

Implements an ordered string map, providing case-sensitive and case insensitive versions. The order of insertion is retained and names/value pairs can be accessed by index or looked up by name.

The keys and values in the map may contain embedded NUL characters. The values can also be the NULL pointer, which the API retains distinctly from empty strings.

Member Function Documentation

template<class StringCompare>
void net_instaweb::StringMultiMap< StringCompare >::Add ( const StringPiece &  key,
const StringPiece &  value 
)
inline

Add a new variable. The value can be null.

To avoid letting you corrupt the comparison sanity of an STL set, the 'insert' method returns an iterator that returns you only a const reference to the stored entry. However, the mutation we are going to do here is to change the key to point to storage we'll own in the entry, which we want to allocate only the first time it is added.

We also need to be able to mutate the entry to allow adding new value entries.

The first time we insert, make a copy of the key in storage we own.

template<class StringCompare>
void net_instaweb::StringMultiMap< StringCompare >::AddFromNameValuePairs ( const StringPiece &  name_value_list,
const StringPiece &  separators,
char  value_separator,
bool  omit_if_no_value 
)
inline

Parse and add from a string of name-value pairs. For example, "name1=value1,name2=value2,name3=" where separators is "," and value_separator is '='. If omit_if_no_value is true, a name-value pair with an empty value will not be added.

template<class StringCompare>
bool net_instaweb::StringMultiMap< StringCompare >::Lookup ( const StringPiece &  name,
ConstStringStarVector *  values 
) const
inline

Find the value(s) associated with a variable. Note that you may specify a variable multiple times by calling Add multiple times with the same variable, and each of these values will be returned in the vector.

template<class StringCompare>
const GoogleString* net_instaweb::StringMultiMap< StringCompare >::Lookup1 ( const StringPiece &  name) const
inline

Looks up a single value. Returns NULL if the name is not found or more than one value is found.

template<class StringCompare>
int net_instaweb::StringMultiMap< StringCompare >::num_values ( ) const
inline

Returns the number of distinct values, which can be larger than num_names if Add is called twice with the same name.

template<class StringCompare>
bool net_instaweb::StringMultiMap< StringCompare >::RemoveAllFromSortedArray ( const StringPiece *  names,
int  names_size 
)
inline

Remove all variables by name. Returns true if anything was removed.

The 'names' vector must be sorted based on StringCompare.

compare implements <, and we want <= to allow for for duplicate entries, such as the two Set-Cookie entries that occur in ResponseHeadersTest.TestUpdateFrom. We could also require call-sites to de-dup but this seems easier. We can implement a<=b via !compare(b, a).

Keep around dummy entry for stuffing in keys and doing lookups. The values field for this instance is unused.

First, see if any of the names are in the map. This way we'll avoid making any allocations if there is no work to be done. We cannot actually remove the map entries, though, until we rebuild the vector, since the map owns the StringPiece key storage used by the vector.

< Temp variable for new vector.


The documentation for this class was generated from the following file: