Skip to content
Snippets Groups Projects
Commit 29dd5f01 authored by Nat Goodspeed's avatar Nat Goodspeed
Browse files

DRTVWR-418: Use (protected) LLSingleton to store "null instance"

of LLSafeHandle's referenced type. Using LLSingleton gives us a well-defined
time at which the "null instance" is deleted: LLSingletonBase::deleteAll().
parent 2a5c47eb
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#define LLSAFEHANDLE_H #define LLSAFEHANDLE_H
#include "llerror.h" // *TODO: consider eliminating this #include "llerror.h" // *TODO: consider eliminating this
#include "llsingleton.h"
// Expands LLPointer to return a pointer to a special instance of class Type instead of NULL. // Expands LLPointer to return a pointer to a special instance of class Type instead of NULL.
// This is useful in instances where operations on NULL pointers are semantically safe and/or // This is useful in instances where operations on NULL pointers are semantically safe and/or
...@@ -146,15 +147,24 @@ class LLSafeHandle ...@@ -146,15 +147,24 @@ class LLSafeHandle
} }
} }
static Type* nonNull(Type* ptr) // Define an LLSingleton whose sole purpose is to hold a "null instance"
// of the subject Type: the canonical instance to dereference if this
// LLSafeHandle actually holds a null pointer. We use LLSingleton
// specifically so that the "null instance" can be cleaned up at a well-
// defined time, specifically LLSingletonBase::deleteAll().
// Of course, as with any LLSingleton, the "null instance" is only
// instantiated on demand -- in this case, if you actually try to
// dereference an LLSafeHandle containing null.
class NullInstanceHolder: public LLSingleton<NullInstanceHolder>
{ {
return ptr == NULL ? sNullFunc() : ptr; LLSINGLETON_EMPTY_CTOR(NullInstanceHolder);
} public:
Type mNullInstance;
};
static Type* sNullFunc() static Type* nonNull(Type* ptr)
{ {
static Type sInstance; return ptr? ptr : &NullInstanceHolder::instance().mNullInstance;
return &sInstance;
} }
protected: protected:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment