Author: wyoung
Date: Wed Nov 28 06:35:20 2007
New Revision: 1906
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1906&view=rev
Log:
Added another template parameter to RefCountedPointer to allow user to
change "destruction" behavior from operator delete. Default is the
same, but next checkin will use something else.
Modified:
trunk/lib/refcounted.h
Modified: trunk/lib/refcounted.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/refcounted.h?rev=1906&r1=1905&r2=1906&view=diff
==============================================================================
--- trunk/lib/refcounted.h (original)
+++ trunk/lib/refcounted.h Wed Nov 28 06:35:20 2007
@@ -33,6 +33,21 @@
#include <string>
namespace mysqlpp {
+
+/// \brief Functor to call delete on the pointer you pass to it
+///
+/// The default "destroyer" for RefCountedPointer. You won't use this
+/// directly, you'll pass a functor of your own devising for the second
+/// parameter to the RefCountedPointer template to override this. Or
+/// simpler, just specialize this template for your type if possible:
+/// see ResUse::result_.
+template <class T>
+struct RefCountedPointerDestroyer
+{
+ /// \brief Functor implementation
+ void operator()(T* doomed) { delete doomed; }
+};
+
/// \brief Creates an object that acts as a reference-counted pointer
/// to another object.
@@ -61,7 +76,7 @@
/// of just double. It's a tradeoff, and we've chosen to take a minor
/// complexity hit to avoid the performance hit.
-template <class T>
+template <class T, class Destroyer = RefCountedPointerDestroyer<T> >
class RefCountedPointer
{
public:
@@ -222,7 +237,7 @@
void detach()
{
if (refs_ && (--(*refs_) == 0)) {
- delete counted_;
+ Destroyer()(counted_);
delete refs_;
counted_ = 0;
refs_ = 0;
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits