Sleipnir
|
00001 /***************************************************************************** 00002 * This file is provided under the Creative Commons Attribution 3.0 license. 00003 * 00004 * You are free to share, copy, distribute, transmit, or adapt this work 00005 * PROVIDED THAT you attribute the work to the authors listed below. 00006 * For more information, please see the following web page: 00007 * http://creativecommons.org/licenses/by/3.0/ 00008 * 00009 * This file is a component of the Sleipnir library for functional genomics, 00010 * authored by: 00011 * Curtis Huttenhower (chuttenh@princeton.edu) 00012 * Mark Schroeder 00013 * Maria D. Chikina 00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact) 00015 * 00016 * If you use this library, the included executable tools, or any related 00017 * code in your work, please cite the following publication: 00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and 00019 * Olga G. Troyanskaya. 00020 * "The Sleipnir library for computational functional genomics" 00021 *****************************************************************************/ 00022 #ifndef STDAFX_H 00023 #define STDAFX_H 00024 00025 #include <assert.h> 00026 #include <float.h> 00027 #include <limits.h> 00028 #include <math.h> 00029 #include <pthread.h> 00030 #include <stdio.h> 00031 #include <stdlib.h> 00032 #include <string.h> 00033 #include <sys/stat.h> 00034 #include <unistd.h> 00035 #ifdef _MSC_VER 00036 #include <fcntl.h> 00037 #include <io.h> 00038 #include <winsock2.h> 00039 00040 #define socklen_t int 00041 #else // _MSC_VER 00042 #include <dirent.h> 00043 #include <errno.h> 00044 #include <fcntl.h> 00045 #define __STDC_LIMIT_MACROS 00046 #include <netinet/in.h> 00047 #include <signal.h> 00048 #include <stdarg.h> 00049 #include <sys/mman.h> 00050 #include <sys/socket.h> 00051 #include <sys/time.h> 00052 #include <omp.h> 00053 00054 #define _isnan isnan 00055 #define _lseek lseek 00056 #define _read read 00057 #define _write write 00058 #define closesocket close 00059 #define SOCKET int 00060 #define strcpy_s(a,b,c) strcpy(a,c) 00061 #define strncpy_s(a,b,c,d) strncpy(a,c,d) 00062 00063 00064 inline char* _mktemp_s( char* szTemplate, size_t iSize ) { 00065 00066 return mktemp( szTemplate ); } 00067 00068 inline size_t GetTickCount( ) { 00069 struct timeval sTime; 00070 00071 gettimeofday( &sTime, NULL ); 00072 return ( ( sTime.tv_sec * 1000000 ) + sTime.tv_usec ); } 00073 00074 inline int sprintf_s( char* szDest, size_t iSize, const char* szFormat, 00075 ... ) { 00076 va_list valArgs; 00077 00078 va_start( valArgs, szFormat ); 00079 return vsprintf( szDest, szFormat, valArgs ); } 00080 00081 inline size_t max( size_t iOne, size_t iTwo ) { 00082 00083 return ( ( iOne > iTwo ) ? iOne : iTwo ); } 00084 #endif // _MSC_VER 00085 00086 #pragma warning (disable: 4267) 00087 #include <algorithm> 00088 #include <fstream> 00089 #include <iostream> 00090 #include <map> 00091 #include <queue> 00092 #include <set> 00093 #include <sstream> 00094 #include <vector> 00095 using namespace std; 00096 00097 #ifndef USE_LOG4CPP_STUB 00098 #include <log4cpp/Category.hh> 00099 #include <log4cpp/OstreamAppender.hh> 00100 using namespace log4cpp; 00101 #endif // USE_LOG4CPP_STUB 00102 00103 #if _MSC_VER 00104 #include <windows.h> 00105 #include <psapi.h> 00106 #else // _MSC_VER 00107 #define ios_base ios 00108 #define UINT unsigned int 00109 #endif // _MSC_VER 00110 00111 namespace pnl { } 00112 using namespace pnl; 00113 00114 namespace Sleipnir { 00115 00116 #ifdef USE_LOG4CPP_STUB 00117 00118 struct Priority { 00119 enum PriorityLevel { 00120 EMERG = 0, 00121 FATAL = 0, 00122 ALERT = 1, 00123 CRIT = 2, 00124 ERROR = 3, 00125 WARN = 4, 00126 NOTICE = 5, 00127 INFO = 6, 00128 DEBUG = 7, 00129 NOTSET = 8 00130 }; 00131 00132 const static char* c_aszPriorityLevels[]; 00133 }; 00134 00135 struct Category { 00136 00137 static void shutdown( ) { } 00138 00139 static void log4cpp( const char* szTag, const char* szFormat, va_list& valArgs ) { 00140 00141 fprintf( stderr, "%d ", time( NULL ) ); 00142 fprintf( stderr, szTag ); 00143 fprintf( stderr, " : " ); 00144 vfprintf( stderr, szFormat, valArgs ); 00145 fprintf( stderr, "\n" ); } 00146 00147 void error( const char* szFormat, ... ) const { 00148 va_list valArgs; 00149 00150 va_start( valArgs, szFormat ); 00151 log4cpp( "ERROR", szFormat, valArgs ); } 00152 00153 void info( const char* szFormat, ... ) const { 00154 va_list valArgs; 00155 00156 va_start( valArgs, szFormat ); 00157 log4cpp( "INFO", szFormat, valArgs ); } 00158 00159 void notice( const char* szFormat, ... ) const { 00160 va_list valArgs; 00161 00162 va_start( valArgs, szFormat ); 00163 log4cpp( "NOTICE", szFormat, valArgs ); } 00164 00165 void warn( const char* szFormat, ... ) const { 00166 va_list valArgs; 00167 00168 va_start( valArgs, szFormat ); 00169 log4cpp( "WARN", szFormat, valArgs ); } 00170 00171 void debug( const char* szFormat, ... ) const { 00172 va_list valArgs; 00173 00174 va_start( valArgs, szFormat ); 00175 log4cpp( "DEBUG", szFormat, valArgs ); } 00176 00177 void log( Priority::PriorityLevel ePriority, const char* szFormat, ... ) const { 00178 va_list valArgs; 00179 00180 va_start( valArgs, szFormat ); 00181 log4cpp( Priority::c_aszPriorityLevels[ ePriority ], szFormat, valArgs ); } 00182 00183 bool isDebugEnabled( ) const { 00184 00185 return true; } 00186 00187 bool isInfoEnabled( ) const { 00188 00189 return true; } 00190 00191 bool isNoticeEnabled( ) const { 00192 00193 return true; } 00194 }; 00195 00196 #endif // USE_LOG4CPP_STUB 00197 00198 #ifdef USE_LOG4CPP_STUB 00199 inline Category& g_CatSleipnir( ) { 00200 static Category s_CatSleipnir; 00201 00202 return s_CatSleipnir; } 00203 #else // USE_LOG4CPP_STUB 00204 extern const char c_szSleipnir[]; 00205 00206 inline Category& g_CatSleipnir( ) { 00207 static Category& s_CatSleipnir = Category::getInstance( c_szSleipnir ); 00208 00209 return s_CatSleipnir; } 00210 #endif // USE_LOG4CPP_STUB 00211 00212 } 00213 00214 #endif // STDAFX_H