diff options
author | Vincent Richard <[email protected]> | 2005-07-12 22:28:02 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2005-07-12 22:28:02 +0000 |
commit | 681297e10b666e13cc463f6fbb16236f36c3266c (patch) | |
tree | 5d2392e2283232ed3475cd9c69e22897b03e8a97 /src/addressList.cpp | |
parent | Added contentHandler::extractRaw(). (diff) | |
download | vmime-681297e10b666e13cc463f6fbb16236f36c3266c.tar.gz vmime-681297e10b666e13cc463f6fbb16236f36c3266c.zip |
Reference counting and smart pointers.
Diffstat (limited to 'src/addressList.cpp')
-rw-r--r-- | src/addressList.cpp | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/src/addressList.cpp b/src/addressList.cpp index 9693a663..e4f9ab04 100644 --- a/src/addressList.cpp +++ b/src/addressList.cpp @@ -54,7 +54,7 @@ void addressList::parse(const string& buffer, const string::size_type position, while (pos < end) { - address* parsedAddress = address::parseNext(buffer, pos, end, &pos); + ref <address> parsedAddress = address::parseNext(buffer, pos, end, &pos); if (parsedAddress != NULL) m_list.push_back(parsedAddress); @@ -74,7 +74,7 @@ void addressList::generate(utility::outputStream& os, const string::size_type ma if (!m_list.empty()) { - for (std::vector <address*>::const_iterator i = m_list.begin() ; ; ) + for (std::vector <ref <address> >::const_iterator i = m_list.begin() ; ; ) { (*i)->generate(os, maxLineLength - 2, pos, &pos); @@ -97,10 +97,10 @@ void addressList::copyFrom(const component& other) removeAllAddresses(); - for (std::vector <address*>::const_iterator it = addrList.m_list.begin() ; + for (std::vector <ref <address> >::const_iterator it = addrList.m_list.begin() ; it != addrList.m_list.end() ; ++it) { - m_list.push_back(static_cast <address*>((*it)->clone())); + m_list.push_back((*it)->clone().dynamicCast <address>()); } } @@ -117,27 +117,27 @@ addressList& addressList::operator=(const mailboxList& other) removeAllAddresses(); for (int i = 0 ; i < other.getMailboxCount() ; ++i) - m_list.push_back(other.getMailboxAt(i)->clone()); + m_list.push_back(other.getMailboxAt(i)->clone().dynamicCast <address>()); return (*this); } -addressList* addressList::clone() const +ref <component> addressList::clone() const { - return new addressList(*this); + return vmime::create <addressList>(*this); } -void addressList::appendAddress(address* addr) +void addressList::appendAddress(ref <address> addr) { m_list.push_back(addr); } -void addressList::insertAddressBefore(address* beforeAddress, address* addr) +void addressList::insertAddressBefore(ref <address> beforeAddress, ref <address> addr) { - const std::vector <address*>::iterator it = std::find + const std::vector <ref <address> >::iterator it = std::find (m_list.begin(), m_list.end(), beforeAddress); if (it == m_list.end()) @@ -147,15 +147,15 @@ void addressList::insertAddressBefore(address* beforeAddress, address* addr) } -void addressList::insertAddressBefore(const int pos, address* addr) +void addressList::insertAddressBefore(const int pos, ref <address> addr) { m_list.insert(m_list.begin() + pos, addr); } -void addressList::insertAddressAfter(address* afterAddress, address* addr) +void addressList::insertAddressAfter(ref <address> afterAddress, ref <address> addr) { - const std::vector <address*>::iterator it = std::find + const std::vector <ref <address> >::iterator it = std::find (m_list.begin(), m_list.end(), afterAddress); if (it == m_list.end()) @@ -165,31 +165,27 @@ void addressList::insertAddressAfter(address* afterAddress, address* addr) } -void addressList::insertAddressAfter(const int pos, address* addr) +void addressList::insertAddressAfter(const int pos, ref <address> addr) { m_list.insert(m_list.begin() + pos + 1, addr); } -void addressList::removeAddress(address* addr) +void addressList::removeAddress(ref <address> addr) { - const std::vector <address*>::iterator it = std::find + const std::vector <ref <address> >::iterator it = std::find (m_list.begin(), m_list.end(), addr); if (it == m_list.end()) throw exceptions::no_such_address(); - delete (*it); - m_list.erase(it); } void addressList::removeAddress(const int pos) { - const std::vector <address*>::iterator it = m_list.begin() + pos; - - delete (*it); + const std::vector <ref <address> >::iterator it = m_list.begin() + pos; m_list.erase(it); } @@ -197,7 +193,7 @@ void addressList::removeAddress(const int pos) void addressList::removeAllAddresses() { - free_container(m_list); + m_list.clear(); } @@ -213,25 +209,25 @@ const bool addressList::isEmpty() const } -address* addressList::getAddressAt(const int pos) +ref <address> addressList::getAddressAt(const int pos) { return (m_list[pos]); } -const address* addressList::getAddressAt(const int pos) const +const ref <const address> addressList::getAddressAt(const int pos) const { return (m_list[pos]); } -const std::vector <const address*> addressList::getAddressList() const +const std::vector <ref <const address> > addressList::getAddressList() const { - std::vector <const address*> list; + std::vector <ref <const address> > list; list.reserve(m_list.size()); - for (std::vector <address*>::const_iterator it = m_list.begin() ; + for (std::vector <ref <address> >::const_iterator it = m_list.begin() ; it != m_list.end() ; ++it) { list.push_back(*it); @@ -241,15 +237,15 @@ const std::vector <const address*> addressList::getAddressList() const } -const std::vector <address*> addressList::getAddressList() +const std::vector <ref <address> > addressList::getAddressList() { return (m_list); } -const std::vector <const component*> addressList::getChildComponents() const +const std::vector <ref <const component> > addressList::getChildComponents() const { - std::vector <const component*> list; + std::vector <ref <const component> > list; copy_vector(m_list, list); |