aboutsummaryrefslogtreecommitdiffstats
path: root/src/utility
diff options
context:
space:
mode:
Diffstat (limited to 'src/utility')
-rw-r--r--src/utility/encoder/encoderFactory.cpp18
-rw-r--r--src/utility/parserInputStreamAdapter.cpp4
-rw-r--r--src/utility/seekableInputStreamRegionAdapter.cpp2
-rw-r--r--src/utility/smartPtr.cpp41
-rw-r--r--src/utility/smartPtrInt.cpp295
5 files changed, 12 insertions, 348 deletions
diff --git a/src/utility/encoder/encoderFactory.cpp b/src/utility/encoder/encoderFactory.cpp
index 02800b4c..098a810a 100644
--- a/src/utility/encoder/encoderFactory.cpp
+++ b/src/utility/encoder/encoderFactory.cpp
@@ -61,24 +61,24 @@ encoderFactory::~encoderFactory()
}
-encoderFactory* encoderFactory::getInstance()
+shared_ptr <encoderFactory> encoderFactory::getInstance()
{
static encoderFactory instance;
- return (&instance);
+ return shared_ptr <encoderFactory>(&instance, noop_shared_ptr_deleter <encoderFactory>());
}
-ref <encoder> encoderFactory::create(const string& name)
+shared_ptr <encoder> encoderFactory::create(const string& name)
{
return (getEncoderByName(name)->create());
}
-const ref <const encoderFactory::registeredEncoder> encoderFactory::getEncoderByName(const string& name) const
+const shared_ptr <const encoderFactory::registeredEncoder> encoderFactory::getEncoderByName(const string& name) const
{
const string lcName(utility::stringUtils::toLower(name));
- for (std::vector <ref <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
+ for (std::vector <shared_ptr <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
it != m_encoders.end() ; ++it)
{
if ((*it)->getName() == lcName)
@@ -95,17 +95,17 @@ size_t encoderFactory::getEncoderCount() const
}
-const ref <const encoderFactory::registeredEncoder> encoderFactory::getEncoderAt(const size_t pos) const
+const shared_ptr <const encoderFactory::registeredEncoder> encoderFactory::getEncoderAt(const size_t pos) const
{
return (m_encoders[pos]);
}
-const std::vector <ref <const encoderFactory::registeredEncoder> > encoderFactory::getEncoderList() const
+const std::vector <shared_ptr <const encoderFactory::registeredEncoder> > encoderFactory::getEncoderList() const
{
- std::vector <ref <const registeredEncoder> > res;
+ std::vector <shared_ptr <const registeredEncoder> > res;
- for (std::vector <ref <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
+ for (std::vector <shared_ptr <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
it != m_encoders.end() ; ++it)
{
res.push_back(*it);
diff --git a/src/utility/parserInputStreamAdapter.cpp b/src/utility/parserInputStreamAdapter.cpp
index 0d6248cf..fd10a586 100644
--- a/src/utility/parserInputStreamAdapter.cpp
+++ b/src/utility/parserInputStreamAdapter.cpp
@@ -28,7 +28,7 @@ namespace vmime {
namespace utility {
-parserInputStreamAdapter::parserInputStreamAdapter(ref <seekableInputStream> stream)
+parserInputStreamAdapter::parserInputStreamAdapter(shared_ptr <seekableInputStream> stream)
: m_stream(stream)
{
}
@@ -53,7 +53,7 @@ stream::size_type parserInputStreamAdapter::read
}
-ref <seekableInputStream> parserInputStreamAdapter::getUnderlyingStream()
+shared_ptr <seekableInputStream> parserInputStreamAdapter::getUnderlyingStream()
{
return m_stream;
}
diff --git a/src/utility/seekableInputStreamRegionAdapter.cpp b/src/utility/seekableInputStreamRegionAdapter.cpp
index ec7c20cf..753d81a5 100644
--- a/src/utility/seekableInputStreamRegionAdapter.cpp
+++ b/src/utility/seekableInputStreamRegionAdapter.cpp
@@ -29,7 +29,7 @@ namespace utility {
seekableInputStreamRegionAdapter::seekableInputStreamRegionAdapter
- (ref <seekableInputStream> stream, const size_type begin, const size_type length)
+ (shared_ptr <seekableInputStream> stream, const size_type begin, const size_type length)
: m_stream(stream), m_begin(begin), m_length(length), m_position(0)
{
}
diff --git a/src/utility/smartPtr.cpp b/src/utility/smartPtr.cpp
deleted file mode 100644
index 78cf9032..00000000
--- a/src/utility/smartPtr.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-//
-// VMime library (http://www.vmime.org)
-// Copyright (C) 2002-2013 Vincent Richard <[email protected]>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 3 of
-// the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// Linking this library statically or dynamically with other modules is making
-// a combined work based on this library. Thus, the terms and conditions of
-// the GNU General Public License cover the whole combination.
-//
-
-#include "vmime/object.hpp"
-#include "vmime/utility/smartPtr.hpp"
-
-
-namespace vmime {
-namespace utility {
-
-
-void refManager::deleteObjectImpl(object* obj)
-{
- obj->setRefManager(0);
- delete obj;
-}
-
-
-} // utility
-} // vmime
-
diff --git a/src/utility/smartPtrInt.cpp b/src/utility/smartPtrInt.cpp
deleted file mode 100644
index 2bb9d70d..00000000
--- a/src/utility/smartPtrInt.cpp
+++ /dev/null
@@ -1,295 +0,0 @@
-//
-// VMime library (http://www.vmime.org)
-// Copyright (C) 2002-2013 Vincent Richard <[email protected]>
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 3 of
-// the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-//
-// Linking this library statically or dynamically with other modules is making
-// a combined work based on this library. Thus, the terms and conditions of
-// the GNU General Public License cover the whole combination.
-//
-
-#include "vmime/utility/smartPtrInt.hpp"
-#include "vmime/object.hpp"
-
-
-namespace vmime {
-namespace utility {
-
-
-// static
-refManager* refManager::create(object* obj)
-{
- return new refManagerImpl(obj);
-}
-
-
-//
-// refManager
-//
-
-refManagerImpl::refManagerImpl(object* obj)
- : m_object(obj), m_strongCount(1), m_weakCount(1)
-{
-}
-
-
-refManagerImpl::~refManagerImpl()
-{
-}
-
-
-bool refManagerImpl::addStrong()
-{
- if (m_strongCount <= 0)
- return false;
-
- m_strongCount.increment();
- m_weakCount.increment();
-
- return true;
-}
-
-
-void refManagerImpl::releaseStrong()
-{
- if (m_strongCount.decrement() <= 0)
- deleteObject();
-
- releaseWeak();
-}
-
-
-void refManagerImpl::addWeak()
-{
- m_weakCount.increment();
-}
-
-
-void refManagerImpl::releaseWeak()
-{
- if (m_weakCount.decrement() <= 0)
- deleteManager();
-}
-
-
-object* refManagerImpl::getObject()
-{
- return m_object;
-}
-
-
-void refManagerImpl::deleteManager()
-{
- delete this;
-}
-
-
-void refManagerImpl::deleteObject()
-{
- try
- {
- deleteObjectImpl(m_object);
- }
- catch (...)
- {
- // Exception in destructor
- }
-
- m_object = 0;
-}
-
-
-long refManagerImpl::getStrongRefCount() const
-{
- return m_strongCount;
-}
-
-
-long refManagerImpl::getWeakRefCount() const
-{
- return m_weakCount;
-}
-
-
-
-//
-// refCounter
-//
-
-#ifdef _WIN32
-
-
-refCounter::refCounter(const long initialValue)
- : m_value(initialValue)
-{
-}
-
-
-refCounter::~refCounter()
-{
-}
-
-
-long refCounter::increment()
-{
- return InterlockedIncrement(&m_value);
-}
-
-
-long refCounter::decrement()
-{
- return InterlockedDecrement(&m_value);
-}
-
-
-refCounter::operator long() const
-{
- return m_value;
-}
-
-
-#elif defined(__GNUC__) && (defined(__GLIBCPP__) || defined(__GLIBCXX__))
-
-
-refCounter::refCounter(const long initialValue)
- : m_value(static_cast <int>(initialValue))
-{
-}
-
-
-refCounter::~refCounter()
-{
-}
-
-
-long refCounter::increment()
-{
-#if __GNUC_MINOR__ < 4 && __GNUC__ < 4
- return __exchange_and_add(&m_value, 1) + 1;
-#else
- return __gnu_cxx::__exchange_and_add(&m_value, 1) + 1;
-#endif
-}
-
-
-long refCounter::decrement()
-{
-#if __GNUC_MINOR__ < 4 && __GNUC__ < 4
- return __exchange_and_add(&m_value, -1) - 1;
-#else
- return __gnu_cxx::__exchange_and_add(&m_value, -1) - 1;
-#endif
-}
-
-
-refCounter::operator long() const
-{
-#if __GNUC_MINOR__ < 4 && __GNUC__ < 4
- return static_cast <long>(__exchange_and_add(&m_value, 0));
-#else
- return static_cast <long>(__gnu_cxx::__exchange_and_add(&m_value, 0));
-#endif
-}
-
-
-#elif defined(VMIME_HAVE_PTHREAD)
-
-
-refCounter::refCounter(const long initialValue)
- : m_value(initialValue)
-{
- pthread_mutexattr_t attr;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
- pthread_mutex_init(&m_mutex, &attr);
- pthread_mutexattr_destroy(&attr);
-}
-
-
-refCounter::~refCounter()
-{
- pthread_mutex_destroy(&m_mutex);
-}
-
-
-long refCounter::increment()
-{
- long value;
-
- pthread_mutex_lock(&m_mutex);
- value = ++m_value;
- pthread_mutex_unlock(&m_mutex);
-
- return value;
-}
-
-
-long refCounter::decrement()
-{
- long value;
-
- pthread_mutex_lock(&m_mutex);
- value = --m_value;
- pthread_mutex_unlock(&m_mutex);
-
- return value;
-}
-
-
-refCounter::operator long() const
-{
- return m_value;
-}
-
-
-#else // not thread-safe implementation
-
-
-refCounter::refCounter(const long initialValue)
- : m_value(initialValue)
-{
-}
-
-
-refCounter::~refCounter()
-{
-}
-
-
-long refCounter::increment()
-{
- return ++m_value;
-}
-
-
-long refCounter::decrement()
-{
- return --m_value;
-}
-
-
-refCounter::operator long() const
-{
- return m_value;
-}
-
-
-#endif
-
-
-} // utility
-} // vmime
-