Ref class reference
[Base module]

Declaration  

#include <QtLua/Ref>

namespace QtLua {
template <typename X, typename Xnoconst = X> class Ref;
};

This class is a member of the QtLua namespace.

Description  

This template class implements a smart pointer with reference counter.

The UserData class and derived classes are commonly used with this smart pointer class in QtLua to take advantages of the lua garbage collector. This allows objects to be deleted when no reference are left in both C++ code and lua interpreter state.

This smart pointer template class can be used as pointer to objects with class derived from the Refobj class. Most of the time you need UserData based objects and you don't want to inherit from the Refobj class directly.

A Ref pointer object can be assigned with an object of type X or with an other Ref pointer object.

The QTLUA_REFNEW macro must be used to dynamically create new objects. Objects allocated with this macro will be deleted automatically when no more reference remains.

Variable and member objects not allocated with the QTLUA_REFNEW macro, can be handled too but they won't be automatically deleted. They will still be checked for remaining references when destroyed.

Template parameters:

  • X: Pointed object type, may be const.
  • Xnoconst: Bare pointed object type. This parameter is optional, default is same as X.

Two shortcuts to Ref<X, X> and Ref<const X, X> types are provided for convenience, the X::ptr and X::const_ptr types can be defined with the QTLUA_REFTYPE macro.

Members  

Functions  

Protected function  

Protected field  

Macros  

Members detail  

Ref()  

Construct a null reference.

Ref(const Ref<Xnoconst, Xnoconst> &r)  

Construct a const Ref from non const Ref.

Ref(const Ref<const Xnoconst, Xnoconst> &r)  

Construct a const Ref from const Ref.

template <typename T> Ref(const Ref<T, T> &r)  

Construct a const Ref from derived class Ref.

template <typename T> Ref(const Ref<const T, T> &r)  

Construct a const Ref from derived class const Ref.

Ref(Ref<Xnoconst, Xnoconst> &&r)  

Construct a const Ref from non const Ref.

Ref(Ref<const Xnoconst, Xnoconst> &&r)  

Construct a const Ref from const Ref.

template <typename T> Ref(Ref<T, T> &&r)  

Construct a const Ref from derived class Ref.

template <typename T> Ref(Ref<const T, T> &&r)  

Construct a const Ref from derived class const Ref.

Ref(X &obj)  

Construct a Ref which points to specified object.

Ref(X *obj)  

This member access is protected.

~Ref()  

Drop a Ref

#define QTLUA_REFNEW(X, ...)  

This macro dynamically allocate and construct an object of requested type with given constructor arguments and returns an associated Ref object.

Parameters list:

  • X: object type to construct
  • ...: constructor arguments

Usage example:

// code from examples/cpp/userdata/ref.cc:48

QtLua::UserData::ptr ud = QTLUA_REFNEW(QtLua::UserData, );
MyObject::ptr my = QTLUA_REFNEW(MyObject, 42);

#define QTLUA_REFTYPE(X)  

This macro may be used to declare the X::ptr and X::const_ptr shortcuts to Ref types in class derived from Refobj. It should be invoked from class body public part.

Parameters list:

  • X: macro invocation class.

Usage example:

// code from examples/cpp/userdata/ref.cc:26

class MyObject : public QtLua::UserData
{
public:
QTLUA_REFTYPE(MyObject);

MyObject(int a)
: a_(a) {}

private:
int a_;
};

MyObject::ptr my;

This macro expands to:

/** Shortcut for @ref QtLua::Ref smart pointer class to X type provided for convenience */
typedef QtLua::Ref<const X, X> const_ptr;
/** Shortcut for @ref QtLua::Ref smart pointer class to X type provided for convenience */
typedef QtLua::Ref<X, X> ptr;

X *_obj  

This member access is protected.

template <typename T> Ref<T, T> constcast() const  

Const cast const Ref to Ref of given type

int count() const  

Get object Reference count

template <typename T> Ref<T, T> dynamiccast() const  

Dynamic cast Ref to Ref of given type

template <typename T> Ref<const T, T> dynamiccast_const() const  

Dynamic cast Ref to const Ref of given type

void invalidate()  

Invalidate Ref (set internal pointer to null)

bool operator!=(const Ref &r) const  

Test if pointed ojects are not the same

X & operator*() const  

Access object

X * operator->() const  

Access object

Ref & operator=(const Ref &r)  

Initialize Ref from Ref

Ref & operator=(Ref &&r)  

No documentation available

Ref & operator=(X &obj)  

Initialize Ref from object Reference

bool operator==(const Ref &r) const  

Test if pointed ojects are the same

X * ptr() const  

Get Ref internal object pointer

template <typename T> Ref<T, T> staticcast() const  

Static cast Ref to Ref of given type

template <typename T> Ref<const T, T> staticcast_const() const  

Static cast Ref to const Ref of given type

bool valid() const  

Test if Ref is valid (check if internal pointer is not null)

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 15:29:54 2013 using MkDoc