From d63c54cb78514db41fc275bf4e2dc67ea92be93a Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Thu, 15 Mar 2012 03:19:28 +0100 Subject: [PATCH] Allow AIThreadSafe*DC classes to be constructed with zero or one parameter. Also, allow AIThreadSafeSingleThreadDC objects to auto convert to it's underlaying type, to assign that type and to write it directly to an ostream. --- indra/llcommon/aithreadsafe.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/indra/llcommon/aithreadsafe.h b/indra/llcommon/aithreadsafe.h index e22f587e2..225be3681 100644 --- a/indra/llcommon/aithreadsafe.h +++ b/indra/llcommon/aithreadsafe.h @@ -256,6 +256,8 @@ class AIThreadSafeDC : public AIThreadSafe public: // Construct a wrapper around a default constructed object. AIThreadSafeDC(void) { new (AIThreadSafe::ptr()) T; } + // Allow an arbitrary parameter to be passed for construction. + template AIThreadSafeDC(T2 const& val) { new (AIThreadSafe::ptr()) T(val); } }; /** @@ -472,10 +474,12 @@ class AIThreadSafeSimpleDC : public AIThreadSafeSimple public: // Construct a wrapper around a default constructed object. AIThreadSafeSimpleDC(void) { new (AIThreadSafeSimple::ptr()) T; } + // Allow an arbitrary parameter to be passed for construction. + template AIThreadSafeSimpleDC(T2 const& val) { new (AIThreadSafeSimple::ptr()) T(val); } protected: // For use by AIThreadSafeSimpleDCRootPool - AIThreadSafeSimpleDC(LLAPRPool& parent) : AIThreadSafeSimple(parent) { new (AIThreadSafeSimple::ptr()) T; } + AIThreadSafeSimpleDC(LLAPRRootPool& parent) : AIThreadSafeSimple(parent) { new (AIThreadSafeSimple::ptr()) T; } }; // Helper class for AIThreadSafeSimpleDCRootPool to assure initialization of @@ -664,6 +668,17 @@ class AIThreadSafeSingleThreadDC : public AIThreadSafeSingleThread public: // Construct a wrapper around a default constructed object. AIThreadSafeSingleThreadDC(void) { new (AIThreadSafeSingleThread::ptr()) T; } + // Allow an arbitrary parameter to be passed for construction. + template AIThreadSafeSingleThreadDC(T2 const& val) { new (AIThreadSafeSingleThread::ptr()) T(val); } + + // Allow assigning with T. + AIThreadSafeSingleThreadDC& operator=(T const& val) { AIThreadSafeSingleThread::accessed(); *AIThreadSafeSingleThread::ptr() = val; return *this; } + // Allow writing to an ostream. + friend std::ostream& operator<<(std::ostream& os, AIThreadSafeSingleThreadDC const& wrapped_val) { wrapped_val.accessed(); return os << *wrapped_val.ptr(); } + + // Automatic conversion to T. + operator T&(void) { AIThreadSafeSingleThread::accessed(); return *AIThreadSafeSingleThread::ptr(); } + operator T const&(void) const { AIThreadSafeSingleThread::accessed(); return *AIThreadSafeSingleThread::ptr(); } }; /**