/usr/include/ossim/base/ossimRefPtr.h is in libossim-dev 1.8.16-4ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | /* -*-c++-*- ossim - Copyright (C) since 2004 Garrett Potts
*
* This was taken directly from OpenSceneGraph and will retain OSGGPL license.
* This is basically an LGPL.
*
*/
#ifndef ossimRefPtr_HEADER
#define ossimRefPtr_HEADER
#include <ossim/base/ossimConstants.h>
template<class T> class ossimRefPtr
{
public:
typedef T element_type;
ossimRefPtr() :m_ptr(0) {}
ossimRefPtr(T* t):m_ptr(t) { if (m_ptr) m_ptr->ref(); }
ossimRefPtr(const ossimRefPtr& rp):m_ptr(rp.m_ptr) { if (m_ptr) m_ptr->ref(); }
~ossimRefPtr() { if (m_ptr) m_ptr->unref(); m_ptr=0; }
inline ossimRefPtr& operator = (const ossimRefPtr& rp)
{
if (m_ptr==rp.m_ptr) return *this;
T* tmpPtr = m_ptr;
m_ptr = rp.m_ptr;
if (m_ptr) m_ptr->ref();
// unref second to prevent any deletion of any object which might
// be referenced by the other object. i.e rp is child of the
// original _ptr.
if (tmpPtr) tmpPtr->unref();
return *this;
}
inline ossimRefPtr& operator = (T* ptr)
{
if (m_ptr==ptr) return *this;
T* tmpPtr = m_ptr;
m_ptr = ptr;
if (m_ptr) m_ptr->ref();
// unref second to prevent any deletion of any object which might
// be referenced by the other object. i.e rp is child of the
// original m_ptr.
if (tmpPtr) tmpPtr->unref();
return *this;
}
// comparison operators for ossimRefPtr.
inline bool operator == (const ossimRefPtr& rp) const { return (m_ptr==rp.m_ptr); }
inline bool operator != (const ossimRefPtr& rp) const { return (m_ptr!=rp.m_ptr); }
inline bool operator < (const ossimRefPtr& rp) const { return (m_ptr<rp.m_ptr); }
inline bool operator > (const ossimRefPtr& rp) const { return (m_ptr>rp.m_ptr); }
// comparion operator for const T*.
inline bool operator == (const T* ptr) const { return (m_ptr==ptr); }
inline bool operator != (const T* ptr) const { return (m_ptr!=ptr); }
inline bool operator < (const T* ptr) const { return (m_ptr<ptr); }
inline bool operator > (const T* ptr) const { return (m_ptr>ptr); }
inline T& operator*() { return *m_ptr; }
inline const T& operator*() const { return *m_ptr; }
inline T* operator->() { return m_ptr; }
inline const T* operator->() const { return m_ptr; }
inline bool operator!() const { return m_ptr==0L; }
inline bool valid() const { return m_ptr!=0L; }
inline T* get() { return m_ptr; }
inline const T* get() const { return m_ptr; }
/** take control over the object pointed to by ref_ptr, unreference but do not delete even if ref count goes to 0,
* return the pointer to the object.
* Note, do not use this unless you are 100% sure your code handles the deletion of the object correctly, and
* only use when absolutely required.*/
inline T* take() { return release();}
inline T* release() { T* tmp=m_ptr; if (m_ptr) m_ptr->unref_nodelete(); m_ptr=0; return tmp;}
private:
T* m_ptr;
};
#endif
|