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.

This template class is declared in QtLua/qtluaref.hh source file, line 79.

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  

Static function  

Protected field  

Macros  

Members detail  

Ref()  

This constructor is declared in QtLua/qtluaref.hh source file, line 120.

Construct a null reference.

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

This constructor is declared in QtLua/qtluaref.hh source file, line 126.

Construct a const Ref from non const Ref.

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

This constructor is declared in QtLua/qtluaref.hh source file, line 134.

Construct a const Ref from const Ref.

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

This template constructor is declared in QtLua/qtluaref.hh source file, line 143.

Construct a const Ref from derived class Ref.

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

This template constructor is declared in QtLua/qtluaref.hh source file, line 152.

Construct a const Ref from derived class const Ref.

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

This constructor is declared in QtLua/qtluaref.hh source file, line 161.

Construct a const Ref from non const Ref.

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

This constructor is declared in QtLua/qtluaref.hh source file, line 168.

Construct a const Ref from const Ref.

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

This template constructor is declared in QtLua/qtluaref.hh source file, line 176.

Construct a const Ref from derived class Ref.

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

This template constructor is declared in QtLua/qtluaref.hh source file, line 184.

Construct a const Ref from derived class const Ref.

Ref(X &obj)  

This constructor is declared in QtLua/qtluaref.hh source file, line 192.

Construct a Ref which points to specified object.

Ref(X *obj)  

This constructor is declared in QtLua/qtluaref.hh source file, line 346.

This member access is protected.

~Ref()  

This destructor is declared in QtLua/qtluaref.hh source file, line 284.

Drop a Ref

#define QTLUA_REFNEW(X, ...)  

This macro is declared in QtLua/qtluaref.hh source file, line 95.

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);

This macro expands to:

(X::ptr::allocated(new X(__VA_ARGS__)))

#define QTLUA_REFTYPE(X)  

This macro is declared in QtLua/qtluaref.hh source file, line 110.

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 variable is declared in QtLua/qtluaref.hh source file, line 351.

This member access is protected.

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

This template function is declared in QtLua/qtluaref.hh source file, line 278.

Const cast const Ref to Ref of given type

int count() const  

This function is declared in QtLua/qtluaref.hh source file, line 326.

Get object Reference count

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

This template function is declared in QtLua/qtluaref.hh source file, line 250.

Dynamic cast Ref to Ref of given type

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

This template function is declared in QtLua/qtluaref.hh source file, line 257.

Dynamic cast Ref to const Ref of given type

void invalidate()  

This function is declared in QtLua/qtluaref.hh source file, line 291.

Invalidate Ref (set internal pointer to null)

bool operator!=(const Ref &r) const  

This function is declared in QtLua/qtluaref.hh source file, line 338.

Test if pointed ojects are not the same

X & operator*() const  

This function is declared in QtLua/qtluaref.hh source file, line 306.

Access object

X * operator->() const  

This function is declared in QtLua/qtluaref.hh source file, line 313.

Access object

Ref & operator=(const Ref &r)  

This function is declared in QtLua/qtluaref.hh source file, line 210.

Initialize Ref from Ref

Ref & operator=(Ref &&r)  

This function is declared in QtLua/qtluaref.hh source file, line 223.

Ref & operator=(X &obj)  

This function is declared in QtLua/qtluaref.hh source file, line 236.

Initialize Ref from object Reference

bool operator==(const Ref &r) const  

This function is declared in QtLua/qtluaref.hh source file, line 332.

Test if pointed ojects are the same

X * ptr() const  

This function is declared in QtLua/qtluaref.hh source file, line 320.

Get Ref internal object pointer

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

This template function is declared in QtLua/qtluaref.hh source file, line 264.

Static cast Ref to Ref of given type

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

This template function is declared in QtLua/qtluaref.hh source file, line 271.

Static cast Ref to const Ref of given type

bool valid() const  

This function is declared in QtLua/qtluaref.hh source file, line 300.

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

static Ref allocated(X *obj)  

This function is for internal use only.

This function is declared in QtLua/qtluaref.hh source file, line 203.

Construct Ref from dynamically allocated object pointer. Pointed object is marked as deletable when last reference is destroyed.

Valid XHTML 1.0 StrictGenerated by diaxen on Sat Mar 30 16:23:03 2013 using MkDoc