00001 #ifndef INPUT_LIBRARY_HEADER_INCLUDED
00002 #define INPUT_LIBRARY_HEADER_INCLUDED
00003
00004 #include <iostream>
00005 #include "arrutil.h"
00006
00007 template <typename ItemType>
00008 ItemType get_bounded_both(ItemType lower, ItemType upper,
00009 std::istream & read_from = std::cin,
00010 const char prompt[] = "Enter value: ",
00011 bool supress = false,
00012 const char errmsg[] = "Invalid -- try again!\n")
00013 {
00014 ItemType value;
00015 if (read_from == std::cin)
00016 {
00017 std::cout << prompt;
00018 }
00019 read_from >> value;
00020 while ((value > upper) || (value < lower))
00021 {
00022 if (!supress)
00023 {
00024 std::cerr << "Value must be between " << lower
00025 << " and " << upper << " inclusive!\n";
00026 }
00027 std::cerr << errmsg;
00028 if (read_from == std::cin)
00029 {
00030 std::cout << prompt;
00031 }
00032 read_from >> value;
00033 }
00034 return value;
00035 }
00036
00037 template <typename ItemType>
00038 ItemType get_bounded_upper(ItemType upper,
00039 std::istream & read_from = std::cin,
00040 const char prompt[] = "Enter value: ",
00041 bool supress = false,
00042 const char errmsg[] = "Invalid -- try again!\n")
00043 {
00044 ItemType value;
00045 if (read_from == std::cin)
00046 {
00047 std::cout << prompt;
00048 }
00049 read_from >> value;
00050 while (value > upper)
00051 {
00052 if (!supress)
00053 {
00054 std::cerr << "Value must be less than or equal to " << upper
00055 << "!\n";
00056 }
00057 std::cerr << errmsg;
00058 if (read_from == std::cin)
00059 {
00060 std::cout << prompt;
00061 }
00062 read_from >> value;
00063 }
00064 return value;
00065 }
00066
00067 template <typename ItemType>
00068 ItemType get_bounded_lower(ItemType lower,
00069 std::istream & read_from = std::cin,
00070 const char prompt[] = "Enter value: ",
00071 bool supress = false,
00072 const char errmsg[] = "Invalid -- try again!\n")
00073 {
00074 ItemType value;
00075 if (read_from == std::cin)
00076 {
00077 std::cout << prompt;
00078 }
00079 read_from >> value;
00080 while (value < lower)
00081 {
00082 if (!supress)
00083 {
00084 std::cerr << "Value must be greater than or equal to " << lower
00085 << "!\n";
00086 }
00087 std::cerr << errmsg;
00088 if (read_from == std::cin)
00089 {
00090 std::cout << prompt;
00091 }
00092 read_from >> value;
00093 }
00094 return value;
00095 }
00096
00097 char get_in_set(const char valid[] = "YyNn",
00098 const char prompt[] = "Would you like to quit? ",
00099 const char errmsg[] = "Invalid response! Choose Yes or No!\n");
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 #endif