qi::Object¶
Summary¶
class qi::Object
Functions (class qi::Object)
-
qi::detail::GenericObjectBounce<O>::findMethod
qi::detail::GenericObjectBounce<O>::metaObject
qi::detail::GenericObjectBounce<O>::clearStats
qi::detail::GenericObjectBounce<O>::isStatsEnabled
qi::detail::GenericObjectBounce<O>::executionContext
qi::detail::GenericObjectBounce<O>::disconnect
qi::detail::GenericObjectBounce<O>::setProperty
qi::detail::GenericObjectBounce<O>::isTraceEnabled
qi::detail::GenericObjectBounce<O>::property
qi::detail::GenericObjectBounce<O>::metaCall
qi::detail::GenericObjectBounce<O>::connect
qi::detail::GenericObjectBounce<O>::enableTrace
qi::detail::GenericObjectBounce<O>::stats
qi::detail::GenericObjectBounce<O>::enableStats
qi::detail::GenericObjectBounce<O>::forceExecutionContext
qi::detail::GenericObjectBounce<O>::metaPost
qi::Object<T>::deleteGenericObjectOnly
qi::Object<T>::asGenericObject
qi::Object<T>::deleteCustomDeleter
qi::Object<T>::keepManagedObjectPtr
qi::Object<T>::operator Object<Empty>
qi::Object<T>::managedObjectPtr
Global Classes
Detailed Description¶
qi::AnyObject¶
qi::AnyObject
is a specialization of qi::Object
that provides type
erasure on objects, similar to what qi::AnyValue
does on values. It can only
work on registered objects. We’ll use Graph::Drawer
from the
registering guide. You can make an qi::Object
from
a boost::shared_ptr
.
qi::AnyObject obj = boost::make_shared<Graph::Drawer>();
qi::Object
uses a shared_ptr
semantics, so the object will be destroyed when
there are no more references to it. You can also get a qi::AnyObject
from a
session, another service, etc.
You can call a function with call or async if you want the call to be asynchronous. You can also connect signals and change properties.
// do a synchronous call
obj.call<bool>("draw", Graph::Point(10, 20), Graph::Green);
// do an ansynchronous call
qi::Future<bool> future =
obj.async<bool>("draw", Graph::Point(10, 20), Graph::Green);
// do stuff...
future.wait();
// connect a signal and disconnect it
int id = obj.connect("drawDone", &mycallback);
obj.disconnect(id);
// set a property and get it
obj.setProperty("origin", Graph::Point(0, 12));
Graph::Point p = obj.property<Graph::Point>("origin");
std::cout << p.y << std::endl; // 12
Signal Connection¶
When connecting a callback, as usual, the signature of the callback must match the signature of the signal. But since we are in a type-erased context, if this rule is not respected, the error will only appear (in the logs) when the signal is triggered, not at compile-time or at the connection.
Furthermore, the connect()
function expects any type of boost::function
since we don’t know that until runtime, so it must be explicitly cast to the
correct type, particularly in case of boost::bind
.
// this works because mycallback has a specific signature
obj.connect("drawDone", &mycallback);
// this fails at compile time because boost::bind does not force a signature
obj.connect("drawDone", boost::bind(mycallback, _1));
// this works, you must specify the signature expected by the signal
obj.connect("drawDone",
boost::function<void(const Point&)>(boost::bind(mycallback, _1)));
qi::Object<T>¶
qi::Object
can be specialized with T if the object is T or inherits from T.
qi::Object<Graph::Drawer> obj = boost::make_shared<Graph::Drawer>();
obj->draw(Graph::Point(11, 12), Graph::Green);
qi::Object
‘s specializations do not work with remote objects yet.
Passing an object as argument¶
Some methods in the services you will use expect an object as argument, for instance Logger::addListener(Object<LogListener> listener);. To call this method, you must first implement the LogListener interface into your own class, and then wrap a pointer to an instance of this class into an Object<LogListener> or a qi::AnyObject that will take ownership of the pointer:
class MyLogListener: public LogListener
{
// Implement LogListener interface
};
void someFunction()
{
qi::AnyObject logger = session.service("Logger");
qi::AnyObject o(boost::make_shared<LogListener>());
logger.call("addListener", o);
}
In the example above, your instance of MyLogListener will be kept alive as long as the logger service holds a qi::AnyObject on it. The same holds true when returning objects.
Reference¶
- typedef Object< Empty > AnyObject¶
qi::Object Class Reference¶
Introduction¶
#include <qi/anyobject.hpp>
- Inherits:
qi::detail::GenericObjectBounce< Object< T > >
- Inherited by:
qi::AnyModule
Public Functions¶
-
(GenericObject* go)Object
-
(T* ptr)Object
-
(GenericObject* go, boost::function<void(GenericObject*)> deleter)Object
-
(T* ptr, boost::function<void(T*)> deleter)Object
-
()Object
- template<typename U>
-
(const Object<U>& o)Object
- template<typename U>
-
Object<T>&
(const Object<U>& o)operator=
-
(const Object& o)Object
-
Object<T>&
(const Object& o)operator=
-
(const qi::Future<MaybeAnyObject>& fobj)Object
-
(const qi::FutureSync<MaybeAnyObject>& fobj)Object
- template<typename U>
-
(GenericObject* go, boost::shared_ptr<U> other)Object
- template<typename U>
-
(boost::shared_ptr<U> other)Object
-
bool
(const Object& b) constoperator<
- template<typename U>
-
bool
(const Object<U>& b) constoperator!=
- template<typename U>
-
bool
(const Object<U>& b) constoperator==
-
() constoperator bool
-
() constoperator Object<Empty>
-
boost::shared_ptr<T>
()asSharedPtr
-
T&
() constasT
-
T*
() constoperator->
-
T&
() constoperator*
-
bool
() constunique
-
GenericObject*
() constasGenericObject
-
void
()reset
-
unsigned int
() constuse_count
-
ObjectTypeInterface*
()interface
-
void
()checkT
-
detail::ManagedObjectPtr
()managedObjectPtr
-
const MetaObject&
() constmetaObject
-
qi::Future<AnyReference>
(unsigned int method, const GenericFunctionParameters& params, MetaCallType callType, Signature returnSignature)metaCall
-
int
(const std::string& name, const GenericFunctionParameters& parameters) constfindMethod
-
qi::Future<AnyReference>
(const std::string& nameWithOptionalSignature, const GenericFunctionParameters& params, MetaCallType callType, Signature returnSignature)metaCall
-
void
(unsigned int event, const GenericFunctionParameters& params) constmetaPost
-
void
(const std::string& nameWithOptionalSignature, const GenericFunctionParameters& in) constmetaPost
- template<typename... Args>
-
() - template<typename FUNCTOR_TYPE>
-
qi::FutureSync<SignalLink>
(const std::string& eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel) constconnect
-
qi::FutureSync<SignalLink>
(const std::string& name, const SignalSubscriber& functor) constconnect
-
qi::FutureSync<SignalLink>
(unsigned int signal, const SignalSubscriber& subscriber) constconnect
-
qi::FutureSync<SignalLink>
(unsigned int signal, AnyObject target, unsigned int slot) constconnect
-
qi::FutureSync<void>
(SignalLink linkId) constdisconnect
- template<typename T>
-
qi::FutureSync<T>
(const std::string& name) constproperty
- template<typename T>
-
qi::FutureSync<void>
(const std::string& name, const T& val) constsetProperty
-
qi::FutureSync<AnyValue>
(unsigned int id) constproperty
-
qi::FutureSync<void>
(unsigned int id, const AnyValue& val) constsetProperty
-
ExecutionContext*
() constexecutionContext
-
bool
() constisStatsEnabled
-
void
(bool enable) constenableStats
-
ObjectStatistics
() conststats
-
void
() constclearStats
-
bool
() constisTraceEnabled
-
void
(bool enable)enableTrace
-
void
(boost::shared_ptr<qi::ExecutionContext> ec)forceExecutionContext
- template<typename R, typename... Args>
-
() - template<typename R, typename... Args>
-
()
Public Static Functions¶
-
void
(detail::ManagedObjectPtr ptr)keepManagedObjectPtr
- template<typename U>
-
void
(GenericObject* obj, boost::shared_ptr<U> ptr)keepReference
-
void
(T*)noDeleteT
-
void
(GenericObject*)noDelete
-
void
(GenericObject* obj)deleteGenericObjectOnly
- template<typename U>
-
void
(GenericObject* obj, U)deleteGenericObjectOnlyAndKeep
-
void
(GenericObject* obj, boost::function<void(T*)> deleter)deleteCustomDeleter
Types¶
- typedef typename boost::mpl::if_< typename boost::is_same< T, Empty >::type, None, Object< Empty >>::type MaybeAnyObject¶
Detailed Description¶
Type erased object that has a known interface T.
In case T is unknown, you can use qi::AnyObject which aliases to Object<qi::Empty>.
You can then use the object with type-erasure or call the object directly using the operator ->.
Functions Documentation¶
- template<typename U>
- template<typename U>
-
static void
qi::Object<T>::
deleteGenericObjectOnlyAndKeep
(GenericObject* obj, U)¶
-
static void
qi::Object<T>::
deleteCustomDeleter
(GenericObject* obj, boost::function<void(T*)> deleter)¶
-
qi::Object<T>::
Object
(GenericObject* go)¶ These constructors take ownership of the underlying pointers. If a callback is given, it will be called instead of the default behavior of deleting the stored GenericObject and the underlying T object.
-
qi::Object<T>::
Object
(T* ptr)¶
-
qi::Object<T>::
Object
(GenericObject* go, boost::function<void(GenericObject*)> deleter)¶
-
qi::Object<T>::
Object
(T* ptr, boost::function<void(T*)> deleter)¶
-
qi::Object<T>::
Object
()¶
- template<typename U>
-
qi::Object<T>::
Object
(const Object<U>& o)¶
- template<typename U>
-
Object<T>&
qi::Object<T>::
operator=
(const Object<U>& o)¶
-
qi::Object<T>::
Object
(const Object& o)¶
-
Object<T>&
qi::Object<T>::
operator=
(const Object& o)¶
-
qi::Object<T>::
Object
(const qi::Future<MaybeAnyObject>& fobj)¶
-
qi::Object<T>::
Object
(const qi::FutureSync<MaybeAnyObject>& fobj)¶
- template<typename U>
Shares ref counter with other, which must handle the destruction of go.
- template<typename U>
-
qi::Object<T>::
operator
Object<Empty>()const
¶
-
T&
qi::Object<T>::
asT
()const
¶
-
T*
qi::Object<T>::
operator->
()const
¶
-
T&
qi::Object<T>::
operator*
()const
¶
-
GenericObject*
qi::Object<T>::
asGenericObject
()const
¶
-
unsigned int
qi::Object<T>::
use_count
()const
¶
-
ObjectTypeInterface*
qi::Object<T>::
interface
()¶
-
detail::ManagedObjectPtr
qi::Object<T>::
managedObjectPtr
()¶
-
const MetaObject&
qi::detail::GenericObjectBounce<O>::
metaObject
()const
¶
-
qi::Future<AnyReference>
qi::detail::GenericObjectBounce<O>::
metaCall
(unsigned int method, const GenericFunctionParameters& params, MetaCallType callType = MetaCallType_Auto, Signature returnSignature = Signature()¶
-
int
qi::detail::GenericObjectBounce<O>::
findMethod
(const std::string& name, const GenericFunctionParameters& parameters)const
¶
-
qi::Future<AnyReference>
qi::detail::GenericObjectBounce<O>::
metaCall
(const std::string& nameWithOptionalSignature, const GenericFunctionParameters& params, MetaCallType callType = MetaCallType_Auto, Signature returnSignature = Signature()¶
-
void
qi::detail::GenericObjectBounce<O>::
metaPost
(unsigned int event, const GenericFunctionParameters& params)const
¶
-
void
qi::detail::GenericObjectBounce<O>::
metaPost
(const std::string& nameWithOptionalSignature, const GenericFunctionParameters& in)const
¶
-
()
- template<typename FUNCTOR_TYPE>
-
qi::FutureSync<SignalLink>
qi::detail::GenericObjectBounce<O>::
connect
(const std::string& eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel = MetaCallType_Auto)const
¶
-
qi::FutureSync<SignalLink>
qi::detail::GenericObjectBounce<O>::
connect
(const std::string& name, const SignalSubscriber& functor)const
¶
-
qi::FutureSync<SignalLink>
qi::detail::GenericObjectBounce<O>::
connect
(unsigned int signal, const SignalSubscriber& subscriber)const
¶
-
qi::FutureSync<SignalLink>
qi::detail::GenericObjectBounce<O>::
connect
(unsigned int signal, AnyObject target, unsigned int slot)const
¶
-
qi::FutureSync<void>
qi::detail::GenericObjectBounce<O>::
disconnect
(SignalLink linkId)const
¶
- template<typename T>
-
qi::FutureSync<T>
qi::detail::GenericObjectBounce<O>::
property
(const std::string& name)const
¶
- template<typename T>
-
qi::FutureSync<void>
qi::detail::GenericObjectBounce<O>::
setProperty
(const std::string& name, const T& val)const
¶
-
qi::FutureSync<AnyValue>
qi::detail::GenericObjectBounce<O>::
property
(unsigned int id)const
¶
-
qi::FutureSync<void>
qi::detail::GenericObjectBounce<O>::
setProperty
(unsigned int id, const AnyValue& val)const
¶
-
ExecutionContext*
qi::detail::GenericObjectBounce<O>::
executionContext
()const
¶
-
ObjectStatistics
qi::detail::GenericObjectBounce<O>::
stats
()const
¶
-
()
-
()