Changed protected inheritance to simple composition.

This commit is contained in:
Vincent Richard 2005-02-06 17:14:08 +00:00
parent 95b56a7035
commit 726af25bf0
4 changed files with 90 additions and 26 deletions

View File

@ -2,6 +2,11 @@
VERSION 0.6.4cvs
================
2005-02-06 Vincent Richard <vincent@vincent-richard.net>
* mailboxList.{cpp|hpp}: dropped protected inheritance which was not
appropriate for this type of composition.
2005-02-05 Vincent Richard <vincent@vincent-richard.net>
* parserHelpers.hpp: moved 'static' functions into 'parserHelpers' class.

View File

@ -119,7 +119,11 @@ addressList& addressList::operator=(const addressList& other)
addressList& addressList::operator=(const mailboxList& other)
{
copyFrom(other);
removeAllAddresses();
for (int i = 0 ; i < other.getMailboxCount() ; ++i)
m_list.push_back(other.getMailboxAt(i)->clone());
return (*this);
}

View File

@ -31,14 +31,14 @@ mailboxList::mailboxList()
mailboxList::mailboxList(const mailboxList& mboxList)
: addressList(mboxList)
: component(), m_list(mboxList.m_list)
{
}
void mailboxList::appendMailbox(mailbox* mbox)
{
addressList::appendAddress(mbox);
m_list.appendAddress(mbox);
}
@ -46,7 +46,7 @@ void mailboxList::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
{
try
{
addressList::insertAddressBefore(beforeMailbox, mbox);
m_list.insertAddressBefore(beforeMailbox, mbox);
}
catch (exceptions::no_such_address&)
{
@ -57,7 +57,7 @@ void mailboxList::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
void mailboxList::insertMailboxBefore(const int pos, mailbox* mbox)
{
addressList::insertAddressBefore(pos, mbox);
m_list.insertAddressBefore(pos, mbox);
}
@ -65,7 +65,7 @@ void mailboxList::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
{
try
{
addressList::insertAddressAfter(afterMailbox, mbox);
m_list.insertAddressAfter(afterMailbox, mbox);
}
catch (exceptions::no_such_address&)
{
@ -76,7 +76,7 @@ void mailboxList::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
void mailboxList::insertMailboxAfter(const int pos, mailbox* mbox)
{
addressList::insertAddressAfter(pos, mbox);
m_list.insertAddressAfter(pos, mbox);
}
@ -84,7 +84,7 @@ void mailboxList::removeMailbox(mailbox* mbox)
{
try
{
addressList::removeAddress(mbox);
m_list.removeAddress(mbox);
}
catch (exceptions::no_such_address&)
{
@ -95,43 +95,43 @@ void mailboxList::removeMailbox(mailbox* mbox)
void mailboxList::removeMailbox(const int pos)
{
addressList::removeAddress(pos);
m_list.removeAddress(pos);
}
void mailboxList::removeAllMailboxes()
{
addressList::removeAllAddresses();
m_list.removeAllAddresses();
}
const int mailboxList::getMailboxCount() const
{
return (addressList::getAddressCount());
return (m_list.getAddressCount());
}
const bool mailboxList::isEmpty() const
{
return (addressList::isEmpty());
return (m_list.isEmpty());
}
mailbox* mailboxList::getMailboxAt(const int pos)
{
return static_cast <mailbox*>(addressList::getAddressAt(pos));
return static_cast <mailbox*>(m_list.getAddressAt(pos));
}
const mailbox* mailboxList::getMailboxAt(const int pos) const
{
return static_cast <const mailbox*>(addressList::getAddressAt(pos));
return static_cast <const mailbox*>(m_list.getAddressAt(pos));
}
const std::vector <const mailbox*> mailboxList::getMailboxList() const
{
const std::vector <const address*> addrList = addressList::getAddressList();
const std::vector <const address*> addrList = m_list.getAddressList();
std::vector <const mailbox*> res;
for (std::vector <const address*>::const_iterator it = addrList.begin() ;
@ -149,7 +149,7 @@ const std::vector <const mailbox*> mailboxList::getMailboxList() const
const std::vector <mailbox*> mailboxList::getMailboxList()
{
const std::vector <address*> addrList = addressList::getAddressList();
const std::vector <address*> addrList = m_list.getAddressList();
std::vector <mailbox*> res;
for (std::vector <address*>::const_iterator it = addrList.begin() ;
@ -165,4 +165,45 @@ const std::vector <mailbox*> mailboxList::getMailboxList()
}
mailboxList* mailboxList::clone() const
{
return new mailboxList(*this);
}
void mailboxList::copyFrom(const component& other)
{
const mailboxList& mboxList = dynamic_cast <const mailboxList&>(other);
m_list = mboxList.m_list;
}
mailboxList& mailboxList::operator=(const mailboxList& other)
{
copyFrom(other);
return (*this);
}
const std::vector <const component*> mailboxList::getChildComponents() const
{
return (m_list.getChildComponents());
}
void mailboxList::parse(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
m_list.parse(buffer, position, end, newPosition);
}
void mailboxList::generate(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
m_list.generate(os, maxLineLength, curLinePos, newLinePos);
}
} // vmime

View File

@ -30,24 +30,25 @@ namespace vmime
/** A list of mailboxes (basic type).
*
* This class works exactly like 'addressList' except it prevents user
* from inserting mailbox groups where it is not allowed by the RFC.
*/
#if (defined(__GNUC__) && (__GNUC__ >= 3) && (__GNUC_MINOR__ <= 2)) || defined(VMIME_NO_PROTECTED_INHERITANCE)
class mailboxList : public addressList // BUG with gcc <= 3.2
#else
class mailboxList : protected addressList
#endif
class mailboxList : public component
{
friend class mailboxGroup;
public:
// This class works exactly like 'addressList' except it prevents user
// from inserting mailbox groups where it is not allowed by the RFC.
mailboxList();
mailboxList(const mailboxList& mboxList);
mailboxList* clone() const;
void copyFrom(const component& other);
mailboxList& operator=(const mailboxList& other);
const std::vector <const component*> getChildComponents() const;
/** Add a mailbox at the end of the list.
*
* @param mbox mailbox to append
@ -139,6 +140,19 @@ public:
* @return list of mailboxes
*/
const std::vector <mailbox*> getMailboxList();
private:
addressList m_list;
public:
using component::parse;
using component::generate;
// Component parsing & assembling
void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const;
};