Go to the documentation of this file.
45 #include <type_traits>
65 virtual const char*
what()
const throw() {
return "FutureThreadError\n";}
69 virtual const char*
what()
const throw() {
return "FutureWhenError\n";}
239 #ifndef DOXYGEN_PARSING
240 namespace FutureHelper {
248 struct WhenWrapperArg {
249 mutable std::unique_ptr<const Cgu::Callback::CallbackArg<const Val&>> when;
254 when(std::move(when_)) {}
255 WhenWrapperArg(WhenWrapperArg&& w): when(std::move(w.when)) {}
264 struct WhenWrapperArgRel {
265 mutable std::unique_ptr<Cgu::SafeEmitterArg<const Val&>> when;
270 when(std::move(when_)) {}
271 WhenWrapperArgRel(WhenWrapperArgRel&& w): when(std::move(w.when)) {}
275 #endif // DOXYGEN_PARSING
281 std::unique_ptr<Cgu::Thread::Thread> thread_u;
282 std::unique_ptr<Cgu::Callback::Callback> cb_u;
292 template <
class T,
class Ret,
class... Args>
293 void run_wrapper(T*, Ret (T::*)(Args...),
const Args&...);
295 template <
class T,
class Ret,
class... Args>
296 void run_wrapper_const(
const T*, Ret (T::*)(Args...)
const,
const Args&...);
298 template <
class Ret,
class... Args>
299 void run_wrapper_static(Ret (*)(Args...),
const Args&...);
301 template <
class Func>
302 void run_wrapper_functor(Func&);
304 void cancel_cleanup();
307 void post_done(
const FutureHelper::WhenWrapperArg<Val>&,
308 gint, GMainContext*);
310 void post_done_rel(
const FutureHelper::WhenWrapperArgRel<Val>&,
311 gint, GMainContext*);
317 const std::unique_ptr<const Cgu::Callback::Callback>& func,
321 Future(): val(), done(
false), running(
false), error(
false), emitter_error(
false) {}
369 template <
class Ret,
class T>
405 template <
class Ret,
class Param1,
class Arg1,
class T>
407 Ret (T::*func)(Param1),
442 template <
class Ret,
class Param1,
class Param2,
class Arg1,
class Arg2,
class T>
444 Ret (T::*func)(Param1, Param2),
480 template <
class Ret,
class Param1,
class Param2,
class Param3,
481 class Arg1,
class Arg2,
class Arg3,
class T>
483 Ret (T::*func)(Param1, Param2, Param3),
519 template <
class Ret,
class T>
521 Ret (T::*func)()
const);
555 template <
class Ret,
class Param1,
class Arg1,
class T>
557 Ret (T::*func)(Param1)
const,
592 template <
class Ret,
class Param1,
class Param2,
class Arg1,
class Arg2,
class T>
594 Ret (T::*func)(Param1, Param2)
const,
630 template <
class Ret,
class Param1,
class Param2,
class Param3,
631 class Arg1,
class Arg2,
class Arg3,
class T>
633 Ret (T::*func)(Param1, Param2, Param3)
const,
699 template <
class Ret,
class Param1,
class Arg1>
735 template <
class Ret,
class Param1,
class Param2,
class Arg1,
class Arg2>
772 template <
class Ret,
class Param1,
class Param2,
class Param3,
773 class Arg1,
class Arg2,
class Arg3>
811 template <
class Ret,
class Param1,
class Param2,
class Param3,
class Param4,
812 class Arg1,
class Arg2,
class Arg3,
class Arg4>
856 template <
class Func>
1233 gint priority = G_PRIORITY_DEFAULT,
1234 GMainContext* context = 0);
1382 template <class When,
1383 class = typename std::enable_if<!std::is_convertible<typename std::remove_reference<When>::type,
1384 const
Cgu::
Callback::CallbackArg<const Val&>*>::value>::type>
1386 gint priority = G_PRIORITY_DEFAULT,
1387 GMainContext* context = 0) {
1388 return when(Callback::lambda<const Val&>(std::forward<When>(w)),
1508 gint priority = G_PRIORITY_DEFAULT,
1509 GMainContext* context = 0);
1636 template <
class When,
1637 class =
typename std::enable_if<!std::is_convertible<typename std::remove_reference<When>::type,
1641 gint priority = G_PRIORITY_DEFAULT,
1642 GMainContext* context = 0) {
1643 return when(Callback::lambda<const Val&>(std::forward<When>(w)),
1746 GMainContext* context = 0);
1851 template <
class Fail,
1852 class =
typename std::enable_if<!std::is_convertible<typename std::remove_reference<Fail>::type,
1855 GMainContext* context = 0) {
1856 fail(Callback::lambda<>(std::forward<Fail>(f)),
1934 GMainContext* context = 0);
2017 template <
class Fail,
2018 class =
typename std::enable_if<!std::is_convertible<typename std::remove_reference<Fail>::type,
2022 GMainContext* context = 0) {
2023 fail(Callback::lambda<>(std::forward<Fail>(f)),
2208 template <class Obj, class Ret, class... Params, class... Args>
2210 Ret (Obj::*func)(Params...),
2250 template <
class Obj,
class Ret,
class... Params,
class... Args>
2252 Ret (Obj::*func)(Params...)
const,
2292 template <
class Ret,
class... Params,
class... Args>
2353 template <
class Ret,
class Func>
2361 #ifndef DOXYGEN_PARSING
2362 template <
class Func>
2376 #include <c++-gtk-utils/future.tpp>
virtual const char * what() const
Definition: future.h:69
The callback interface class.
Definition: callback.h:650
Future(const Future &)=delete
Definition: application.h:44
SafeEmitter done_emitter
Definition: future.h:2165
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(const T &t, Ret(T::*func)(Param1) const, Arg1 &&arg1)
Cgu::IntrusivePtr< Cgu::Thread::Future< Ret > > make_future(Obj &obj, Ret(Obj::*func)(Params...), Args &&... args)
Definition: future.h:2209
Cgu::Callback::SafeFunctor when(const Cgu::Callback::CallbackArg< const Val & > *cb, Cgu::Releaser &r, gint priority=G_PRIORITY_DEFAULT, GMainContext *context=0)
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(const T &t, Ret(T::*func)(Param1, Param2) const, Arg1 &&arg1, Arg2 &&arg2)
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(Func &&func)
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(Ret(*func)(Param1), Arg1 &&arg1)
A wrapper class for pthread condition variables.
Definition: mutex.h:449
This is a smart pointer for managing objects allocated on freestore which maintain their own referenc...
Definition: intrusive_ptr.h:98
This file provides classes for type erasure.
bool is_emitter_done() const noexcept
void fail(const Cgu::Callback::Callback *cb, GMainContext *context=0)
void fail(Fail &&f, Cgu::Releaser &r, GMainContext *context=0)
Definition: future.h:2020
bool is_done() const noexcept
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(Ret(*func)(Param1, Param2, Param3, Param4), Arg1 &&arg1, Arg2 &&arg2, Arg3 &&arg3, Arg4 &&arg4)
Cgu::Callback::SafeFunctor when(When &&w, Cgu::Releaser &r, gint priority=G_PRIORITY_DEFAULT, GMainContext *context=0)
Definition: future.h:1639
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(T &t, Ret(T::*func)(Param1, Param2), Arg1 &&arg1, Arg2 &&arg2)
CallbackArg Callback
Definition: callback.h:567
void fail(const Cgu::Callback::Callback *cb, Cgu::Releaser &r, GMainContext *context=0)
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(Ret(*func)())
void fail(Fail &&f, GMainContext *context=0)
Definition: future.h:1854
Future & operator=(const Future &)=delete
A thread-safe class to execute callbacks connected to it, with provision for automatic disconnection.
Definition: emitter.h:922
Functor class holding a Callback::CallbackArg object, with thread-safe reference count.
Definition: callback.h:1080
SafeFunctorArg SafeFunctor
Definition: callback.h:780
A class representing a pthread thread which will provide a value.
Definition: future.h:279
#define CGU_GLIB_MEMORY_SLICES_FUNCS
Definition: cgu_config.h:84
This is a counter class providing the ref() and unref() functions required by IntrusivePtr,...
Definition: intrusive_ptr.h:349
Provides wrapper classes for pthread mutexes and condition variables, and scoped locking classes for ...
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(Ret(*func)(Param1, Param2), Arg1 &&arg1, Arg2 &&arg2)
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(const T &t, Ret(T::*func)() const)
Cgu::Callback::SafeFunctor when(const Cgu::Callback::CallbackArg< const Val & > *cb, gint priority=G_PRIORITY_DEFAULT, GMainContext *context=0)
bool is_error() const noexcept
A class used for tracking EmitterArg and SafeEmitterArg connections.
Definition: emitter.h:352
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(T &t, Ret(T::*func)(Param1, Param2, Param3), Arg1 &&arg1, Arg2 &&arg2, Arg3 &&arg3)
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(Ret(*func)(Param1, Param2, Param3), Arg1 &&arg1, Arg2 &&arg2, Arg3 &&arg3)
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(T &t, Ret(T::*func)(Param1), Arg1 &&arg1)
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(const T &t, Ret(T::*func)(Param1, Param2, Param3) const, Arg1 &&arg1, Arg2 &&arg2, Arg3 &&arg3)
This file provides a thread-safe signal/slot mechanism, with automatic disconnection.
A wrapper class for pthread mutexes.
Definition: mutex.h:117
A class representing a pthread thread.
Definition: thread.h:166
bool is_emitter_error() const noexcept
virtual const char * what() const
Definition: future.h:65
static Cgu::IntrusivePtr< Cgu::Thread::Future< Val > > make(T &t, Ret(T::*func)())