From f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 21 Nov 2013 22:16:57 +0100 Subject: Boost/C++11 shared pointers. --- src/platforms/posix/posixChildProcess.cpp | 19 ++++++++--------- src/platforms/posix/posixFile.cpp | 34 +++++++++++++++---------------- src/platforms/posix/posixHandler.cpp | 16 +++++++-------- src/platforms/posix/posixSocket.cpp | 12 +++++------ 4 files changed, 39 insertions(+), 42 deletions(-) (limited to 'src/platforms/posix') diff --git a/src/platforms/posix/posixChildProcess.cpp b/src/platforms/posix/posixChildProcess.cpp index 09119996..c4761624 100644 --- a/src/platforms/posix/posixChildProcess.cpp +++ b/src/platforms/posix/posixChildProcess.cpp @@ -32,8 +32,6 @@ #include "vmime/exception.hpp" -#include "vmime/utility/smartPtr.hpp" - #include #include #include @@ -49,9 +47,9 @@ namespace posix { // posixChildProcessFactory -ref posixChildProcessFactory::create(const utility::file::path& path) const +shared_ptr posixChildProcessFactory::create(const utility::file::path& path) const { - return vmime::create (path); + return make_shared (path); } @@ -215,7 +213,7 @@ private: posixChildProcess::posixChildProcess(const utility::file::path& path) : m_processPath(path), m_started(false), - m_stdIn(NULL), m_stdOut(NULL), m_pid(0), m_argArray(NULL) + m_stdIn(null), m_stdOut(null), m_pid(0), m_argArray(NULL) { m_pipe[0] = 0; m_pipe[1] = 0; @@ -319,7 +317,7 @@ void posixChildProcess::start(const std::vector args, const int flags) if (flags & FLAG_REDIRECT_STDIN) { - m_stdIn = vmime::create (m_pipe[1]); + m_stdIn = make_shared (m_pipe[1]); } else { @@ -329,7 +327,7 @@ void posixChildProcess::start(const std::vector args, const int flags) if (flags & FLAG_REDIRECT_STDOUT) { - m_stdOut = vmime::create (m_pipe[0]); + m_stdOut = make_shared (m_pipe[0]); } else { @@ -342,13 +340,13 @@ void posixChildProcess::start(const std::vector args, const int flags) } -ref posixChildProcess::getStdIn() +shared_ptr posixChildProcess::getStdIn() { return (m_stdIn); } -ref posixChildProcess::getStdOut() +shared_ptr posixChildProcess::getStdOut() { return (m_stdOut); } @@ -377,8 +375,7 @@ void posixChildProcess::waitForFinish() { if (WEXITSTATUS(wstat) == 255) { - vmime::utility::auto_ptr pfsf - = new posixFileSystemFactory(); + std::auto_ptr pfsf(new posixFileSystemFactory()); throw exceptions::system_error("Could not execute '" + pfsf->pathToString(m_processPath) + "'"); diff --git a/src/platforms/posix/posixFile.cpp b/src/platforms/posix/posixFile.cpp index 744f01ff..1e4dd070 100644 --- a/src/platforms/posix/posixFile.cpp +++ b/src/platforms/posix/posixFile.cpp @@ -79,9 +79,9 @@ bool posixFileIterator::hasMoreElements() const } -ref posixFileIterator::nextElement() +shared_ptr posixFileIterator::nextElement() { - ref file = vmime::create + shared_ptr file = make_shared (m_path / vmime::utility::file::path::component(m_dirEntry->d_name)); getNextElement(); @@ -258,14 +258,14 @@ posixFileWriter::posixFileWriter(const vmime::utility::file::path& path, const v } -ref posixFileWriter::getOutputStream() +shared_ptr posixFileWriter::getOutputStream() { int fd = 0; if ((fd = ::open(m_nativePath.c_str(), O_WRONLY, 0660)) == -1) posixFileSystemFactory::reportError(m_path, errno); - return vmime::create (m_path, fd); + return make_shared (m_path, fd); } @@ -280,14 +280,14 @@ posixFileReader::posixFileReader(const vmime::utility::file::path& path, const v } -ref posixFileReader::getInputStream() +shared_ptr posixFileReader::getInputStream() { int fd = 0; if ((fd = ::open(m_nativePath.c_str(), O_RDONLY, 0640)) == -1) posixFileSystemFactory::reportError(m_path, errno); - return vmime::create (m_path, fd); + return make_shared (m_path, fd); } @@ -417,12 +417,12 @@ bool posixFile::exists() const } -ref posixFile::getParent() const +shared_ptr posixFile::getParent() const { if (m_path.isEmpty()) - return NULL; + return null; else - return vmime::create (m_path.getParent()); + return make_shared (m_path.getParent()); } @@ -465,24 +465,24 @@ void posixFile::remove() } -ref posixFile::getFileWriter() +shared_ptr posixFile::getFileWriter() { - return vmime::create (m_path, m_nativePath); + return make_shared (m_path, m_nativePath); } -ref posixFile::getFileReader() +shared_ptr posixFile::getFileReader() { - return vmime::create (m_path, m_nativePath); + return make_shared (m_path, m_nativePath); } -ref posixFile::getFiles() const +shared_ptr posixFile::getFiles() const { if (!isDirectory()) throw vmime::exceptions::not_a_directory(m_path); - return vmime::create (m_path, m_nativePath); + return make_shared (m_path, m_nativePath); } @@ -508,9 +508,9 @@ void posixFile::createDirectoryImpl(const vmime::utility::file::path& fullPath, // posixFileSystemFactory // -ref posixFileSystemFactory::create(const vmime::utility::file::path& path) const +shared_ptr posixFileSystemFactory::create(const vmime::utility::file::path& path) const { - return vmime::create (path); + return make_shared (path); } diff --git a/src/platforms/posix/posixHandler.cpp b/src/platforms/posix/posixHandler.cpp index 73005d7e..b5d08ce6 100644 --- a/src/platforms/posix/posixHandler.cpp +++ b/src/platforms/posix/posixHandler.cpp @@ -109,11 +109,11 @@ namespace posix { posixHandler::posixHandler() { #if VMIME_HAVE_MESSAGING_FEATURES - m_socketFactory = vmime::create (); + m_socketFactory = make_shared (); #endif #if VMIME_HAVE_FILESYSTEM_FEATURES - m_fileSysFactory = vmime::create (); - m_childProcFactory = vmime::create (); + m_fileSysFactory = make_shared (); + m_childProcFactory = make_shared (); #endif } @@ -249,7 +249,7 @@ unsigned int posixHandler::getThreadId() const #if VMIME_HAVE_MESSAGING_FEATURES -ref posixHandler::getSocketFactory() +shared_ptr posixHandler::getSocketFactory() { return m_socketFactory; } @@ -259,13 +259,13 @@ ref posixHandler::getSocketFactory() #if VMIME_HAVE_FILESYSTEM_FEATURES -ref posixHandler::getFileSystemFactory() +shared_ptr posixHandler::getFileSystemFactory() { return m_fileSysFactory; } -ref posixHandler::getChildProcessFactory() +shared_ptr posixHandler::getChildProcessFactory() { return m_childProcFactory; } @@ -308,9 +308,9 @@ void posixHandler::generateRandomBytes(unsigned char* buffer, const unsigned int } -ref posixHandler::createCriticalSection() +shared_ptr posixHandler::createCriticalSection() { - return vmime::create (); + return make_shared (); } diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp index bee9f89e..e0bcf03a 100644 --- a/src/platforms/posix/posixSocket.cpp +++ b/src/platforms/posix/posixSocket.cpp @@ -59,7 +59,7 @@ namespace posix { // posixSocket // -posixSocket::posixSocket(ref th) +posixSocket::posixSocket(shared_ptr th) : m_timeoutHandler(th), m_desc(-1), m_status(0) { } @@ -631,16 +631,16 @@ unsigned int posixSocket::getStatus() const // posixSocketFactory // -ref posixSocketFactory::create() +shared_ptr posixSocketFactory::create() { - ref th = NULL; - return vmime::create (th); + shared_ptr th; + return make_shared (th); } -ref posixSocketFactory::create(ref th) +shared_ptr posixSocketFactory::create(shared_ptr th) { - return vmime::create (th); + return make_shared (th); } -- cgit