OSGAspectStore.inl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 OSG_BEGIN_NAMESPACE
00040
00045
00046
00047
00048 inline
00049 AspectStore::~AspectStore(void)
00050 {
00051 #ifdef OSG_ENABLE_MEMORY_DEBUGGING
00052 for(UInt32 i = 0; i < _vAspects.size(); ++i)
00053 {
00054 _vAspects[i] = reinterpret_cast<FieldContainer *>(0xDEADBEEF);
00055 }
00056 #endif
00057 }
00058
00059 inline
00060 FieldContainer *AspectStore::getPtr(const UInt32 uiAspect) const
00061 {
00062 if(uiAspect < _vAspects.size())
00063 {
00064 #ifdef OSG_ENABLE_MEMORY_DEBUGGING
00065 OSG_ASSERT(_vAspects[uiAspect] != reinterpret_cast<FieldContainer *>(0xDEADBEEF));
00066 #endif
00067
00068 return _vAspects[uiAspect];
00069 }
00070 else
00071 {
00072 return NULL;
00073 }
00074 }
00075
00076
00077 inline
00078 FieldContainer *AspectStore::getPtr(void) const
00079 {
00080 return getPtr(Thread::getCurrentAspect());
00081 }
00082
00083 inline
00084 void AspectStore::setPtrForAspect( FieldContainer *pContainer,
00085 const UInt32 uiAspect )
00086 {
00087 _vAspects.resize(osgMax<UInt32>(_vAspects.size(), uiAspect + 1), NULL);
00088
00089 _vAspects[uiAspect] = pContainer;
00090 }
00091
00092 inline
00093 void AspectStore::removePtrForAspect(const UInt32 uiAspect)
00094 {
00095 if(uiAspect >= _vAspects.size())
00096 {
00097 return;
00098 }
00099
00100 _vAspects[uiAspect] = NULL;
00101 }
00102
00103 inline
00104 UInt32 AspectStore::getNumAspects(void) const
00105 {
00106 return _vAspects.size();
00107 }
00108
00109
00110
00111
00112 inline
00113 void AspectStore::addRef(void)
00114 {
00115 osgAtomicIncrement(&_refCount);
00116 }
00117
00118 inline
00119 void AspectStore::subRef(void)
00120 {
00121 RefCountStore tmpRefCount = osgAtomicExchangeAndAdd(&_refCount, -1);
00122
00123 if(tmpRefCount <= 1)
00124 delete this;
00125 }
00126
00127 inline
00128 Int32 AspectStore::getRefCount(void)
00129 {
00130 return osgAtomicExchangeAndAdd(&_refCount, 0);
00131 }
00132
00133
00134
00135
00136 inline
00137 AspectStore::AspectStore(void) :
00138 _vAspects( ),
00139 _refCount(0)
00140 {
00141 }
00142
00143 inline
00144 AspectStore::AspectStore(const AspectStore &) :
00145 _vAspects( ),
00146 _refCount(0)
00147 {
00148 }
00149
00150 inline
00151 void AspectStore::fillOffsetArray(AspectOffsetStore & oStore,
00152 FieldContainer * const pRef )
00153 {
00154 Char8 *pRefMem = reinterpret_cast<Char8 *>(pRef);
00155
00156 oStore.resize(ThreadManager::getNumAspects());
00157
00158 std::fill(oStore.begin(), oStore.end(), -1);
00159
00160 for(UInt32 i = 0; i < _vAspects.size(); ++i)
00161 {
00162 Char8 *pCurrMem = reinterpret_cast<Char8 *>(_vAspects[i]);
00163
00164 if(pCurrMem != pRefMem && pCurrMem != NULL)
00165 {
00166 oStore[i] = pCurrMem - pRefMem;
00167 }
00168 }
00169 }
00170
00171 inline
00172 void AspectStore::dump(void)
00173 {
00174 fprintf(stderr, "RC : %d\n", _refCount);
00175
00176 for(UInt32 i = 0; i < _vAspects.size(); ++i)
00177 {
00178 fprintf(stderr, "AS %d : %p\n", i, _vAspects[i]);
00179 }
00180 }
00181
00182 inline
00183 void addRef(const OSG::AspectStoreP pObject)
00184 {
00185 if(pObject != NULL)
00186 pObject->addRef();
00187 }
00188
00189 inline
00190 void subRef(const OSG::AspectStoreP pObject)
00191 {
00192 if(pObject != NULL)
00193 pObject->subRef();
00194 }
00195
00196
00197 OSG_END_NAMESPACE