diff options
Diffstat (limited to 'src/utility/smartPtr.cpp')
-rw-r--r-- | src/utility/smartPtr.cpp | 131 |
1 files changed, 3 insertions, 128 deletions
diff --git a/src/utility/smartPtr.cpp b/src/utility/smartPtr.cpp index 16249df8..08a8f57c 100644 --- a/src/utility/smartPtr.cpp +++ b/src/utility/smartPtr.cpp @@ -29,135 +29,10 @@ namespace vmime { namespace utility { -// refManager - -refManager::refManager(object* obj) - : m_object(obj), m_strongCount(1), m_weakCount(1) -{ -} - - -refManager::~refManager() -{ -} - - -const bool refManager::addStrong() -{ - if (m_strongCount <= 0) - return false; - - m_strongCount.increment(); - m_weakCount.increment(); - - return true; -} - - -void refManager::releaseStrong() -{ - m_strongCount.decrement(); - - if (m_strongCount.compareExchange(0, -424242) == 0) // prevent from adding strong refs later - deleteObject(); - - releaseWeak(); -} - - -void refManager::addWeak() -{ - m_weakCount.increment(); -} - - -void refManager::releaseWeak() -{ - if (m_weakCount.decrement() == 0) - deleteManager(); -} - - -object* refManager::getObject() -{ - return m_object; -} - - -void refManager::deleteManager() -{ - delete this; -} - - -void refManager::deleteObject() -{ - try - { - m_object->setRefManager(0); - delete m_object; - } - catch (...) - { - // Exception in destructor - } - - m_object = 0; -} - - -const long refManager::getStrongRefCount() const -{ - return m_strongCount; -} - - -const long refManager::getWeakRefCount() const -{ - return m_weakCount; -} - - - -// refCounter - -refCounter::refCounter(const long initialValue) - : m_value(initialValue) -{ -} - - -refCounter::~refCounter() -{ -} - - -const long refCounter::increment() -{ - return ++m_value; -} - - -const long refCounter::decrement() -{ - return --m_value; -} - - -const long refCounter::compareExchange(const long compare, const long exchangeWith) -{ - const int prev = m_value; - - if (m_value == compare) - m_value = exchangeWith; - - return prev; -} - - -refCounter::operator long() const +void refManager::deleteObjectImpl(object* obj) { - return m_value; + obj->setRefManager(0); + delete obj; } |