Scarab  v3.9.2
Project 8 C++ Utility Library
Public Member Functions | Public Attributes | List of all members
cancelable_wrapper Struct Reference

Lightweight wrapper for a cancelable object only temporarily added to signal_handler. More...

#include <cancelable.hh>

Inheritance diagram for cancelable_wrapper:
Inheritance graph

Public Member Functions

 cancelable_wrapper (cancelable &a_cancelable)
 
virtual ~cancelable_wrapper ()
 
virtual void do_cancellation (int a_code)
 
- Public Member Functions inherited from cancelable
 cancelable ()
 
 cancelable (const cancelable &a_orig)
 
 cancelable (cancelable &&a_orig)
 
virtual ~cancelable ()
 
cancelableoperator= (const cancelable &a_orig)
 
cancelableoperator= (cancelable &&a_orig)
 
void cancel (int a_code=0)
 asynchronous cancel function More...
 
void reset_cancel ()
 reset to non-canceled state More...
 
bool is_canceled () const
 check canceled state More...
 

Public Attributes

cancelablef_wrapped
 

Additional Inherited Members

- Protected Attributes inherited from cancelable
std::atomic< bool > f_canceled
 

Detailed Description

Lightweight wrapper for a cancelable object only temporarily added to signal_handler.

Author
N. S. Oblath
 Sometimes a cancelable object is created on the stack in a local scope, or it's temporarily added to signal_handler 
 while a specific action is performed.  In this case you can use this lightweight wrapper to add the cancelable object to the signal handler.

 NOTE: the wrapper does not track the lifetime of the wrapped object.  Only use this wrapper if you can guarantee that the lifetime of the 
 wrapped object is not shorter than that of the wrapper.

 Example:
   {
       my_cancelable t_obj;  // here's the local object we want to have temporarily added to signal_handler
       auto t_obj_wrap = wrap_cancelable( t_obj );  // use wrap_cancelable() (declared below) to create the wrapper
       scarab::signal_handler t_handler;  // creating the signal_handler sets the signal-handling functions, if it hasn't been done before
       t_handler.add_cancelable( t_obj_wrap );  // add the wrapper
       t_obj.execute();  // do the cancelable action

end of scope: t_obj_wrap is destroyed, which removes it from signal_handler automatically }

Definition at line 103 of file cancelable.hh.

Constructor & Destructor Documentation

◆ cancelable_wrapper()

cancelable_wrapper ( cancelable a_cancelable)

Definition at line 69 of file cancelable.cc.

◆ ~cancelable_wrapper()

~cancelable_wrapper ( )
virtual

Definition at line 73 of file cancelable.cc.

Member Function Documentation

◆ do_cancellation()

void do_cancellation ( int  a_code)
inlinevirtual

Reimplemented from cancelable.

Definition at line 135 of file cancelable.hh.

Member Data Documentation

◆ f_wrapped

cancelable* f_wrapped

Definition at line 108 of file cancelable.hh.


The documentation for this struct was generated from the following files: