OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
ossimReferenced Class Reference

ossimReferenced allows for shared object ref counting if the reference count ever gets to 0 or less it will delete 'this' object. More...

#include <ossimReferenced.h>

Inheritance diagram for ossimReferenced:
ossimApplanixEOFile ossimApplanixEORecord ossimAtbMatchPoint ossimAtbPointSource ossimAutRegUtil ossimBatchTest ossimCeosData ossimChipperUtil ossimCsvFile ossimCsvFile::Record ossimDynamicLibrary ossimElevationAccuracyInfo ossimElevationCellDatabase::CellInfo ossimEnviHeader ossimEpsgProjectionDatabase ossimEpsgProjectionDatabase::ProjDbRecord ossimFfL7 ossimFfRevb ossimFgdcTxtDoc ossimFixedTileCache ossimGeometryFactoryWrapper ossimGpkgDatabaseRecordBase ossimHdf5 ossimHdf5ImageDataset ossimIgen ossimImageUtil ossimInfoBase ossimIvtGeomXform ossimJpipMessage ossimJpipMessageDecoder ossimJpipMessageHeader ossimKeywordlist ossimKMeansClustering ossimLagrangeInterpolator ossimMultiBandHistogram ossimMultiResLevelHistogram ossimNitfFile ossimNmeaMessage ossimObject ossimOverviewSequencer ossimPointRecord ossimPolyArea2d ossimRgbImage ossimRpcSolver ossimRpfBoundaryRectSectionSubheader ossimRpfBoundaryRectTable ossimRpfFrame ossimRpfFrameFileIndexSectionSubheader ossimRpfFrameFileIndexSubsection ossimRpfReplaceUpdateSectionSubheader ossimRpfReplaceUpdateTable ossimRpfToc ossimRpfUtil ossimStreamBase ossimTieGpt ossimVideoGeometry ossimVisitor ossimWmsBoundingBox ossimWmsCapabilitiesDocument ossimWmsCapability ossimWmsContactAdress ossimWmsContactInformation ossimWmsDataUrl ossimWmsGetCapabilities ossimWmsGetMap ossimWmsLayer ossimWmsMetadataUrl ossimWmsRequest ossimWmsScaleHint ossimWmsService ossimWmsStyle ossimWmsTimeExtent

Public Member Functions

 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 

Protected Member Functions

virtual ~ossimReferenced ()
 

Private Attributes

std::atomic_int m_refCount
 

Detailed Description

ossimReferenced allows for shared object ref counting if the reference count ever gets to 0 or less it will delete 'this' object.

Currently uses std::mutex to control the locking of the reference count variable.

Eventually we would like to replace all of ossimReferenced and ossimRefPtr with C++11 std::shared_ptr

Definition at line 23 of file ossimReferenced.h.

Constructor & Destructor Documentation

◆ ossimReferenced() [1/2]

ossimReferenced::ossimReferenced ( )
inline

Definition at line 26 of file ossimReferenced.h.

27  : m_refCount(0)
28  {}
std::atomic_int m_refCount

◆ ossimReferenced() [2/2]

ossimReferenced::ossimReferenced ( const ossimReferenced )
inline

Definition at line 30 of file ossimReferenced.h.

31  : m_refCount(0)
32  {}
std::atomic_int m_refCount

◆ ~ossimReferenced()

ossimReferenced::~ossimReferenced ( )
protectedvirtual

Definition at line 6 of file ossimReferenced.cpp.

References ossimNotify(), ossimNotifyLevel_WARN, and referenceCount().

7 {
8  int count = referenceCount();
9  if (count>0)
10  {
11  ossimNotify(ossimNotifyLevel_WARN)<<"Warning: deleting still referenced object "<<this<<std::endl;
12  ossimNotify(ossimNotifyLevel_WARN)<<" the final reference count was "<<count
13  <<", memory corruption possible."<<std::endl;
14  }
15 }
int referenceCount() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

Member Function Documentation

◆ operator=()

ossimReferenced& ossimReferenced::operator= ( const ossimReferenced )
inline

Definition at line 33 of file ossimReferenced.h.

Referenced by ossim2dTo2dTransform::operator=(), and ossimTieGpt::operator=().

33 { return *this; }

◆ ref()

void ossimReferenced::ref ( ) const
inline

◆ referenceCount()

int ossimReferenced::referenceCount ( ) const
inline
Returns
the number pointers currently referencing this object.

Definition at line 67 of file ossimReferenced.h.

Referenced by ~ossimReferenced().

67 { return m_refCount.load(); }
std::atomic_int m_refCount

◆ unref()

void ossimReferenced::unref ( ) const
inline

decrement the reference count by one, indicating that a pointer to this object is referencing it.

If the reference count goes to zero, it is assumed that this object is no longer referenced and is automatically deleted.

Definition at line 82 of file ossimReferenced.h.

References m_refCount.

Referenced by ossimGdalOgrVectorAnnotation::deleteTables(), ossimImageHandlerMtAdaptor::getTile(), ossimUsgsDemTileSource::getTile(), ossimJpegTileSource::getTile(), ossimGpkgReader::getTile(), ossimHdf5ImageHandler::getTile(), ossimCcfTileSource::getTile(), ossimHdfReader::getTile(), ossimDtedTileSource::getTile(), ossimH5ImageHandler::getTile(), ossimPngReader::getTile(), ossimAdrgTileSource::getTile(), and ossimGeoPdfReader::getTile().

83 {
84  bool needDelete = false;
85  {
86  // fetch_sub should return the value before subtraction.
87  // so if 1 was before the subtraction that means it should
88  // be zero after the subtraction so we will test <=1
89  needDelete = m_refCount.fetch_sub(1) <= 1;
90  }
91 
92  if (needDelete)
93  {
94  delete this;
95  }
96 }
std::atomic_int m_refCount

◆ unref_nodelete()

void ossimReferenced::unref_nodelete ( ) const
inline

decrement the reference count by one, indicating that a pointer to this object is referencing it.

However, do not delete it, even if ref count goes to 0. Warning, unref_nodelete() should only be called if the user knows exactly who will be resonsible for, one should prefer unref() over unref_nodelete() as the later can lead to memory leaks.

Definition at line 58 of file ossimReferenced.h.

59  {
60  // std::lock_guard<std::mutex> lock(theRefMutex);
61  --m_refCount;
62  }
std::atomic_int m_refCount

Member Data Documentation

◆ m_refCount

std::atomic_int ossimReferenced::m_refCount
mutableprivate

Definition at line 74 of file ossimReferenced.h.

Referenced by ref(), and unref().


The documentation for this class was generated from the following files: