From f3d249c81b6395550fe81c31da9a63b9146810cf Mon Sep 17 00:00:00 2001 From: Laurent Richard Date: Wed, 6 Oct 2004 11:04:00 +0000 Subject: [PATCH] Adding functions in 'header' object to retrieve a list of fields by name/type --- src/header.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++--- src/header.hpp | 9 ++++++--- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/header.cpp b/src/header.cpp index f7745360..eb972de0 100644 --- a/src/header.cpp +++ b/src/header.cpp @@ -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 { // 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 header::fieldsContainer::findAllByType(const headerField::Types fieldType) +{ + std::vector result; + + std::vector ::const_iterator pos = m_fields.begin(); + const std::vector ::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 header::fieldsContainer::findAllByName(const string& fieldName) +{ + const string name = toLower(fieldName); + + std::vector result; + + std::vector ::const_iterator pos = m_fields.begin(); + const std::vector ::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) { // Find the first field that matches the specified type diff --git a/src/header.hpp b/src/header.hpp index 8ce070b9..b675e6fc 100644 --- a/src/header.hpp +++ b/src/header.hpp @@ -56,13 +56,11 @@ class header : public component friend class body; friend class message; -protected: +public: header(); ~header(); -public: - // A sub-class for field manipulation class fieldsContainer { @@ -125,6 +123,11 @@ public: headerField& find(const headerField::Types fieldType) 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 findAllByType(const headerField::Types fieldType); + std::vector findAllByName(const string& fieldName); + // Find the first field that matches the specified type/name. // If no field is found, one will be created. headerField& get(const headerField::Types fieldType);