pflib v3.9.0-rc3-11-g2537d8f
Pretty Fine HGCROC Interaction Library
Loading...
Searching...
No Matches
pflib::menu::Menu< T >::Line Class Reference

A command in the menu. More...

Collaboration diagram for pflib::menu::Menu< T >::Line:
[legend]

Public Member Functions

 Line (const char *n, const char *d, SingleTargetCommand f, unsigned int category=0)
 define a menu line that uses a single target command
 
 Line (const char *n, const char *d, MultipleTargetCommands f, unsigned int category=0)
 define a menu line that uses a multiple command function
 
 Line (const char *n, const char *d, std::shared_ptr< Menu > m, unsigned int category=0)
 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
 
bool execute (TargetHandle p) const
 Execute this line.
 
bool empty () const
 Check if this line is an empty one.
 
void build ()
 build this line
 
void hide (unsigned int categories)
 pass on configuration on which categories to hide
 
const char * name () const
 name of this line to select it
 
const char * desc () const
 short description to print with menu
 
unsigned int category () const
 category int for hiding if certain categories are disabled
 
void print (std::ostream &s, int indent=0) const
 More specialized printing function to make it easier to recursively printout entire menu with descriptions.
 

Private Attributes

const char * name_
 the name of this line
 
const char * desc_
 short description for what this line is
 
std::shared_ptr< 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)
 
unsigned int category_
 category integer for disabling menu lines by groups
 

Friends

std::ostreamoperator<< (std::ostream &s, const Line &l)
 Overload output stream operator for easier printing.
 

Detailed Description

template<typename T>
class pflib::menu::Menu< T >::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 >
pflib::menu::Menu< T >::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

◆ build()

template<typename T >
void pflib::menu::Menu< T >::Line::build ( )
inline

build this line

we only need to do something if this line is a sub-menu in which we case we call build on the submenu.

◆ execute()

template<typename T >
bool pflib::menu::Menu< T >::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: