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/bodyPart.cpp | 70 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'src/bodyPart.cpp') diff --git a/src/bodyPart.cpp b/src/bodyPart.cpp index f63fd670..be5b8e3a 100644 --- a/src/bodyPart.cpp +++ b/src/bodyPart.cpp @@ -29,26 +29,17 @@ namespace vmime bodyPart::bodyPart() - : m_header(vmime::create
()), - m_body(vmime::create ()), - m_parent(NULL) + : m_header(make_shared
()), + m_body(make_shared ()), + m_parent() { - m_body->setParentPart(thisRef().dynamicCast ()); -} - - -bodyPart::bodyPart(weak_ref parentPart) - : m_header(vmime::create
()), - m_body(vmime::create ()), - m_parent(parentPart) -{ - m_body->setParentPart(thisRef().dynamicCast ()); + m_body->setParentPart(this); } void bodyPart::parseImpl (const parsingContext& ctx, - ref parser, + shared_ptr parser, const utility::stream::size_type position, const utility::stream::size_type end, utility::stream::size_type* newPosition) @@ -88,11 +79,11 @@ utility::stream::size_type bodyPart::getGeneratedSize(const generationContext& c } -ref bodyPart::clone() const +shared_ptr bodyPart::clone() const { - ref p = vmime::create (); + shared_ptr p = make_shared (); - p->m_parent = null; + p->m_parent = NULL; p->m_header->copyFrom(*m_header); p->m_body->copyFrom(*m_body); @@ -117,64 +108,79 @@ bodyPart& bodyPart::operator=(const bodyPart& other) } -const ref bodyPart::getHeader() const +const shared_ptr bodyPart::getHeader() const { return (m_header); } -ref
bodyPart::getHeader() +shared_ptr
bodyPart::getHeader() { return (m_header); } -void bodyPart::setHeader(ref
h) +void bodyPart::setHeader(shared_ptr
h) { m_header = h; } -const ref bodyPart::getBody() const +const shared_ptr bodyPart::getBody() const { return (m_body); } -ref bodyPart::getBody() +shared_ptr bodyPart::getBody() { return (m_body); } -void bodyPart::setBody(ref b) +void bodyPart::setBody(shared_ptr b) { - ref oldPart = b->m_part.acquire(); + bodyPart* oldPart = b->m_part; m_body = b; - m_body->setParentPart(thisRef().dynamicCast ()); + m_body->setParentPart(this); // A body is associated to one and only one part if (oldPart != NULL) - oldPart->setBody(vmime::create ()); + oldPart->setBody(make_shared ()); } -ref bodyPart::getParentPart() +bodyPart* bodyPart::getParentPart() { - return m_parent.acquire(); + return m_parent; +} + + +const bodyPart* bodyPart::getParentPart() const +{ + return m_parent; +} + + +shared_ptr bodyPart::createChildPart() +{ + shared_ptr part = make_shared (); + part->m_parent = this; + + return part; } -ref bodyPart::getParentPart() const +void bodyPart::importChildPart(shared_ptr part) { - return m_parent.acquire(); + part->m_parent = this; } -const std::vector > bodyPart::getChildComponents() +const std::vector > bodyPart::getChildComponents() { - std::vector > list; + std::vector > list; list.push_back(m_header); list.push_back(m_body); -- cgit v1.2.3