1D Heat Equation Solver 1.0
Computational Methods Assignment 2025
Loading...
Searching...
No Matches
user_input.h File Reference

Utility functions for safe user input from the console. More...

#include <functional>
#include <iostream>
#include <limits>
#include <string>
Include dependency graph for user_input.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename T>
askForNumber (const std::string &prompt, const std::function< bool(T)> &isValid, const std::string &errorMessage)
 Generic template for asking a numeric value from the user.
int askForInteger (const std::string &prompt, const std::function< bool(int)> &isValid, const std::string &errorMessage)
 Ask for an integer value from the user.
double askForDouble (const std::string &prompt, const std::function< bool(double)> &isValid, const std::string &errorMessage)
 Ask for a floating-point value from the user.

Detailed Description

Utility functions for safe user input from the console.

Provides generic and typed functions to read and validate numeric values from the standard input stream, with customizable prompts and validation rules.

Definition in file user_input.h.

Function Documentation

◆ askForDouble()

double askForDouble ( const std::string & prompt,
const std::function< bool(double)> & isValid,
const std::string & errorMessage )

Ask for a floating-point value from the user.

Parameters
promptMessage shown before user input.
isValidValidation function returning true if the input is acceptable.
errorMessageMessage displayed when validation fails.
Returns
double The valid floating-point number entered by the user.

Ask for a floating-point value from the user.

Definition at line 17 of file user_input.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ askForInteger()

int askForInteger ( const std::string & prompt,
const std::function< bool(int)> & isValid,
const std::string & errorMessage )

Ask for an integer value from the user.

Parameters
promptMessage shown before user input.
isValidValidation function returning true if the input is acceptable.
errorMessageMessage displayed when validation fails.
Returns
int The valid integer entered by the user.

Ask for an integer value from the user.

Definition at line 6 of file user_input.cpp.

Here is the call graph for this function:

◆ askForNumber()

template<typename T>
T askForNumber ( const std::string & prompt,
const std::function< bool(T)> & isValid,
const std::string & errorMessage )

Generic template for asking a numeric value from the user.

This function continuously asks the user for input until a valid number is provided and passes the validation rule.

Template Parameters
TType of number (int, double, etc.)
Parameters
promptMessage shown before user input.
isValidValidation function returning true if the input is acceptable.
errorMessageMessage displayed when validation fails.
Returns
T The valid numeric value entered by the user.

Definition at line 30 of file user_input.h.

Here is the caller graph for this function: