GridComputing
Job Management in Grid Computing
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
consolereader.h File Reference
#include <iostream>
#include <string>
#include <stdexcept>
#include <sstream>
#include <functional>

Go to the source code of this file.

Classes

class  InvalidValue
 Exception thrown when an invalid value is read from the console. More...
 
class  EOFCharacterValue
 Exception thrown when Ctrl+Z (Windows) or Ctrl+D (Linux) is pressed in the console. More...
 

Functions

template<typename T >
ReadValue (const std::string &prompt, std::function< bool(T)> validator)
 Reads a value of the given type T from the console.
 
template<typename T >
ReadValue (const std::string &prompt)
 See ReadValue<T>(const std::string&, std::function<bool(T)>)
 
template<>
std::string ReadValue< std::string > (const std::string &prompt, std::function< bool(std::string)> validator)
 

Function Documentation

template<typename T >
T ReadValue ( const std::string &  prompt,
std::function< bool(T)>  validator 
)

Reads a value of the given type T from the console.

Parameters
promptMessage to display before requiring a value to be entered in the console
validatorA function that accepts that read value as argument and it must return true for the value to be considered valid int value = ReadValue<int>("Age: ", [](int val) { return val > 0 && val < 150; }
template<typename T >
T ReadValue ( const std::string &  prompt)

See ReadValue<T>(const std::string&, std::function<bool(T)>)

template<>
std::string ReadValue< std::string > ( const std::string &  prompt,
std::function< bool(std::string)>  validator 
)