aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llmemory.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:34 -0500
committerJacek Antonelli2008-08-15 23:45:34 -0500
commitcd17687f01420952712a500107e0f93e7ab8d5f8 (patch)
treece48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/llcommon/llmemory.h
parentSecond Life viewer sources 1.19.0.5 (diff)
downloadmeta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2
meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz
Second Life viewer sources 1.19.1.0
Diffstat (limited to '')
-rw-r--r--linden/indra/llcommon/llmemory.h50
1 files changed, 32 insertions, 18 deletions
diff --git a/linden/indra/llcommon/llmemory.h b/linden/indra/llcommon/llmemory.h
index 8a3ca0b..e1af7ba 100644
--- a/linden/indra/llcommon/llmemory.h
+++ b/linden/indra/llcommon/llmemory.h
@@ -243,25 +243,25 @@ protected:
243// Expands LLPointer to return a pointer to a special instance of class Type instead of NULL. 243// Expands LLPointer to return a pointer to a special instance of class Type instead of NULL.
244// This is useful in instances where operations on NULL pointers are semantically safe and/or 244// This is useful in instances where operations on NULL pointers are semantically safe and/or
245// when error checking occurs at a different granularity or in a different part of the code 245// when error checking occurs at a different granularity or in a different part of the code
246// than when referencing an object via a LLHandle. 246// than when referencing an object via a LLSafeHandle.
247// 247//
248 248
249template <class Type> 249template <class Type>
250class LLHandle 250class LLSafeHandle
251{ 251{
252public: 252public:
253 LLHandle() : 253 LLSafeHandle() :
254 mPointer(NULL) 254 mPointer(NULL)
255 { 255 {
256 } 256 }
257 257
258 LLHandle(Type* ptr) : 258 LLSafeHandle(Type* ptr) :
259 mPointer(NULL) 259 mPointer(NULL)
260 { 260 {
261 assign(ptr); 261 assign(ptr);
262 } 262 }
263 263
264 LLHandle(const LLHandle<Type>& ptr) : 264 LLSafeHandle(const LLSafeHandle<Type>& ptr) :
265 mPointer(NULL) 265 mPointer(NULL)
266 { 266 {
267 assign(ptr.mPointer); 267 assign(ptr.mPointer);
@@ -269,13 +269,13 @@ public:
269 269
270 // support conversion up the type hierarchy. See Item 45 in Effective C++, 3rd Ed. 270 // support conversion up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
271 template<typename Subclass> 271 template<typename Subclass>
272 LLHandle(const LLHandle<Subclass>& ptr) : 272 LLSafeHandle(const LLSafeHandle<Subclass>& ptr) :
273 mPointer(NULL) 273 mPointer(NULL)
274 { 274 {
275 assign(ptr.get()); 275 assign(ptr.get());
276 } 276 }
277 277
278 ~LLHandle() 278 ~LLSafeHandle()
279 { 279 {
280 unref(); 280 unref();
281 } 281 }
@@ -300,17 +300,17 @@ public:
300 operator const Type*() const { return mPointer; } 300 operator const Type*() const { return mPointer; }
301 bool operator !=(Type* ptr) const { return (mPointer != ptr); } 301 bool operator !=(Type* ptr) const { return (mPointer != ptr); }
302 bool operator ==(Type* ptr) const { return (mPointer == ptr); } 302 bool operator ==(Type* ptr) const { return (mPointer == ptr); }
303 bool operator ==(const LLHandle<Type>& ptr) const { return (mPointer == ptr.mPointer); } 303 bool operator ==(const LLSafeHandle<Type>& ptr) const { return (mPointer == ptr.mPointer); }
304 bool operator < (const LLHandle<Type>& ptr) const { return (mPointer < ptr.mPointer); } 304 bool operator < (const LLSafeHandle<Type>& ptr) const { return (mPointer < ptr.mPointer); }
305 bool operator > (const LLHandle<Type>& ptr) const { return (mPointer > ptr.mPointer); } 305 bool operator > (const LLSafeHandle<Type>& ptr) const { return (mPointer > ptr.mPointer); }
306 306
307 LLHandle<Type>& operator =(Type* ptr) 307 LLSafeHandle<Type>& operator =(Type* ptr)
308 { 308 {
309 assign(ptr); 309 assign(ptr);
310 return *this; 310 return *this;
311 } 311 }
312 312
313 LLHandle<Type>& operator =(const LLHandle<Type>& ptr) 313 LLSafeHandle<Type>& operator =(const LLSafeHandle<Type>& ptr)
314 { 314 {
315 assign(ptr.mPointer); 315 assign(ptr.mPointer);
316 return *this; 316 return *this;
@@ -318,7 +318,7 @@ public:
318 318
319 // support assignment up the type hierarchy. See Item 45 in Effective C++, 3rd Ed. 319 // support assignment up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
320 template<typename Subclass> 320 template<typename Subclass>
321 LLHandle<Type>& operator =(const LLHandle<Subclass>& ptr) 321 LLSafeHandle<Type>& operator =(const LLSafeHandle<Subclass>& ptr)
322 { 322 {
323 assign(ptr.get()); 323 assign(ptr.get());
324 return *this; 324 return *this;
@@ -399,11 +399,25 @@ protected:
399 399
400//---------------------------------------------------------------------------- 400//----------------------------------------------------------------------------
401 401
402// LLSingleton implements the getInstance() method part of the Singleton pattern. It can't make 402// LLSingleton implements the getInstance() method part of the Singleton
403// the derived class constructors protected, though, so you have to do that yourself. 403// pattern. It can't make the derived class constructors protected, though, so
404// The proper way to use LLSingleton is to inherit from it while using the typename that you'd 404// you have to do that yourself.
405// like to be static as the template parameter, like so: 405//
406// class FooBar: public LLSingleton<FooBar> 406// There are two ways to use LLSingleton. The first way is to inherit from it
407// while using the typename that you'd like to be static as the template
408// parameter, like so:
409//
410// class Foo: public LLSingleton<Foo>{};
411//
412// Foo* instance = Foo::getInstance();
413//
414// The second way is to define a seperate class that exposes the singleton
415// interface:
416//
417// class FooSingleton: public LLSingleton<Foo>{};
418//
419// Foo* instance = FooSingleton::getInstance();
420//
407// As currently written, it is not thread-safe. 421// As currently written, it is not thread-safe.
408template <typename T> 422template <typename T>
409class LLSingleton 423class LLSingleton