C++ Samples
Demonstrates how to create a C++ application using the VideoXpert SDK
CppSamples::Common::MenuItem Class Reference

MenuItem is a Plugin. It represents a menu. More...

#include <MenuItem.h>

Public Member Functions

 MenuItem (const std::string description)
 
 ~MenuItem ()
 
CppSamples::Common::PluginRun (CppSamples::Common::DataModel *dataModel) override
 Print all the sub menu under this menu and accept a user input to select submenu to continue. More...
 
void AddBackMenu ()
 A default Back menu will be added as submenu of this. More...
 
void AddChild (Plugin *plugin)
 The given plugin item will be added as submenu of this. More...
 
void AddExitMenu ()
 A default Exit menu will be added as submenu of this. More...
 
- Public Member Functions inherited from CppSamples::Common::Plugin
 Plugin (const std::string description)
 
virtual ~Plugin ()
 
std::string GetDescription () const
 Gets the description of this plugin. More...
 
PluginGetParent () const
 Gets the reference to the parent of this plugin. More...
 
void SetParent (Plugin *parent)
 Sets the reference to the parent of this plugin. More...
 

Private Attributes

std::vector< Plugin * > _children
 

Detailed Description

MenuItem is a Plugin. It represents a menu.

Definition at line 12 of file MenuItem.h.

Inherits CppSamples::Common::Plugin.

Constructor & Destructor Documentation

CppSamples::Common::MenuItem::MenuItem ( const std::string  description)
inline

Definition at line 14 of file MenuItem.h.

14 : CppSamples::Common::Plugin(description) { }
Plugin is the abstract class which can be a menu item and/or a sample. Every sample and menu item mus...
Definition: Plugin.h:33
CppSamples::Common::MenuItem::~MenuItem ( )
inline

Definition at line 15 of file MenuItem.h.

15 { }

Member Function Documentation

void MenuItem::AddBackMenu ( )

A default Back menu will be added as submenu of this.

Definition at line 36 of file MenuItem.cpp.

36  {
37  // Add a default back menu
38  AddChild(new BackMenu());
39 }
void AddChild(Plugin *plugin)
The given plugin item will be added as submenu of this.
Definition: MenuItem.cpp:41
This class represents a default Back menu
Definition: MenuItem.h:46
void MenuItem::AddChild ( Plugin plugin)

The given plugin item will be added as submenu of this.

Parameters
pluginInstance of Plugin to be added.

Definition at line 41 of file MenuItem.cpp.

41  {
42  // While adding a child plugin, set the parent-child relationship.
43  plugin->SetParent(this);
44  // Add child plugin to the collection.
45  _children.push_back(plugin);
46 }
void SetParent(Plugin *parent)
Sets the reference to the parent of this plugin.
Definition: Plugin.h:58
std::vector< Plugin * > _children
Definition: MenuItem.h:40
void MenuItem::AddExitMenu ( )

A default Exit menu will be added as submenu of this.

Definition at line 48 of file MenuItem.cpp.

48  {
49  // Add a default exit menu
50  AddChild(new ExitMenu());
51 }
This class represents a default Exit menu
Definition: MenuItem.h:68
void AddChild(Plugin *plugin)
The given plugin item will be added as submenu of this.
Definition: MenuItem.cpp:41
Plugin * MenuItem::Run ( CppSamples::Common::DataModel dataModel)
overridevirtual

Print all the sub menu under this menu and accept a user input to select submenu to continue.

Parameters
dataModelInstance of data model.

Implements CppSamples::Common::Plugin.

Definition at line 13 of file MenuItem.cpp.

13  {
14 
15  // Define an instance of OptionSelector class.
16  OptionSelector<Plugin*> optionSelector;
17  // Heading of menu
18  optionSelector.Heading = GetDescription();
19  // Clear the screen before start printing
20  optionSelector.ClearScreenAlways = true;
21  // Print header and footer for menu
22  optionSelector.ShowHeaderFooter = true;
23  // Ensure to print the menu after user input
24  optionSelector.RepeatInput = true;
25 
26  // Add all children to the option selector
27  for (int i = 0; i < (int)_children.size(); i++)
28  optionSelector.AddItem(_children[i]->GetDescription(), _children[i]);
29 
30  // Print the menu and accept user input using OptionSelector.
31  Plugin* result = nullptr;
32  optionSelector.SelectOption(&result);
33  return result;
34 }
std::vector< Plugin * > _children
Definition: MenuItem.h:40
Plugin is the abstract class which can be a menu item and/or a sample. Every sample and menu item mus...
Definition: Plugin.h:33
bool SelectOption(T *result)
Prints a collection of options and chose a user defined one.
void AddItem(std::string name, T item)
The given name and item will be added to the collection.
std::string GetDescription() const
Gets the description of this plugin.
Definition: Plugin.h:41
This helper class prints a collection of options and chose a user defined option. ...

Member Data Documentation

std::vector<Plugin*> CppSamples::Common::MenuItem::_children
private

Definition at line 40 of file MenuItem.h.


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