CCAFFEINE
0.8.8
|
00001 #ifndef __IO_H__ 00002 #define __IO_H__ 00003 00004 #if defined(__SUNPRO_CC) || defined(__sgi) 00005 #include <stdio.h> 00006 #include <stdlib.h> 00007 #include <stdarg.h> 00008 #else 00009 //#include <cstdio> 00010 //#include <cstdlib> 00011 //#include <cstdarg> 00012 #include <stdio.h> 00013 #include <stdlib.h> 00014 #include <stdarg.h> 00015 #endif //__SUNPRO_CC 00016 00017 #include <string> 00018 00019 00028 #define IO_C(Q) const_cast<const char *>(Q) 00029 //No way to get macros to include comma'd arguments -- holy cow: 00030 #define IO_dn1(X) IO::dn(__FILE__, __LINE__, X ) 00031 #define IO_dn2(X, Y) IO::dn(__FILE__, __LINE__, (X), (Y) ) 00032 #define IO_dn3(X, Y, Z) IO::dn(__FILE__, __LINE__, (X), (Y), (Z) ) 00033 #define IO_dn4(X, Y, Z, A) IO::dn(__FILE__, __LINE__, (X), (Y), (Z), (A) ) 00034 #define IO_dn5(X, Y, Z, A, B) IO::dn(__FILE__, __LINE__, (X), (Y), (Z), (A), (B)) 00035 #define IO_dn6(X, Y, Z, A, B, C) IO::dn(__FILE__, __LINE__, (X), (Y), (Z), (A), (B), (C)) 00036 #define IO_dn7(X, Y, Z, A, B, C, D) IO::dn(__FILE__, __LINE__, (X), (Y), (Z), (A), (B), (C), (D)) 00037 00038 //No way to get macros to include comma'd arguments -- holy cow: 00039 #define IO_en1(X) IO::errorOut(IO_C(__FILE__), __LINE__, IO_C(X) ) 00040 #define IO_en2(X, Y) IO::errorOut(IO_C(__FILE__), __LINE__, IO_C(X), (Y) ) 00041 #define IO_en3(X, Y, Z) IO::errorOut(IO_C(__FILE__), __LINE__, IO_C(X), (Y), (Z) ) 00042 #define IO_en4(X, Y, Z, A) IO::errorOut(IO_C(__FILE__), __LINE__, IO_C(X), (Y), (Z), (A) ) 00043 #define IO_en5(X, Y, Z, A, B) IO::errorOut(IO_C(__FILE__), __LINE__, IO_C(X), (Y), (Z), (A), (B)) 00044 #define IO_en6(X, Y, Z, A, B, C) IO::errorOut(IO_C(__FILE__), __LINE__, IO_C(X), (Y), (Z), (A), (B), (C)) 00045 #define IO_en7(X, Y, Z, A, B, C, D) IO::errorOut(IO_C(__FILE__), __LINE__, IO_C(X), (Y), (Z), (A), (B), (C), (D)) 00046 00047 // Same thing only returns the string that must subsequently be freed. 00048 #define IO_sn1(X) IO::sn(__FILE__, __LINE__, X ) 00049 #define IO_sn2(X, Y) IO::sn(__FILE__, __LINE__, (X), (Y) ) 00050 #define IO_sn3(X, Y, Z) IO::sn(__FILE__, __LINE__, (X), (Y), (Z) ) 00051 #define IO_sn4(X, Y, Z, A) IO::sn(__FILE__, __LINE__, (X), (Y), (Z), (A) ) 00052 #define IO_sn5(X, Y, Z, A, B) IO::sn(__FILE__, __LINE__, (X), (Y), (Z), (A), (B)) 00053 #define IO_sn6(X, Y, Z, A, B, C) IO::sn(__FILE__, __LINE__, (X), (Y), (Z), (A), (B), (C)) 00054 #define IO_sn7(X, Y, Z, A, B, C, D) IO::sn(__FILE__, __LINE__, (X), (Y), (Z), (A), (B), (C), (D)) 00055 00056 class IO { 00057 00058 private: 00059 00060 static bool debug; 00061 00062 // these are default init to stdout/stdin/stderr in IO.cxx 00063 #if 1 //old 00064 00065 static FILE* _out; 00066 static FILE* _in; 00067 static FILE* _err; 00068 #else 00069 FILE * _out; 00070 FILE * _in; 00071 FILE * _err; 00072 #endif 00073 00074 public: 00075 00076 IO(){} 00077 00078 static bool getDebug() { return IO::debug; } 00079 00080 static void setDebug(bool tf) { 00081 IO::debug = tf; 00082 } 00083 00085 static char *getline(FILE *fp, char *line, long lineMaxSize); 00086 00088 static char *getline(char *line, long lineMaxSize); 00089 00090 00092 static void p(char* fmt, ...) ; 00093 static void p(char const* fmt, ...) ; 00094 00096 static void pn(char * fmt, ...) ; 00097 static void pn(const char * fmt, ...) ; 00098 00100 static void e(const char* fmt, ...) ; 00101 00103 static void err(const char* fmt, va_list ap); 00104 00106 static void en(const char* fmt, ...); 00107 static void en(const std::string & s); 00108 00110 static void errorOut(const char * file, const int line, const char * fmt, ...); 00111 00113 // static void errorOut(char const * fname, const int lineno, char const * fmt, ... ); 00114 00116 static void errn(const char* fmt, va_list ap); 00117 00119 static void dn(const char* file, const int line, 00120 const char* ufmt, ...); 00121 00123 static /*CFREE*/ char * sn(const char* file, const int line, 00124 const char* ufmt, ...); 00125 00128 static void initId(int pid); 00129 00131 static int getId(); 00132 00133 00135 static void setOut(FILE *out) ; 00136 static void setErr(FILE *err) ; 00137 static void setIn(FILE *in) ; 00138 00140 static FILE *out() ; 00141 static FILE *err() ; 00142 static FILE *in() ; 00143 00145 static FILE *getOut() ; 00146 static FILE *getErr() ; 00147 static FILE *getIn() ; 00148 00150 static void testMacros(); 00151 }; 00152 #endif // __IO_H__ 00153