From 3217dd9bf9476a544d450e9ac636ca629ad141d9 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Mon, 20 Dec 2004 12:33:55 +0000 Subject: [PATCH] Added component::getChildComponents() function. --- src/addressList.cpp | 8 ++++++++ src/addressList.hpp | 2 ++ src/base.hpp | 13 +++++++++++++ src/body.cpp | 10 ++++++++++ src/body.hpp | 2 ++ src/bodyPart.cpp | 11 +++++++++++ src/bodyPart.hpp | 2 ++ src/charset.cpp | 6 ++++++ src/charset.hpp | 2 ++ src/component.cpp | 18 ++++++++++++++++++ src/component.hpp | 12 ++++++++++++ src/dateTime.cpp | 6 ++++++ src/dateTime.hpp | 2 ++ src/disposition.cpp | 6 ++++++ src/disposition.hpp | 2 ++ src/encoding.cpp | 6 ++++++ src/encoding.hpp | 2 ++ src/header.cpp | 10 ++++++++++ src/header.hpp | 2 ++ src/headerField.cpp | 10 ++++++++++ src/headerField.hpp | 2 ++ src/mailbox.cpp | 6 ++++++ src/mailbox.hpp | 2 ++ src/mailboxGroup.cpp | 11 +++++++++++ src/mailboxGroup.hpp | 2 ++ src/mediaType.cpp | 6 ++++++ src/mediaType.hpp | 2 ++ src/messageId.cpp | 6 ++++++ src/messageId.hpp | 2 ++ src/parameter.cpp | 10 ++++++++++ src/parameter.hpp | 2 ++ src/relay.cpp | 7 +++++++ src/relay.hpp | 2 ++ src/text.cpp | 7 +++++++ src/text.hpp | 2 ++ src/typeAdapter.hpp | 5 +++++ 36 files changed, 206 insertions(+) diff --git a/src/addressList.cpp b/src/addressList.cpp index b10bfe1a..2ac24776 100644 --- a/src/addressList.cpp +++ b/src/addressList.cpp @@ -248,6 +248,14 @@ const std::vector addressList::getAddressList() } +const std::vector addressList::getChildComponents() const +{ + std::vector list; + + copy_vector(m_list, list); + + return (list); +} } // vmime diff --git a/src/addressList.hpp b/src/addressList.hpp index 6048936a..5d7ef18d 100644 --- a/src/addressList.hpp +++ b/src/addressList.hpp @@ -52,6 +52,8 @@ public: addressList& operator=(const addressList& other); addressList& operator=(const mailboxList& other); + const std::vector getChildComponents() const; + /** Add a address at the end of the list. * diff --git a/src/base.hpp b/src/base.hpp index 735b8893..9e06bba6 100644 --- a/src/base.hpp +++ b/src/base.hpp @@ -90,6 +90,19 @@ namespace vmime c.clear(); } + // Copy one vector to another, with type conversion + + template + void copy_vector(T1& v1, T2& v2) + { + const typename T1::size_type count = v1.size(); + + v2.resize(count); + + for (typename T1::size_type i = 0 ; i < count ; ++i) + v2[i] = v1[i]; + } + /* diff --git a/src/body.cpp b/src/body.cpp index 5e369d4b..dca3409a 100644 --- a/src/body.cpp +++ b/src/body.cpp @@ -706,4 +706,14 @@ const std::vector body::getPartList() } +const std::vector body::getChildComponents() const +{ + std::vector list; + + copy_vector(m_parts, list); + + return (list); +} + + } // vmime diff --git a/src/body.hpp b/src/body.hpp index b12ebcc7..9008fea9 100644 --- a/src/body.hpp +++ b/src/body.hpp @@ -231,6 +231,8 @@ public: void copyFrom(const component& other); body& operator=(const body& other); + const std::vector getChildComponents() const; + private: string m_prologText; diff --git a/src/bodyPart.cpp b/src/bodyPart.cpp index 90962c7c..45998aea 100644 --- a/src/bodyPart.cpp +++ b/src/bodyPart.cpp @@ -120,5 +120,16 @@ bodyPart* bodyPart::getParentPart() const } +const std::vector bodyPart::getChildComponents() const +{ + std::vector list; + + list.push_back(&m_header); + list.push_back(&m_body); + + return (list); +} + + } // vmime diff --git a/src/bodyPart.hpp b/src/bodyPart.hpp index bf52b248..222b8db9 100644 --- a/src/bodyPart.hpp +++ b/src/bodyPart.hpp @@ -77,6 +77,8 @@ public: void copyFrom(const component& other); bodyPart& operator=(const bodyPart& other); + const std::vector getChildComponents() const; + private: header m_header; diff --git a/src/charset.cpp b/src/charset.cpp index 5a06722c..793ea1f7 100644 --- a/src/charset.cpp +++ b/src/charset.cpp @@ -274,4 +274,10 @@ void charset::copyFrom(const component& other) } +const std::vector charset::getChildComponents() const +{ + return std::vector (); +} + + } // vmime diff --git a/src/charset.hpp b/src/charset.hpp index 1a42afbb..8de75329 100644 --- a/src/charset.hpp +++ b/src/charset.hpp @@ -53,6 +53,8 @@ public: const bool operator==(const charset& value) const; const bool operator!=(const charset& value) const; + const std::vector getChildComponents() const; + /** Returns the default charset used on the system. * * This function simply calls platformDependantHandler::getLocaleCharset() diff --git a/src/component.cpp b/src/component.cpp index 35ff3dc0..cbedac63 100644 --- a/src/component.cpp +++ b/src/component.cpp @@ -75,4 +75,22 @@ void component::setParsedBounds(const string::size_type start, const string::siz } +const std::vector component::getChildComponents() +{ + const std::vector constList = + const_cast (this)->getChildComponents(); + + std::vector list; + + const std::vector ::size_type count = constList.size(); + + list.resize(count); + + for (std::vector ::size_type i = 0 ; i < count ; ++i) + list[i] = const_cast (constList[i]); + + return (list); +} + + } diff --git a/src/component.hpp b/src/component.hpp index b09d78bf..af5386b2 100644 --- a/src/component.hpp +++ b/src/component.hpp @@ -104,6 +104,18 @@ public: */ const string::size_type getParsedLength() const; + /** Return the list of children of this component. + * + * @return list of child components + */ + const std::vector getChildComponents(); + + /** Return the list of children of this component (const version). + * + * @return list of child components + */ + virtual const std::vector getChildComponents() const = 0; + protected: void setParsedBounds(const string::size_type start, const string::size_type end); diff --git a/src/dateTime.cpp b/src/dateTime.cpp index 7760d651..08ad89e9 100644 --- a/src/dateTime.cpp +++ b/src/dateTime.cpp @@ -709,6 +709,12 @@ datetime* datetime::clone() const } +const std::vector datetime::getChildComponents() const +{ + return std::vector (); +} + + const int datetime::getYear() const { return (m_year); } const int datetime::getMonth() const { return (m_month); } const int datetime::getDay() const { return (m_day); } diff --git a/src/dateTime.hpp b/src/dateTime.hpp index 7d1157e4..40ff90fc 100644 --- a/src/dateTime.hpp +++ b/src/dateTime.hpp @@ -220,6 +220,8 @@ public: // Current date and time static const datetime now(); + const std::vector getChildComponents() const; + private: static const int dayOfWeek(const int year, const int month, const int day); diff --git a/src/disposition.cpp b/src/disposition.cpp index 9ac862c1..17dba56d 100644 --- a/src/disposition.cpp +++ b/src/disposition.cpp @@ -117,4 +117,10 @@ void disposition::setName(const string& name) } +const std::vector disposition::getChildComponents() const +{ + return std::vector (); +} + + } // vmime diff --git a/src/disposition.hpp b/src/disposition.hpp index 4ca2fe92..15ab4980 100644 --- a/src/disposition.hpp +++ b/src/disposition.hpp @@ -59,6 +59,8 @@ public: void copyFrom(const component& other); disposition& operator=(const disposition& other); + const std::vector getChildComponents() const; + disposition& operator=(const string& name); diff --git a/src/encoding.cpp b/src/encoding.cpp index de7e3287..4b270c8d 100644 --- a/src/encoding.cpp +++ b/src/encoding.cpp @@ -187,4 +187,10 @@ void encoding::setName(const string& name) } +const std::vector encoding::getChildComponents() const +{ + return std::vector (); +} + + } // vmime diff --git a/src/encoding.hpp b/src/encoding.hpp index 52e48bd5..e8d358ac 100644 --- a/src/encoding.hpp +++ b/src/encoding.hpp @@ -66,6 +66,8 @@ public: const bool operator==(const encoding& value) const; const bool operator!=(const encoding& value) const; + const std::vector getChildComponents() const; + /** Decide which encoding to use based on the specified data. * * \deprecated Use the new decide() method which takes a contentHandler parameter. diff --git a/src/header.cpp b/src/header.cpp index fbe6921f..492b4576 100644 --- a/src/header.cpp +++ b/src/header.cpp @@ -510,4 +510,14 @@ const std::vector header::getFieldList() } +const std::vector header::getChildComponents() const +{ + std::vector list; + + copy_vector(m_fields, list); + + return (list); +} + + } // vmime diff --git a/src/header.hpp b/src/header.hpp index bf0b74e9..d191e776 100644 --- a/src/header.hpp +++ b/src/header.hpp @@ -214,6 +214,8 @@ public: void copyFrom(const component& other); header& operator=(const header& other); + const std::vector getChildComponents() const; + private: std::vector m_fields; diff --git a/src/headerField.cpp b/src/headerField.cpp index 791b6891..0efcd0a3 100644 --- a/src/headerField.cpp +++ b/src/headerField.cpp @@ -97,4 +97,14 @@ const bool headerField::isCustom() const } +const std::vector headerField::getChildComponents() const +{ + std::vector list; + + list.push_back(&getValue()); + + return (list); +} + + } // vmime diff --git a/src/headerField.hpp b/src/headerField.hpp index 3bdc3116..081c809a 100644 --- a/src/headerField.hpp +++ b/src/headerField.hpp @@ -49,6 +49,8 @@ public: void copyFrom(const component& other); headerField& operator=(const headerField& other); + const std::vector getChildComponents() const; + /** Return the name of this field. * * @return field name diff --git a/src/mailbox.cpp b/src/mailbox.cpp index 89ede107..65031064 100644 --- a/src/mailbox.cpp +++ b/src/mailbox.cpp @@ -504,4 +504,10 @@ void mailbox::setEmail(const string& email) } +const std::vector mailbox::getChildComponents() const +{ + return std::vector (); +} + + } // vmime diff --git a/src/mailbox.hpp b/src/mailbox.hpp index e3f458e0..0acc2cc8 100644 --- a/src/mailbox.hpp +++ b/src/mailbox.hpp @@ -81,6 +81,8 @@ public: void clear(); + const std::vector getChildComponents() const; + const bool isGroup() const; diff --git a/src/mailboxGroup.cpp b/src/mailboxGroup.cpp index eac2a125..7b830030 100644 --- a/src/mailboxGroup.cpp +++ b/src/mailboxGroup.cpp @@ -350,4 +350,15 @@ const std::vector mailboxGroup::getMailboxList() } +const std::vector mailboxGroup::getChildComponents() const +{ + std::vector list; + + copy_vector(m_list, list); + + return (list); + +} + + } // vmime diff --git a/src/mailboxGroup.hpp b/src/mailboxGroup.hpp index 3cf1266c..d0d7fd93 100644 --- a/src/mailboxGroup.hpp +++ b/src/mailboxGroup.hpp @@ -48,6 +48,8 @@ public: mailboxGroup* clone() const; mailboxGroup& operator=(const component& other); + const std::vector getChildComponents() const; + /** Return the name of the group. * * @return group name diff --git a/src/mediaType.cpp b/src/mediaType.cpp index c16c316f..0bf74c95 100644 --- a/src/mediaType.cpp +++ b/src/mediaType.cpp @@ -169,4 +169,10 @@ void mediaType::setFromString(const string& type) } +const std::vector mediaType::getChildComponents() const +{ + return std::vector (); +} + + } // vmime diff --git a/src/mediaType.hpp b/src/mediaType.hpp index a5bf1a09..7f88c965 100644 --- a/src/mediaType.hpp +++ b/src/mediaType.hpp @@ -51,6 +51,8 @@ public: void copyFrom(const component& other); mediaType& operator=(const mediaType& other); + const std::vector getChildComponents() const; + /** Return the media type. * See the constants in vmime::mediaTypes. * diff --git a/src/messageId.cpp b/src/messageId.cpp index 42ac7cb6..35ab76b6 100644 --- a/src/messageId.cpp +++ b/src/messageId.cpp @@ -227,4 +227,10 @@ void messageId::setRight(const string& right) } +const std::vector messageId::getChildComponents() const +{ + return std::vector (); +} + + } // vmime diff --git a/src/messageId.hpp b/src/messageId.hpp index 85b9fd2f..467b554b 100644 --- a/src/messageId.hpp +++ b/src/messageId.hpp @@ -91,6 +91,8 @@ public: void copyFrom(const component& other); messageId& operator=(const messageId& other); + const std::vector getChildComponents() const; + private: string m_left; diff --git a/src/parameter.cpp b/src/parameter.cpp index 9feff1cc..a47a5a1a 100644 --- a/src/parameter.cpp +++ b/src/parameter.cpp @@ -149,4 +149,14 @@ void parameter::generateValue(utility::outputStream& os, const string::size_type } +const std::vector parameter::getChildComponents() const +{ + std::vector list; + + list.push_back(&getValue()); + + return (list); +} + + } // vmime diff --git a/src/parameter.hpp b/src/parameter.hpp index 6c08722e..8e718a26 100644 --- a/src/parameter.hpp +++ b/src/parameter.hpp @@ -39,6 +39,8 @@ public: void copyFrom(const component& other); parameter& operator=(const parameter& other); + const std::vector getChildComponents() const; + /** Return the name of the parameter. * * @return name of the parameter diff --git a/src/relay.cpp b/src/relay.cpp index 32cc99d8..b2a4d102 100644 --- a/src/relay.cpp +++ b/src/relay.cpp @@ -334,4 +334,11 @@ std::vector & relay::getWithList() } +const std::vector relay::getChildComponents() const +{ + // TODO: should fields inherit from 'component'? (using typeAdapter) + return std::vector (); +} + + } // vmime diff --git a/src/relay.hpp b/src/relay.hpp index 8559bccd..aac9d2bc 100644 --- a/src/relay.hpp +++ b/src/relay.hpp @@ -47,6 +47,8 @@ public: void copyFrom(const component& other); relay& operator=(const relay& other); + const std::vector getChildComponents() const; + const string& getFrom() const; void setFrom(const string& from); diff --git a/src/text.cpp b/src/text.cpp index b2f29966..cfbbea7a 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -840,4 +840,11 @@ void text::decodeAndUnfold(const string::const_iterator& inStart, const string:: } +const std::vector text::getChildComponents() const +{ + // TODO: 'word' should inherit from 'component' + return std::vector (); +} + + } // vmime diff --git a/src/text.hpp b/src/text.hpp index e7971f01..8af0c78d 100644 --- a/src/text.hpp +++ b/src/text.hpp @@ -53,6 +53,8 @@ public: text& operator=(const component& other); text& operator=(const text& other); + const std::vector getChildComponents() const; + /** Add a word at the end of the list. * * @param w word to append diff --git a/src/typeAdapter.hpp b/src/typeAdapter.hpp index 6405b108..7ae04a6b 100644 --- a/src/typeAdapter.hpp +++ b/src/typeAdapter.hpp @@ -107,6 +107,11 @@ public: *newLinePos = curLinePos + oss.str().length(); } + const std::vector getChildComponents() const + { + return std::vector (); + } + private: TYPE m_value;