DispatchProxy class reference
[Base module]

Declaration  

#include <QtLua/DispatchProxy>

namespace QtLua {
class DispatchProxy;
};

This class is a member of the QtLua namespace.

Description  

This class may be used to dispatch operations to several underlying UserData objects.

This can be used to create a composite object where different operations are handled by different objects. Table operations are handled in a special way which enables to expose table entries from multiple objects as if all entries were merged in a single table object.

Order in which underlying objects are added to the dispatcher object matters. See operation functions documentation in this class for a detailed description of the associated behaviors.

Please read the Members detail section for details about behavior of different operations.

// code from examples/cpp/proxy/dispatchproxy_string.cc:33

typedef QMap<QtLua::String, QtLua::String> Container;

class Composite : public QtLua::DispatchProxy
{
public:

Composite()
: _c1_proxy(_c1)
, _c2_proxy(_c2)
{
// references to underlying objects will count as a reference to this
_c1_proxy.ref_delegate(this);
_c2_proxy.ref_delegate(this);

// populate read-only hash c1
_c1.insert("a", "1");
_c1.insert("b", "2");

// populate hash c2
_c2.insert("c", "3");
_c2.insert("d", "4");

// register hash proxies
add_target(&_c1_proxy);
add_target(&_c2_proxy);
}

private:
Container _c1;
QtLua::QHashProxyRo<Container> _c1_proxy;
Container _c2;
QtLua::QHashProxy<Container> _c2_proxy;
};

[ ... ]

Composite proxy;

QtLua::State state;
state.openlib(QtLua::QtLuaLib);

// Declare a lua global variable using our composite proxy
state["composite"] = proxy;

// Iterate through Composite object from lua script
state.exec_statements("for key, value in each(composite) do print(key, value) end");

Members  

Inherited members  

Types  

Functions  

  • DispatchProxy()
  • ~DispatchProxy()
  • template unsigned int add_target(T *t, ValueBase::Operations mask = [...], bool new_keys = [...])
  • template unsigned int insert_target(T *t, unsigned int pos = [...], ValueBase::Operations mask = [...], bool new_keys = [...])
  • virtual ValueBase::List meta_call(State *ls, const ValueBase::List &args)
  • virtual bool meta_contains(State *ls, const Value &key)
  • virtual Value meta_index(State *ls, const Value &key)
  • virtual void meta_newindex(State *ls, const Value &key, const Value &value)
  • virtual Value meta_operation(State *ls, ValueBase::Operation op, const Value &a, const Value &b)
  • virtual Ref<Iterator> new_iterator(State *ls)
  • template void remove_target(T *t)
  • virtual bool support(ValueBase::Operation c) const

Members detail  

DispatchProxy()  

No documentation available

~DispatchProxy()  

No documentation available

template <typename T> unsigned int add_target(T *t, ValueBase::Operations mask = Value::OpAll, bool new_keys = true)  

This function register a new target object which will be used to provide support for some operations. It returns the position of the new entry. The mask parameter can be used to prevent use of this object to provide support for some operations.

Template argument may be used to force use of operation functions from a specific class in the UserData inheritance tree. When this feature is used, a reimplementation of the UserData::meta_contains function must be available in the same class if either the UserData::meta_index function or the UserData::meta_newindex function is reimplemented.

typedef Ref<const DispatchProxy, DispatchProxy> const_ptr  

Shortcut for Ref smart pointer class to DispatchProxy type provided for convenience

template <typename T> unsigned int insert_target(T *t, unsigned int pos = 0, ValueBase::Operations mask = Value::OpAll, bool new_keys = true)  

This function performs the same way as the DispatchProxy::add_target function but inserts the new target entry at specified position.

virtual ValueBase::List meta_call(State *ls, const ValueBase::List &args)  

This virtual function overrides the meta_call virtual function defined in the UserData base class.

This function handles the ValueBase::OpCall operation by relying on the first registered object which supports this operation and had this operation enabled when registered with the DispatchProxy::add_target function.

virtual bool meta_contains(State *ls, const Value &key)  

This virtual function overrides the meta_contains virtual function defined in the UserData base class.

This function queries all registered object which support the ValueBase::OpIndex or ValueBase::OpNewindex operations and had one of these operations enabled when registered with the DispatchProxy::add_target function.

virtual Value meta_index(State *ls, const Value &key)  

This virtual function overrides the meta_index virtual function defined in the UserData base class.

This function handles the ValueBase::OpIndex operation by querying all registered objects which support this operation and had this operation enabled when registered with the DispatchProxy::add_target function.

virtual void meta_newindex(State *ls, const Value &key, const Value &value)  

This virtual function overrides the meta_newindex virtual function defined in the UserData base class.

This function handles the ValueBase::OpNewindex operation by writing to the first registered object which supports this operation and had this operation enabled when registered with the DispatchProxy::add_target function.

If the new_keys argument to the DispatchProxy::add_target function was false on registration, the associated object is skipped if it does not already contains the passed key (according to object DispatchProxy::meta_contains function).

If a previous object contains an entry for the passed key but only supports the ValueBase::OpIndex table access operation and had this operation enabled when registered, an exception is thrown before the call to DispatchProxy::meta_newindex is forwarded. This avoids shadowing a table entry.

virtual Value meta_operation(State *ls, ValueBase::Operation op, const Value &a, const Value &b)  

This virtual function overrides the meta_operation virtual function defined in the UserData base class.

This function handles the requested operation by relying on the first registered object which supports the operation and had associated operations enabled when registered with the DispatchProxy::add_target function.

virtual Ref<Iterator> new_iterator(State *ls)  

This virtual function overrides the new_iterator virtual function defined in the UserData base class.

This function handles the ValueBase::OpIterate operation by relying on all registered objects which support this operation and had this operation enabled when registered with the DispatchProxy::add_target function. Iterators for underlying objects are created in registration order to expose all entries.

Shortcut for Ref smart pointer class to DispatchProxy type provided for convenience

template <typename T> void remove_target(T *t)  

This function removes an entry from target objects list.

virtual bool support(ValueBase::Operation c) const  

This virtual function overrides the support virtual function defined in the UserData base class.

This function check if one of the underlying objects can handle the specified operation and had this operation enabled when registered with the DispatchProxy::add_target function.

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