Files
@ r7596:afd285ff90bb
Branch filter:
Location: cpp/openttd-patchpack/source/src/misc/autoptr.hpp
r7596:afd285ff90bb
1.9 KiB
text/x-c++hdr
(svn r11123) -Update: WebTranslator2 update to 2007-09-17 12:45:29
afrikaans - 47 fixed, 52 changed by TrueTenacity (99)
brazilian_portuguese - 23 changed by fukumori (23)
bulgarian - 14 fixed by thetitan (14)
catalan - 3 changed by arnaullv (3)
croatian - 6 fixed, 12 changed by knovak (15), tperic (3)
danish - 20 fixed by ThomasA (20)
finnish - 20 fixed by habazi (20)
german - 10 fixed by Timwi (10)
hungarian - 1 fixed by miham (1)
italian - 1 fixed by lorenzodv (1)
japanese - 6 fixed by ickoonite (6)
norwegian_nynorsk - 6 fixed by pollux (6)
piglatin - 20 fixed by adammw (20)
russian - 20 fixed by Smoky555 (20)
slovak - 1 fixed by lengyel (1)
slovenian - 7 fixed by Necrolyte (7)
spanish - 1 changed by Cabu (1)
traditional_chinese - 21 fixed by xbddc (21)
afrikaans - 47 fixed, 52 changed by TrueTenacity (99)
brazilian_portuguese - 23 changed by fukumori (23)
bulgarian - 14 fixed by thetitan (14)
catalan - 3 changed by arnaullv (3)
croatian - 6 fixed, 12 changed by knovak (15), tperic (3)
danish - 20 fixed by ThomasA (20)
finnish - 20 fixed by habazi (20)
german - 10 fixed by Timwi (10)
hungarian - 1 fixed by miham (1)
italian - 1 fixed by lorenzodv (1)
japanese - 6 fixed by ickoonite (6)
norwegian_nynorsk - 6 fixed by pollux (6)
piglatin - 20 fixed by adammw (20)
russian - 20 fixed by Smoky555 (20)
slovak - 1 fixed by lengyel (1)
slovenian - 7 fixed by Necrolyte (7)
spanish - 1 changed by Cabu (1)
traditional_chinese - 21 fixed by xbddc (21)
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | /* $Id$ */
/** @file autoptr.hpp */
#ifndef AUTOPTR_HPP
#define AUTOPTR_HPP
/** AutoPtrT - kind of smart pointer that ensures the owned object gets
* deleted when its pointer goes out of scope.
* It is non-invasive smart pointer (no reference counter).
* When copied, the copy takes ownership of underlying object
* and original becomes NULL!
* Can be used also for polymorphic data types (interfaces).
*/
template <class T>
class AutoPtrT {
public:
typedef T obj_t;
protected:
mutable T* m_p; ///< points to the data
public:
FORCEINLINE AutoPtrT()
: m_p(NULL)
{};
FORCEINLINE AutoPtrT(const AutoPtrT<T>& src)
: m_p(src.m_p)
{
if (m_p != NULL) src.m_p = NULL;
};
FORCEINLINE AutoPtrT(T *p)
: m_p(p)
{}
FORCEINLINE ~AutoPtrT()
{
if (m_p != NULL) {
T *p = m_p;
m_p = NULL;
delete p;
}
}
/** give-up ownership and NULLify the raw pointer */
FORCEINLINE T* Detach()
{
T* p = m_p;
m_p = NULL;
return p;
}
/** raw-pointer cast operator (read only) */
FORCEINLINE operator const T* () const
{
return m_p;
}
/** raw-pointer cast operator */
FORCEINLINE operator T* ()
{
return m_p;
}
/** dereference operator (read only) */
FORCEINLINE const T* operator -> () const
{
assert(m_p != NULL);
return m_p;
}
/** dereference operator (read / write) */
FORCEINLINE T* operator -> ()
{
assert(m_p != NULL);
return m_p;
}
/** assignment operator */
FORCEINLINE AutoPtrT& operator = (const AutoPtrT& src)
{
/* Save original pointer and replace it with the given one to avoid recursive calls. */
T* p = m_p;
m_p = src.m_p;
if (m_p != NULL) src.m_p = NULL;
if (p != NULL) {
/* Now we can safely delete the old one. */
delete p;
}
return *this;
}
/** forwarding 'lower than' operator to the underlaying items */
FORCEINLINE bool operator < (const AutoPtrT& other) const
{
assert(m_p != NULL);
assert(other.m_p != NULL);
return (*m_p) < (*other.m_p);
}
};
#endif /* AUTOPTR_HPP */
|