pflib v2.7.0-1-gd371ab6a
Polarfire Interaction Library
Menu< T, H >::Line Class Reference

A command in the menu. More...

Collaboration diagram for Menu< T, H >::Line:
[legend]

Public Member Functions

 Line (const char *n, const char *d, SingleTargetCommand f)
 define a menu line that uses a single target command
 
 Line (const char *n, const char *d, MultipleTargetCommands f)
 define a menu line that uses a multiple command function
 
 Line (const char *n, const char *d, Menu *m)
 define a menu line that enters a sub menu
 
 Line (const char *n, const char *d)
 define an empty menu line with only a name and description More...
 
 Line (Line &&l) noexcept
 noexcept move constructor allows std::vector to use it when expanding capacity
 
 Line (const Line &l)=default
 
bool execute (TargetHandle p) const
 Execute this line. More...
 
bool empty () const
 Check if this line is an empty one.
 
void render ()
 add an exit line if this is a menu, otherwise do nothing
 
const char * name () const
 name of this line to select it
 
const char * desc () const
 short description to print with menu
 

Private Attributes

const char * name_
 the name of this line
 
const char * desc_
 short description for what this line is
 
Menusub_menu_
 pointer to sub menu (if it exists)
 
SingleTargetCommand cmd_
 function pointer to execute (if exists)
 
MultipleTargetCommands mult_cmds_
 function handling multiple commands to execute (if exists)
 

Friends

std::ostreamoperator<< (std::ostream &s, const Line &l)
 

Detailed Description

template<typename T, typename H = T*>
class Menu< T, H >::Line

A command in the menu.

A menu command can do one of two tasks:

  1. Enter a sub-menu
  2. Execute a specific command on the target

There are two ways to execute a command on the target, the user can provide a function that only does one command on the target (the function signature is SingleTargetCommand) or the user can provide a function that can do multiple commands on a target (the function signature is MultipleTargetCommands) where the first argument to that function will be the name of that Line.

Constructor & Destructor Documentation

◆ Line()

template<typename T , typename H = T*>
Menu< T, H >::Line::Line ( const char *  n,
const char *  d 
)
inline

define an empty menu line with only a name and description

empty lines are used to exit menus because they will do nothing when execute is called and will leave the do-while loop in Menu::steer

Member Function Documentation

◆ execute()

template<typename T , typename H = T*>
bool Menu< T, H >::Line::execute ( TargetHandle  p) const
inline

Execute this line.

If this line is a sub-menu, we give the target to that menu's steer function. Otherwise, we execute the function that is available for this line, perferring the single target command.

Note
Empty menu lines will just do nothing when executed.
Parameters
[in]ppointer to target
Returns
true if we were a sub-menu and the command options need to be reset to the parent menu options

The documentation for this class was generated from the following file: