// Widely used declarations. // // File: basic.h // Author: course (Bob Walton , // Attila Bodis ) // Version: 5 // This file contains declarations which are frequently // used in this course, and declarations that are // needed to compensate for differences between various // supported computer systems. // // You should use the declarations below for error and // error_jmp wherever appropriate. Each program must // provide its own implementation of error and // error_jmp if the program uses these. You should use // enable_out_of_memory_error(true) when you do not // wish to check for memory allocation failure in // your own code. // The following is a standard way of preventing // problems when programmers include a file more than // once. The first inclusion of this file defines // _BASIC_H_. Subsequent inclusions of this file see // this definition and skip the contents of the file. // #ifndef _BASIC_H_ #define _BASIC_H_ // Standard inclusions: // #include // Standard library. #include // I/O streams (cin, cout, // <<, >>, etc.). #include "estream.h" // Echo streams (see estream.h // for documentation). #include // I/O stream manipulators // (setw, setprecision, etc.). #include // String functions // (strcmp, etc.). #include // Character type functions // (isalpha, toupper, etc.). #include // Setjmp, longjmp, and jmp_buf. // Debugging; uncomment the following line to disable // debugging by making the assert macro compile no code. // // #define NDEBUG // #include // Assert macro. // These are supposed to be defined in , but // sometimes aren't... // #ifndef EXIT_SUCCESS #define EXIT_SUCCESS 0 #endif #ifndef EXIT_FAILURE #define EXIT_FAILURE 1 #endif // The max and min functions, overloaded to work with // ints and doubles: // inline int max(int i, int j) { return ((i > j) ? i : j); } inline int min(int i, int j) { return ((i < j) ? i : j); } inline int max(int i, int j, int k) { return ((i > j) ? ((i > k) ? i : k) : ((j > k) ? j : k)); } inline int min(int i, int j, int k) { return ((i < j) ? ((i < k) ? i : k) : ((j < k) ? j : k)); } inline double max(double i, double j) { return ((i > j) ? i : j); } inline double min(double i, double j) { return ((i < j) ? i : j); } inline double max(double i, double j, double k) { return ((i > j) ? ((i > k) ? i : k) : ((j > k) ? j : k)); } inline double min(double i, double j, double k) { return ((i < j) ? ((i < k) ? i : k) : ((j < k) ? j : k)); } // The CPU time function; returns the amount of CPU // time used so far by this program, in seconds. // double cputime(); // Error function prototypes; each program must // provide its own definitions of these. Only the // ones used by a program need to be defined. Error // messages are of the general form: // // \nERROR: .\n // void error (char *s); void error (char *s, char *v); void error (char *s, char v); void error (char *s, int v); void error (char *s, long v); void error (char *s, double v); // Setjmp buffer for errors. Programs that use this // setjmp buffer typically define the error routines // above such that they do a longjmp to error_jmp after // printing their error message (see error.cc for // documentation). // extern jmp_buf error_jmp; // Hardware-dependent return type to be used when you // want to return a pointer to a jmp_buf. Using // jmp_buf * does not seem to work at all. // #ifdef __hp9000s800 typedef double * jmp_buf_pointer; #else typedef int * jmp_buf_pointer; #endif // Enable or disable the calling of error by memory // allocation if out of memory. Enable calling error // if enable_flag true; disable if false. // void enable_out_of_memory_error (bool enable_flag); #endif // _BASIC_H_