A simple thread-safe shared object. More...
#include <SharedObject.h>
Public Member Functions | |
void | addReference () |
void | operator= (const SharedObject &) |
int | referenceCount () const |
bool | removeReference () |
SharedObject () | |
SharedObject (const SharedObject &) | |
virtual | ~SharedObject () |
Static Public Member Functions | |
static void | removeReference (SharedObject *object) |
A simple thread-safe shared object.
QGpCoreTools::SharedObject::SharedObject | ( | ) | [inline] |
{_referenceCount=0;}
QGpCoreTools::SharedObject::SharedObject | ( | const SharedObject & | ) | [inline] |
{_referenceCount=0;}
virtual QGpCoreTools::SharedObject::~SharedObject | ( | ) | [inline, virtual] |
{ASSERT(_referenceCount<=0);}
QGpCoreTools::SharedObject::addReference | ( | ) | [inline] |
Call this function every time the object is used. The reference counter is increased by one.
Referenced by GeopsyCore::MetaDataMap::add(), GeopsyCore::CustomFileFormats::add(), QGpCoreTools::CoreApplicationPrivate::beginRedirectStream(), GeopsyCore::MetaDataMap::data(), GeopsyCore::SubSignalPool::insertSignal(), QGpGuiTools::LogView::LogView(), main(), GeopsyCore::SignalFileFormat::operator=(), DinverCore::ParentIndex::ParentIndex(), Process::Process(), DinverDCGui::DCModelViewer::rejectModels(), reportMode(), DinverDCGui::DCModelViewer::selectModels(), QGpCoreTools::AbstractStream::setPrevious(), DinverDCCore::DCModelInfo::setReport(), DinverCore::ModelRepository::setStorage(), QGpCoreTools::CoreApplicationPrivate::setStream(), and GeopsyCore::SignalFileFormat::SignalFileFormat().
{_referenceCount.fetchAndAddOrdered(1);}
void QGpCoreTools::SharedObject::operator= | ( | const SharedObject & | ) | [inline] |
{}
int QGpCoreTools::SharedObject::referenceCount | ( | ) | const [inline] |
Referenced by GeopsyCore::MetaDataMap::add(), GeopsyCore::SharedMetaData::add(), GeopsyCore::SubSignalPool::debugSignalSharing(), GeopsyCore::Signal::xml_writeChildren(), GeopsyCore::Signal::xml_writeProperties(), and GeopsyCore::Signal::~Signal().
{return _referenceCount.fetchAndAddOrdered(0);}
QGpCoreTools::SharedObject::removeReference | ( | ) | [inline] |
Call this function every time the object is not used anymore and you do not want to delete it immediately. If the reference counter reaches 0, it returns true.
Referenced by QGpCoreTools::CoreApplicationPrivate::beginRedirectStream(), GeopsyCore::MetaDataMap::clear(), GeopsyCore::CustomFileFormats::clear(), QGpCoreTools::CoreApplicationPrivate::destructorCleanUp(), QGpCoreTools::CoreApplicationPrivate::endRedirectStream(), QGpGuiTools::LogView::remove(), GeopsyCore::MetaDataMap::remove(), GeopsyCore::CustomFileFormats::remove(), GeopsyCore::SubSignalPool::remove(), GeopsyCore::SubSignalPool::removeAll(), GeopsyCore::SubSignalPool::removeAt(), removeReference(), QGpGuiTools::LogWidget::removeView(), QGpCoreTools::AbstractStream::setPrevious(), DinverCore::ModelRepository::setStorage(), QGpCoreTools::CoreApplicationPrivate::setStream(), GeopsyCore::Signal::setTemporary(), QGpCoreTools::CoreApplicationPrivate::threadDeleted(), QGpCoreTools::AbstractStream::~AbstractStream(), DinverCore::ModelRepository::~ModelRepository(), DinverCore::ParentIndex::~ParentIndex(), and Process::~Process().
{return _referenceCount.fetchAndAddOrdered(-1)<=1;}
void QGpCoreTools::SharedObject::removeReference | ( | SharedObject * | object | ) | [inline, static] |
Call this function every time the object is not used anymore and you want to delete it. If the reference counter reach 0, the object is automatically deleted.
References removeReference().
{ if(object->removeReference()) delete object; }