Setup codebase

This commit is contained in:
Joel Thomas
2026-05-19 09:56:36 +05:30
parent f39f9d0e79
commit a7ad188801
59 changed files with 3840 additions and 0 deletions
@@ -0,0 +1,58 @@
/*
* File: InputHelper.h
* Description: Handles input validation and error handling
* Author: Trenser
* Created: 18-May-2026
*/
#pragma once
#include <iostream>
#include <limits>
#include <string>
#include <stdexcept>
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 <typename T>
inline void read(T& value)
{
if (!(std::cin >> value))
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
throw std::runtime_error("Invalid console input");
}
}
/*
* Function: read
* Description: Reads a line of text input from console into a string.
* 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);
}
/*
* Function: pressEnter
* Description: Pauses execution until the user presses Enter.
* Parameters: None
* Returns: void - no return value
*/
inline void pressEnter()
{
system("pause");
}
}