LS2SmartRef

From ismods.com: dedicated to promoting white hat, EULA-compliant Inner Space and LavishScript mods
Jump to: navigation, search

LS2SmartRef<T> is a helper class to simplify LavishScript 2's Reference counting model.

Any time you have an object following the LavishScript 2 reference counting model, and need to hold a reference to it, it is wise to use LS2SmartRef.

Construction

  • LS2SmartRef()
Constructs a LS2SmartRef, initially with a null reference
  • LS2SmartRef(T &Object, bool bAddRef=true)
Constructs a LS2SmartRef with a known-good object. This will call AddRef() if bAddRef is true. Pass false to construct the LS2SmartRef with a new object which already has a count of 1 and no other references.
  • LS2SmartRef(T *Object, bool bAddRef=true)
Constructs a LS2SmartRef with a known-good object. This will call AddRef() if bAddRef is true. Pass false to construct the LS2SmartRef with a new object which already has a count of 1 and no other references.

Operators

  • !
determine if there is not a valid object, e.g. if (!pMySmartRef)
  • ->
access members of the T object, e.g. pMySmartRef->SomeMethod() (where SomeMethod is from T, not LS2SmartRef)
  • .
access members of the LS2SmartRef, e.g. pMySmartRef.Set(*new LS2String(L"I can haz UTF-16?"),false) (note the false in this usage, due to a new object which aready has a count f1 and no other references)
  • T*
pass the LS2SmartRef to a function that requires a T*
  • T&
pass the LS2SmartRef to a function that requires a T&
  • T**
pass the LS2SmartRef to a function that requires a T**. For the purposes of the reference, T** is assumed to be a Set (write), where T* and T& are assumed to be accesses (read). Therefore, the T** operator will first release its current reference if it has one, assuming that it is meant to receive a new reference.

Methods

  • Set(T &Object, bool bAddRef=true)
This is the same as the T& constructor, but first releases its current reference if it has one.
  • Clear()
Releases its current reference if it has one.

See Also