From e7a3a150a7403db43c6ad517595584031e72644a Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Thu, 3 May 2012 16:29:24 +0200 Subject: [PATCH] Add AIThreadSafeBits::wrapper_cast to cast wrapped object back to wrapper class. --- indra/llcommon/aithreadsafe.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/indra/llcommon/aithreadsafe.h b/indra/llcommon/aithreadsafe.h index 2c11908af..a8b1ac490 100644 --- a/indra/llcommon/aithreadsafe.h +++ b/indra/llcommon/aithreadsafe.h @@ -132,6 +132,14 @@ public: // Only for use by AITHREADSAFE, see below. void* memory() const { return const_cast(&mMemory[0]); } + // Cast a T* back to AIThreadSafeBits. This is the inverse of memory(). + template + static AIThreadSafeBits* wrapper_cast(T2* ptr) + { return reinterpret_cast*>(reinterpret_cast(ptr) - offsetof(AIThreadSafeBits, mMemory[0])); } + template + static AIThreadSafeBits const* wrapper_cast(T2 const* ptr) + { return reinterpret_cast const*>(reinterpret_cast(ptr) - offsetof(AIThreadSafeBits, mMemory[0])); } + protected: // Accessors. T const* ptr() const { return reinterpret_cast(mMemory); }