mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-29 15:16:05 +00:00
Fixed: Strict aliasing warnings
--HG-- branch : develop
This commit is contained in:
parent
3c568ce8a3
commit
50b6af6d3d
4 changed files with 30 additions and 28 deletions
|
@ -108,7 +108,7 @@ template <class TPtr, class TKey, class TResourceFinder>
|
||||||
class CResourcePtr
|
class CResourcePtr
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CRefCount::CPtrInfo *pinfo; // A ptr to the handle of the object.
|
CRefCount::CPtrInfoBase *pinfo; // A ptr to the handle of the object.
|
||||||
TKey Key; // The key used to find the pointer
|
TKey Key; // The key used to find the pointer
|
||||||
mutable TPtr *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*()
|
mutable TPtr *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*()
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ template <class TPtr, class TKey, class TResourceFinder> SMART_INLINE void CReso
|
||||||
if(pinfo->Ptr)
|
if(pinfo->Ptr)
|
||||||
{
|
{
|
||||||
// Inform the Object that no more CResourcePtr points on it.
|
// Inform the Object that no more CResourcePtr points on it.
|
||||||
((TPtr*)(pinfo->Ptr))->pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
((TPtr*)(pinfo->Ptr))->pinfo = &CRefCount::NullPtrInfo;
|
||||||
}
|
}
|
||||||
// Then delete the pinfo.
|
// Then delete the pinfo.
|
||||||
delete pinfo;
|
delete pinfo;
|
||||||
|
@ -74,7 +74,7 @@ template <class TPtr, class TKey, class TResourceFinder> SMART_INLINE void CReso
|
||||||
// Cons - dest.
|
// Cons - dest.
|
||||||
template <class TPtr, class TKey, class TResourceFinder> inline CResourcePtr<TPtr, TKey, TResourceFinder>::CResourcePtr()
|
template <class TPtr, class TKey, class TResourceFinder> inline CResourcePtr<TPtr, TKey, TResourceFinder>::CResourcePtr()
|
||||||
{
|
{
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinf o= &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
|
|
||||||
REF_TRACE("Smart()");
|
REF_TRACE("Smart()");
|
||||||
|
@ -95,7 +95,7 @@ template <class TPtr, class TKey, class TResourceFinder> inline CResourcePtr<TPt
|
||||||
pinfo->RefCount++;
|
pinfo->RefCount++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
|
|
||||||
REF_TRACE("Smart(TPtr*)");
|
REF_TRACE("Smart(TPtr*)");
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ template <class TPtr, class TKey, class TResourceFinder> inline CResourcePtr<TPt
|
||||||
REF_TRACE("~Smart()");
|
REF_TRACE("~Smart()");
|
||||||
|
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ template <class TPtr, class TKey, class TResourceFinder> CResourcePtr<TPtr, TKey
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ template <class TPtr, class TKey, class TResourceFinder> void CResourcePtr<T>::k
|
||||||
|
|
||||||
// First, release the refptr.
|
// First, release the refptr.
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
|
|
||||||
// Then delete the pointer.
|
// Then delete the pointer.
|
||||||
|
@ -196,7 +196,7 @@ template <class TPtr, class TKey, class TResourceFinder> inline CResourcePtr<TPt
|
||||||
|
|
||||||
// Refresh the Ptr.
|
// Refresh the Ptr.
|
||||||
Ptr= (TPtr*)pinfo->Ptr;
|
Ptr= (TPtr*)pinfo->Ptr;
|
||||||
if (pinfo != static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo))
|
if (pinfo != &CRefCount::NullPtrInfo)
|
||||||
{
|
{
|
||||||
// Does the pointer has been deleted ?
|
// Does the pointer has been deleted ?
|
||||||
if (Ptr == NULL)
|
if (Ptr == NULL)
|
||||||
|
@ -310,7 +310,7 @@ template <class TPtr, class TKey, class TResourceFinder> void CStaticResourcePtr
|
||||||
|
|
||||||
// First, release the refptr.
|
// First, release the refptr.
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
|
|
||||||
// Then delete the pointer.
|
// Then delete the pointer.
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
/// Destructor which release pinfo if necessary.
|
/// Destructor which release pinfo if necessary.
|
||||||
~CRefCount();
|
~CRefCount();
|
||||||
/// Default constructor init crefs to 0.
|
/// Default constructor init crefs to 0.
|
||||||
CRefCount() { crefs = 0; pinfo=static_cast<CPtrInfo*>(&NullPtrInfo); }
|
CRefCount() { crefs = 0; pinfo = &NullPtrInfo; }
|
||||||
|
|
||||||
/* The instance handle.
|
/* The instance handle.
|
||||||
Can't put those to private since must be used by CRefPtr (and friend doesn't work with template).
|
Can't put those to private since must be used by CRefPtr (and friend doesn't work with template).
|
||||||
|
@ -56,6 +56,7 @@ public:
|
||||||
sint RefCount; // RefCount of ptrinfo (!= instance)
|
sint RefCount; // RefCount of ptrinfo (!= instance)
|
||||||
bool IsNullPtrInfo; // For dll problems, must use a flag to mark NullPtrInfo.
|
bool IsNullPtrInfo; // For dll problems, must use a flag to mark NullPtrInfo.
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CPtrInfo : public CPtrInfoBase
|
struct CPtrInfo : public CPtrInfoBase
|
||||||
{
|
{
|
||||||
CPtrInfo(CRefCount const* p) {Ptr=p; RefCount=0; IsNullPtrInfo=false;}
|
CPtrInfo(CRefCount const* p) {Ptr=p; RefCount=0; IsNullPtrInfo=false;}
|
||||||
|
@ -76,12 +77,12 @@ public:
|
||||||
// Provide incref()/decref() function doen't work since decref() can't do a delete this on a non virtual dtor.
|
// Provide incref()/decref() function doen't work since decref() can't do a delete this on a non virtual dtor.
|
||||||
// So Ptr gestion can only be used via CSmartPtr.
|
// So Ptr gestion can only be used via CSmartPtr.
|
||||||
mutable sint crefs; // The ref counter for SmartPtr use.
|
mutable sint crefs; // The ref counter for SmartPtr use.
|
||||||
mutable CPtrInfo *pinfo; // The ref ptr for RefPtr use.
|
mutable CPtrInfoBase *pinfo; // The ref ptr for RefPtr use.
|
||||||
|
|
||||||
/// operator= must NOT copy crefs/pinfo!!
|
/// operator= must NOT copy crefs/pinfo!!
|
||||||
CRefCount &operator=(const CRefCount &) {return *this;}
|
CRefCount &operator=(const CRefCount &) {return *this;}
|
||||||
/// copy cons must NOT copy crefs/pinfo!!
|
/// copy cons must NOT copy crefs/pinfo!!
|
||||||
CRefCount(const CRefCount &) {crefs = 0; pinfo=static_cast<CPtrInfo*>(&NullPtrInfo);}
|
CRefCount(const CRefCount &) { crefs = 0; pinfo = &NullPtrInfo; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// To use CVirtualRefPtr (or if you just want to have a RefCount with virtual destructor), derive from this class.
|
// To use CVirtualRefPtr (or if you just want to have a RefCount with virtual destructor), derive from this class.
|
||||||
|
@ -99,7 +100,7 @@ public:
|
||||||
#define SMART_TRACE(_s) ((void)0)
|
#define SMART_TRACE(_s) ((void)0)
|
||||||
#define REF_TRACE(_s) ((void)0)
|
#define REF_TRACE(_s) ((void)0)
|
||||||
//#define SMART_TRACE(_s) printf("%s: %d \n", _s, Ptr?Ptr->crefs:0)
|
//#define SMART_TRACE(_s) printf("%s: %d \n", _s, Ptr?Ptr->crefs:0)
|
||||||
//#define REF_TRACE(_s) printf("%s: %d \n", _s, pinfo!=&CRefCount::NullPtrInfo?pinfo->RefCount:0)
|
//#define REF_TRACE(_s) printf("%s: %d \n", _s, pinfo != &CRefCount::NullPtrInfo?pinfo->RefCount:0)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -294,7 +295,8 @@ template <class T>
|
||||||
class CRefPtr
|
class CRefPtr
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CRefCount::CPtrInfo *pinfo; // A ptr to the handle of the object.
|
CRefCount::CPtrInfoBase *pinfo; // A ptr to the handle of the object.
|
||||||
|
|
||||||
mutable T *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*()
|
mutable T *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*()
|
||||||
|
|
||||||
void unRef() const; // Just release the handle pinfo, but do not update pinfo/Ptr, if deleted.
|
void unRef() const; // Just release the handle pinfo, but do not update pinfo/Ptr, if deleted.
|
||||||
|
@ -380,7 +382,7 @@ template <class T>
|
||||||
class CVirtualRefPtr
|
class CVirtualRefPtr
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CRefCount::CPtrInfo *pinfo; // A ptr to the handle of the object.
|
CRefCount::CPtrInfoBase *pinfo; // A ptr to the handle of the object.
|
||||||
mutable T *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*()
|
mutable T *Ptr; // A cache for pinfo->Ptr. Useful to speed up ope->() and ope*()
|
||||||
|
|
||||||
void unRef() const; // Just release the handle pinfo, but do not update pinfo/Ptr, if deleted.
|
void unRef() const; // Just release the handle pinfo, but do not update pinfo/Ptr, if deleted.
|
||||||
|
|
|
@ -134,7 +134,7 @@ SMART_INLINE void CRefPtr<T>::unRef() const
|
||||||
if(pinfo->Ptr)
|
if(pinfo->Ptr)
|
||||||
{
|
{
|
||||||
// Inform the Object that no more CRefPtr points on it.
|
// Inform the Object that no more CRefPtr points on it.
|
||||||
pinfo->Ptr->pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo->Ptr->pinfo = &CRefCount::NullPtrInfo;
|
||||||
}
|
}
|
||||||
// Then delete the pinfo.
|
// Then delete the pinfo.
|
||||||
delete pinfo;
|
delete pinfo;
|
||||||
|
@ -148,7 +148,7 @@ SMART_INLINE void CRefPtr<T>::unRef() const
|
||||||
// Cons - dest.
|
// Cons - dest.
|
||||||
template <class T> inline CRefPtr<T>::CRefPtr()
|
template <class T> inline CRefPtr<T>::CRefPtr()
|
||||||
{
|
{
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
|
|
||||||
REF_TRACE("Smart()");
|
REF_TRACE("Smart()");
|
||||||
|
@ -170,7 +170,7 @@ template <class T> inline CRefPtr<T>::CRefPtr(T *v)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
|
|
||||||
REF_TRACE("Smart(T*)");
|
REF_TRACE("Smart(T*)");
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ template <class T> inline CRefPtr<T>::~CRefPtr(void)
|
||||||
REF_TRACE("~Smart()");
|
REF_TRACE("~Smart()");
|
||||||
|
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ template <class T> CRefPtr<T> &CRefPtr<T>::operator=(T *v)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,7 +250,7 @@ template <class T> void CRefPtr<T>::kill()
|
||||||
|
|
||||||
// First, release the refptr.
|
// First, release the refptr.
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
|
|
||||||
// Then delete the pointer.
|
// Then delete the pointer.
|
||||||
|
@ -316,7 +316,7 @@ SMART_INLINE void CVirtualRefPtr<T>::unRef() const
|
||||||
if(pinfo->Ptr)
|
if(pinfo->Ptr)
|
||||||
{
|
{
|
||||||
// Inform the Object that no more CVirtualRefPtr points on it.
|
// Inform the Object that no more CVirtualRefPtr points on it.
|
||||||
pinfo->Ptr->pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo->Ptr->pinfo = &CRefCount::NullPtrInfo;
|
||||||
}
|
}
|
||||||
// Then delete the pinfo.
|
// Then delete the pinfo.
|
||||||
delete pinfo;
|
delete pinfo;
|
||||||
|
@ -330,7 +330,7 @@ SMART_INLINE void CVirtualRefPtr<T>::unRef() const
|
||||||
// Cons - dest.
|
// Cons - dest.
|
||||||
template <class T> inline CVirtualRefPtr<T>::CVirtualRefPtr()
|
template <class T> inline CVirtualRefPtr<T>::CVirtualRefPtr()
|
||||||
{
|
{
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
|
|
||||||
REF_TRACE("Smart()");
|
REF_TRACE("Smart()");
|
||||||
|
@ -352,7 +352,7 @@ template <class T> inline CVirtualRefPtr<T>::CVirtualRefPtr(T *v)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
|
|
||||||
REF_TRACE("Smart(T*)");
|
REF_TRACE("Smart(T*)");
|
||||||
}
|
}
|
||||||
|
@ -370,7 +370,7 @@ template <class T> inline CVirtualRefPtr<T>::~CVirtualRefPtr(void)
|
||||||
REF_TRACE("~Smart()");
|
REF_TRACE("~Smart()");
|
||||||
|
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ template <class T> CVirtualRefPtr<T> &CVirtualRefPtr<T>::operator=(T *v)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -435,7 +435,7 @@ template <class T> void CVirtualRefPtr<T>::kill()
|
||||||
|
|
||||||
// First, release the refptr.
|
// First, release the refptr.
|
||||||
unRef();
|
unRef();
|
||||||
pinfo= static_cast<CRefCount::CPtrInfo*>(&CRefCount::NullPtrInfo);
|
pinfo = &CRefCount::NullPtrInfo;
|
||||||
Ptr= NULL;
|
Ptr= NULL;
|
||||||
|
|
||||||
// Then delete the pointer.
|
// Then delete the pointer.
|
||||||
|
|
Loading…
Reference in a new issue