DUDS
Distributed Update of Data from Something
duds::ui::menu::MenuAccess Class Reference

Provides an exclusive lock on a Menu to allow the menu to be changed. More...

#include <MenuAccess.hpp>

Collaboration diagram for duds::ui::menu::MenuAccess:

Public Member Functions

 MenuAccess (const std::shared_ptr< Menu > &m)
 Creates a new MenuAccess object to modify the given Menu. More...
 
 MenuAccess (Menu &m)
 Creates a new MenuAccess object to modify the given Menu. More...
 
 ~MenuAccess ()
 Gives up access to the menu. More...
 
void append (MenuItemSptr &&mi) const
 Appends a new item to the end of the menu. More...
 
void append (const MenuItemSptr &mi) const
 Appends a new item to the end of the menu. More...
 
void changeEnabledState (std::size_t index, bool en) const
 Enables or disables an item on the menu. More...
 
void changeToggle (std::size_t index, bool state) const
 Changes the toggle state of an item on the menu to the indicated state. More...
 
void changeVisibility (std::size_t index, bool vis) const
 Changes the visibility of an item on the menu. More...
 
void clear () const
 Removes all items from the menu. More...
 
void clearToggle (std::size_t index) const
 Clears the toggle state of an item on the menu. More...
 
void disable (std::size_t index) const
 Disables an item on the menu. More...
 
void enable (std::size_t index) const
 Enables an item on the menu. More...
 
bool haveToggles () const
 True if the menu has at least one MenuItem that is a toggle. More...
 
void hide (std::size_t index) const
 Hides an item on the menu from view. More...
 
void insert (std::size_t index, MenuItemSptr &&mi) const
 Inserts a new item into the menu. More...
 
void insert (std::size_t index, const MenuItemSptr &mi) const
 Inserts a new item into the menu. More...
 
const MenuItemSptritem (std::size_t index) const
 Returns the MenuItem object at the given position. More...
 
const std::string & label (std::size_t index) const
 Returns a menu item's currently set label. More...
 
void label (std::size_t index, const std::string &label)
 Changes a menu item's label text. More...
 
void remove (const MenuItemSptr &mi) const
 Removes an item from the menu. More...
 
void remove (std::size_t index) const
 Removes an item from the menu. More...
 
void retire () noexcept
 Gives up access to the menu. More...
 
void setToggle (std::size_t index) const
 Sets the toggle state of an item on the menu. More...
 
void show (std::size_t index) const
 Shows an item on the menu that was hidden. More...
 
std::size_t size () const
 Returns the number of items in the menu. More...
 
const std::string & title () const
 Returns the title of the menu. More...
 
void title (const std::string &newTitle) const
 Change the title of the menu. More...
 
bool toggle (std::size_t index) const
 Toggles the toggle state of an item on the menu. More...
 
const std::string & value (std::size_t index) const
 Returns a menu item's currently set value. More...
 
void value (std::size_t index, const std::string &value)
 Changes a menu item's optional value. More...
 

Private Attributes

Menumenu
 The menu to operate upon. More...
 

Detailed Description

Provides an exclusive lock on a Menu to allow the menu to be changed.

The lock is recursive.

MenuItem objects can also modify the menu. They will also obtain an exclusive lock. The initial lock has a notable amount of overhead, while changing the recursive count for each recurive lock and unlock has minimal overhead. As a result, modifying many MenuItem objects will go quicker if a MenuAccess object is first made, even if its functions are not used. Using a MenuAccess object this way also ensures that no other thread can modify or render the menu until the modifications are complete.

Author
Jeff Jackowski
Examples:
bppmenu.cpp.

Definition at line 32 of file MenuAccess.hpp.

Constructor & Destructor Documentation

◆ MenuAccess() [1/2]

duds::ui::menu::MenuAccess::MenuAccess ( const std::shared_ptr< Menu > &  m)
inline

Creates a new MenuAccess object to modify the given Menu.

Parameters
mThe menu to access for modifications.

Definition at line 42 of file MenuAccess.hpp.

◆ MenuAccess() [2/2]

duds::ui::menu::MenuAccess::MenuAccess ( Menu m)
inline

Creates a new MenuAccess object to modify the given Menu.

Parameters
mThe menu to access for modifications.

Definition at line 51 of file MenuAccess.hpp.

◆ ~MenuAccess()

duds::ui::menu::MenuAccess::~MenuAccess ( )
inline

Gives up access to the menu.

Definition at line 57 of file MenuAccess.hpp.

Member Function Documentation

◆ append() [1/2]

void duds::ui::menu::MenuAccess::append ( MenuItemSptr &&  mi) const
inline

Appends a new item to the end of the menu.

Parameters
miThe menu item to add. It will be moved into an internal vector.
Exceptions
MenuNoItemErrorAn attempt was made to add nothing.
Examples:
bppmenu.cpp.

Definition at line 112 of file MenuAccess.hpp.

◆ append() [2/2]

void duds::ui::menu::MenuAccess::append ( const MenuItemSptr mi) const
inline

Appends a new item to the end of the menu.

Parameters
miThe menu item to add.
Exceptions
MenuNoItemErrorAn attempt was made to add nothing.

Definition at line 120 of file MenuAccess.hpp.

◆ changeEnabledState()

void duds::ui::menu::MenuAccess::changeEnabledState ( std::size_t  index,
bool  en 
) const
inline

Enables or disables an item on the menu.

Parameters
indexThe index of the menu item to modify.
enTrue to enable, false to disable. If this is the same as the current enable/disable state, the menu's update index will not change.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 198 of file MenuAccess.hpp.

Referenced by disable(), and enable().

◆ changeToggle()

void duds::ui::menu::MenuAccess::changeToggle ( std::size_t  index,
bool  state 
) const
inline

Changes the toggle state of an item on the menu to the indicated state.

Precondition
The menu item can be toggled; its Toggle flag is set.
Parameters
indexThe index of the menu item to modify.
stateThe new toggle state. If this is the same as the current state, the menu's update index will not change.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.
MenuItemNotAToggleThe MenuItem is not a toggle.

Definition at line 239 of file MenuAccess.hpp.

Referenced by clearToggle(), and setToggle().

◆ changeVisibility()

void duds::ui::menu::MenuAccess::changeVisibility ( std::size_t  index,
bool  vis 
) const
inline

Changes the visibility of an item on the menu.

Parameters
indexThe index of the menu item to modify.
visTrue to make visible, false for invisible. If this is the same as the current visible state, the menu's update index will not change.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 171 of file MenuAccess.hpp.

Referenced by hide(), and show().

◆ clear()

void duds::ui::menu::MenuAccess::clear ( ) const
inline

Removes all items from the menu.

Definition at line 96 of file MenuAccess.hpp.

◆ clearToggle()

void duds::ui::menu::MenuAccess::clearToggle ( std::size_t  index) const
inline

Clears the toggle state of an item on the menu.

Precondition
The menu item can be toggled; its Toggle flag is set.
Parameters
indexThe index of the menu item to modify.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.
MenuItemNotAToggleThe MenuItem is not a toggle.

Definition at line 250 of file MenuAccess.hpp.

◆ disable()

void duds::ui::menu::MenuAccess::disable ( std::size_t  index) const
inline

Disables an item on the menu.

Parameters
indexThe index of the menu item to modify.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 206 of file MenuAccess.hpp.

◆ enable()

void duds::ui::menu::MenuAccess::enable ( std::size_t  index) const
inline

Enables an item on the menu.

Parameters
indexThe index of the menu item to modify.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 214 of file MenuAccess.hpp.

◆ haveToggles()

bool duds::ui::menu::MenuAccess::haveToggles ( ) const
inline

True if the menu has at least one MenuItem that is a toggle.

Definition at line 90 of file MenuAccess.hpp.

◆ hide()

void duds::ui::menu::MenuAccess::hide ( std::size_t  index) const
inline

Hides an item on the menu from view.

Parameters
indexThe index of the menu item to modify.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 179 of file MenuAccess.hpp.

◆ insert() [1/2]

void duds::ui::menu::MenuAccess::insert ( std::size_t  index,
MenuItemSptr &&  mi 
) const
inline

Inserts a new item into the menu.

Parameters
indexThe location where the item will go.
miThe menu item to insert. It will be moved into an internal vector.
Exceptions
MenuNoItemErrorAn attempt was made to insert nothing.
MenuBoundsErrorThe insertion location is beyond the bounds of the menu.

Definition at line 132 of file MenuAccess.hpp.

◆ insert() [2/2]

void duds::ui::menu::MenuAccess::insert ( std::size_t  index,
const MenuItemSptr mi 
) const
inline

Inserts a new item into the menu.

Parameters
indexThe location where the item will go.
miThe menu item to insert.
Exceptions
MenuNoItemErrorAn attempt was made to insert nothing.
MenuBoundsErrorThe insertion location is beyond the bounds of the menu.

Definition at line 143 of file MenuAccess.hpp.

◆ item()

const MenuItemSptr& duds::ui::menu::MenuAccess::item ( std::size_t  index) const
inline

Returns the MenuItem object at the given position.

Parameters
indexThe position of the menu item to return.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 104 of file MenuAccess.hpp.

Referenced by changeEnabledState(), changeToggle(), changeVisibility(), label(), toggle(), and value().

◆ label() [1/2]

const std::string& duds::ui::menu::MenuAccess::label ( std::size_t  index) const
inline

Returns a menu item's currently set label.

Parameters
indexThe index of the menu item to query.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 269 of file MenuAccess.hpp.

◆ label() [2/2]

void duds::ui::menu::MenuAccess::label ( std::size_t  index,
const std::string &  label 
)
inline

Changes a menu item's label text.

Parameters
indexThe index of the menu item to modify.
labelThe new label to use.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 278 of file MenuAccess.hpp.

◆ remove() [1/2]

void duds::ui::menu::MenuAccess::remove ( const MenuItemSptr mi) const
inline

Removes an item from the menu.

Parameters
miThe menu item to remove.
Exceptions
MenuNoItemErrorAn attempt was made to remove nothing.
MenuItemDoesNotExistThe MenuItem is not in the menu.

Definition at line 152 of file MenuAccess.hpp.

◆ remove() [2/2]

void duds::ui::menu::MenuAccess::remove ( std::size_t  index) const
inline

Removes an item from the menu.

Parameters
indexThe position of the menu item to remove.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 160 of file MenuAccess.hpp.

◆ retire()

void duds::ui::menu::MenuAccess::retire ( )
inlinenoexcept

Gives up access to the menu.

Definition at line 63 of file MenuAccess.hpp.

Referenced by ~MenuAccess().

◆ setToggle()

void duds::ui::menu::MenuAccess::setToggle ( std::size_t  index) const
inline

Sets the toggle state of an item on the menu.

Precondition
The menu item can be toggled; its Toggle flag is set.
Parameters
indexThe index of the menu item to modify.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.
MenuItemNotAToggleThe MenuItem is not a toggle.

Definition at line 261 of file MenuAccess.hpp.

◆ show()

void duds::ui::menu::MenuAccess::show ( std::size_t  index) const
inline

Shows an item on the menu that was hidden.

Parameters
indexThe index of the menu item to modify.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 187 of file MenuAccess.hpp.

◆ size()

std::size_t duds::ui::menu::MenuAccess::size ( ) const
inline

Returns the number of items in the menu.

Definition at line 84 of file MenuAccess.hpp.

◆ title() [1/2]

const std::string& duds::ui::menu::MenuAccess::title ( ) const
inline

Returns the title of the menu.

Definition at line 71 of file MenuAccess.hpp.

◆ title() [2/2]

void duds::ui::menu::MenuAccess::title ( const std::string &  newTitle) const
inline

Change the title of the menu.

Parameters
newTitleThe new title for the menu.

Definition at line 78 of file MenuAccess.hpp.

◆ toggle()

bool duds::ui::menu::MenuAccess::toggle ( std::size_t  index) const
inline

Toggles the toggle state of an item on the menu.

Precondition
The menu item can be toggled; its Toggle flag is set.
Parameters
indexThe index of the menu item to modify.
Returns
The new toggle state.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.
MenuItemNotAToggleThe MenuItem is not a toggle.

Definition at line 226 of file MenuAccess.hpp.

◆ value() [1/2]

const std::string& duds::ui::menu::MenuAccess::value ( std::size_t  index) const
inline

Returns a menu item's currently set value.

The value is optional, so an empty string is a normal valid result.

Parameters
indexThe index of the menu item to query.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 287 of file MenuAccess.hpp.

◆ value() [2/2]

void duds::ui::menu::MenuAccess::value ( std::size_t  index,
const std::string &  value 
)
inline

Changes a menu item's optional value.

Parameters
indexThe index of the menu item to modify.
valueThe new value to store.
Exceptions
MenuBoundsErrorThe index is beyond the bounds of this menu.

Definition at line 296 of file MenuAccess.hpp.

Member Data Documentation

◆ menu

Menu* duds::ui::menu::MenuAccess::menu
private

The menu to operate upon.

Definition at line 36 of file MenuAccess.hpp.


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