From fa1d3f305b6a31c11b068a3d10924d2adc9d8279 Mon Sep 17 00:00:00 2001 From: Machiavelli Date: Sun, 25 Mar 2012 21:21:23 +0200 Subject: Core/Misc: Implement Trinity::Auto_Ptr. Ditches ACE_Refcounted_AutoPtr (we strongly suspect it does NOT clean up the underlying pointer properly). Underlying type is now ACE_Strong_Bound_Ptr --- src/server/shared/AutoPtr.h | 53 ++++++++++++++++++++++++++++++++ src/server/shared/Database/QueryResult.h | 6 ++-- src/server/shared/Database/Transaction.h | 2 +- 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/server/shared/AutoPtr.h (limited to 'src/server/shared') diff --git a/src/server/shared/AutoPtr.h b/src/server/shared/AutoPtr.h new file mode 100644 index 00000000000..988c46cc5a2 --- /dev/null +++ b/src/server/shared/AutoPtr.h @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2008-2012 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _TRINITY_AUTO_PTR_H +#define _TRINITY_AUTO_PTR_H + +#include + +namespace Trinity +{ + template + class AutoPtr : public ACE_Strong_Bound_Ptr + { + public: + AutoPtr() : ACE_Strong_Bound_Ptr() {} + + AutoPtr(Pointer* x) + { + ACE_Strong_Bound_Ptr::reset(x); + } + + operator bool() const + { + return ACE_Strong_Bound_Ptr::get() != NULL; + } + + bool operator !() const + { + return ACE_Strong_Bound_Ptr::get() == NULL; + } + + bool operator !=(Pointer* x) const + { + return ACE_Strong_Bound_Ptr::get() != x; + } + }; +}; + +#endif \ No newline at end of file diff --git a/src/server/shared/Database/QueryResult.h b/src/server/shared/Database/QueryResult.h index 524532f30ec..2c09cb19c81 100755 --- a/src/server/shared/Database/QueryResult.h +++ b/src/server/shared/Database/QueryResult.h @@ -19,7 +19,7 @@ #ifndef QUERYRESULT_H #define QUERYRESULT_H -#include +#include "AutoPtr.h" #include #include "Field.h" @@ -58,7 +58,7 @@ class ResultSet MYSQL_FIELD* _fields; }; -typedef ACE_Refcounted_Auto_Ptr QueryResult; +typedef Trinity::AutoPtr QueryResult; class PreparedResultSet { @@ -103,7 +103,7 @@ class PreparedResultSet }; -typedef ACE_Refcounted_Auto_Ptr PreparedQueryResult; +typedef Trinity::AutoPtr PreparedQueryResult; #endif diff --git a/src/server/shared/Database/Transaction.h b/src/server/shared/Database/Transaction.h index 92002819951..a12f66ceced 100755 --- a/src/server/shared/Database/Transaction.h +++ b/src/server/shared/Database/Transaction.h @@ -47,7 +47,7 @@ class Transaction bool _cleanedUp; }; -typedef ACE_Refcounted_Auto_Ptr SQLTransaction; +typedef Trinity::AutoPtr SQLTransaction; /*! Low level class*/ class TransactionTask : public SQLOperation -- cgit v1.2.3