menu.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef MENU_H_INCLUDED
  2. #define MENU_H_INCLUDED
  3. #include <map>
  4. #include <string>
  5. typedef int (*menuFuncPtr)();
  6. struct MenuItem
  7. {
  8. std::string title;
  9. menuFuncPtr item;
  10. MenuItem(const std::string _title, const menuFuncPtr _item) : title(_title), item(_item) {};
  11. };
  12. typedef std::map<char, MenuItem> menuMap;
  13. typedef menuMap::iterator menuMapIt;
  14. typedef menuMap::const_iterator menuMapCIt;
  15. typedef menuMap::value_type menuMapValue;
  16. typedef menuMap::key_type menuMapKey;
  17. typedef menuMap::mapped_type menuMapItem;
  18. class CMenu
  19. {
  20. protected:
  21. std::string m_Title;
  22. std::string m_Prefix;
  23. std::string m_Divider;
  24. menuMap m_MenuMap;
  25. static const char STR_DEFAULT_TITLE[];
  26. static const char STR_DEFAULT_PREFIX[];
  27. static const char STR_DEFAULT_DIVIDER[];
  28. public:
  29. CMenu() : m_Title(STR_DEFAULT_TITLE),
  30. m_Prefix(STR_DEFAULT_PREFIX),
  31. m_Divider(STR_DEFAULT_DIVIDER) {};
  32. CMenu(const std::string _title) : m_Title(_title),
  33. m_Prefix(STR_DEFAULT_PREFIX),
  34. m_Divider(STR_DEFAULT_DIVIDER) {};
  35. virtual ~CMenu() {};
  36. virtual bool addItem(const menuMapValue &_item);
  37. virtual bool addItem(const menuMapKey _key, const menuMapItem &_item);
  38. virtual bool addItem(const menuMapKey _key, const std::string _title, const menuFuncPtr _item);
  39. virtual void draw() const;
  40. virtual int selectItem() const;
  41. virtual void setTitle(const std::string _title) {m_Title = _title;}
  42. virtual void setPrefix(const std::string _prefix) {m_Prefix = _prefix;}
  43. virtual void setDivider(const std::string _divider) {m_Divider = _divider;}
  44. private:
  45. CMenu(const CMenu& _copy) {};
  46. CMenu& operator=(const CMenu& _copy) {return *this;};
  47. };
  48. #endif // MENU_H_INCLUDED