From ad12b4614276f5eff596bbfb3338caa0de728409 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 1 May 2022 10:21:14 +0300 Subject: Autocommit at 01.05.2022 @ 10:21 --- src/ConsoleInterface/Menu.cpp | 11 +++++++---- src/List/List.cpp | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ConsoleInterface/Menu.cpp b/src/ConsoleInterface/Menu.cpp index 27471a6..669fb6c 100644 --- a/src/ConsoleInterface/Menu.cpp +++ b/src/ConsoleInterface/Menu.cpp @@ -2,19 +2,22 @@ #include "Toolbox.h" Menu::Menu(const Command* commands, unsigned commandCount) { - menuOptions = List(); - for (unsigned i = 0; i < commandCount; i++) - menuOptions.add(commands[i]); + menuOptions = List(commands, commandCount); } void Menu::navigate() const { + if (menuOptions.get_count() == 0) { + std::cout << "Menu is empty!" << std::endl; + return; + } + resetOrderedList(); for (unsigned i = 0; i < menuOptions.get_count(); i++) printOrderedListElem(menuOptions[i].get_nameInMenu()); unsigned buffer = 0; while (0 == buffer || buffer >= menuOptions.get_count()) { - std::cout << "Execute No [0-" << menuOptions.get_count() << "]: "; + std::cout << "Execute No [1-" << menuOptions.get_count() << "]: "; std::cin >> buffer; } diff --git a/src/List/List.cpp b/src/List/List.cpp index fbd3288..bdb9b4a 100644 --- a/src/List/List.cpp +++ b/src/List/List.cpp @@ -29,8 +29,9 @@ void List::copyFrom(const List& other) { /* Public */ template -List::List(const T* elements, unsigned elementsCount) { - +List::List(const T* elements, unsigned elementsCount) : List() { + for (unsigned i = 0; i < elementsCount; i++) + add(elements[i]); } template -- cgit v1.3.1-26-gb76a