1.8
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EventLoop Class Reference

Event loop interface. More...

Public Types

using IdleCallback = std::function< void()>
 Event callback function definition. More...
 

Public Member Functions

 EventLoop (const Application &app) noexcept
 
 EventLoop (const EventLoop &)=delete
 
 EventLoop (EventLoop &&)=delete
 
 ~EventLoop () noexcept
 
void add_idle_callback (IdleCallback func)
 Add a callback to be called any time the event loop is idle. More...
 
void draw ()
 Perform a draw. More...
 
asio::io_context & io ()
 Get a reference to the internal ASIO io_context object. More...
 
EventLoopoperator= (const EventLoop &)=delete
 
EventLoopoperator= (EventLoop &&)=delete
 
int poll ()
 Run some pending events and return. More...
 
void quit (int exit_value=0)
 Quit the event loop. More...
 
int run ()
 Run the event loop. More...
 
int step ()
 Single step on the event loop. More...
 

Protected Member Functions

void invoke_idle_callbacks ()
 Invoke idle callbacks. More...
 
int wait ()
 Wait for an event to occur. More...
 

Protected Attributes

const Applicationm_app
 Application reference. More...
 
bool m_do_quit {false}
 Used internally to determine whether the event loop should exit. More...
 
int m_exit_value
 Return value when application quits. More...
 
std::vector< IdleCallbackm_idle
 Registered idle callbacks. More...
 
std::unique_ptr< EventLoopImpl > m_impl
 Internal event loop implementation. More...
 

Detailed Description

Event loop interface.

Member Typedef Documentation

◆ IdleCallback

using IdleCallback = std::function<void ()>

Event callback function definition.

Constructor & Destructor Documentation

◆ EventLoop() [1/3]

EventLoop ( const Application app)
explicitnoexcept

◆ EventLoop() [2/3]

EventLoop ( const EventLoop )
delete

◆ EventLoop() [3/3]

EventLoop ( EventLoop &&  )
delete

◆ ~EventLoop()

~EventLoop ( )
noexcept

Member Function Documentation

◆ add_idle_callback()

void add_idle_callback ( IdleCallback  func)

Add a callback to be called any time the event loop is idle.

◆ draw()

void draw ( )

Perform a draw.

Note
You do not normally need to call this directly. It is called by step() and run() automatically.

◆ invoke_idle_callbacks()

void invoke_idle_callbacks ( )
protected

Invoke idle callbacks.

◆ io()

asio::io_context& io ( )

Get a reference to the internal ASIO io_context object.

◆ operator=() [1/2]

EventLoop& operator= ( const EventLoop )
delete

◆ operator=() [2/2]

EventLoop& operator= ( EventLoop &&  )
delete

◆ poll()

int poll ( )

Run some pending events and return.

Note
This does not call draw(). If poll() returns a non-zero value, you must manually call draw().
Returns
The number of events handled.

◆ quit()

void quit ( int  exit_value = 0)

Quit the event loop.

This will cause the run() function to return.

Note
Allow optional non-zero exit value

◆ run()

int run ( )

Run the event loop.

This will not return until quit() is called.

Returns
The number of events handled.

◆ step()

int step ( )

Single step on the event loop.

This is the same as calling:

auto ret = poll();
if (ret)
draw();
void draw()
Perform a draw.
int poll()
Run some pending events and return.
Note
If calling this manually, this will not invoke any idle callbacks.
Returns
The number of events handled.

◆ wait()

int wait ( )
protected

Wait for an event to occur.

Member Data Documentation

◆ m_app

const Application& m_app
protected

Application reference.

◆ m_do_quit

bool m_do_quit {false}
protected

Used internally to determine whether the event loop should exit.

◆ m_exit_value

int m_exit_value
protected

Return value when application quits.

◆ m_idle

std::vector<IdleCallback> m_idle
protected

Registered idle callbacks.

◆ m_impl

std::unique_ptr<EventLoopImpl> m_impl
protected

Internal event loop implementation.