summaryrefslogtreecommitdiff
path: root/yapf/autocopyptr.hpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-01-02 19:19:48 +0000
committerrubidium <rubidium@openttd.org>2007-01-02 19:19:48 +0000
commit66bbf336c6af7353ef0aeed58002c46543b30635 (patch)
treead4a63860df2626b22f77e7dac712e958bea54cb /yapf/autocopyptr.hpp
parentccc0a3f4dbf58c005b22341ac8874252924690cd (diff)
downloadopenttd-66bbf336c6af7353ef0aeed58002c46543b30635.tar.xz
(svn r7759) -Merge: makefile rewrite. This merge features:
- A proper ./configure, so everything needs to be configured only once, not for every make. - Usage of makedepend when available. This greatly reduces the time needed for generating the dependencies. - A generator for all project files. There is a single file with sources, which is used to generate Makefiles and the project files for MSVC. - Proper support for OSX universal binaries. - Object files for non-MSVC compiles are also placed in separate directories, making is faster to switch between debug and release compiles and it does not touch the directory with the source files. - Functionality to make a bundle of all needed files for for example a nightly or distribution of a binary with all needed GRFs and language files. Note: as this merge moves almost all files, it is recommended to make a backup of your working copy before updating your working copy.
Diffstat (limited to 'yapf/autocopyptr.hpp')
-rw-r--r--yapf/autocopyptr.hpp83
1 files changed, 0 insertions, 83 deletions
diff --git a/yapf/autocopyptr.hpp b/yapf/autocopyptr.hpp
deleted file mode 100644
index fb6bfa028..000000000
--- a/yapf/autocopyptr.hpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/* $Id$ */
-
-#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 behavior 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 */