7 #ifndef _QI_TYPE_DETAIL_OBJECT_HXX_
8 #define _QI_TYPE_DETAIL_OBJECT_HXX_
10 #include <boost/mpl/if.hpp>
33 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
34 template<typename T comma ATYPEDECL> \
35 Object<T> constructObject(ADECL) \
37 return Object<T>(new T(AUSE)); \
44 typedef std::map<TypeInfo, boost::function<AnyReference(AnyObject)> >
74 return go()->
metaCall(method, params, callType, returnSignature);
82 return go()->
metaCall(nameWithOptionalSignature, params, callType, returnSignature);
86 return go()->
metaPost(event, params);
90 return go()->
metaPost(nameWithOptionalSignature, in);
92 inline void post(
const std::string& eventName,
102 return go()->
post(eventName, p1, p2, p3, p4, p5, p6, p7, p8);
104 template <
typename FUNCTOR_TYPE>
108 return go()->
connect(eventName, callback, threadingModel);
112 return go()->
connect(name, functor);
116 return go()->
connect(signal, subscriber);
127 return go()->template property<T>(name);
156 return go()->
stats();
174 #define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
175 template<typename R> qi::Future<R> async( \
176 const std::string& methodName comma \
177 QI_GEN_ARGSDECLSAMETYPE(n, qi::AutoAnyReference)) const { \
178 return go()->template async<R>(methodName comma AUSE); \
180 template<typename R> R call( \
181 const std::string& methodName comma \
182 QI_GEN_ARGSDECLSAMETYPE(n, qi::AutoAnyReference)) const { \
183 return go()->template call<R>(methodName comma AUSE); \
189 inline GenericObject* go()
const
191 GenericObject* g =
static_cast<const O*
>(
this)->asGenericObject();
193 throw std::runtime_error(
"This object is null");
243 Object(T* ptr, boost::function<
void(T*)> deleter);
248 template<
typename U>
Object(boost::shared_ptr<U> other);
252 operator bool()
const;
258 const T&
asT()
const;
285 deleter((T*)obj->
value);
304 qiLogDebug(
"qi.object") <<
"deleteObject " << obj <<
" "
323 boost::weak_ptr<GenericObject>
_ptr;
332 std::stringstream err;
333 err <<
"Object<T> can only be used on registered object types. ("
335 throw std::runtime_error(err.str());
395 _obj->_internal_accept_owner(&other, go);
402 T* ptr =
static_cast<T*
>(other.get());
408 return Object<U>(other).managedObjectPtr();
449 return boost::shared_ptr<T>(&asT(),
boost::bind(&keepManagedObjectPtr, _obj));
455 if (!boost::is_same<T, Empty>::value && obj)
475 if (boost::is_same<T, Empty>::value || !_obj)
477 if (_obj->type->info() != typeOf<T>()->info()
478 && _obj->type->inherits(typeOf<T>())==-1)
481 detail::ProxyGeneratorMap::iterator it = map.find(typeOf<T>()->info());
484 qiLogDebug(
"qitype.anyobject") <<
"Upgrading Object to specialized proxy.";
490 throw std::runtime_error(std::string() +
"Object does not have interface " + typeOf<T>()->infoString());
496 return *
reinterpret_cast<T*
>(_obj->value);
501 return *
reinterpret_cast<const T*
>(_obj->value);
521 return _obj.unique();
537 return go()->
connect(signal, target, slot);
549 public TypeImpl<boost::shared_ptr<GenericObject> >
563 #endif // _QITYPE_DETAILS_GENERICOBJECT_HXX_
boost::shared_ptr< T > asSharedPtr()
GenericObject * asGenericObject() const
static void noDeleteT(T *)
boost::weak_ptr< GenericObject > _ptr
qi::Future< AnyReference > metaCall(const std::string &nameWithOptionalSignature, const GenericFunctionParameters ¶ms, MetaCallType callType=MetaCallType_Auto, Signature returnSignature=Signature()) const
qi::FutureSync< void > setProperty(const std::string &name, const T &val) const
qi::FutureSync< void > disconnect(SignalLink linkId) const
qi::FutureSync< SignalLink > connect(const std::string &eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel=MetaCallType_Direct)
qi::FutureSync< AnyValue > property(unsigned int id) const
void enableStats(bool enable)
Set statistics gathering status.
int findMethod(const std::string &name, const GenericFunctionParameters ¶meters) const
boost::function< RF > bind(const AF &fun,...)
void enableStats(bool enable) const
void checkT()
Check tha value actually has the T interface.
bool operator<(const Object &b) const
qi::FutureSync< SignalLink > connect(unsigned int signal, const SignalSubscriber &subscriber) const
Honor the default behavior.
qi::FutureSync< T > property(const std::string &name) const
boost::mpl::if_< typename boost::is_same< T, Empty >::type, None, Object< Empty > >::type MaybeAnyObject
const ValueType & value(int msecs=FutureTimeout_Infinite) const
qi::FutureSync< SignalLink > connect(const std::string &eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel=MetaCallType_Auto) const
void enableTrace(bool enable)
bool isStatsEnabled() const
int findMethod(const std::string &name, const GenericFunctionParameters ¶meters)
static void deleteGenericObjectOnly(GenericObject *obj)
ManagedObjectPtr fromSharedPtr(Object< T > &dst, boost::shared_ptr< U > &other, boost::false_type)
unsigned use_count() const
void destroy()
Deletes storage.
WeakObject(const Object< U > &o)
boost::shared_ptr< class GenericObject > ManagedObjectPtr
ProxyGeneratorMap & proxyGeneratorMap()
void operator=(const Object< U > &o)
void forceExecutionContext(boost::shared_ptr< qi::ExecutionContext > ec)
T to() const
Convert to anything or throw trying.
qi::FutureSync< void > disconnect(SignalLink linkId)
Disconnect an event link. Returns if disconnection was successful.
bool operator==(const Object< U > &b) const
detail::ManagedObjectPtr managedObjectPtr()
#define genCall(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)
const MetaObject & metaObject() const
qi::FutureSync< void > setProperty(const std::string &name, const T &val)
void metaPost(unsigned int event, const GenericFunctionParameters ¶ms) const
bool isStatsEnabled() const
ObjectTypeInterface * type
void post(const std::string &eventName, qi::AutoAnyReference p1=qi::AutoAnyReference(), qi::AutoAnyReference p2=qi::AutoAnyReference(), qi::AutoAnyReference p3=qi::AutoAnyReference(), qi::AutoAnyReference p4=qi::AutoAnyReference(), qi::AutoAnyReference p5=qi::AutoAnyReference(), qi::AutoAnyReference p6=qi::AutoAnyReference(), qi::AutoAnyReference p7=qi::AutoAnyReference(), qi::AutoAnyReference p8=qi::AutoAnyReference())
void metaPost(unsigned int event, const GenericFunctionParameters ¶ms)
virtual void destroy(void *)=0
Free all resources of a storage.
void enableTrace(bool enable)
WeakObject< Empty > AnyWeakObject
qi::FutureSync< void > setProperty(unsigned int id, const AnyValue &val) const
static void keepReference(GenericObject *obj, boost::shared_ptr< U > ptr)
qi::FutureSync< T > property(const std::string &name)
std::map< unsigned int, MethodStatistics > ObjectStatistics
const char * infoString()
ObjectTypeInterface * interface()
qi::FutureSync< SignalLink > connect(const std::string &name, const SignalSubscriber &functor) const
boost::shared_ptr< ExecutionContext > executionContext() const
const MetaObject & metaObject()
Object< Empty > AnyObject
static void keepManagedObjectPtr(detail::ManagedObjectPtr ptr)
bool isTraceEnabled() const
static void noDelete(GenericObject *)
ObjectStatistics stats() const
const ValueType & value(int msecs=FutureTimeout_Infinite) const
Return the value associated to a Future.
bool operator!=(const Object< U > &b) const
qi::Future< AnyReference > metaCall(unsigned int method, const GenericFunctionParameters ¶ms, MetaCallType callType=MetaCallType_Auto, Signature returnSignature=Signature()) const
std::map< TypeInfo, boost::function< AnyReference(AnyObject)> > ProxyGeneratorMap
void forceExecutionContext(boost::shared_ptr< ExecutionContext > eventLoop)
Override all ThreadingModel and force dispatch to given event loop.
bool isTraceEnabled() const
void clearStats()
Reset all statistical data.
qi::Future< AnyReference > metaCall(unsigned int method, const GenericFunctionParameters ¶ms, MetaCallType callType=MetaCallType_Auto, Signature returnSignature=Signature())
ObjectStatistics stats() const
void post(const std::string &eventName, qi::AutoAnyReference p1=qi::AutoAnyReference(), qi::AutoAnyReference p2=qi::AutoAnyReference(), qi::AutoAnyReference p3=qi::AutoAnyReference(), qi::AutoAnyReference p4=qi::AutoAnyReference(), qi::AutoAnyReference p5=qi::AutoAnyReference(), qi::AutoAnyReference p6=qi::AutoAnyReference(), qi::AutoAnyReference p7=qi::AutoAnyReference(), qi::AutoAnyReference p8=qi::AutoAnyReference()) const
void init(qi::LogLevel verb=qi::LogLevel_Info, qi::LogContext context=qi::LogContextAttr_ShortVerbosity|qi::LogContextAttr_Tid|qi::LogContextAttr_Category, bool synchronous=true)
Initialization of the logging system (could be avoided)
void metaPost(const std::string &nameWithOptionalSignature, const GenericFunctionParameters &in) const
static void deleteCustomDeleter(GenericObject *obj, boost::function< void(T *)> deleter)
ExecutionContext * executionContext() const
static void deleteGenericObjectOnlyAndKeep(GenericObject *obj, U)