C++ Samples
Demonstrates how to create a C++ application using the VideoXpert SDK
CppSamples::Common::OptionSelector< T > Class Template Reference

This helper class prints a collection of options and chose a user defined option. More...

#include <OptionSelector.h>

Public Member Functions

 OptionSelector ()
 
 ~OptionSelector ()
 
void AddItem (std::string name, T item)
 The given name and item will be added to the collection. More...
 
bool SelectOption (T *result)
 Prints a collection of options and chose a user defined one. More...
 

Public Attributes

bool ClearScreenAlways
 
std::string Heading
 
bool ShowHeaderFooter
 
std::string OptionSeperator
 
bool RepeatInput
 

Private Attributes

std::vector< std::string > _names
 
std::vector< T > _items
 

Detailed Description

template<class T>
class CppSamples::Common::OptionSelector< T >

This helper class prints a collection of options and chose a user defined option.

Definition at line 18 of file OptionSelector.h.

Constructor & Destructor Documentation

template<class T >
CppSamples::Common::OptionSelector< T >::OptionSelector ( )

Definition at line 49 of file OptionSelector.h.

template<class T>
CppSamples::Common::OptionSelector< T >::~OptionSelector ( )
inline

Definition at line 21 of file OptionSelector.h.

21 { }

Member Function Documentation

template<class T >
void CppSamples::Common::OptionSelector< T >::AddItem ( std::string  name,
item 
)

The given name and item will be added to the collection.

Parameters
nameString value of an option to be displayed.
itemThe item to be added to the collection.

Definition at line 63 of file OptionSelector.h.

63  {
64  _names.push_back(name);
65  _items.push_back(item);
66  }
std::vector< std::string > _names
template<class T >
bool CppSamples::Common::OptionSelector< T >::SelectOption ( T *  result)

Prints a collection of options and chose a user defined one.

Parameters
resultThe selected item will be assigned to this pointer.
Returns
True if user selects a valid option. False otherwise.

Definition at line 74 of file OptionSelector.h.

74  {
75 
76  bool isInvalidOption = false;
77  while (true) {
80 
81  if (ShowHeaderFooter)
82  std::cout << "========================================================" << "\n\t";
83  std::cout << Heading;
84  if (ShowHeaderFooter)
85  std::cout << "\n" << "========================================================";
86 
87  int index = 0;
88  int size = _names.size();
89  for (; index < size; index++)
90  std::cout << OptionSeperator << (index + 1) << ". " << _names[index];
91 
92  if (ShowHeaderFooter)
93  std::cout << "\n========================================================";
94 
95  if (isInvalidOption) {
96  std::cout << "\n" << "Invalid option!!!";
97  isInvalidOption = false;
98  }
99 
100  std::cout << "\n" << "Select your option [1-" << index << "] : ";
101  int option = Utility::ReadInt();
102  if (option > 0 && option <= index) {
103  *result = _items[option - 1];
104  return true;
105  }
106 
107  if (!RepeatInput)
108  break;
109 
110  isInvalidOption = true;
111  }
112 
113  return false;
114  }
static int ReadInt()
Read an integer from console input
Definition: Utility.cpp:269
std::vector< std::string > _names
static void ClearScreen()
Clear the screen
Definition: Utility.cpp:249

Member Data Documentation

template<class T>
std::vector<T> CppSamples::Common::OptionSelector< T >::_items
private

Definition at line 45 of file OptionSelector.h.

template<class T>
std::vector<std::string> CppSamples::Common::OptionSelector< T >::_names
private

Definition at line 44 of file OptionSelector.h.

template<class T>
bool CppSamples::Common::OptionSelector< T >::ClearScreenAlways

Definition at line 37 of file OptionSelector.h.

template<class T>
std::string CppSamples::Common::OptionSelector< T >::Heading

Definition at line 38 of file OptionSelector.h.

template<class T>
std::string CppSamples::Common::OptionSelector< T >::OptionSeperator

Definition at line 40 of file OptionSelector.h.

template<class T>
bool CppSamples::Common::OptionSelector< T >::RepeatInput

Definition at line 41 of file OptionSelector.h.

template<class T>
bool CppSamples::Common::OptionSelector< T >::ShowHeaderFooter

Definition at line 39 of file OptionSelector.h.


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