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
- Ref()
- Ref(const Ref<Xnoconst, Xnoconst> &r)
- Ref(const Ref<const Xnoconst, Xnoconst> &r)
- template Ref(const Ref<T, T> &r)
- template Ref(const Ref<const T, T> &r)
- Ref(Ref<Xnoconst, Xnoconst> &&r)
- Ref(Ref<const Xnoconst, Xnoconst> &&r)
- template Ref(Ref<T, T> &&r)
- template Ref(Ref<const T, T> &&r)
- Ref(X &obj)
- ~Ref()
- template Ref<T, T> constcast() const
- int count() const
- template Ref<T, T> dynamiccast() const
- template Ref<const T, T> dynamiccast_const() const
- void invalidate()
- bool operator!=(const Ref &r) const
- X & operator*() const
- X * operator->() const
- Ref & operator=(const Ref &r)
- Ref & operator=(Ref &&r)
- Ref & operator=(X &obj)
- bool operator==(const Ref &r) const
- X * ptr() const
- template Ref<T, T> staticcast() const
- template Ref<const T, T> staticcast_const() const
- bool valid() const
Protected function
- Ref(X *obj)
Protected field
- X *_obj
Macros
Members detail
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.
Construct a Ref which points to specified object.
This member access is protected.
Drop a Ref
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 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;
This member access is protected.
template <typename T> Ref<T, T> constcast() const
Const cast const Ref to Ref of given type
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
Invalidate Ref (set internal pointer to null)
bool operator!=(const Ref &r) const
Test if pointed ojects are not the same
Access object
Access object
Initialize Ref from Ref
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
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
Test if Ref is valid (check if internal pointer is not null)