interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

VUtil::vRef< T > Class Template Reference

#include <vos/vos/refcount.hh>

List of all members.


Detailed Description

template<class T>
class VUtil::vRef< T >

This is a "smart pointer" wrapper class around any RefCounted object.

When you assign a pointer to a vRef, it calls aquire(), increasing the refcount on that object. When vRef goes out of scope (i.e., when it is destroyed) it automatically calls release on the wrapped object. For more discussion and examples, see the VOS manual and the tutorial programs (in "apps/tutorials").

Note:
vRef is not threadsafe. You must not share the same vRef instance between threads -- copy it instead!

Definition at line 182 of file refcount.hh.

Public Member Functions


Constructor & Destructor Documentation

template<class T>
VUtil::vRef< T >::vRef (  )  [inline]

Initialize an empty vRef that points to nothing.

Definition at line 189 of file refcount.hh.

template<class T>
VUtil::vRef< T >::vRef ( T *  x,
bool  doacquire 
) [inline]

Parameters:
x Pointer to object to wrap in this vRef: it must be a RefCounted class or subclass.
doacquire If true, object will be acquired and reference count will be incremented. If false, the object will retain it's current reference count. Note that when a RefCounted object is created with "new" its reference count is already 1, and in this case you shouldn't increment the count.

Definition at line 199 of file refcount.hh.

template<class T>
VUtil::vRef< T >::vRef ( T &  x,
bool  doacquire 
) [inline]

Parameters:
x Reference to object to wrap in this vRef: it must be a RefCounted class or subclass.
doacquire If true, object will be acquired and reference count will be incremented. If false, the object will retain it's current reference count. Note that when a RefCounted object is created with "new" its reference count is already 1, and in this case you shouldn't increment the count.

Definition at line 210 of file refcount.hh.

template<class T>
VUtil::vRef< T >::vRef ( const vRef< T > &  x  )  [inline]

Create a new vRef containing the same object as another vRef.

The reference count of the object will be incremented.

Parameters:
x vRef to copy.

Definition at line 216 of file refcount.hh.

template<class T>
template<class T2>
VUtil::vRef< T >::vRef ( const vRef< T2 > &  x  )  [inline]

Create a new vRef containing the same object as another vRef.

The reference count of the object will be incremented. This form allows the other vRef to use a different class in its template.

Parameters:
x vRef to copy.

Definition at line 223 of file refcount.hh.

template<class T>
VUtil::vRef< T >::~vRef (  )  [inline]

Destructor.

Decrements the reference count on the underlying pointer.

Definition at line 232 of file refcount.hh.


Member Function Documentation

template<class T>
template<class T2>
vRef<T>& VUtil::vRef< T >::assign ( T2 *  x,
bool  doacquire 
) [inline]

Assign a new object to this vRef.

If this vRef is holding an object, that object will be released (it's reference count decremented).

Parameters:
x the new pointer
doacquire If true, object will be acquired and reference count will be incremented. If false, the object will retain it's current reference count. When a new RefCounted object is created (e.g. with "new"), its reference count is already 1, and you don't need to increment the count.

Definition at line 263 of file refcount.hh.

template<class T>
void VUtil::vRef< T >::clear (  )  [inline]

Release object and set internal pointer to 0.

Definition at line 316 of file refcount.hh.

template<class T>
T* VUtil::vRef< T >::get (  )  const [inline]

Return pointer to wrapped object.

Exceptions:
NullPointerError if internal pointer is 0 (no object held)

Definition at line 310 of file refcount.hh.

Referenced by VOS::meta_cast(), VUtil::vRef< VOS::IrcBridge >::operator=(), and VUtil::vRef< VOS::IrcBridge >::vRef().

template<class T>
bool VUtil::vRef< T >::isValid (  )  const [inline]

Test whether this vRef holds a valid pointer or not.

Returns:
true if internal pointer is not null (0), false if internal pointer is null (0).

Definition at line 238 of file refcount.hh.

Referenced by VOS::Site::createVobject(), VOS::Site::createVobject2(), VOS::Site::createVobject3(), VOS::Site::createVobject4(), VOS::Site::createVobject5(), VOS::VobjectBase::getAccessControlsFor(), VUtil::vRef< VOS::IrcBridge >::operator=(), and VUtil::vRef< VOS::IrcBridge >::vRef().

template<class T>
T& VUtil::vRef< T >::operator * (  )  const [inline]

Return reference to wrapped object.

Exceptions:
NullPointerError if internal pointer is 0 (no object held)

Definition at line 293 of file refcount.hh.

template<class T>
VUtil::vRef< T >::operator T & (  )  [inline]

Cast to reference.

Same as the operator*(). Usually used by implicit cast in a function call.

Exceptions:
NullPointerError if internal pointer is 0 (no object is held)

Definition at line 337 of file refcount.hh.

template<class T>
VUtil::vRef< T >::operator T * (  )  [inline]

Cast to pointer.

Same as get(). Usually used by implicit cast in a function call.

Exceptions:
NullPointerError if internal pointer is 0 (no object held)

Definition at line 328 of file refcount.hh.

template<class T>
bool VUtil::vRef< T >::operator! (  )  const [inline]

Returns:
true if the wrapped pointer is null, false if it is valid

Definition at line 243 of file refcount.hh.

template<class T>
bool VUtil::vRef< T >::operator!= ( const T &  x  )  const [inline]

Definition at line 252 of file refcount.hh.

template<class T>
bool VUtil::vRef< T >::operator!= ( const T *  x  )  const [inline]

Definition at line 249 of file refcount.hh.

template<class T>
bool VUtil::vRef< T >::operator!= ( const vRef< T > &  x  )  const [inline]

Definition at line 246 of file refcount.hh.

template<class T>
T* VUtil::vRef< T >::operator-> (  )  const [inline]

Return pointer to wrapped object.

Exceptions:
NullPointerError if internal pointer is 0 (no object held)

Definition at line 302 of file refcount.hh.

template<class T>
template<class T2>
vRef<T>& VUtil::vRef< T >::operator= ( const vRef< T2 > &  x  )  [inline]

Assign to another vRef.

Old wrapped object is released, and new wrapped object is acquired.

Definition at line 281 of file refcount.hh.

template<class T>
vRef<T>& VUtil::vRef< T >::operator= ( const vRef< T > &  x  )  [inline]

Assign to another vRef.

Old wrapped object is released, and new wrapped object is acquired.

Definition at line 272 of file refcount.hh.

template<class T>
bool VUtil::vRef< T >::operator== ( const T &  x  )  const [inline]

Definition at line 251 of file refcount.hh.

template<class T>
bool VUtil::vRef< T >::operator== ( const T *  x  )  const [inline]

Definition at line 248 of file refcount.hh.

template<class T>
bool VUtil::vRef< T >::operator== ( const vRef< T > &  x  )  const [inline]

Definition at line 245 of file refcount.hh.


The documentation for this class was generated from the following file: