Files
joelthomastrenser 53713f444b Implement serialization/deserialization and persistent storage across services
- Add serialize/deserialize support for core models
- Add file-based load/save functions in management services
- Introduce FileManager, Config, Utility and helper utilities
- Persist observer IDs for notification services
- Resolve object relationships during load (services, bookings, invoices, job cards)
- Add controller-level loadSystemData/saveSystemData
- Load data at app startup and save on shutdown
2026-05-22 16:50:28 +05:30

67 lines
1.7 KiB
C++

/*
* 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 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()
{
system("pause");
}
}