/* * File: InputHelper.h * Description: Handles input validation and error handling * Author: Trenser * Created: 18-May-2026 */ #pragma once #include #include #include #include namespace util { /* * Function: read * Description: Reads input from console into a variable of type T. * Parameters: * value - reference to a variable of type T where the input will be stored * Returns: * void - throws runtime_error if input is invalid */ template inline void read(T& value) { if (!(std::cin >> value)) { std::cin.clear(); std::cin.ignore(std::numeric_limits::max(), '\n'); throw std::runtime_error("Invalid console input"); } } /* * Function: read * Description: Reads a line of text input from console into a string and cleans it up. * Parameters: * value - reference to a string where the input will be stored * Returns: * void - no return value */ inline void read(std::string& value) { std::getline(std::cin >> std::ws, value); std::string cleanedValue; for (int index = 0; index < value.length(); index++) { if (value[index] != ',') { cleanedValue += value[index]; } } value = cleanedValue; } /* * Function: pressEnter * Description: Pauses execution until the user presses Enter. * Parameters: None * Returns: void - no return value */ inline void pressEnter() { std::cout << std::endl; system("pause"); } }