diff options
author | Vincent Richard <[email protected]> | 2005-07-12 22:28:02 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2005-07-12 22:28:02 +0000 |
commit | 681297e10b666e13cc463f6fbb16236f36c3266c (patch) | |
tree | 5d2392e2283232ed3475cd9c69e22897b03e8a97 /src/platforms | |
parent | Added contentHandler::extractRaw(). (diff) | |
download | vmime-681297e10b666e13cc463f6fbb16236f36c3266c.tar.gz vmime-681297e10b666e13cc463f6fbb16236f36c3266c.zip |
Reference counting and smart pointers.
Diffstat (limited to 'src/platforms')
-rw-r--r-- | src/platforms/posix/posixChildProcess.cpp | 15 | ||||
-rw-r--r-- | src/platforms/posix/posixFile.cpp | 33 | ||||
-rw-r--r-- | src/platforms/posix/posixSocket.cpp | 4 | ||||
-rw-r--r-- | src/platforms/windows/windowsFile.cpp | 37 | ||||
-rw-r--r-- | src/platforms/windows/windowsSocket.cpp | 6 |
5 files changed, 47 insertions, 48 deletions
diff --git a/src/platforms/posix/posixChildProcess.cpp b/src/platforms/posix/posixChildProcess.cpp index 54410bf6..cd3aafb3 100644 --- a/src/platforms/posix/posixChildProcess.cpp +++ b/src/platforms/posix/posixChildProcess.cpp @@ -39,9 +39,9 @@ namespace posix { // posixChildProcessFactory -utility::childProcess* posixChildProcessFactory::create(const utility::file::path& path) const +ref <utility::childProcess> posixChildProcessFactory::create(const utility::file::path& path) const { - return new posixChildProcess(path); + return vmime::create <posixChildProcess>(path); } @@ -220,9 +220,6 @@ posixChildProcess::~posixChildProcess() if (m_pipe[1] != 0) close(m_pipe[1]); - delete (m_stdIn); - delete (m_stdOut); - delete [] (m_argArray); } @@ -307,7 +304,7 @@ void posixChildProcess::start(const std::vector <string> args, const int flags) if (flags & FLAG_REDIRECT_STDIN) { - m_stdIn = new outputStreamPosixPipeAdapter(m_pipe[1]); + m_stdIn = vmime::create <outputStreamPosixPipeAdapter>(m_pipe[1]); } else { @@ -317,7 +314,7 @@ void posixChildProcess::start(const std::vector <string> args, const int flags) if (flags & FLAG_REDIRECT_STDOUT) { - m_stdOut = new inputStreamPosixPipeAdapter(m_pipe[0]); + m_stdOut = vmime::create <inputStreamPosixPipeAdapter>(m_pipe[0]); } else { @@ -330,13 +327,13 @@ void posixChildProcess::start(const std::vector <string> args, const int flags) } -utility::outputStream* posixChildProcess::getStdIn() +ref <utility::outputStream> posixChildProcess::getStdIn() { return (m_stdIn); } -utility::inputStream* posixChildProcess::getStdOut() +ref <utility::inputStream> posixChildProcess::getStdOut() { return (m_stdOut); } diff --git a/src/platforms/posix/posixFile.cpp b/src/platforms/posix/posixFile.cpp index 83ea0f1b..2f2ef39f 100644 --- a/src/platforms/posix/posixFile.cpp +++ b/src/platforms/posix/posixFile.cpp @@ -68,9 +68,10 @@ const bool posixFileIterator::hasMoreElements() const } -vmime::utility::file* posixFileIterator::nextElement() +ref <vmime::utility::file> posixFileIterator::nextElement() { - posixFile* file = new posixFile(m_path / vmime::utility::file::path::component(m_dirEntry->d_name)); + ref <posixFile> file = vmime::create <posixFile> + (m_path / vmime::utility::file::path::component(m_dirEntry->d_name)); getNextElement(); @@ -182,14 +183,14 @@ posixFileWriter::posixFileWriter(const vmime::utility::file::path& path, const v } -vmime::utility::outputStream* posixFileWriter::getOutputStream() +ref <vmime::utility::outputStream> posixFileWriter::getOutputStream() { int fd = 0; if ((fd = ::open(m_nativePath.c_str(), O_WRONLY, 0660)) == -1) posixFileSystemFactory::reportError(m_path, errno); - return new posixFileWriterOutputStream(m_path, fd); + return vmime::create <posixFileWriterOutputStream>(m_path, fd); } @@ -204,14 +205,14 @@ posixFileReader::posixFileReader(const vmime::utility::file::path& path, const v } -vmime::utility::inputStream* posixFileReader::getInputStream() +ref <vmime::utility::inputStream> posixFileReader::getInputStream() { int fd = 0; if ((fd = ::open(m_nativePath.c_str(), O_RDONLY, 0640)) == -1) posixFileSystemFactory::reportError(m_path, errno); - return new posixFileReaderInputStream(m_path, fd); + return vmime::create <posixFileReaderInputStream>(m_path, fd); } @@ -299,12 +300,12 @@ const bool posixFile::exists() const } -const vmime::utility::file* posixFile::getParent() const +ref <vmime::utility::file> posixFile::getParent() const { if (m_path.isEmpty()) return NULL; else - return new posixFile(m_path.getParent()); + return vmime::create <posixFile>(m_path.getParent()); } @@ -340,24 +341,24 @@ void posixFile::remove() } -vmime::utility::fileWriter* posixFile::getFileWriter() +ref <vmime::utility::fileWriter> posixFile::getFileWriter() { - return new posixFileWriter(m_path, m_nativePath); + return vmime::create <posixFileWriter>(m_path, m_nativePath); } -vmime::utility::fileReader* posixFile::getFileReader() +ref <vmime::utility::fileReader> posixFile::getFileReader() { - return new posixFileReader(m_path, m_nativePath); + return vmime::create <posixFileReader>(m_path, m_nativePath); } -vmime::utility::fileIterator* posixFile::getFiles() const +ref <vmime::utility::fileIterator> posixFile::getFiles() const { if (!isDirectory()) throw vmime::exceptions::not_a_directory(m_path); - return new posixFileIterator(m_path, m_nativePath); + return vmime::create <posixFileIterator>(m_path, m_nativePath); } @@ -383,9 +384,9 @@ void posixFile::createDirectoryImpl(const vmime::utility::file::path& fullPath, // posixFileSystemFactory // -vmime::utility::file* posixFileSystemFactory::create(const vmime::utility::file::path& path) const +ref <vmime::utility::file> posixFileSystemFactory::create(const vmime::utility::file::path& path) const { - return new posixFile(path); + return vmime::create <posixFile>(path); } diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp index a958680f..be346b2a 100644 --- a/src/platforms/posix/posixSocket.cpp +++ b/src/platforms/posix/posixSocket.cpp @@ -172,9 +172,9 @@ void posixSocket::sendRaw(const char* buffer, const int count) // posixSocketFactory // -vmime::messaging::socket* posixSocketFactory::create() +ref <vmime::messaging::socket> posixSocketFactory::create() { - return new posixSocket(); + return vmime::create <posixSocket>(); } diff --git a/src/platforms/windows/windowsFile.cpp b/src/platforms/windows/windowsFile.cpp index 2cc7c289..4d2b708d 100644 --- a/src/platforms/windows/windowsFile.cpp +++ b/src/platforms/windows/windowsFile.cpp @@ -34,9 +34,9 @@ namespace platforms { namespace windows { -vmime::utility::file* windowsFileSystemFactory::create(const vmime::utility::file::path& path) const +ref <vmime::utility::file> windowsFileSystemFactory::create(const vmime::utility::file::path& path) const { - return new windowsFile(path); + return vmime::create <windowsFile>(path); } @@ -105,7 +105,7 @@ const bool windowsFileSystemFactory::isValidPathComponent( if (firstComponent && (buffer.length() == 2) && (buffer[1] == ':')) { char drive = tolower(buffer[0]); - if ((drive >= 'a') && (drive <= 'z')) + if ((drive >= 'a') && (drive <= 'z')) return true; } @@ -131,7 +131,7 @@ const bool windowsFileSystemFactory::isValidPathComponent( } string upperBuffer = vmime::utility::stringUtils::toUpper(buffer); - + // Check for reserved names if (upperBuffer.length() == 3) { @@ -300,12 +300,12 @@ const bool windowsFile::exists() const return false; } -const vmime::utility::file* windowsFile::getParent() const +ref <vmime::utility::file> windowsFile::getParent() const { if (m_path.isEmpty()) return NULL; else - return new windowsFile(m_path.getParent()); + return vmime::create <windowsFile>(m_path.getParent()); } void windowsFile::rename(const path& newName) @@ -326,19 +326,19 @@ void windowsFile::remove() windowsFileSystemFactory::reportError(m_path, GetLastError()); } -vmime::utility::fileWriter* windowsFile::getFileWriter() +ref <vmime::utility::fileWriter> windowsFile::getFileWriter() { - return new windowsFileWriter(m_path, m_nativePath); + return vmime::create <windowsFileWriter>(m_path, m_nativePath); } -vmime::utility::fileReader* windowsFile::getFileReader() +ref <vmime::utility::fileReader> windowsFile::getFileReader() { - return new windowsFileReader(m_path, m_nativePath); + return vmime::create <windowsFileReader>(m_path, m_nativePath); } -vmime::utility::fileIterator* windowsFile::getFiles() const +ref <vmime::utility::fileIterator> windowsFile::getFiles() const { - return new windowsFileIterator(m_path, m_nativePath); + return vmime::create <windowsFileIterator>(m_path, m_nativePath); } void windowsFile::createDirectoryImpl(const vmime::utility::file::path& fullPath, const vmime::utility::file::path& path, const bool recursive) @@ -373,9 +373,10 @@ const bool windowsFileIterator::hasMoreElements() const return m_moreElements; } -vmime::utility::file* windowsFileIterator::nextElement() +ref <vmime::utility::file> windowsFileIterator::nextElement() { - vmime::utility::file* pFile = new windowsFile(m_path / vmime::utility::file::path::component(m_findData.cFileName)); + ref <vmime::utility::file> pFile = vmime::create <windowsFile> + (m_path / vmime::utility::file::path::component(m_findData.cFileName)); findNext(); @@ -422,7 +423,7 @@ windowsFileReader::windowsFileReader(const vmime::utility::file::path& path, con { } -vmime::utility::inputStream* windowsFileReader::getInputStream() +ref <vmime::utility::inputStream> windowsFileReader::getInputStream() { HANDLE hFile = CreateFile( m_nativePath.c_str(), @@ -434,7 +435,7 @@ vmime::utility::inputStream* windowsFileReader::getInputStream() NULL); if (hFile == INVALID_HANDLE_VALUE) windowsFileSystemFactory::reportError(m_path, GetLastError()); - return new windowsFileReaderInputStream(m_path, hFile); + return vmime::create <windowsFileReaderInputStream>(m_path, hFile); } windowsFileReaderInputStream::windowsFileReaderInputStream(const vmime::utility::file::path& path, HANDLE hFile) @@ -479,7 +480,7 @@ windowsFileWriter::windowsFileWriter(const vmime::utility::file::path& path, con { } -vmime::utility::outputStream* windowsFileWriter::getOutputStream() +ref <vmime::utility::outputStream> windowsFileWriter::getOutputStream() { HANDLE hFile = CreateFile( m_nativePath.c_str(), @@ -491,7 +492,7 @@ vmime::utility::outputStream* windowsFileWriter::getOutputStream() NULL); if (hFile == INVALID_HANDLE_VALUE) windowsFileSystemFactory::reportError(m_path, GetLastError()); - return new windowsFileWriterOutputStream(m_path, hFile); + return vmime::create <windowsFileWriterOutputStream>(m_path, hFile); } windowsFileWriterOutputStream::windowsFileWriterOutputStream(const vmime::utility::file::path& path, HANDLE hFile) diff --git a/src/platforms/windows/windowsSocket.cpp b/src/platforms/windows/windowsSocket.cpp index a572a271..b325eedd 100644 --- a/src/platforms/windows/windowsSocket.cpp +++ b/src/platforms/windows/windowsSocket.cpp @@ -77,7 +77,7 @@ void windowsSocket::connect(const vmime::string& address, const vmime::port_t po // Error: cannot resolve address throw vmime::exceptions::connection_error("Cannot resolve address."); } - + memcpy(reinterpret_cast <char*>(&addr.sin_addr), hostInfo->h_addr, hostInfo->h_length); } @@ -167,9 +167,9 @@ void windowsSocket::sendRaw(const char* buffer, const int count) // posixSocketFactory // -vmime::messaging::socket* windowsSocketFactory::create() +ref <vmime::messaging::socket> windowsSocketFactory::create() { - return new windowsSocket(); + return vmime::create <windowsSocket>(); } |