66 lines
1.4 KiB
C++
66 lines
1.4 KiB
C++
//
|
|
// Created by TheSkyWinds on 10/25/24.
|
|
//
|
|
|
|
// TODO: Add documentation on how it is used.
|
|
// TODO: Figure out how to document code.
|
|
|
|
#ifndef ERRORSEAL_H
|
|
#define ERRORSEAL_H
|
|
|
|
#include <iostream>
|
|
#include <limits>
|
|
|
|
namespace error {
|
|
// Clears the buffer for std::cin.
|
|
inline void ignoreLine() {
|
|
|
|
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
|
|
|
}
|
|
|
|
/*
|
|
* cinError() returns true if an error occurs.
|
|
* cinError() also clears up the error and buffer, so that the program can continue to work.
|
|
*/
|
|
inline bool cinError(){
|
|
bool errorState{false};
|
|
if (!std::cin) {
|
|
|
|
if (std::cin.eof()) {
|
|
std::exit(0); // Shut down the program now
|
|
}
|
|
|
|
std::cin.clear();
|
|
ignoreLine();
|
|
errorState = true;
|
|
}
|
|
return errorState;
|
|
}
|
|
|
|
/*
|
|
* Throws a generic, undefined error message, but does the same as the function above.
|
|
* Primarily used for quick and easy debugging.
|
|
*/
|
|
|
|
inline bool cinErrorVerbose() {
|
|
bool errorState{false};
|
|
if (!std::cin) {
|
|
|
|
if (std::cin.eof()) {
|
|
std::exit(0);
|
|
}
|
|
|
|
std::cin.clear();
|
|
ignoreLine();
|
|
|
|
std::cerr << "Whoops, you broke the program!\n";
|
|
errorState = true;
|
|
}
|
|
return errorState;
|
|
}
|
|
}
|
|
|
|
|
|
#endif //ERRORSEAL_H
|