7 #ifndef _QI_TYPE_DETAIL_GENERIC_OBJECT_HPP_
8 #define _QI_TYPE_DETAIL_GENERIC_OBJECT_HPP_
14 #include <boost/smart_ptr/enable_shared_from_this.hpp>
25 # pragma warning( push )
26 # pragma warning( disable: 4251 )
43 ,
public boost::enable_shared_from_this<GenericObject>
51 template <
typename R,
typename... Args>
52 R call(
const std::string& methodName, Args&&... args);
54 template <
typename R,
typename... Args>
87 void post(
const std::string& eventName,
105 template <
typename FUNCTOR_TYPE>
152 std::string makeFindMethodErrorMessage(
153 const std::string& nameWithOptionalSignature,
167 template <
typename FUNCTION_TYPE>
169 FUNCTION_TYPE callback,
179 template <
typename T>
181 template <
typename T>
183 template <
typename T>
194 template <
typename R,
typename... Args>
199 throw std::runtime_error(
"Invalid GenericObject");
202 return detail::extractFuture<R>(fmeta);
208 template <
typename R,
typename... Args>
212 int methodId =
findMethod(methodName, anyArgs);
214 return makeFutureError<R>(makeFindMethodErrorMessage(methodName, anyArgs, methodId));
215 auto futureMeta = metaCallNoUnwrap(methodId, anyArgs,
MetaCallType_Queued, typeOf<R>()->signature());
227 std::ostringstream ss;
228 ss <<
"property \"" << name <<
"\" was not found";
229 return makeFutureError<T>(ss.str());
244 std::ostringstream ss;
245 ss <<
"property \"" << name <<
"\" was not found";
246 return makeFutureError<void>(ss.str());
268 return AnyReference((*val)->type, (*val)->value);
271 void set(
void** storage, AnyReference source)
override
277 throw std::runtime_error(
"cannot set object from an invalid value");
279 if (source.type()->info() == info())
288 auto content = source.content();
289 if (!content.isValid())
290 throw std::runtime_error(
"cannot set object from an invalid dynamic value");
291 set(storage, source.content());
296 detail::ManagedObjectPtr op(
new GenericObject(static_cast<ObjectTypeInterface*>(source.type()), source.rawValue()));
301 PointerTypeInterface* ptype =
static_cast<PointerTypeInterface*
>(source.type());
304 qiLogInfo() <<
"Object will *not* track original shared pointer";
305 set(storage, *source);
309 set(storage, source.content());
312 throw std::runtime_error((std::string)
"Cannot assign non-object " + source.type()->infoString() +
" to Object");
315 using Methods = DefaultTypeImplMethods<detail::ManagedObjectPtr, TypeByPointerPOD<detail::ManagedObjectPtr>>;
322 # pragma warning( pop )
boost::shared_ptr< GenericObject > ManagedObjectPtr
qi::Future< R > async(const std::string &methodName, Args &&...args)
ObjectUid uid
Uid of "value".
void connect(const AF &fun, FutureCallbackType type=FutureCallbackType_Auto)
qi::FutureSync< SignalLink > connect(const std::string &eventName, FUNCTOR_TYPE callback, MetaCallType threadingModel=MetaCallType_Direct)
qi::Future< AnyReference > metaCall(ExecutionContext *ec, ObjectThreadingModel objectThreadingModel, MetaCallType methodThreadingModel, MetaCallType callType, AnyObject manageable, unsigned int methodId, AnyFunction func, const GenericFunctionParameters ¶ms, bool noCloneFirst=false, unsigned int callerId=0, qi::os::timeval postTimestamp=qi::os::timeval())
#define qiLogCategory(Cat)
static AnyValue from(const T &r)
Honor the default behavior.
dll import/export and compiler message
int findMethod(const std::string &name, const GenericFunctionParameters ¶meters)
Find method named name callable with arguments parameters.
#define qiLogWarning(...)
Log in warning mode.
Future< T > future() const
Get a future linked to this promise. Can be called multiple times.
R call(const std::string &methodName, Args &&...args)
Force a synchronous call.
#define qiLogInfo(...)
Log in info mode.
#define _QI_BOUNCE_TYPE_METHODS(Bounce)
Implement all methods of Type as bouncers to Bouncer.
qi::FutureSync< void > setProperty(const std::string &name, const T &val)
auto async(F &&callback) -> decltype(asyncDelay(std::forward< F >(callback), qi::Duration(0)))
ObjectTypeInterface * type
qi::FutureSync< T > property(const std::string &name)
const MetaObject & metaObject()
T src(const std::atomic< T > &x)
static AnyFunction from(F &&func)
static AnyReference from(const T &ref)
qi::Future< AnyReference > metaCall(const std::string &nameWithOptionalSignature, const GenericFunctionParameters ¶ms, MetaCallType callType=MetaCallType_Auto, Signature returnSignature=Signature())
Force an asynchronous call in an other thread.
std::enable_if< std::is_function< RF >::value, boost::function< RF > >::type bind(AF &&fun, Arg0 &&arg0, Args &&...args)
void adaptFutureUnwrap(Future< AnyReference > &f, Promise< R > &p)
Feed a promise from a generic future which may be unwrapped if it contains itself a future...