author | KUDr |
Sat, 21 Apr 2007 08:23:57 +0000 | |
branch | cpp_gui |
changeset 6308 | 646711c5feaa |
parent 6296 | 3205d21b662f |
permissions | -rw-r--r-- |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
1 |
/* $Id$ */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
2 |
|
6308 | 3 |
/** @file countedptr.hpp */ |
4 |
||
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
5 |
#ifndef COUNTEDPTR_HPP |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
6 |
#define COUNTEDPTR_HPP |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
7 |
|
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
5884
diff
changeset
|
8 |
#if 1 // reenable when needed |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
9 |
/** @file CCountedPtr - smart pointer implementation */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
10 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
11 |
/** CCountedPtr - simple reference counting smart pointer. |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
12 |
* |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
13 |
* One of the standard ways how to maintain object's lifetime. |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
14 |
* |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
15 |
* See http://ootips.org/yonat/4dev/smart-pointers.html for more |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
16 |
* general info about smart pointers. |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
17 |
* |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
18 |
* This class implements ref-counted pointer for objects/interfaces that |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
19 |
* support AddRef() and Release() methods. |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4434
diff
changeset
|
20 |
*/ |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
21 |
template <class Tcls_> |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
22 |
class CCountedPtr { |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
23 |
/** redefine the template argument to make it visible for derived classes */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
24 |
public: |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
25 |
typedef Tcls_ Tcls; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
26 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
27 |
protected: |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
28 |
/** here we hold our pointer to the target */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
29 |
Tcls* m_pT; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
30 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
31 |
public: |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
32 |
/** default (NULL) construct or construct from a raw pointer */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
33 |
FORCEINLINE CCountedPtr(Tcls* pObj = NULL) : m_pT(pObj) {AddRef();}; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
34 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
35 |
/** copy constructor (invoked also when initializing from another smart ptr) */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
36 |
FORCEINLINE CCountedPtr(const CCountedPtr& src) : m_pT(src.m_pT) {AddRef();}; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
37 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
38 |
/** destructor releasing the reference */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
39 |
FORCEINLINE ~CCountedPtr() {Release();}; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
40 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
41 |
protected: |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
42 |
/** add one ref to the underlaying object */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
43 |
FORCEINLINE void AddRef() {if (m_pT != NULL) m_pT->AddRef();} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
44 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
45 |
public: |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
46 |
/** release smart pointer (and decrement ref count) if not null */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
47 |
FORCEINLINE void Release() {if (m_pT != NULL) {m_pT->Release(); m_pT = NULL;}} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
48 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
49 |
/** dereference of smart pointer - const way */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
50 |
FORCEINLINE const Tcls* operator -> () const {assert(m_pT != NULL); return m_pT;}; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
51 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
52 |
/** dereference of smart pointer - non const way */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
53 |
FORCEINLINE Tcls* operator -> () {assert(m_pT != NULL); return m_pT;}; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
54 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
55 |
/** raw pointer casting operator - const way */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
56 |
FORCEINLINE operator const Tcls*() const {assert(m_pT == NULL); return m_pT;} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
57 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
58 |
/** raw pointer casting operator - non-const way */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
5884
diff
changeset
|
59 |
FORCEINLINE operator Tcls*() {return m_pT;} |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
60 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
61 |
/** operator & to support output arguments */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
62 |
FORCEINLINE Tcls** operator &() {assert(m_pT == NULL); return &m_pT;} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
63 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
64 |
/** assignment operator from raw ptr */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
65 |
FORCEINLINE CCountedPtr& operator = (Tcls* pT) {Assign(pT); return *this;} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
66 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
67 |
/** assignment operator from another smart ptr */ |
6296 | 68 |
FORCEINLINE CCountedPtr& operator = (const CCountedPtr& src) {Assign(src.m_pT); return *this;} |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
69 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
70 |
/** assignment operator helper */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
71 |
FORCEINLINE void Assign(Tcls* pT); |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
72 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
73 |
/** one way how to test for NULL value */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
74 |
FORCEINLINE bool IsNull() const {return m_pT == NULL;} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
75 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
76 |
/** another way how to test for NULL value */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
5884
diff
changeset
|
77 |
//FORCEINLINE bool operator == (const CCountedPtr& sp) const {return m_pT == sp.m_pT;} |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
78 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
79 |
/** yet another way how to test for NULL value */ |
6235
5077e6ed3788
(svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents:
5884
diff
changeset
|
80 |
//FORCEINLINE bool operator != (const CCountedPtr& sp) const {return m_pT != sp.m_pT;} |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
81 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
82 |
/** assign pointer w/o incrementing ref count */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
83 |
FORCEINLINE void Attach(Tcls* pT) {Release(); m_pT = pT;} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
84 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
85 |
/** detach pointer w/o decrementing ref count */ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
86 |
FORCEINLINE Tcls* Detach() {Tcls* pT = m_pT; m_pT = NULL; return pT;} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
87 |
}; |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
88 |
|
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
89 |
template <class Tcls_> |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
90 |
FORCEINLINE void CCountedPtr<Tcls_>::Assign(Tcls* pT) |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
91 |
{ |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
92 |
// if they are the same, we do nothing |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
93 |
if (pT != m_pT) { |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
94 |
if (pT) pT->AddRef(); // AddRef new pointer if any |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
95 |
Tcls* pTold = m_pT; // save original ptr |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
96 |
m_pT = pT; // update m_pT to new value |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
97 |
if (pTold) pTold->Release(); // release old ptr if any |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
98 |
} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
99 |
} |
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
100 |
|
6269
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
101 |
/** |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
102 |
* Adapter wrapper for CCountedPtr like classes that can't be used directly by stl |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
103 |
* collections as item type. For example CCountedPtr has overloaded operator & which |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
104 |
* prevents using CCountedPtr in stl collections (i.e. std::list<CCountedPtr<MyType> >) |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
105 |
*/ |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
106 |
template <class T> struct AdaptT { |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
107 |
T m_t; |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
108 |
|
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
109 |
/** construct by wrapping the given object */ |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
110 |
AdaptT(const T &t) |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
111 |
: m_t(t) |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
112 |
{} |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
113 |
|
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
114 |
/** assignment operator */ |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
115 |
T& operator = (const T &t) |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
116 |
{ |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
117 |
m_t = t; |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
118 |
return t; |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
119 |
} |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
120 |
|
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
121 |
/** type-cast operator (used when AdaptT is used instead of T) */ |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
122 |
operator T& () |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
123 |
{ |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
124 |
return m_t; |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
125 |
} |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
126 |
|
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
127 |
/** const type-cast operator (used when AdaptT is used instead of const T) */ |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
128 |
operator const T& () const |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
129 |
{ |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
130 |
return m_t; |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
131 |
} |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
132 |
}; |
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
133 |
|
3b3bd4fe0736
(svn r8947) [cpp_gui] -Codechange: proprietary smart pointer adapter replaced by generic one
KUDr
parents:
6256
diff
changeset
|
134 |
|
6256
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
135 |
/** Simple counted object. Use it as base of your struct/class if you want to use |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
136 |
* basic reference counting. Your struct/class will destroy and free itself when |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
137 |
* last reference to it is released (using Relese() method). The initial reference |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
138 |
* count (when it is created) is zero (don't forget AddRef() at least one time if |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
139 |
* not using CCountedPtr<T>. |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
140 |
* |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
141 |
* @see misc/countedobj.cpp for implementation. |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
142 |
*/ |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
143 |
struct SimpleCountedObject { |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
144 |
int32 m_ref_cnt; |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
145 |
|
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
146 |
SimpleCountedObject() |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
147 |
: m_ref_cnt(0) |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
148 |
{} |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
149 |
|
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
150 |
virtual ~SimpleCountedObject() |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
151 |
{}; |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
152 |
|
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
153 |
virtual int32 AddRef(); |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
154 |
virtual int32 Release(); |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
155 |
virtual void FinalRelease() {}; |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
156 |
}; |
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
157 |
|
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
158 |
|
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
159 |
|
220cd0db67a4
(svn r8774) [cpp_gui] -Codechange: CountedObject renamed to SimpleCountedObject and moved to countedptr.hpp and countedobj.cpp
KUDr
parents:
6235
diff
changeset
|
160 |
|
5094
f089c2bb68e9
(svn r7163) -Codechange: Disable compilation of additional yapf code.
Darkvater
parents:
4549
diff
changeset
|
161 |
#endif /* 0 */ |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff
changeset
|
162 |
#endif /* COUNTEDPTR_HPP */ |