MeshLib
 
Loading...
Searching...
No Matches
MRPythonAppendCommand.h
Go to the documentation of this file.
1#pragma once
2#include "MRCommandLoop.h"
3
4namespace MR
5{
6
7// Moves function func and copies/moves arguments to inner lambda object.
8// After that pushes it to the event loop instead of immediate call.
9template<typename F, typename... Args>
10void pythonAppendOrRun( F func, Args&&... args )
11{
12 auto deferredAction = [funcLocal = std::move( func ), &...argsLocal = args]() mutable
13 {
14 funcLocal( std::forward<Args>( argsLocal )... );
15 };
16 MR::CommandLoop::runCommandFromGUIThread( std::move( deferredAction ) );
17}
18
19// Returns lambda which runs specified function `f` on commandLoop
20// deferred instead of immediate call on current thread
21// with signature of `f` and returns void
22template<typename R, typename... Args>
23[[nodiscard]] auto pythonRunFromGUIThread( std::function<R( Args... )>&& f ) -> std::function<void( Args... )>
24{
25 return[fLocal = std::move( f )]( Args&&... args ) mutable
26 {
27 // fLocal must not be moved
28 pythonAppendOrRun( fLocal, std::forward<Args>( args )... );
29 };
30}
31
32template<typename F>
33[[nodiscard]] auto pythonRunFromGUIThread( F&& f )
34{
35 return pythonRunFromGUIThread( std::function( std::forward<F>( f ) ) );
36}
37
38template<typename R, typename T, typename... Args>
39auto pythonRunFromGUIThread( R( T::* memFunction )( Args... ) )
40{
41 return pythonRunFromGUIThread( std::function<R( T*, Args... )>( std::mem_fn( memFunction ) ) );
42}
43
44}
static MRVIEWER_API void runCommandFromGUIThread(CommandFunc func)
Definition MRCameraOrientationPlugin.h:7
auto pythonRunFromGUIThread(std::function< R(Args...)> &&f) -> std::function< void(Args...)>
Definition MRPythonAppendCommand.h:23
void pythonAppendOrRun(F func, Args &&... args)
Definition MRPythonAppendCommand.h:10