summaryrefslogtreecommitdiff
path: root/indra/llcommon/llpointer.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/llpointer.h')
-rw-r--r--indra/llcommon/llpointer.h145
1 files changed, 73 insertions, 72 deletions
diff --git a/indra/llcommon/llpointer.h b/indra/llcommon/llpointer.h
index f9de0c7929..64aceddf32 100644
--- a/indra/llcommon/llpointer.h
+++ b/indra/llcommon/llpointer.h
@@ -46,33 +46,32 @@
template <class Type> class LLPointer
{
public:
-
- LLPointer() :
+ LLPointer() :
mPointer(NULL)
{
}
- LLPointer(Type* ptr) :
+ LLPointer(Type* ptr) :
mPointer(ptr)
{
ref();
}
- LLPointer(const LLPointer<Type>& ptr) :
+ LLPointer(const LLPointer<Type>& ptr) :
mPointer(ptr.mPointer)
{
ref();
}
- // support conversion up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
+ // Support conversion up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
template<typename Subclass>
- LLPointer(const LLPointer<Subclass>& ptr) :
+ LLPointer(const LLPointer<Subclass>& ptr) :
mPointer(ptr.get())
{
ref();
}
- ~LLPointer()
+ ~LLPointer()
{
unref();
}
@@ -83,39 +82,39 @@ public:
const Type& operator*() const { return *mPointer; }
Type& operator*() { return *mPointer; }
- operator BOOL() const { return (mPointer != NULL); }
- operator bool() const { return (mPointer != NULL); }
+ operator BOOL() const { return (mPointer != NULL); }
+ operator bool() const { return (mPointer != NULL); }
bool operator!() const { return (mPointer == NULL); }
bool isNull() const { return (mPointer == NULL); }
bool notNull() const { return (mPointer != NULL); }
- operator Type*() const { return mPointer; }
- bool operator !=(Type* ptr) const { return (mPointer != ptr); }
- bool operator ==(Type* ptr) const { return (mPointer == ptr); }
- bool operator ==(const LLPointer<Type>& ptr) const { return (mPointer == ptr.mPointer); }
- bool operator < (const LLPointer<Type>& ptr) const { return (mPointer < ptr.mPointer); }
- bool operator > (const LLPointer<Type>& ptr) const { return (mPointer > ptr.mPointer); }
+ operator Type*() const { return mPointer; }
+ bool operator !=(Type* ptr) const { return (mPointer != ptr); }
+ bool operator ==(Type* ptr) const { return (mPointer == ptr); }
+ bool operator ==(const LLPointer<Type>& ptr) const { return (mPointer == ptr.mPointer); }
+ bool operator < (const LLPointer<Type>& ptr) const { return (mPointer < ptr.mPointer); }
+ bool operator > (const LLPointer<Type>& ptr) const { return (mPointer > ptr.mPointer); }
- LLPointer<Type>& operator =(Type* ptr)
- {
+ LLPointer<Type>& operator =(Type* ptr)
+ {
assign(ptr);
- return *this;
+ return *this;
}
- LLPointer<Type>& operator =(const LLPointer<Type>& ptr)
- {
+ LLPointer<Type>& operator =(const LLPointer<Type>& ptr)
+ {
assign(ptr);
- return *this;
+ return *this;
}
// support assignment up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
template<typename Subclass>
- LLPointer<Type>& operator =(const LLPointer<Subclass>& ptr)
- {
+ LLPointer<Type>& operator =(const LLPointer<Subclass>& ptr)
+ {
assign(ptr.get());
- return *this;
+ return *this;
}
-
+
// Just exchange the pointers, which will not change the reference counts.
static void swap(LLPointer<Type>& a, LLPointer<Type>& b)
{
@@ -129,16 +128,6 @@ protected:
void ref();
void unref();
#else
-
- void assign(const LLPointer<Type>& ptr)
- {
- if( mPointer != ptr.mPointer )
- {
- unref();
- mPointer = ptr.mPointer;
- ref();
- }
- }
void ref()
{
if (mPointer)
@@ -161,7 +150,18 @@ protected:
}
}
}
-#endif
+#endif // LL_LIBRARY_INCLUDE
+
+ void assign(const LLPointer<Type>& ptr)
+ {
+ if (mPointer != ptr.mPointer)
+ {
+ unref();
+ mPointer = ptr.mPointer;
+ ref();
+ }
+ }
+
protected:
Type* mPointer;
};
@@ -169,18 +169,18 @@ protected:
template <class Type> class LLConstPointer
{
public:
- LLConstPointer() :
+ LLConstPointer() :
mPointer(NULL)
{
}
- LLConstPointer(const Type* ptr) :
+ LLConstPointer(const Type* ptr) :
mPointer(ptr)
{
ref();
}
- LLConstPointer(const LLConstPointer<Type>& ptr) :
+ LLConstPointer(const LLConstPointer<Type>& ptr) :
mPointer(ptr.mPointer)
{
ref();
@@ -188,7 +188,7 @@ public:
// support conversion up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
template<typename Subclass>
- LLConstPointer(const LLConstPointer<Subclass>& ptr) :
+ LLConstPointer(const LLConstPointer<Subclass>& ptr) :
mPointer(ptr.get())
{
ref();
@@ -203,55 +203,55 @@ public:
const Type* operator->() const { return mPointer; }
const Type& operator*() const { return *mPointer; }
- operator BOOL() const { return (mPointer != NULL); }
- operator bool() const { return (mPointer != NULL); }
+ operator BOOL() const { return (mPointer != NULL); }
+ operator bool() const { return (mPointer != NULL); }
bool operator!() const { return (mPointer == NULL); }
bool isNull() const { return (mPointer == NULL); }
bool notNull() const { return (mPointer != NULL); }
- operator const Type*() const { return mPointer; }
- bool operator !=(const Type* ptr) const { return (mPointer != ptr); }
- bool operator ==(const Type* ptr) const { return (mPointer == ptr); }
- bool operator ==(const LLConstPointer<Type>& ptr) const { return (mPointer == ptr.mPointer); }
- bool operator < (const LLConstPointer<Type>& ptr) const { return (mPointer < ptr.mPointer); }
- bool operator > (const LLConstPointer<Type>& ptr) const { return (mPointer > ptr.mPointer); }
+ operator const Type*() const { return mPointer; }
+ bool operator !=(const Type* ptr) const { return (mPointer != ptr); }
+ bool operator ==(const Type* ptr) const { return (mPointer == ptr); }
+ bool operator ==(const LLConstPointer<Type>& ptr) const { return (mPointer == ptr.mPointer); }
+ bool operator < (const LLConstPointer<Type>& ptr) const { return (mPointer < ptr.mPointer); }
+ bool operator > (const LLConstPointer<Type>& ptr) const { return (mPointer > ptr.mPointer); }
- LLConstPointer<Type>& operator =(const Type* ptr)
+ LLConstPointer<Type>& operator =(const Type* ptr)
{
if( mPointer != ptr )
{
- unref();
- mPointer = ptr;
+ unref();
+ mPointer = ptr;
ref();
}
- return *this;
+ return *this;
}
- LLConstPointer<Type>& operator =(const LLConstPointer<Type>& ptr)
- {
+ LLConstPointer<Type>& operator =(const LLConstPointer<Type>& ptr)
+ {
if( mPointer != ptr.mPointer )
{
- unref();
+ unref();
mPointer = ptr.mPointer;
ref();
}
- return *this;
+ return *this;
}
// support assignment up the type hierarchy. See Item 45 in Effective C++, 3rd Ed.
template<typename Subclass>
- LLConstPointer<Type>& operator =(const LLConstPointer<Subclass>& ptr)
- {
+ LLConstPointer<Type>& operator =(const LLConstPointer<Subclass>& ptr)
+ {
if( mPointer != ptr.get() )
{
- unref();
+ unref();
mPointer = ptr.get();
ref();
}
- return *this;
+ return *this;
}
-
+
// Just exchange the pointers, which will not change the reference counts.
static void swap(LLConstPointer<Type>& a, LLConstPointer<Type>& b)
{
@@ -262,11 +262,11 @@ public:
protected:
#ifdef LL_LIBRARY_INCLUDE
- void ref();
+ void ref();
void unref();
-#else
- void ref()
- {
+#else // LL_LIBRARY_INCLUDE
+ void ref()
+ {
if (mPointer)
{
mPointer->ref();
@@ -277,9 +277,9 @@ protected:
{
if (mPointer)
{
- const Type *tempp = mPointer;
+ const Type *temp = mPointer;
mPointer = NULL;
- tempp->unref();
+ temp->unref();
if (mPointer != NULL)
{
LL_WARNS() << "Unreference did assignment to non-NULL because of destructor" << LL_ENDL;
@@ -287,7 +287,8 @@ protected:
}
}
}
-#endif
+#endif // LL_LIBRARY_INCLUDE
+
protected:
const Type* mPointer;
};
@@ -297,13 +298,13 @@ class LLCopyOnWritePointer : public LLPointer<Type>
{
public:
typedef LLCopyOnWritePointer<Type> self_t;
- typedef LLPointer<Type> pointer_t;
-
- LLCopyOnWritePointer()
+ typedef LLPointer<Type> pointer_t;
+
+ LLCopyOnWritePointer()
: mStayUnique(false)
{}
- LLCopyOnWritePointer(Type* ptr)
+ LLCopyOnWritePointer(Type* ptr)
: LLPointer<Type>(ptr),
mStayUnique(false)
{}