33 using std::ostringstream;
42 template <
typename CharT>
43 std::streamsize ignore_line (std::basic_istream<CharT>& in,
bool always_discard =
false );
71 inline void Prompt (
string prompt,
string & val)
74 ignore_line( std::cin );
75 getline(std::cin, val);
98 inline void Prompt (
string prompt, T & val)
103 while(std::cin.fail())
106 std::cin.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
132 inline void Prompt(
string prompt,T& val, T minval, T maxval)
135 while ( val < minval || val > maxval)
137 std::cout <<
"The entered value must be with the range " << minval <<
" to " << maxval << std::endl;
161 std::cout << prompt <<
" (Y/N)"<< std::endl;
162 ignore_line( std::cin );
164 std::cin >> user_input;
165 if ( user_input ==
"Y" || user_input ==
"y")
169 if (user_input ==
"N" || user_input ==
"n")
193 struct timespec tim, tim2;
195 tim.tv_nsec = time*10000000;
196 nanosleep(&tim , &tim2);
216 time_t rawtime = time(0);
217 struct tm * timeinfo;
219 timeinfo = localtime ( &rawtime );
220 return asctime (timeinfo);
232 struct tm * now = localtime( & t );
234 tm << (now->tm_year + 1900) <<
'-' 235 << setfill(
'0') << setw(2) <<(now->tm_mon + 1) <<
'-' 236 << setfill(
'0') << setw(2) << now->tm_mday <<
"-" 237 << setfill(
'0') << setw(2) << now->tm_hour <<
":" 238 << setfill(
'0') << setw(2) << now->tm_min <<
":" 239 << setfill(
'0') << setw(2) << now->tm_sec ;
270 std::transform(input.begin(), input.end(), input.begin(),
271 [](
unsigned char c){
return std::tolower(c); });
281 std::transform(input.begin(), input.end(), input.begin(),
282 [](
unsigned char c){
return std::toupper(c); });
295 if(input==
"true" || input ==
"1"){
return true;}
296 if(input==
"false" || input ==
"0"){
return false;}
311 inline bool VeryClose(
float A,
float B,
float epsilon = 0.0005f)
313 return (fabs(A - B) < epsilon);
324 template <
typename T>
342 std::random_device rd;
343 std::mt19937 gen(rd());
344 std::uniform_int_distribution<> dis(min,max);
358 for (
unsigned int i = 0; i < str.length(); i++)
359 if (! isdigit(str[i])){
return false;}
375 int temp = stoi(input);
378 catch(...){
return false;}
395 double temp = stod(input);
398 catch(...){
return false;}
419 std::cout <<
"The PassFail function is designed to take an expresson as its parameter\n something that evaluates to true or false\n you are not using the fuction properly stopping execution of your program. line number " <<__LINE__ << endl;
422 return (in) ?
"Pass":
"Fail";
452 for(
unsigned int loop=0;loop<size-1;loop++)
453 if(data[loop]>data[loop+1])
459 #ifndef DONT_DOCUMENT 464 template<
class T,
size_t N>
468 for(
unsigned int loop=0;loop<N -1;loop++)
469 if(data[loop]>data[loop+1])
494 for(
unsigned int loop=0;loop<size-1;loop++)
495 if(data[loop]<data[loop+1])
502 #ifndef DONT_DOCUMENT 507 template<
class T,
size_t N>
511 for(
unsigned int loop=0;loop<N -1;loop++)
512 if(data[loop]<data[loop+1])
527 inline string RED(
string input){
return string(
"\033[1;31m"+input+
"\033[0m");}
531 inline string GREEN(
string input){
return string(
"\033[1;32m"+input+
"\033[0m");}
535 inline string YELLOW(
string input){
return string(
"\033[1;33m"+input+
"\033[0m");}
539 inline string BLUE(
string input){
return string(
"\033[1;34m"+input+
"\033[0m");}
543 inline string MAGENTA(
string input){
return string(
"\033[1;35m"+input+
"\033[0m");}
547 inline string CYAN(
string input){
return string(
"\033[1;36m"+input+
"\033[0m");}
602 template <
typename T>
606 char * ptemp = abi::__cxa_demangle(
typeid(T).name(),0,0,&itemp);
607 std::string temp( ptemp);
621 #ifndef DONT_DOCUMENT 622 template <
typename CharT>
623 std::streamsize ignore_line (
624 std::basic_istream<CharT>& in,
bool always_discard )
626 std::streamsize nread = 0;
628 || ( in.rdbuf()->sungetc() != std::char_traits<CharT>::eof()
629 && in.get() != in.widen (
'\n' ) ) )
633 in.ignore ( std::numeric_limits<std::streamsize>::max(), in.widen (
'\n' ) );
void ClearScreen()
clear the screen
Definition: cmpslib19.h:203
char * GetTime()
get the time
Definition: cmpslib19.h:214
string GREEN(string input)
return a string formatted to display in color
Definition: cmpslib19.h:531
string BLUE(string input)
return a string formatted to display in color
Definition: cmpslib19.h:539
bool IsInteger(string input)
can this string be converted to an integer numeric value
Definition: cmpslib19.h:371
string ChangeToGreen()
returns a string formated to display in a color and does not reset to white
Definition: cmpslib19.h:558
string CYAN(string input)
return a string formatted to display in color
Definition: cmpslib19.h:547
string RED(string input)
return a string formatted to display in color
Definition: cmpslib19.h:527
bool PromptYN(string prompt)
for simple yes or no questions
Definition: cmpslib19.h:157
string ChangeToYellow()
returns a string formated to display in a color and does not reset to white
Definition: cmpslib19.h:563
string ChangeToWhite()
returns a string formated to display in a color and does not reset to white
Definition: cmpslib19.h:583
bool StringToBool(string input)
convert string to bool
Definition: cmpslib19.h:292
bool VeryClose(float A, float B, float epsilon=0.0005f)
compare two floats
Definition: cmpslib19.h:311
double StringToDouble(string input)
convert string to double
Definition: cmpslib19.h:262
void PositionCursor(int row, int col)
move the cursor to the position indcated by the row and column
Definition: cmpslib19.h:594
string ChangeToCyan()
returns a string formated to display in a color and does not reset to white
Definition: cmpslib19.h:578
std::string GetClassName(const T &a)
get the class name as a string for the object
Definition: cmpslib19.h:603
bool IsSortedDescending(T *data, unsigned int size)
is an array sorted a function that will tell you if an array is sorted
Definition: cmpslib19.h:492
string PassFail(int in)
convert bool value into "Pass" or "Fail"
Definition: cmpslib19.h:415
int StringToInteger(string input)
convert string to int
Definition: cmpslib19.h:255
string NumberToString(T Number)
convert a numveric value to string
Definition: cmpslib19.h:325
string ToUpperCase(string input)
convert string to uppercase
Definition: cmpslib19.h:279
string PF(int in)
same as PassFail same as PassFail
Definition: cmpslib19.h:430
string ToLowerCase(string input)
convert string to lowercase
Definition: cmpslib19.h:268
string ChangeToMagenta()
returns a string formated to display in a color and does not reset to white
Definition: cmpslib19.h:573
bool IsSortedAscending(T *data, unsigned int size)
is an array sorted a function that will tell you if an array is sorted
Definition: cmpslib19.h:450
string GetDateTime()
The DateTime as a string.
Definition: cmpslib19.h:229
void Prompt(string prompt, string &val)
use to request input from the user
Definition: cmpslib19.h:71
bool IsDouble(string input)
can this string be converted to an double value
Definition: cmpslib19.h:390
bool IsNumber(string str)
can this string be converted to a numeric value
Definition: cmpslib19.h:356
string YELLOW(string input)
return a string formatted to display in color
Definition: cmpslib19.h:535
void WaitHundredth(int time)
Do nothing for a period of time.
Definition: cmpslib19.h:191
string MAGENTA(string input)
return a string formatted to display in color
Definition: cmpslib19.h:543
int CreateRandomNumber(int min, int max)
create a random number
Definition: cmpslib19.h:340
string ChangeToRed()
returns a string formated to display in a color and does not reset to white
Definition: cmpslib19.h:553
string ChangeToBlue()
returns a string formated to display in a color and does not reset to white
Definition: cmpslib19.h:568