summaryrefslogtreecommitdiff
path: root/src/misc/countedptr.hpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2015-08-08 13:19:38 +0000
committeralberth <alberth@openttd.org>2015-08-08 13:19:38 +0000
commit1105b4d2c99e99750f42b7a39443bb03b40f4afa (patch)
treea936197f608b155036ffd2c553065cc8cbabc014 /src/misc/countedptr.hpp
parentb885d79f506bde93b4ab278b3f84b8ca6254f3b9 (diff)
downloadopenttd-1105b4d2c99e99750f42b7a39443bb03b40f4afa.tar.xz
(svn r27363) -Codechange: Fix codestyle of one-line methods and header codestyle of derived structs.
Diffstat (limited to 'src/misc/countedptr.hpp')
-rw-r--r--src/misc/countedptr.hpp92
1 files changed, 73 insertions, 19 deletions
diff --git a/src/misc/countedptr.hpp b/src/misc/countedptr.hpp
index 1a783cf3e..e7b28a626 100644
--- a/src/misc/countedptr.hpp
+++ b/src/misc/countedptr.hpp
@@ -35,48 +35,97 @@ protected:
public:
/** default (NULL) construct or construct from a raw pointer */
- inline CCountedPtr(Tcls *pObj = NULL) : m_pT(pObj) {AddRef();}
+ inline CCountedPtr(Tcls *pObj = NULL) : m_pT(pObj)
+ {
+ AddRef();
+ }
/** copy constructor (invoked also when initializing from another smart ptr) */
- inline CCountedPtr(const CCountedPtr &src) : m_pT(src.m_pT) {AddRef();}
+ inline CCountedPtr(const CCountedPtr &src) : m_pT(src.m_pT)
+ {
+ AddRef();
+ }
/** destructor releasing the reference */
- inline ~CCountedPtr() {Release();}
+ inline ~CCountedPtr()
+ {
+ Release();
+ }
protected:
/** add one ref to the underlaying object */
- inline void AddRef() {if (m_pT != NULL) m_pT->AddRef();}
+ inline void AddRef()
+ {
+ if (m_pT != NULL) m_pT->AddRef();
+ }
public:
/** release smart pointer (and decrement ref count) if not null */
- inline void Release() {if (m_pT != NULL) {Tcls *pT = m_pT; m_pT = NULL; pT->Release();}}
+ inline void Release()
+ {
+ if (m_pT != NULL) {
+ Tcls *pT = m_pT;
+ m_pT = NULL;
+ pT->Release();
+ }
+ }
/** dereference of smart pointer - const way */
- inline const Tcls *operator->() const {assert(m_pT != NULL); return m_pT;}
+ inline const Tcls *operator->() const
+ {
+ assert(m_pT != NULL);
+ return m_pT;
+ }
/** dereference of smart pointer - non const way */
- inline Tcls *operator->() {assert(m_pT != NULL); return m_pT;}
+ inline Tcls *operator->()
+ {
+ assert(m_pT != NULL);
+ return m_pT;
+ }
/** raw pointer casting operator - const way */
- inline operator const Tcls*() const {assert(m_pT == NULL); return m_pT;}
+ inline operator const Tcls*() const
+ {
+ assert(m_pT == NULL);
+ return m_pT;
+ }
/** raw pointer casting operator - non-const way */
- inline operator Tcls*() {return m_pT;}
+ inline operator Tcls*()
+ {
+ return m_pT;
+ }
/** operator & to support output arguments */
- inline Tcls** operator&() {assert(m_pT == NULL); return &m_pT;}
+ inline Tcls** operator&()
+ {
+ assert(m_pT == NULL);
+ return &m_pT;
+ }
/** assignment operator from raw ptr */
- inline CCountedPtr& operator=(Tcls *pT) {Assign(pT); return *this;}
+ inline CCountedPtr& operator=(Tcls *pT)
+ {
+ Assign(pT);
+ return *this;
+ }
/** assignment operator from another smart ptr */
- inline CCountedPtr& operator=(const CCountedPtr &src) {Assign(src.m_pT); return *this;}
+ inline CCountedPtr& operator=(const CCountedPtr &src)
+ {
+ Assign(src.m_pT);
+ return *this;
+ }
/** assignment operator helper */
inline void Assign(Tcls *pT);
/** one way how to test for NULL value */
- inline bool IsNull() const {return m_pT == NULL;}
+ inline bool IsNull() const
+ {
+ return m_pT == NULL;
+ }
/** another way how to test for NULL value */
//inline bool operator == (const CCountedPtr &sp) const {return m_pT == sp.m_pT;}
@@ -85,10 +134,19 @@ public:
//inline bool operator != (const CCountedPtr &sp) const {return m_pT != sp.m_pT;}
/** assign pointer w/o incrementing ref count */
- inline void Attach(Tcls *pT) {Release(); m_pT = pT;}
+ inline void Attach(Tcls *pT)
+ {
+ Release();
+ m_pT = pT;
+ }
/** detach pointer w/o decrementing ref count */
- inline Tcls *Detach() {Tcls *pT = m_pT; m_pT = NULL; return pT;}
+ inline Tcls *Detach()
+ {
+ Tcls *pT = m_pT;
+ m_pT = NULL;
+ return pT;
+ }
};
template <class Tcls_>
@@ -136,7 +194,6 @@ template <class T> struct AdaptT {
}
};
-
/**
* Simple counted object. Use it as base of your struct/class if you want to use
* basic reference counting. Your struct/class will destroy and free itself when
@@ -161,7 +218,4 @@ struct SimpleCountedObject {
virtual void FinalRelease() {};
};
-
-
-
#endif /* COUNTEDPTR_HPP */