aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-11-21 21:16:57 +0000
committerVincent Richard <[email protected]>2013-11-21 21:16:57 +0000
commitf9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8 (patch)
tree2bdc90e361a8f6e0a81164cf67afec9f78f9b959 /examples
parentPer-protocol include files. (diff)
downloadvmime-f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8.tar.gz
vmime-f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8.zip
Boost/C++11 shared pointers.
Diffstat (limited to 'examples')
-rw-r--r--examples/example1.cpp8
-rw-r--r--examples/example2.cpp10
-rw-r--r--examples/example3.cpp24
-rw-r--r--examples/example6.cpp73
-rw-r--r--examples/example7.cpp10
-rw-r--r--examples/viewer/viewer.cpp8
6 files changed, 68 insertions, 65 deletions
diff --git a/examples/example1.cpp b/examples/example1.cpp
index 851f681a..9948d606 100644
--- a/examples/example1.cpp
+++ b/examples/example1.cpp
@@ -52,24 +52,24 @@ int main()
mb.setExpeditor(vmime::mailbox("[email protected]"));
vmime::addressList to;
- to.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
+ to.appendAddress(vmime::make_shared <vmime::mailbox>("[email protected]"));
mb.setRecipients(to);
vmime::addressList bcc;
- bcc.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
+ bcc.appendAddress(vmime::make_shared <vmime::mailbox>("[email protected]"));
mb.setBlindCopyRecipients(bcc);
mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder"));
// Message body
- mb.getTextPart()->setText(vmime::create <vmime::stringContentHandler>(
+ mb.getTextPart()->setText(vmime::make_shared <vmime::stringContentHandler>(
"I'm writing this short text to test message construction " \
"using the vmime::messageBuilder component."));
// Construction
- vmime::ref <vmime::message> msg = mb.construct();
+ vmime::shared_ptr <vmime::message> msg = mb.construct();
// Raw text generation
std::cout << "Generated message:" << std::endl;
diff --git a/examples/example2.cpp b/examples/example2.cpp
index d09a597c..56f01b03 100644
--- a/examples/example2.cpp
+++ b/examples/example2.cpp
@@ -52,24 +52,24 @@ int main()
mb.setExpeditor(vmime::mailbox("[email protected]"));
vmime::addressList to;
- to.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
+ to.appendAddress(vmime::make_shared <vmime::mailbox>("[email protected]"));
mb.setRecipients(to);
vmime::addressList bcc;
- bcc.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
+ bcc.appendAddress(vmime::make_shared <vmime::mailbox>("[email protected]"));
mb.setBlindCopyRecipients(bcc);
mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder"));
// Message body
- mb.getTextPart()->setText(vmime::create <vmime::stringContentHandler>(
+ mb.getTextPart()->setText(vmime::make_shared <vmime::stringContentHandler>(
"I'm writing this short text to test message construction " \
"with attachment, using the vmime::messageBuilder component."));
// Adding an attachment
- vmime::ref <vmime::fileAttachment> a = vmime::create <vmime::fileAttachment>
+ vmime::shared_ptr <vmime::fileAttachment> a = vmime::make_shared <vmime::fileAttachment>
(
"./example2.cpp", // full path to file
vmime::mediaType("application/octet-stream"), // content type
@@ -82,7 +82,7 @@ int main()
mb.attach(a);
// Construction
- vmime::ref <vmime::message> msg = mb.construct();
+ vmime::shared_ptr <vmime::message> msg = mb.construct();
// Raw text generation
vmime::string dataToSend = msg->generate();
diff --git a/examples/example3.cpp b/examples/example3.cpp
index 31e26534..56b3c7e7 100644
--- a/examples/example3.cpp
+++ b/examples/example3.cpp
@@ -52,12 +52,12 @@ int main()
mb.setExpeditor(vmime::mailbox("[email protected]"));
vmime::addressList to;
- to.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
+ to.appendAddress(vmime::make_shared <vmime::mailbox>("[email protected]"));
mb.setRecipients(to);
vmime::addressList bcc;
- bcc.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
+ bcc.appendAddress(vmime::make_shared <vmime::mailbox>("[email protected]"));
mb.setBlindCopyRecipients(bcc);
@@ -69,35 +69,35 @@ int main()
// Fill in the text part: the message is available in two formats: HTML and plain text.
// HTML text part also includes an inline image (embedded into the message).
- vmime::htmlTextPart& textPart = *mb.getTextPart().dynamicCast <vmime::htmlTextPart>();
+ vmime::htmlTextPart& textPart = *vmime::dynamicCast <vmime::htmlTextPart>(mb.getTextPart());
// -- embed an image (the returned "CID" (content identifier) is used to reference
// -- the image into HTML content).
- vmime::ref <vmime::utility::fileSystemFactory> fs =
+ vmime::shared_ptr <vmime::utility::fileSystemFactory> fs =
vmime::platform::getHandler()->getFileSystemFactory();
- vmime::ref <vmime::utility::file> imageFile =
+ vmime::shared_ptr <vmime::utility::file> imageFile =
fs->create(fs->stringToPath("/path/to/image.jpg"));
- vmime::ref <vmime::utility::fileReader> fileReader =
+ vmime::shared_ptr <vmime::utility::fileReader> fileReader =
imageFile->getFileReader();
- vmime::ref <vmime::contentHandler> imageCts =
- vmime::create <vmime::streamContentHandler>
+ vmime::shared_ptr <vmime::contentHandler> imageCts =
+ vmime::make_shared <vmime::streamContentHandler>
(fileReader->getInputStream(), imageFile->getLength());
- vmime::ref <const vmime::htmlTextPart::embeddedObject> obj = textPart.addObject
+ vmime::shared_ptr <const vmime::htmlTextPart::embeddedObject> obj = textPart.addObject
(imageCts, vmime::mediaType(vmime::mediaTypes::IMAGE, vmime::mediaTypes::IMAGE_JPEG));
// -- message text
- textPart.setText(vmime::create <vmime::stringContentHandler>
+ textPart.setText(vmime::make_shared <vmime::stringContentHandler>
(vmime::string("This is the <b>HTML text</b>.<br/>"
"<img src=\"") + obj->getReferenceId() + vmime::string("\"/>")));
- textPart.setPlainText(vmime::create <vmime::stringContentHandler>
+ textPart.setPlainText(vmime::make_shared <vmime::stringContentHandler>
("This is the plain text (without HTML formatting)."));
// Construction
- vmime::ref <vmime::message> msg = mb.construct();
+ vmime::shared_ptr <vmime::message> msg = mb.construct();
// Raw text generation
vmime::string dataToSend = msg->generate();
diff --git a/examples/example6.cpp b/examples/example6.cpp
index 721f7624..d2206e7a 100644
--- a/examples/example6.cpp
+++ b/examples/example6.cpp
@@ -31,8 +31,8 @@
// Global session object
-static vmime::ref <vmime::net::session> g_session
- = vmime::create <vmime::net::session>();
+static vmime::shared_ptr <vmime::net::session> g_session
+ = vmime::make_shared <vmime::net::session>();
#if VMIME_HAVE_SASL_SUPPORT
@@ -40,9 +40,9 @@ static vmime::ref <vmime::net::session> g_session
// SASL authentication handler
class interactiveAuthenticator : public vmime::security::sasl::defaultSASLAuthenticator
{
- const std::vector <vmime::ref <vmime::security::sasl::SASLMechanism> > getAcceptableMechanisms
- (const std::vector <vmime::ref <vmime::security::sasl::SASLMechanism> >& available,
- vmime::ref <vmime::security::sasl::SASLMechanism> suggested) const
+ 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
{
std::cout << std::endl << "Available SASL mechanisms:" << std::endl;
@@ -59,7 +59,7 @@ class interactiveAuthenticator : public vmime::security::sasl::defaultSASLAuthen
return defaultSASLAuthenticator::getAcceptableMechanisms(available, suggested);
}
- void setSASLMechanism(vmime::ref <vmime::security::sasl::SASLMechanism> mech)
+ void setSASLMechanism(vmime::shared_ptr <vmime::security::sasl::SASLMechanism> mech)
{
std::cout << "Trying '" << mech->getName() << "' authentication mechanism" << std::endl;
@@ -147,7 +147,7 @@ class interactiveCertificateVerifier : public vmime::security::cert::defaultCert
{
public:
- void verify(vmime::ref <vmime::security::cert::certificateChain> chain, const vmime::string& hostname)
+ void verify(vmime::shared_ptr <vmime::security::cert::certificateChain> chain, const vmime::string& hostname)
{
try
{
@@ -158,7 +158,7 @@ public:
catch (vmime::exceptions::certificate_verification_exception&)
{
// Obtain subject's certificate
- vmime::ref <vmime::security::cert::certificate> cert = chain->getAt(0);
+ vmime::shared_ptr <vmime::security::cert::certificate> cert = chain->getAt(0);
std::cout << std::endl;
std::cout << "Server sent a '" << cert->getType() << "'" << " certificate." << std::endl;
@@ -174,8 +174,8 @@ public:
// Accept it, and remember user's choice for later
if (cert->getType() == "X.509")
{
- m_trustedCerts.push_back(cert.dynamicCast
- <vmime::security::cert::X509Certificate>());
+ m_trustedCerts.push_back(vmime::dynamicCast
+ <vmime::security::cert::X509Certificate>(cert));
setX509TrustedCerts(m_trustedCerts);
defaultCertificateVerifier::verify(chain, hostname);
@@ -191,11 +191,11 @@ public:
private:
- static std::vector <vmime::ref <vmime::security::cert::X509Certificate> > m_trustedCerts;
+ static std::vector <vmime::shared_ptr <vmime::security::cert::X509Certificate> > m_trustedCerts;
};
-std::vector <vmime::ref <vmime::security::cert::X509Certificate> >
+std::vector <vmime::shared_ptr <vmime::security::cert::X509Certificate> >
interactiveCertificateVerifier::m_trustedCerts;
#endif // VMIME_HAVE_TLS_SUPPORT
@@ -208,7 +208,8 @@ std::vector <vmime::ref <vmime::security::cert::X509Certificate> >
*/
static const std::string findAvailableProtocols(const vmime::net::service::Type type)
{
- vmime::net::serviceFactory* sf = vmime::net::serviceFactory::getInstance();
+ vmime::shared_ptr <vmime::net::serviceFactory> sf =
+ vmime::net::serviceFactory::getInstance();
std::ostringstream res;
int count = 0;
@@ -292,11 +293,11 @@ static std::ostream& operator<<(std::ostream& os, const vmime::exception& e)
* @param s structure object
* @param level current depth
*/
-static void printStructure(vmime::ref <const vmime::net::messageStructure> s, const int level = 0)
+static void printStructure(vmime::shared_ptr <const vmime::net::messageStructure> s, const int level = 0)
{
for (int i = 0 ; i < s->getPartCount() ; ++i)
{
- vmime::ref <const vmime::net::messagePart> part = s->getPartAt(i);
+ vmime::shared_ptr <const vmime::net::messagePart> part = s->getPartAt(i);
for (int j = 0 ; j < level * 2 ; ++j)
std::cout << " ";
@@ -311,7 +312,7 @@ static void printStructure(vmime::ref <const vmime::net::messageStructure> s, co
}
-static const vmime::string getFolderPathString(vmime::ref <vmime::net::folder> f)
+static const vmime::string getFolderPathString(vmime::shared_ptr <vmime::net::folder> f)
{
const vmime::string n = f->getName().getBuffer();
@@ -321,7 +322,7 @@ static const vmime::string getFolderPathString(vmime::ref <vmime::net::folder> f
}
else
{
- vmime::ref <vmime::net::folder> p = f->getParent();
+ vmime::shared_ptr <vmime::net::folder> p = f->getParent();
return getFolderPathString(p) + n + "/";
}
}
@@ -331,14 +332,14 @@ static const vmime::string getFolderPathString(vmime::ref <vmime::net::folder> f
*
* @param folder current folder
*/
-static void printFolders(vmime::ref <vmime::net::folder> folder, const int level = 0)
+static void printFolders(vmime::shared_ptr <vmime::net::folder> folder, const int level = 0)
{
for (int j = 0 ; j < level * 2 ; ++j)
std::cout << " ";
std::cout << getFolderPathString(folder) << std::endl;
- std::vector <vmime::ref <vmime::net::folder> > subFolders = folder->getFolders(false);
+ std::vector <vmime::shared_ptr <vmime::net::folder> > subFolders = folder->getFolders(false);
for (unsigned int i = 0 ; i < subFolders.size() ; ++i)
printFolders(subFolders[i], level + 1);
@@ -395,8 +396,8 @@ static void sendMessage()
vmime::utility::url url(urlString);
- vmime::ref <vmime::net::transport> tr =
- g_session->getTransport(url, vmime::create <interactiveAuthenticator>());
+ vmime::shared_ptr <vmime::net::transport> tr =
+ g_session->getTransport(url, vmime::make_shared <interactiveAuthenticator>());
#if VMIME_HAVE_TLS_SUPPORT
@@ -406,7 +407,7 @@ static void sendMessage()
// Set the object responsible for verifying certificates, in the
// case a secured connection is used (TLS/SSL)
tr->setCertificateVerifier
- (vmime::create <interactiveCertificateVerifier>());
+ (vmime::make_shared <interactiveCertificateVerifier>());
#endif // VMIME_HAVE_TLS_SUPPORT
@@ -435,7 +436,7 @@ static void sendMessage()
cont = (toString.size() != 0);
if (cont)
- to.appendMailbox(vmime::create <vmime::mailbox>(toString));
+ to.appendMailbox(vmime::make_shared <vmime::mailbox>(toString));
}
std::cout << "Enter message data, including headers (end with '.' on a single line):" << std::endl;
@@ -505,10 +506,10 @@ static void connectStore()
// If no authenticator is given in argument to getStore(), a default one
// is used. Its behaviour is to get the user credentials from the
// session properties "auth.username" and "auth.password".
- vmime::ref <vmime::net::store> st;
+ vmime::shared_ptr <vmime::net::store> st;
if (url.getUsername().empty() || url.getPassword().empty())
- st = g_session->getStore(url, vmime::create <interactiveAuthenticator>());
+ st = g_session->getStore(url, vmime::make_shared <interactiveAuthenticator>());
else
st = g_session->getStore(url);
@@ -520,7 +521,7 @@ static void connectStore()
// Set the object responsible for verifying certificates, in the
// case a secured connection is used (TLS/SSL)
st->setCertificateVerifier
- (vmime::create <interactiveCertificateVerifier>());
+ (vmime::make_shared <interactiveCertificateVerifier>());
#endif // VMIME_HAVE_TLS_SUPPORT
@@ -528,15 +529,15 @@ static void connectStore()
st->connect();
// Display some information about the connection
- vmime::ref <vmime::net::connectionInfos> ci = st->getConnectionInfos();
+ vmime::shared_ptr <vmime::net::connectionInfos> ci = st->getConnectionInfos();
std::cout << std::endl;
std::cout << "Connected to '" << ci->getHost() << "' (port " << ci->getPort() << ")" << std::endl;
std::cout << "Connection is " << (st->isSecuredConnection() ? "" : "NOT ") << "secured." << std::endl;
// Open the default folder in this store
- vmime::ref <vmime::net::folder> f = st->getDefaultFolder();
-// vmime::ref <vmime::net::folder> f = st->getFolder(vmime::utility::path("a"));
+ vmime::shared_ptr <vmime::net::folder> f = st->getDefaultFolder();
+// vmime::shared_ptr <vmime::net::folder> f = st->getFolder(vmime::utility::path("a"));
f->open(vmime::net::folder::MODE_READ_WRITE);
@@ -547,7 +548,7 @@ static void connectStore()
for (bool cont = true ; cont ; )
{
- typedef std::map <int, vmime::ref <vmime::net::message> > MessageList;
+ typedef std::map <int, vmime::shared_ptr <vmime::net::message> > MessageList;
MessageList msgList;
try
@@ -567,7 +568,7 @@ static void connectStore()
const int choice = printMenu(choices);
// Request message number
- vmime::ref <vmime::net::message> msg;
+ vmime::shared_ptr <vmime::net::message> msg;
if (choice != 6 && choice != 7 && choice != 8)
{
@@ -677,7 +678,7 @@ static void connectStore()
// List folders
case 7:
{
- vmime::ref <vmime::net::folder>
+ vmime::shared_ptr <vmime::net::folder>
root = st->getRootFolder();
printFolders(root);
@@ -692,7 +693,7 @@ static void connectStore()
std::string path;
std::getline(std::cin, path);
- vmime::ref <vmime::net::folder> newFolder = st->getRootFolder();
+ vmime::shared_ptr <vmime::net::folder> newFolder = st->getRootFolder();
for (std::string::size_type s = 0, p = 0 ; ; s = p + 1)
{
@@ -744,16 +745,16 @@ static void connectStore()
// Folder renaming
{
- vmime::ref <vmime::net::folder> f = st->getFolder(vmime::net::folder::path("c"));
+ vmime::shared_ptr <vmime::net::folder> f = st->getFolder(vmime::net::folder::path("c"));
f->rename(vmime::net::folder::path("c2"));
- vmime::ref <vmime::net::folder> g = st->getFolder(vmime::net::folder::path("c2"));
+ vmime::shared_ptr <vmime::net::folder> g = st->getFolder(vmime::net::folder::path("c2"));
g->rename(vmime::net::folder::path("c"));
}
// Message copy: copy all messages from 'f' to 'g'
{
- vmime::ref <vmime::net::folder> g = st->getFolder(vmime::net::folder::path("TEMP"));
+ vmime::shared_ptr <vmime::net::folder> g = st->getFolder(vmime::net::folder::path("TEMP"));
if (!g->exists())
g->create(vmime::net::folder::TYPE_CONTAINS_MESSAGES);
diff --git a/examples/example7.cpp b/examples/example7.cpp
index ec7d2b86..241b4d33 100644
--- a/examples/example7.cpp
+++ b/examples/example7.cpp
@@ -43,18 +43,19 @@ int main()
vmime::platform::setHandler<vmime::platforms::posix::posixHandler>();
// Enumerate encoders
- vmime::utility::encoder::encoderFactory* ef = vmime::utility::encoder::encoderFactory::getInstance();
+ vmime::shared_ptr <vmime::utility::encoder::encoderFactory> ef =
+ vmime::utility::encoder::encoderFactory::getInstance();
std::cout << "Available encoders:" << std::endl;
for (int i = 0 ; i < ef->getEncoderCount() ; ++i)
{
- vmime::ref <const vmime::utility::encoder::encoderFactory::registeredEncoder>
+ vmime::shared_ptr <const vmime::utility::encoder::encoderFactory::registeredEncoder>
enc = ef->getEncoderAt(i);
std::cout << " * " << enc->getName() << std::endl;
- vmime::ref <vmime::utility::encoder::encoder> e =
+ vmime::shared_ptr <vmime::utility::encoder::encoder> e =
vmime::utility::encoder::encoderFactory::getInstance()->create(enc->getName());
std::vector <vmime::string> props = e->getAvailableProperties();
@@ -66,7 +67,8 @@ int main()
std::cout << std::endl;
// Enumerate messaging services and their properties
- vmime::net::serviceFactory* sf = vmime::net::serviceFactory::getInstance();
+ vmime::shared_ptr <vmime::net::serviceFactory> sf =
+ vmime::net::serviceFactory::getInstance();
std::cout << "Available messaging services:" << std::endl;
diff --git a/examples/viewer/viewer.cpp b/examples/viewer/viewer.cpp
index 5290758a..1d6daa05 100644
--- a/examples/viewer/viewer.cpp
+++ b/examples/viewer/viewer.cpp
@@ -49,18 +49,18 @@ GtkWidget* textArea = NULL;
GtkTreeStore* treeModel = NULL;
-vmime::ref <vmime::message> currentMessage = NULL;
+vmime::shared_ptr <vmime::message> currentMessage;
-void insertRowInModel(GtkTreeStore* model, vmime::ref <vmime::component> comp, GtkTreeIter* parent = NULL)
+void insertRowInModel(GtkTreeStore* model, vmime::shared_ptr <vmime::component> comp, GtkTreeIter* parent = NULL)
{
GtkTreeIter iter;
gtk_tree_store_append(model, &iter, parent);
gtk_tree_store_set(model, &iter, 0, typeid(*comp).name(), 1, comp.get(), -1);
- const std::vector <vmime::ref <vmime::component> > children = comp->getChildComponents();
+ const std::vector <vmime::shared_ptr <vmime::component> > children = comp->getChildComponents();
for (int i = 0 ; i < children.size() ; ++i)
{
@@ -139,7 +139,7 @@ void openFile(const std::string& filename)
}
while (file.gcount());
- vmime::ref <vmime::message> msg = vmime::create <vmime::message>();
+ vmime::shared_ptr <vmime::message> msg = vmime::make_shared <vmime::message>();
msg->parse(data);
currentMessage = msg;