diff options
author | rubidium <rubidium@openttd.org> | 2008-04-23 22:16:41 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-04-23 22:16:41 +0000 |
commit | 2b85217bfe7197684e22a0257cabe9b4a37cb7d6 (patch) | |
tree | 3c648d4bd6e453e588d664c0eabe3c948a556f7c /src/misc | |
parent | 7c8fe9791b3fb63a2842f45c85c8c428780a7a4e (diff) | |
download | openttd-2b85217bfe7197684e22a0257cabe9b4a37cb7d6.tar.xz |
(svn r12857) -Fix [FS#1948]: remove the last uses of AutoPtr in the station code.
Diffstat (limited to 'src/misc')
-rw-r--r-- | src/misc/autocopyptr.hpp | 85 | ||||
-rw-r--r-- | src/misc/autoptr.hpp | 106 |
2 files changed, 0 insertions, 191 deletions
diff --git a/src/misc/autocopyptr.hpp b/src/misc/autocopyptr.hpp deleted file mode 100644 index 0c684aac2..000000000 --- a/src/misc/autocopyptr.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/* $Id$ */ - -/** @file autocopyptr.hpp */ - -#ifndef AUTOCOPYPTR_HPP -#define AUTOCOPYPTR_HPP - -#if 0 // reenable when needed -/** CAutoCopyPtrT - kind of CoW (Copy on Write) pointer. - * It is non-invasive smart pointer (reference counter is held outside - * of Tdata). - * When copied, its new copy shares the same underlaying structure Tdata. - * When dereferenced, its behaviour depends on 2 factors: - * - whether the data is shared (used by more than one pointer) - * - type of access (read/write) - * When shared pointer is dereferenced for write, new clone of Tdata - * is made first. - * Can't be used for polymorphic data types (interfaces). - */ -template <class Tdata_> -class CAutoCopyPtrT { -protected: - typedef Tdata_ Tdata; - - struct CItem { - int m_ref_cnt; ///< reference counter - Tdata m_data; ///< custom data itself - - FORCEINLINE CItem() : m_ref_cnt(1) {}; - FORCEINLINE CItem(const Tdata& data) : m_ref_cnt(1), m_data(data) {}; - FORCEINLINE CItem(const CItem& src) : m_ref_cnt(1), m_data(src.m_data) {}; - }; - - mutable CItem* m_pI; ///< points to the ref-counted data - -public: - FORCEINLINE CAutoCopyPtrT() : m_pI(NULL) {}; - FORCEINLINE CAutoCopyPtrT(const Tdata& data) : m_pI(new CItem(data)) {}; - FORCEINLINE CAutoCopyPtrT(const CAutoCopyPtrT& src) : m_pI(src.m_pI) {if (m_pI != NULL) m_pI->m_ref_cnt++;} - FORCEINLINE ~CAutoCopyPtrT() {if (m_pI == NULL || (--m_pI->m_ref_cnt) > 0) return; delete m_pI; m_pI = NULL;} - - /** data accessor (read only) */ - FORCEINLINE const Tdata& GetDataRO() const {if (m_pI == NULL) m_pI = new CItem(); return m_pI->m_data;} - /** data accessor (read / write) */ - FORCEINLINE Tdata& GetDataRW() {CloneIfShared(); if (m_pI == NULL) m_pI = new CItem(); return m_pI->m_data;} - - /** clone data if it is shared */ - FORCEINLINE void CloneIfShared() - { - if (m_pI != NULL && m_pI->m_ref_cnt > 1) { - // we share data item with somebody, clone it to become an exclusive owner - CItem* pNewI = new CItem(*m_pI); - m_pI->m_ref_cnt--; - m_pI = pNewI; - } - } - - /** assign pointer from the other one (maintaining ref counts) */ - FORCEINLINE void Assign(const CAutoCopyPtrT& src) - { - if (m_pI == src.m_pI) return; - if (m_pI != NULL && (--m_pI->m_ref_cnt) <= 0) delete m_pI; - m_pI = src.m_pI; - if (m_pI != NULL) m_pI->m_ref_cnt++; - } - - /** dereference operator (read only) */ - FORCEINLINE const Tdata* operator -> () const {return &GetDataRO();} - /** dereference operator (read / write) */ - FORCEINLINE Tdata* operator -> () {return &GetDataRW();} - - /** assignment operator */ - FORCEINLINE CAutoCopyPtrT& operator = (const CAutoCopyPtrT& src) {Assign(src); return *this;} - - /** forwarding 'lower then' operator to the underlaying items */ - FORCEINLINE bool operator < (const CAutoCopyPtrT& other) const - { - assert(m_pI != NULL); - assert(other.m_pI != NULL); - return (m_pI->m_data) < (other.m_pI->m_data); - } -}; - -#endif /* 0 */ -#endif /* AUTOCOPYPTR_HPP */ diff --git a/src/misc/autoptr.hpp b/src/misc/autoptr.hpp deleted file mode 100644 index 8b0d920f5..000000000 --- a/src/misc/autoptr.hpp +++ /dev/null @@ -1,106 +0,0 @@ -/* $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 */ |