|
DUDS
|
Distributed Update of Data from Something
|
Compiles a list of visible menu items based on the selected item of a MenuView. More...
#include <MenuOutput.hpp>
Public Member Functions | |
| MenuOutput ()=default | |
| Constructs a menu output without a view. More... | |
| MenuOutput (const std::shared_ptr< MenuView > &view, int vis) | |
| Constructs a new output for a given menu view that will start with a specified maximum number of visible items. More... | |
| void | attach (const std::shared_ptr< MenuView > &view, int vis=0) |
| Attaches this object to the given MenuView. More... | |
| const std::shared_ptr< Menu > & | menu () const |
| Returns the Menu used by this output view. More... | |
| const std::shared_ptr< MenuView > & | view () const |
| Returns the MenuView used by this output view. More... | |
Static Public Member Functions | |
| static std::shared_ptr< MenuOutput > | make (const std::shared_ptr< MenuView > &view, int vis) |
| Makes a new output view for a given menu that will start with a specified maximum number of visible items, and returns a std::shared_ptr that will manage its memory. More... | |
Private Member Functions | |
| bool | changed () const |
| True if the view has changed. More... | |
| bool | fore (Menu::ItemVec::const_iterator &iter) |
| A helper function for update() that moves iter towards the front of the menu until it finds a visible menu item or the start of the menu. More... | |
| void | lock (std::size_t newRange) |
| Handles several tasks to lock and prepare menu data. More... | |
| void | maxVisible (std::size_t newRange) |
| Changes the maximum number of visible menu items and causes the visible list to be regenerated. More... | |
| bool | revr (Menu::ItemVec::const_iterator &iter) |
| A helper function for update() that moves iter towards the back of the menu until it finds a visible menu item or the end of the menu. More... | |
| void | unlock () |
| Informs the MenuView that it has one fewer MenuOutput objects acting upon it, and releases the shared lock on the menu data. More... | |
| void | updateVisible () |
| Updates which items should be visible. More... | |
Private Attributes | |
| std::size_t | firstIdx |
| Index of the first menu item that is visible. More... | |
| MenuVisibleList | items |
| The currently visible menu items. More... | |
| std::size_t | lastIdx |
| Index of the last menu item that is visible. More... | |
| friend | MenuOutputAccess |
| std::shared_ptr< MenuView > | mview |
| The menu view handling the selected menu item. More... | |
| std::size_t | range = 1 |
| The maximum number of visible items. More... | |
| std::size_t | selected = 0 |
| Index of the selected item from the container of all menu items. More... | |
| std::size_t | selectedVis |
| Index of the selected item within the list of currently visible menu items. More... | |
| MenuVisibleList::const_iterator | seliter |
| Iterator to the currently selected item. More... | |
| bool | showFirst |
| True if the visible list includes the first visible item on the menu. More... | |
| bool | showLast |
| True if the visible list includes the last visible item on the menu. More... | |
| int | updateIdx = -1 |
| The menu's update index value when this subview was last rendered. More... | |
| bool | vchg |
| True when the view has changed since the last access, and false otherwise. More... | |
Compiles a list of visible menu items based on the selected item of a MenuView.
The visible items are queried from a MenuOutputAccess object. MenuOutputAccess handles locking and unlocking the required data. This class holds more persistent data, and allows reuse of the visible list when no changes have occurred.
Updating a MenuView and output views requires the MenuView to have a brief exclusive lock on the menu data. After the update, a shared lock on the menu data is maintained by the output view while it is in use. This prevents a MenuView object from being used at the same time by multiple MenuOutput objects on the same thread. The deadlock can be avoided by having only one MenuOutputAccess object on the stack at the same time. Technically, two on the satck will work if they use different MenuView objects even if they use the same menu, but this shouldn't be required to make anything work.
Definition at line 45 of file MenuOutput.hpp.
|
default |
Constructs a menu output without a view.
Before this object can be used, attach() must be called.
| duds::ui::menu::MenuOutput::MenuOutput | ( | const std::shared_ptr< MenuView > & | view, |
| int | vis | ||
| ) |
Constructs a new output for a given menu view that will start with a specified maximum number of visible items.
| view | The MenuView that will feed this output. |
| vis | The initial maximum number of visible menu items. |
Definition at line 17 of file MenuOutput.cpp.
| void duds::ui::menu::MenuOutput::attach | ( | const std::shared_ptr< MenuView > & | view, |
| int | vis = 0 |
||
| ) |
Attaches this object to the given MenuView.
The object may be re-attached to different MenuView objects during its lifetime.
| view | The MenuView that will feed this output. |
| vis | The maximum number of visible menu items, or 0 for no change. If this object has not yet been attached to a view and 0 is specified, a value of 1 will be used. |
Definition at line 20 of file MenuOutput.cpp.
Referenced by make().
|
inlineprivate |
True if the view has changed.
Definition at line 170 of file MenuOutput.hpp.
Referenced by duds::ui::menu::MenuOutputAccess::changed().
|
private |
A helper function for update() that moves iter towards the front of the menu until it finds a visible menu item or the start of the menu.
| iter | The location to start the search. |
Definition at line 72 of file MenuOutput.cpp.
Referenced by updateVisible().
|
private |
Handles several tasks to lock and prepare menu data.
| newRange | The number of menu items that can be displayed, or -1 to not change the range. |
Definition at line 39 of file MenuOutput.cpp.
Referenced by duds::ui::menu::MenuOutputAccess::MenuOutputAccess().
|
inlinestatic |
Makes a new output view for a given menu that will start with a specified maximum number of visible items, and returns a std::shared_ptr that will manage its memory.
| view | The MenuView that will feed this output. |
| vis | The initial maximum number of visible menu items. |
Definition at line 196 of file MenuOutput.hpp.
|
private |
Changes the maximum number of visible menu items and causes the visible list to be regenerated.
| newRange | The number of menu items that can be displayed. |
Definition at line 61 of file MenuOutput.cpp.
Referenced by duds::ui::menu::MenuOutputAccess::maxVisible().
| const std::shared_ptr< Menu > & duds::ui::menu::MenuOutput::menu | ( | ) | const |
Returns the Menu used by this output view.
| MenuOutputNotAttached | This object hasn't been attached to a MenuView. This can happen if it is constructed using the default constructor and attach() is not called. |
Definition at line 32 of file MenuOutput.cpp.
Referenced by fore(), lock(), duds::ui::menu::MenuOutputAccess::MenuOutputAccess(), revr(), updateVisible(), and view().
|
private |
A helper function for update() that moves iter towards the back of the menu until it finds a visible menu item or the end of the menu.
| iter | The location to start the search. |
Definition at line 85 of file MenuOutput.cpp.
Referenced by updateVisible().
|
private |
Informs the MenuView that it has one fewer MenuOutput objects acting upon it, and releases the shared lock on the menu data.
Definition at line 56 of file MenuOutput.cpp.
Referenced by duds::ui::menu::MenuOutputAccess::retire().
|
private |
Updates which items should be visible.
If an even number of items are visible, an additional item will be in the direction of the last change from the selected item so that the user will see more items ahead of the change.
Definition at line 98 of file MenuOutput.cpp.
Referenced by lock(), and maxVisible().
|
inline |
Returns the MenuView used by this output view.
Definition at line 215 of file MenuOutput.hpp.
|
private |
Index of the first menu item that is visible.
Definition at line 77 of file MenuOutput.hpp.
Referenced by duds::ui::menu::MenuOutputAccess::firstIndex(), and updateVisible().
|
private |
The currently visible menu items.
This data is only guarenteed to be valid while a MenuOutputAccess object is acting upon this MenuOutput. The data may or may not remain valid between accesses. The locks caused by the access object include a shared lock on the menu, which is why shared pointers are not needed here.
Definition at line 58 of file MenuOutput.hpp.
Referenced by attach(), duds::ui::menu::MenuOutputAccess::begin(), duds::ui::menu::MenuOutputAccess::empty(), duds::ui::menu::MenuOutputAccess::end(), duds::ui::menu::MenuOutputAccess::MenuOutputAccess(), duds::ui::menu::MenuOutputAccess::showingAll(), duds::ui::menu::MenuOutputAccess::size(), and updateVisible().
|
private |
Index of the last menu item that is visible.
Definition at line 81 of file MenuOutput.hpp.
Referenced by duds::ui::menu::MenuOutputAccess::lastIndex(), and updateVisible().
|
private |
Definition at line 173 of file MenuOutput.hpp.
|
private |
The menu view handling the selected menu item.
Definition at line 50 of file MenuOutput.hpp.
Referenced by attach(), lock(), menu(), unlock(), updateVisible(), and view().
|
private |
The maximum number of visible items.
Definition at line 85 of file MenuOutput.hpp.
Referenced by attach(), lock(), duds::ui::menu::MenuOutputAccess::maxVisible(), maxVisible(), and updateVisible().
|
private |
Index of the selected item from the container of all menu items.
When a MenuOutputAccess is operating upon this object, it is the currently selected item. Otherwise it is the previously selected item.
Definition at line 91 of file MenuOutput.hpp.
Referenced by duds::ui::menu::MenuOutputAccess::selectedIndex(), and updateVisible().
|
private |
Index of the selected item within the list of currently visible menu items.
When a MenuOutputAccess is not operating upon this object, this value has no meaning. Otherwise, it is the number of items from the first in the visible list to the selected item. If the menu is empty, this value should not be used.
Definition at line 73 of file MenuOutput.hpp.
Referenced by duds::ui::menu::MenuOutputAccess::selectedVisible(), and updateVisible().
|
private |
Iterator to the currently selected item.
It will be the end iterator only if no item is selected. A view of a menu with at least one item will have a selected item when a MenuOutputAccess object is operating on the view.
Definition at line 65 of file MenuOutput.hpp.
Referenced by duds::ui::menu::MenuOutputAccess::selectedItem(), duds::ui::menu::MenuOutputAccess::selectedIter(), and updateVisible().
|
private |
True if the visible list includes the first visible item on the menu.
Definition at line 104 of file MenuOutput.hpp.
Referenced by duds::ui::menu::MenuOutputAccess::showingAll(), duds::ui::menu::MenuOutputAccess::showingFirst(), and updateVisible().
|
private |
True if the visible list includes the last visible item on the menu.
Definition at line 108 of file MenuOutput.hpp.
Referenced by duds::ui::menu::MenuOutputAccess::showingAll(), duds::ui::menu::MenuOutputAccess::showingLast(), and updateVisible().
|
private |
The menu's update index value when this subview was last rendered.
Definition at line 95 of file MenuOutput.hpp.
Referenced by attach(), lock(), maxVisible(), and updateVisible().
|
private |
True when the view has changed since the last access, and false otherwise.
Changed in updateVisible().
Definition at line 100 of file MenuOutput.hpp.
Referenced by changed(), and updateVisible().