Skip to content

Commit

Permalink
Avoid copy by passing shared_ptr<> with const reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-richard committed Aug 18, 2018
1 parent 997616c commit f173b0a
Show file tree
Hide file tree
Showing 217 changed files with 626 additions and 624 deletions.
8 changes: 4 additions & 4 deletions doc/book/net.tex
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ \section{User credentials and authenticators}

const std::vector <vmime::shared_ptr <mechanism> > getAcceptableMechanisms
(const std::vector <vmime::shared_ptr <mechanism> >& available,
vmime::shared_ptr <mechanism> suggested) const
const vmime::shared_ptr <mechanism>& suggested) const
{
// Here, you can sort the SASL mechanisms in the order they will be
// tried. If no SASL mechanism is acceptable (ie. for example, not
Expand All @@ -372,7 +372,7 @@ \section{User credentials and authenticators}
getAcceptableMechanisms(available, suggested);
}

void setSASLMechanism(vmime::shared_ptr <mechanism> mech)
void setSASLMechanism(const vmime::shared_ptr <mechanism>& mech)
{
// This is called when the authentication process is going to
// try the specified mechanism.
Expand Down Expand Up @@ -982,7 +982,7 @@ \subsubsection{Writing your own certificate verifier} % ......................
{
public:

void verify(vmime::shared_ptr <certificateChain> certs)
void verify(const vmime::shared_ptr <certificateChain>& certs)
{
// Obtain the subject's certificate
vmime::shared_ptr <vmime::security::cert::certificate> cert = chain->getAt(0);
Expand Down Expand Up @@ -1130,7 +1130,7 @@ \section{Tracing connection}
public:

vmime::shared_ptr <vmime::net::tracer> create
(vmime::shared_ptr <vmime::net::service> serv,
(const vmime::shared_ptr <vmime::net::service>& serv,
const int connectionId)
{
return vmime::make_shared <myTracer>
Expand Down
4 changes: 2 additions & 2 deletions examples/example6_authenticator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class interactiveAuthenticator : public vmime::security::sasl::defaultSASLAuthen
{
const std::vector <vmime::shared_ptr <vmime::security::sasl::SASLMechanism> > getAcceptableMechanisms
(const std::vector <vmime::shared_ptr <vmime::security::sasl::SASLMechanism> >& available,
vmime::shared_ptr <vmime::security::sasl::SASLMechanism> suggested) const
const vmime::shared_ptr <vmime::security::sasl::SASLMechanism>& suggested) const
{
std::cout << std::endl << "Available SASL mechanisms:" << std::endl;

Expand All @@ -24,7 +24,7 @@ class interactiveAuthenticator : public vmime::security::sasl::defaultSASLAuthen
return defaultSASLAuthenticator::getAcceptableMechanisms(available, suggested);
}

void setSASLMechanism(vmime::shared_ptr <vmime::security::sasl::SASLMechanism> mech)
void setSASLMechanism(const vmime::shared_ptr <vmime::security::sasl::SASLMechanism>& mech)
{
std::cout << "Trying '" << mech->getName() << "' authentication mechanism" << std::endl;

Expand Down
2 changes: 1 addition & 1 deletion examples/example6_certificateVerifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class interactiveCertificateVerifier : public vmime::security::cert::defaultCert
{
public:

void verify(vmime::shared_ptr <vmime::security::cert::certificateChain> chain, const vmime::string& hostname)
void verify(const vmime::shared_ptr <vmime::security::cert::certificateChain>& chain, const vmime::string& hostname)
{
try
{
Expand Down
8 changes: 4 additions & 4 deletions examples/example6_tracer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ class myTracer : public vmime::net::tracer
{
public:

myTracer(vmime::shared_ptr <std::ostringstream> stream,
vmime::shared_ptr <vmime::net::service> serv, const int connectionId)
myTracer(const vmime::shared_ptr <std::ostringstream>& stream,
const vmime::shared_ptr <vmime::net::service>& serv, const int connectionId)
: m_stream(stream), m_service(serv), m_connectionId(connectionId)
{
}
Expand Down Expand Up @@ -35,13 +35,13 @@ class myTracerFactory : public vmime::net::tracerFactory
{
public:

myTracerFactory(vmime::shared_ptr <std::ostringstream> stream)
myTracerFactory(const vmime::shared_ptr <std::ostringstream>& stream)
: m_stream(stream)
{
}

vmime::shared_ptr <vmime::net::tracer> create
(vmime::shared_ptr <vmime::net::service> serv, const int connectionId)
(const vmime::shared_ptr <vmime::net::service>& serv, const int connectionId)
{
return vmime::make_shared <myTracer>(m_stream, serv, connectionId);
}
Expand Down
12 changes: 6 additions & 6 deletions src/vmime/addressList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ shared_ptr <component> addressList::clone() const
}


void addressList::appendAddress(shared_ptr <address> addr)
void addressList::appendAddress(const shared_ptr <address> &addr)
{
m_list.push_back(addr);
}


void addressList::insertAddressBefore(shared_ptr <address> beforeAddress, shared_ptr <address> addr)
void addressList::insertAddressBefore(const shared_ptr <address>& beforeAddress, const shared_ptr <address>& addr)
{
const std::vector <shared_ptr <address> >::iterator it = std::find
(m_list.begin(), m_list.end(), beforeAddress);
Expand All @@ -157,7 +157,7 @@ void addressList::insertAddressBefore(shared_ptr <address> beforeAddress, shared
}


void addressList::insertAddressBefore(const size_t pos, shared_ptr <address> addr)
void addressList::insertAddressBefore(const size_t pos, const shared_ptr <address>& addr)
{
if (pos >= m_list.size())
throw std::out_of_range("Invalid position");
Expand All @@ -166,7 +166,7 @@ void addressList::insertAddressBefore(const size_t pos, shared_ptr <address> add
}


void addressList::insertAddressAfter(shared_ptr <address> afterAddress, shared_ptr <address> addr)
void addressList::insertAddressAfter(const shared_ptr <address>& afterAddress, const shared_ptr <address>& addr)
{
const std::vector <shared_ptr <address> >::iterator it = std::find
(m_list.begin(), m_list.end(), afterAddress);
Expand All @@ -178,7 +178,7 @@ void addressList::insertAddressAfter(shared_ptr <address> afterAddress, shared_p
}


void addressList::insertAddressAfter(const size_t pos, shared_ptr <address> addr)
void addressList::insertAddressAfter(const size_t pos, const shared_ptr <address>& addr)
{
if (pos >= m_list.size())
throw std::out_of_range("Invalid position");
Expand All @@ -187,7 +187,7 @@ void addressList::insertAddressAfter(const size_t pos, shared_ptr <address> addr
}


void addressList::removeAddress(shared_ptr <address> addr)
void addressList::removeAddress(const shared_ptr <address>& addr)
{
const std::vector <shared_ptr <address> >::iterator it = std::find
(m_list.begin(), m_list.end(), addr);
Expand Down
12 changes: 6 additions & 6 deletions src/vmime/addressList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class VMIME_EXPORT addressList : public headerFieldValue
*
* @param addr address to append
*/
void appendAddress(shared_ptr <address> addr);
void appendAddress(const shared_ptr <address>& addr);

/** Insert a new address before the specified address.
*
* @param beforeAddress address before which the new address will be inserted
* @param addr address to insert
* @throw std::out_of_range if the address is not in the list
*/
void insertAddressBefore(shared_ptr <address> beforeAddress, shared_ptr <address> addr);
void insertAddressBefore(const shared_ptr <address>& beforeAddress, const shared_ptr <address>& addr);

/** Insert a new address before the specified position.
*
Expand All @@ -80,30 +80,30 @@ class VMIME_EXPORT addressList : public headerFieldValue
* @param addr address to insert
* @throw std::out_of_range if the position is out of range
*/
void insertAddressBefore(const size_t pos, shared_ptr <address> addr);
void insertAddressBefore(const size_t pos, const shared_ptr <address>& addr);

/** Insert a new address after the specified address.
*
* @param afterAddress address after which the new address will be inserted
* @param addr address to insert
* @throw std::out_of_range if the address is not in the list
*/
void insertAddressAfter(shared_ptr <address> afterAddress, shared_ptr <address> addr);
void insertAddressAfter(const shared_ptr <address>& afterAddress, const shared_ptr <address>& addr);

/** Insert a new address after the specified position.
*
* @param pos position of the address before the new address
* @param addr address to insert
* @throw std::out_of_range if the position is out of range
*/
void insertAddressAfter(const size_t pos, shared_ptr <address> addr);
void insertAddressAfter(const size_t pos, const shared_ptr <address>& addr);

/** Remove the specified address from the list.
*
* @param addr address to remove
* @throw std::out_of_range if the address is not in the list
*/
void removeAddress(shared_ptr <address> addr);
void removeAddress(const shared_ptr <address>& addr);

/** Remove the address at the specified position.
*
Expand Down
2 changes: 1 addition & 1 deletion src/vmime/attachment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class VMIME_EXPORT attachment : public object
*
* @param parent body part in which to generate the attachment
*/
virtual void generateIn(shared_ptr <bodyPart> parent) const = 0;
virtual void generateIn(const shared_ptr <bodyPart>& parent) const = 0;
};


Expand Down
14 changes: 7 additions & 7 deletions src/vmime/attachmentHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace vmime

// static
bool attachmentHelper::isBodyPartAnAttachment
(shared_ptr <const bodyPart> part, const unsigned int options)
(const shared_ptr <const bodyPart>& part, const unsigned int options)
{
// First, try with "Content-Disposition" field.
// If not present, we will try with "Content-Type" field.
Expand Down Expand Up @@ -123,7 +123,7 @@ bool attachmentHelper::isBodyPartAnAttachment

// static
shared_ptr <const attachment> attachmentHelper::getBodyPartAttachment
(shared_ptr <const bodyPart> part, const unsigned int options)
(const shared_ptr <const bodyPart>& part, const unsigned int options)
{
if (!isBodyPartAnAttachment(part, options))
return null;
Expand Down Expand Up @@ -159,7 +159,7 @@ shared_ptr <const attachment> attachmentHelper::getBodyPartAttachment
// static
const std::vector <shared_ptr <const attachment> >
attachmentHelper::findAttachmentsInMessage
(shared_ptr <const message> msg, const unsigned int options)
(const shared_ptr <const message>& msg, const unsigned int options)
{
return findAttachmentsInBodyPart(msg, options);
}
Expand All @@ -168,7 +168,7 @@ const std::vector <shared_ptr <const attachment> >
// static
const std::vector <shared_ptr <const attachment> >
attachmentHelper::findAttachmentsInBodyPart
(shared_ptr <const bodyPart> part, const unsigned int options)
(const shared_ptr <const bodyPart>& part, const unsigned int options)
{
std::vector <shared_ptr <const attachment> > atts;

Expand Down Expand Up @@ -196,7 +196,7 @@ const std::vector <shared_ptr <const attachment> >


// static
void attachmentHelper::addAttachment(shared_ptr <message> msg, shared_ptr <attachment> att)
void attachmentHelper::addAttachment(const shared_ptr <message>& msg, const shared_ptr <attachment>& att)
{
// We simply search for a "multipart/mixed" part. If no one exists,
// create it in the root part. This (very simple) algorithm should
Expand Down Expand Up @@ -279,7 +279,7 @@ void attachmentHelper::addAttachment(shared_ptr <message> msg, shared_ptr <attac

// static
shared_ptr <bodyPart> attachmentHelper::findBodyPart
(shared_ptr <bodyPart> part, const mediaType& type)
(const shared_ptr <bodyPart>& part, const mediaType& type)
{
if (part->getBody()->getContentType() == type)
return part;
Expand All @@ -301,7 +301,7 @@ shared_ptr <bodyPart> attachmentHelper::findBodyPart


// static
void attachmentHelper::addAttachment(shared_ptr <message> msg, shared_ptr <message> amsg)
void attachmentHelper::addAttachment(const shared_ptr <message>& msg, const shared_ptr <message>& amsg)
{
shared_ptr <attachment> att = make_shared <parsedMessageAttachment>(amsg);
addAttachment(msg, att);
Expand Down
14 changes: 7 additions & 7 deletions src/vmime/attachmentHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class VMIME_EXPORT attachmentHelper
* @param options search options (see FindOptions)
* @return true if the part is an attachment, false otherwise
*/
static bool isBodyPartAnAttachment(shared_ptr <const bodyPart> part, const unsigned int options = 0);
static bool isBodyPartAnAttachment(const shared_ptr <const bodyPart>& part, const unsigned int options = 0);

/** Return attachment information in the specified body part.
* If the specified body part does not contain attachment
Expand All @@ -70,7 +70,7 @@ class VMIME_EXPORT attachmentHelper
* @return attachment found in the part, or NULL
*/
static shared_ptr <const attachment>
getBodyPartAttachment(shared_ptr <const bodyPart> part, const unsigned int options = 0);
getBodyPartAttachment(const shared_ptr <const bodyPart>& part, const unsigned int options = 0);

/** Find all attachments contained in the specified part
* and all its children parts.
Expand All @@ -81,7 +81,7 @@ class VMIME_EXPORT attachmentHelper
* @return a list of attachments found
*/
static const std::vector <shared_ptr <const attachment> >
findAttachmentsInBodyPart(shared_ptr <const bodyPart> part, const unsigned int options = 0);
findAttachmentsInBodyPart(const shared_ptr <const bodyPart>& part, const unsigned int options = 0);

/** Find all attachments contained in the specified message.
* This is simply a recursive call to getBodyPartAttachment().
Expand All @@ -91,26 +91,26 @@ class VMIME_EXPORT attachmentHelper
* @return a list of attachments found
*/
static const std::vector <shared_ptr <const attachment> >
findAttachmentsInMessage(shared_ptr <const message> msg, const unsigned int options = 0);
findAttachmentsInMessage(const shared_ptr <const message>& msg, const unsigned int options = 0);

/** Add an attachment to the specified message.
*
* @param msg message into which to add the attachment
* @param att attachment to add
*/
static void addAttachment(shared_ptr <message> msg, shared_ptr <attachment> att);
static void addAttachment(const shared_ptr <message>& msg, const shared_ptr <attachment>& att);

/** Add a message attachment to the specified message.
*
* @param msg message into which to add the attachment
* @param amsg message to attach
*/
static void addAttachment(shared_ptr <message> msg, shared_ptr <message> amsg);
static void addAttachment(const shared_ptr <message>& msg, const shared_ptr <message>& amsg);

protected:

static shared_ptr <bodyPart> findBodyPart
(shared_ptr <bodyPart> part, const mediaType& type);
(const shared_ptr <bodyPart>& part, const mediaType& type);
};


Expand Down
6 changes: 3 additions & 3 deletions src/vmime/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ namespace vmime
* This is an alias for dynamic_pointer_cast <T>(obj->clone()).
*/
template <class T>
shared_ptr <T> clone(shared_ptr <T> obj)
shared_ptr <T> clone(const shared_ptr <T>& obj)
{
return dynamic_pointer_cast <T>(obj->clone());
}
Expand All @@ -201,7 +201,7 @@ namespace vmime
* This is an alias for dynamic_pointer_cast <T>(obj->clone()).
*/
template <class T>
shared_ptr <T> clone(shared_ptr <const T> obj)
shared_ptr <T> clone(const shared_ptr <const T>& obj)
{
return dynamic_pointer_cast <T>(obj->clone());
}
Expand All @@ -220,7 +220,7 @@ namespace vmime
* type Type, and DerivedType is derived from Type.
*/
template <class X, class Y>
shared_ptr <X> dynamicCast(shared_ptr <Y> obj)
shared_ptr <X> dynamicCast(const shared_ptr <Y>& obj)
{
return dynamic_pointer_cast <X, Y>(obj);
}
Expand Down
Loading

0 comments on commit f173b0a

Please sign in to comment.