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/htmlTextPart.cpp | 106 +++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 53 deletions(-) (limited to 'src/htmlTextPart.cpp') diff --git a/src/htmlTextPart.cpp b/src/htmlTextPart.cpp index ebb6587c..0aabbdc4 100644 --- a/src/htmlTextPart.cpp +++ b/src/htmlTextPart.cpp @@ -39,8 +39,8 @@ namespace vmime htmlTextPart::htmlTextPart() - : m_plainText(vmime::create ()), - m_text(vmime::create ()) + : m_plainText(make_shared ()), + m_text(make_shared ()) { } @@ -62,13 +62,13 @@ size_t htmlTextPart::getPartCount() const } -void htmlTextPart::generateIn(ref /* message */, ref parent) const +void htmlTextPart::generateIn(shared_ptr /* message */, shared_ptr parent) const { // Plain text if (!m_plainText->isEmpty()) { // -- Create a new part - ref part = vmime::create (); + shared_ptr part = make_shared (); parent->getBody()->appendPart(part); // -- Set contents @@ -79,7 +79,7 @@ void htmlTextPart::generateIn(ref /* message */, ref paren // HTML text // -- Create a new part - ref htmlPart = vmime::create (); + shared_ptr htmlPart = make_shared (); // -- Set contents htmlPart->getBody()->setContents(m_text, @@ -90,7 +90,7 @@ void htmlTextPart::generateIn(ref /* message */, ref paren if (!m_objects.empty()) { // Create a "multipart/related" body part - ref relPart = vmime::create (); + shared_ptr relPart = make_shared (); parent->getBody()->appendPart(relPart); relPart->getHeader()->ContentType()-> @@ -100,10 +100,10 @@ void htmlTextPart::generateIn(ref /* message */, ref paren relPart->getBody()->appendPart(htmlPart); // Also add objects into this part - for (std::vector >::const_iterator it = m_objects.begin() ; + for (std::vector >::const_iterator it = m_objects.begin() ; it != m_objects.end() ; ++it) { - ref objPart = vmime::create (); + shared_ptr objPart = make_shared (); relPart->getBody()->appendPart(objPart); string id = (*it)->getId(); @@ -129,11 +129,11 @@ void htmlTextPart::generateIn(ref /* message */, ref paren void htmlTextPart::findEmbeddedParts(const bodyPart& part, - std::vector >& cidParts, std::vector >& locParts) + std::vector >& cidParts, std::vector >& locParts) { for (size_t i = 0 ; i < part.getBody()->getPartCount() ; ++i) { - ref p = part.getBody()->getPartAt(i); + shared_ptr p = part.getBody()->getPartAt(i); // For a part to be an embedded object, it must have a // Content-Id field or a Content-Location field. @@ -174,25 +174,25 @@ void htmlTextPart::addEmbeddedObject(const bodyPart& part, const string& id, try { - const ref ctf = part.getHeader()->ContentType(); - type = *ctf->getValue().dynamicCast (); + const shared_ptr ctf = part.getHeader()->ContentType(); + type = *ctf->getValue (); } catch (exceptions::no_such_field) { // No "Content-type" field: assume "application/octet-stream". } - m_objects.push_back(vmime::create - (part.getBody()->getContents()->clone().dynamicCast (), + m_objects.push_back(make_shared + (vmime::clone(part.getBody()->getContents()), part.getBody()->getEncoding(), id, type, refType)); } -void htmlTextPart::parse(ref message, ref parent, ref textPart) +void htmlTextPart::parse(shared_ptr message, shared_ptr parent, shared_ptr textPart) { // Search for possible embedded objects in the _whole_ message. - std::vector > cidParts; - std::vector > locParts; + std::vector > cidParts; + std::vector > locParts; findEmbeddedParts(*message, cidParts, locParts); @@ -208,8 +208,8 @@ void htmlTextPart::parse(ref message, ref pare try { - const ref ctf = - textPart->getHeader()->findField(fields::CONTENT_TYPE).dynamicCast (); + const shared_ptr ctf = + textPart->getHeader()->findField (fields::CONTENT_TYPE); m_charset = ctf->getCharset(); } @@ -224,12 +224,12 @@ void htmlTextPart::parse(ref message, ref pare // Extract embedded objects. The algorithm is quite simple: for each previously // found inline part, we check if its CID/Location is contained in the HTML text. - for (std::vector >::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p) + for (std::vector >::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p) { - const ref midField = + const shared_ptr midField = (*p)->getHeader()->findField(fields::CONTENT_ID); - const messageId mid = *midField->getValue().dynamicCast (); + const messageId mid = *midField->getValue (); if (data.find("CID:" + mid.getId()) != string::npos || data.find("cid:" + mid.getId()) != string::npos) @@ -240,12 +240,12 @@ void htmlTextPart::parse(ref message, ref pare } } - for (std::vector >::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p) + for (std::vector >::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p) { - const ref locField = + const shared_ptr locField = (*p)->getHeader()->findField(fields::CONTENT_LOCATION); - const text loc = *locField->getValue().dynamicCast (); + const text loc = *locField->getValue (); const string locStr = loc.getWholeBuffer(); if (data.find(locStr) != string::npos) @@ -259,7 +259,7 @@ void htmlTextPart::parse(ref message, ref pare // Extract plain text, if any. if (!findPlainTextPart(*message, *parent, *textPart)) { - m_plainText = vmime::create (); + m_plainText = make_shared (); } } @@ -269,22 +269,22 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren // We search for the nearest "multipart/alternative" part. try { - const ref ctf = + const shared_ptr ctf = part.getHeader()->findField(fields::CONTENT_TYPE); - const mediaType type = *ctf->getValue().dynamicCast (); + const mediaType type = *ctf->getValue (); if (type.getType() == mediaTypes::MULTIPART && type.getSubType() == mediaTypes::MULTIPART_ALTERNATIVE) { - ref foundPart = NULL; + shared_ptr foundPart; 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); - if (p == &parent || // if "text/html" is in "multipart/related" - p == &textPart) // if not... + if (p.get() == &parent || // if "text/html" is in "multipart/related" + p.get() == &textPart) // if not... { foundPart = p; } @@ -297,14 +297,14 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren // Now, search for the alternative plain text part for (size_t i = 0 ; !found && i < part.getBody()->getPartCount() ; ++i) { - const ref p = part.getBody()->getPartAt(i); + const shared_ptr p = part.getBody()->getPartAt(i); try { - const ref ctf = + const shared_ptr ctf = p->getHeader()->findField(fields::CONTENT_TYPE); - const mediaType type = *ctf->getValue().dynamicCast (); + const mediaType type = *ctf->getValue (); if (type.getType() == mediaTypes::TEXT && type.getSubType() == mediaTypes::TEXT_PLAIN) @@ -354,25 +354,25 @@ void htmlTextPart::setCharset(const charset& ch) } -ref htmlTextPart::getPlainText() const +shared_ptr htmlTextPart::getPlainText() const { return m_plainText; } -void htmlTextPart::setPlainText(ref plainText) +void htmlTextPart::setPlainText(shared_ptr plainText) { m_plainText = plainText->clone(); } -const ref htmlTextPart::getText() const +const shared_ptr htmlTextPart::getText() const { return m_text; } -void htmlTextPart::setText(ref text) +void htmlTextPart::setText(shared_ptr text) { m_text = text->clone(); } @@ -384,15 +384,15 @@ size_t htmlTextPart::getObjectCount() const } -ref htmlTextPart::getObjectAt(const size_t pos) const +shared_ptr htmlTextPart::getObjectAt(const size_t pos) const { return m_objects[pos]; } -ref htmlTextPart::findObject(const string& id) const +shared_ptr htmlTextPart::findObject(const string& id) const { - for (std::vector >::const_iterator o = m_objects.begin() ; + for (std::vector >::const_iterator o = m_objects.begin() ; o != m_objects.end() ; ++o) { if ((*o)->matchesId(id)) @@ -405,7 +405,7 @@ ref htmlTextPart::findObject(const string& bool htmlTextPart::hasObject(const string& id) const { - for (std::vector >::const_iterator o = m_objects.begin() ; + for (std::vector >::const_iterator o = m_objects.begin() ; o != m_objects.end() ; ++o) { if ((*o)->matchesId(id)) @@ -416,12 +416,12 @@ bool htmlTextPart::hasObject(const string& id) const } -ref htmlTextPart::addObject - (ref data, const vmime::encoding& enc, const mediaType& type) +shared_ptr htmlTextPart::addObject + (shared_ptr data, const vmime::encoding& enc, const mediaType& type) { const messageId mid(messageId::generateId()); - ref obj = vmime::create + shared_ptr obj = make_shared (data, enc, mid.getId(), type, embeddedObject::REFERENCED_BY_ID); m_objects.push_back(obj); @@ -430,17 +430,17 @@ ref htmlTextPart::addObject } -ref htmlTextPart::addObject - (ref data, const mediaType& type) +shared_ptr htmlTextPart::addObject + (shared_ptr data, const mediaType& type) { return addObject(data, encoding::decide(data), type); } -ref htmlTextPart::addObject +shared_ptr htmlTextPart::addObject (const string& data, const mediaType& type) { - ref cts = vmime::create (data); + shared_ptr cts = make_shared (data); return addObject(cts, encoding::decide(cts), type); } @@ -451,15 +451,15 @@ ref htmlTextPart::addObject // htmlTextPart::embeddedObject::embeddedObject - (ref data, const encoding& enc, + (shared_ptr data, const encoding& enc, const string& id, const mediaType& type, const ReferenceType refType) - : m_data(data->clone().dynamicCast ()), + : m_data(vmime::clone(data)), m_encoding(enc), m_id(id), m_type(type), m_refType(refType) { } -ref htmlTextPart::embeddedObject::getData() const +shared_ptr htmlTextPart::embeddedObject::getData() const { return m_data; } -- cgit v1.2.3