diff options
Diffstat (limited to 'src/addressList.cpp')
-rw-r--r-- | src/addressList.cpp | 173 |
1 files changed, 118 insertions, 55 deletions
diff --git a/src/addressList.cpp b/src/addressList.cpp index c532c16d..93f0cc5b 100644 --- a/src/addressList.cpp +++ b/src/addressList.cpp @@ -19,6 +19,8 @@ #include "addressList.hpp" #include "parserHelpers.hpp" +#include "exception.hpp" +#include "mailboxList.hpp" namespace vmime @@ -30,23 +32,23 @@ addressList::addressList() } -addressList::addressList(const class addressList& addressList) +addressList::addressList(const addressList& addrList) : component() { - copyFrom(addressList); + copyFrom(addrList); } addressList::~addressList() { - clear(); + removeAllAddresses(); } void addressList::parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition) { - clear(); + removeAllAddresses(); string::size_type pos = position; @@ -69,11 +71,11 @@ void addressList::generate(utility::outputStream& os, const string::size_type ma if (!m_list.empty()) { string::size_type pos = curLinePos; - const_iterator i = m_list.begin(); + std::vector <address*>::const_iterator i = m_list.begin(); for ( ; ; ) { - (*i).generate(os, maxLineLength - 2, pos, &pos); + (*i)->generate(os, maxLineLength - 2, pos, &pos); if (++i != m_list.end()) { @@ -92,97 +94,158 @@ void addressList::generate(utility::outputStream& os, const string::size_type ma } -/** Return the number of addresses in the list. - * - * @return number of addresses in the list - */ +void addressList::copyFrom(const component& other) +{ + const addressList& addrList = dynamic_cast <const addressList&>(other); + + removeAllAddresses(); + + for (std::vector <address*>::const_iterator it = addrList.m_list.begin() ; + it != addrList.m_list.end() ; ++it) + { + m_list.push_back(static_cast <address*>((*it)->clone())); + } +} -const std::vector <address*>::size_type addressList::size() const + +addressList& addressList::operator=(const addressList& other) { - return (m_list.size()); + copyFrom(other); + return (*this); } -/** Return the number of addresses in the list. - * - * @return number of addresses in the list - */ +addressList& addressList::operator=(const mailboxList& other) +{ + copyFrom(other); + return (*this); +} -const std::vector <address*>::size_type addressList::count() const + +addressList* addressList::clone() const { - return (m_list.size()); + return new addressList(*this); } -/** Test whether the list is empty. - * - * @return true if the list is empty, false otherwise - */ +void addressList::appendAddress(address* addr) +{ + m_list.push_back(addr); +} + -const bool addressList::empty() const +void addressList::insertAddressBefore(address* beforeAddress, address* addr) { - return (m_list.empty()); + const std::vector <address*>::iterator it = std::find + (m_list.begin(), m_list.end(), beforeAddress); + + if (it == m_list.end()) + throw exceptions::no_such_address(); + + m_list.insert(it, addr); +} + + +void addressList::insertAddressBefore(const int pos, address* addr) +{ + m_list.insert(m_list.begin() + pos, addr); +} + + +void addressList::insertAddressAfter(address* afterAddress, address* addr) +{ + const std::vector <address*>::iterator it = std::find + (m_list.begin(), m_list.end(), afterAddress); + + if (it == m_list.end()) + throw exceptions::no_such_address(); + + m_list.insert(it + 1, addr); } -/** Append an address to the list. - * - * @param addr the address to add - */ +void addressList::insertAddressAfter(const int pos, address* addr) +{ + m_list.insert(m_list.begin() + pos + 1, addr); +} + -void addressList::append(const address& addr) +void addressList::removeAddress(address* addr) { - m_list.push_back(addr.clone()); + const std::vector <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); } -/** Insert an address at the specified position in the list. - * - * @param it position of the new address - * @param addr the address to insert - */ +void addressList::removeAddress(const int pos) +{ + const std::vector <address*>::iterator it = m_list.begin() + pos; -void addressList::insert(const iterator it, const address& addr) + delete (*it); + + m_list.erase(it); +} + + +void addressList::removeAllAddresses() { - m_list.insert(it.m_iterator, addr.clone()); + free_container(m_list); } -/** Remove the address at the specified position. - * - * @param it position of the address to remove - */ +const int addressList::getAddressCount() const +{ + return (m_list.size()); +} + -void addressList::erase(const iterator it) +const bool addressList::isEmpty() const { - delete (*it.m_iterator); - m_list.erase(it.m_iterator); + return (m_list.empty()); } -/** Remove all the addresses from the list. - */ +address* addressList::getAddressAt(const int pos) +{ + return (m_list[pos]); +} + -void addressList::clear() +const address* const addressList::getAddressAt(const int pos) const { - free_container(m_list); + return (m_list[pos]); } -void addressList::copyFrom(const addressList& source) +const std::vector <const address*> addressList::getAddressList() const { - clear(); + std::vector <const address*> list; - for (std::vector <address*>::const_iterator i = source.m_list.begin() ; i != source.m_list.end() ; ++i) - m_list.push_back((*i)->clone()); + list.reserve(m_list.size()); + + for (std::vector <address*>::const_iterator it = m_list.begin() ; + it != m_list.end() ; ++it) + { + list.push_back(*it); + } + + return (list); } -addressList& addressList::operator=(const addressList& source) +const std::vector <address*> addressList::getAddressList() { - copyFrom(source); - return (*this); + return (m_list); } + + } // vmime |