Adding functions in 'header' object to retrieve a list of fields by name/type
This commit is contained in:
parent
a1f5ebbfbc
commit
f3d249c81b
@ -286,8 +286,6 @@ const bool header::fieldsContainer::has(const string& fieldName) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Find the first field that matches the specified type/name.
|
|
||||||
// If no field is found, an exception is thrown.
|
|
||||||
headerField& header::fieldsContainer::find(const headerField::Types fieldType) const
|
headerField& header::fieldsContainer::find(const headerField::Types fieldType) const
|
||||||
{
|
{
|
||||||
// Find the first field that matches the specified type
|
// Find the first field that matches the specified type
|
||||||
@ -335,7 +333,48 @@ headerField& header::fieldsContainer::find(const string& fieldName) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Find the first field that matches the specified type/name
|
std::vector <headerField*> header::fieldsContainer::findAllByType(const headerField::Types fieldType)
|
||||||
|
{
|
||||||
|
std::vector <headerField*> result;
|
||||||
|
|
||||||
|
std::vector <headerField*>::const_iterator pos = m_fields.begin();
|
||||||
|
const std::vector <headerField*>::const_iterator end = m_fields.end();
|
||||||
|
|
||||||
|
for ( ; pos != end ; ++pos)
|
||||||
|
{
|
||||||
|
// Add the header if it matches the specified type
|
||||||
|
if ((*pos)->type() == fieldType)
|
||||||
|
{
|
||||||
|
result.push_back(*pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector <headerField*> header::fieldsContainer::findAllByName(const string& fieldName)
|
||||||
|
{
|
||||||
|
const string name = toLower(fieldName);
|
||||||
|
|
||||||
|
std::vector <headerField*> result;
|
||||||
|
|
||||||
|
std::vector <headerField*>::const_iterator pos = m_fields.begin();
|
||||||
|
const std::vector <headerField*>::const_iterator end = m_fields.end();
|
||||||
|
|
||||||
|
for ( ; pos != end ; ++pos)
|
||||||
|
{
|
||||||
|
// Add the header if it matches the specified type
|
||||||
|
if (toLower((*pos)->name()) == name)
|
||||||
|
{
|
||||||
|
result.push_back(*pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
headerField& header::fieldsContainer::get(const headerField::Types fieldType)
|
headerField& header::fieldsContainer::get(const headerField::Types fieldType)
|
||||||
{
|
{
|
||||||
// Find the first field that matches the specified type
|
// Find the first field that matches the specified type
|
||||||
|
@ -56,13 +56,11 @@ class header : public component
|
|||||||
friend class body;
|
friend class body;
|
||||||
friend class message;
|
friend class message;
|
||||||
|
|
||||||
protected:
|
public:
|
||||||
|
|
||||||
header();
|
header();
|
||||||
~header();
|
~header();
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
// A sub-class for field manipulation
|
// A sub-class for field manipulation
|
||||||
class fieldsContainer
|
class fieldsContainer
|
||||||
{
|
{
|
||||||
@ -125,6 +123,11 @@ public:
|
|||||||
headerField& find(const headerField::Types fieldType) const;
|
headerField& find(const headerField::Types fieldType) const;
|
||||||
headerField& find(const string& fieldName) const;
|
headerField& find(const string& fieldName) const;
|
||||||
|
|
||||||
|
// Find all fields that matche the specified type/name.
|
||||||
|
// If no field is found, an empty vector is returned.
|
||||||
|
std::vector <headerField*> findAllByType(const headerField::Types fieldType);
|
||||||
|
std::vector <headerField*> findAllByName(const string& fieldName);
|
||||||
|
|
||||||
// Find the first field that matches the specified type/name.
|
// Find the first field that matches the specified type/name.
|
||||||
// If no field is found, one will be created.
|
// If no field is found, one will be created.
|
||||||
headerField& get(const headerField::Types fieldType);
|
headerField& get(const headerField::Types fieldType);
|
||||||
|
Loading…
Reference in New Issue
Block a user