From f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 21 Nov 2013 22:16:57 +0100 Subject: Boost/C++11 shared pointers. --- src/messageParser.cpp | 64 +++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'src/messageParser.cpp') diff --git a/src/messageParser.cpp b/src/messageParser.cpp index 1377072c..41be3803 100644 --- a/src/messageParser.cpp +++ b/src/messageParser.cpp @@ -39,14 +39,14 @@ namespace vmime messageParser::messageParser(const string& buffer) { - ref msg = vmime::create (); + shared_ptr msg = make_shared (); msg->parse(buffer); parse(msg); } -messageParser::messageParser(ref msg) +messageParser::messageParser(shared_ptr msg) { parse(msg); } @@ -57,13 +57,13 @@ messageParser::~messageParser() } -void messageParser::parse(ref msg) +void messageParser::parse(shared_ptr msg) { // Header fields (if field is present, copy its value, else do nothing) #ifndef VMIME_BUILDING_DOC #define TRY_FIELD(var, type, name) \ - try { var = *msg->getHeader()->findField(name)->getValue().dynamicCast (); } \ + try { var = *msg->getHeader()->findField(name)->getValue (); } \ catch (exceptions::no_such_field) { } TRY_FIELD(m_from, mailbox, fields::FROM); @@ -82,14 +82,14 @@ void messageParser::parse(ref msg) try { const headerField& recv = *msg->getHeader()->findField(fields::RECEIVED); - m_date = recv.getValue().dynamicCast ()->getDate(); + m_date = recv.getValue ()->getDate(); } catch (vmime::exceptions::no_such_field&) { try { const headerField& date = *msg->getHeader()->findField(fields::DATE); - m_date = *date.getValue().dynamicCast (); + m_date = *date.getValue (); } catch (vmime::exceptions::no_such_field&) { @@ -105,13 +105,13 @@ void messageParser::parse(ref msg) } -void messageParser::findAttachments(ref msg) +void messageParser::findAttachments(shared_ptr msg) { m_attach = attachmentHelper::findAttachmentsInMessage(msg); } -void messageParser::findTextParts(ref msg, ref part) +void messageParser::findTextParts(shared_ptr msg, shared_ptr part) { // Handle the case in which the message is not multipart: if the body part is // "text/*", take this part. @@ -122,11 +122,11 @@ void messageParser::findTextParts(ref msg, ref try { - const contentTypeField& ctf = dynamic_cast - (*msg->getHeader()->findField(fields::CONTENT_TYPE)); + const contentTypeField& ctf = + *msg->getHeader()->findField (fields::CONTENT_TYPE); const mediaType ctfType = - *ctf.getValue().dynamicCast (); + *ctf.getValue (); if (ctfType.getType() == mediaTypes::TEXT) { @@ -142,7 +142,7 @@ void messageParser::findTextParts(ref msg, ref if (accept) { - ref txtPart = textPartFactory::getInstance()->create(type); + shared_ptr txtPart = textPartFactory::getInstance()->create(type); txtPart->parse(msg, msg, msg); m_textParts.push_back(txtPart); @@ -156,35 +156,35 @@ void messageParser::findTextParts(ref msg, ref } -bool messageParser::findSubTextParts(ref msg, ref part) +bool messageParser::findSubTextParts(shared_ptr msg, shared_ptr part) { // In general, all the text parts are contained in parallel in the same // parent part (or message). // So, wherever the text parts are, all we have to do is to find the first // MIME part which is a text part. - std::vector > textParts; + std::vector > textParts; for (size_t i = 0 ; i < part->getBody()->getPartCount() ; ++i) { - const ref p = part->getBody()->getPartAt(i); + const shared_ptr p = part->getBody()->getPartAt(i); try { - const contentTypeField& ctf = dynamic_cast - (*(p->getHeader()->findField(fields::CONTENT_TYPE))); + const contentTypeField& ctf = + *p->getHeader()->findField (fields::CONTENT_TYPE); - const mediaType type = *ctf.getValue().dynamicCast (); + const mediaType type = *ctf.getValue (); contentDisposition disp; // default should be inline if (type.getType() == mediaTypes::TEXT) { try { - ref cdf = p->getHeader()-> - findField(fields::CONTENT_DISPOSITION).dynamicCast (); + shared_ptr cdf = p->getHeader()-> + findField (fields::CONTENT_DISPOSITION); - disp = *cdf->getValue().dynamicCast (); + disp = *cdf->getValue (); } catch (exceptions::no_such_field&) { @@ -204,17 +204,17 @@ bool messageParser::findSubTextParts(ref msg, ref >::const_iterator p = textParts.begin() ; + for (std::vector >::const_iterator p = textParts.begin() ; p != textParts.end() ; ++p) { - const contentTypeField& ctf = dynamic_cast - (*((*p)->getHeader()->findField(fields::CONTENT_TYPE))); + const contentTypeField& ctf = + *(*p)->getHeader()->findField (fields::CONTENT_TYPE); - const mediaType type = *ctf.getValue().dynamicCast (); + const mediaType type = *ctf.getValue (); try { - ref txtPart = textPartFactory::getInstance()->create(type); + shared_ptr txtPart = textPartFactory::getInstance()->create(type); txtPart->parse(msg, part, *p); m_textParts.push_back(txtPart); @@ -273,7 +273,7 @@ const datetime& messageParser::getDate() const } -const std::vector > messageParser::getAttachmentList() const +const std::vector > messageParser::getAttachmentList() const { return m_attach; } @@ -285,19 +285,19 @@ size_t messageParser::getAttachmentCount() const } -const ref messageParser::getAttachmentAt(const size_t pos) const +const shared_ptr messageParser::getAttachmentAt(const size_t pos) const { return (m_attach[pos]); } -const std::vector > messageParser::getTextPartList() const +const std::vector > messageParser::getTextPartList() const { - std::vector > res; + std::vector > res; res.reserve(m_textParts.size()); - for (std::vector >::const_iterator it = m_textParts.begin() ; + for (std::vector >::const_iterator it = m_textParts.begin() ; it != m_textParts.end() ; ++it) { res.push_back(*it); @@ -313,7 +313,7 @@ size_t messageParser::getTextPartCount() const } -const ref messageParser::getTextPartAt(const size_t pos) const +const shared_ptr messageParser::getTextPartAt(const size_t pos) const { return (m_textParts[pos]); } -- cgit v1.2.3