Utility.h
Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 /****************************************************************************
00004 ** Copyright (c) 2001-2014
00005 **
00006 ** This file is part of the QuickFIX FIX Engine
00007 **
00008 ** This file may be distributed under the terms of the quickfixengine.org
00009 ** license as defined by quickfixengine.org and appearing in the file
00010 ** LICENSE included in the packaging of this file.
00011 **
00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 **
00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
00016 **
00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
00018 ** not clear to you.
00019 **
00020 ****************************************************************************/
00021 
00022 #ifndef FIX_UTILITY_H
00023 #define FIX_UTILITY_H
00024 
00025 #ifdef _MSC_VER
00026 #pragma warning( disable : 4503 4355 4786 4290 )
00027 #endif
00028 
00029 #ifndef _MSC_VER
00030 #include "Allocator.h"
00031 #endif
00032 
00033 #ifdef HAVE_STLPORT
00034   #define ALLOCATOR std::allocator
00035 #elif ENABLE_DEBUG_ALLOCATOR
00036   #include <ext/debug_allocator.h>
00037   #define ALLOCATOR __gnu_cxx::debug_allocator
00038 #elif ENABLE_NEW_ALLOCATOR
00039   #include <ext/new_allocator.h>
00040   #define ALLOCATOR __gnu_cxx::new_allocator
00041 #elif ENABLE_BOOST_FAST_POOL_ALLOCATOR
00042   #include <boost/pool/pool_alloc.hpp>
00043   #define ALLOCATOR boost::fast_pool_allocator
00044 #elif ENABLE_MT_ALLOCATOR
00045   #include <ext/mt_allocator.h>
00046   #define ALLOCATOR __gnu_cxx::__mt_alloc
00047 #elif ENABLE_BOOST_POOL_ALLOCATOR
00048   #include <boost/pool/pool_alloc.hpp>
00049   #define ALLOCATOR boost::pool_allocator
00050 #elif ENABLE_POOL_ALLOCATOR
00051   #include <ext/pool_allocator.h>
00052   #define ALLOCATOR __gnu_cxx::__pool_alloc
00053 #elif ENABLE_BITMAP_ALLOCATOR
00054   #include <ext/bitmap_allocator.h>
00055   #define ALLOCATOR __gnu_cxx::bitmap_allocator
00056 #elif ENABLE_TBB_ALLOCATOR
00057   #include <tbb/scalable_allocator.h>
00058   #define ALLOCATOR tbb::scalable_allocator
00059 #else
00060   #define ALLOCATOR std::allocator
00061 #endif
00062 
00063 #ifdef _MSC_VER
00064 
00065 #include <Winsock2.h>
00066 #include <process.h>
00067 #include <direct.h>
00068 #include <time.h>
00069 typedef int socklen_t;
00071 #else
00072 
00073 #include <sys/types.h>
00074 #include <sys/socket.h>
00075 #include <sys/ioctl.h>
00076 #include <sys/time.h>
00077 #include <sys/stat.h>
00078 #include <netinet/in.h>
00079 #include <netinet/tcp.h>
00080 #include <arpa/inet.h>
00081 #include <netdb.h>
00082 #include <fcntl.h>
00083 #include <unistd.h>
00084 #include <pthread.h>
00085 #include <signal.h>
00086 #include <errno.h>
00087 #include <time.h>
00088 #include <stdlib.h>
00090 #endif
00091 
00092 #include <string>
00093 #include <cstring>
00094 #include <cctype>
00095 #include <ctime>
00096 #include <cstdio>
00097 #include <cstdlib>
00098 
00099 namespace FIX
00100 {
00101 void string_replace( const std::string& oldValue,
00102                      const std::string& newValue,
00103                      std::string& value );
00104 
00105 std::string string_toLower( const std::string& value );
00106 std::string string_toUpper( const std::string& value );
00107 std::string string_strip( const std::string& value );
00108 
00109 void socket_init();
00110 void socket_term();
00111 int socket_createAcceptor( int port, bool reuse = false );
00112 int socket_createConnector();
00113 int socket_connect( int s, const char* address, int port );
00114 int socket_accept( int s );
00115 int socket_send( int s, const char* msg, int length );
00116 void socket_close( int s );
00117 bool socket_fionread( int s, int& bytes );
00118 bool socket_disconnected( int s );
00119 int socket_setsockopt( int s, int opt );
00120 int socket_setsockopt( int s, int opt, int optval );
00121 int socket_getsockopt( int s, int opt, int& optval );
00122 #ifndef _MSC_VER
00123 int socket_fcntl( int s, int opt, int arg );
00124 int socket_getfcntlflag( int s, int arg );
00125 int socket_setfcntlflag( int s, int arg );
00126 #endif
00127 void socket_setnonblock( int s );
00128 bool socket_isValid( int socket );
00129 #ifndef _MSC_VER
00130 bool socket_isBad( int s );
00131 #endif
00132 void socket_invalidate( int& socket );
00133 short socket_hostport( int socket );
00134 const char* socket_hostname( int socket );
00135 const char* socket_hostname( const char* name );
00136 const char* socket_peername( int socket );
00137 std::pair<int, int> socket_createpair();
00138 
00139 tm time_gmtime( const time_t* t );
00140 tm time_localtime( const time_t* t );
00141 
00142 #ifdef _MSC_VER
00143 typedef unsigned int (_stdcall THREAD_START_ROUTINE)(void *);
00144 #define  THREAD_PROC unsigned int _stdcall
00145 #else
00146 extern "C" { typedef void * (THREAD_START_ROUTINE)(void *); }
00147 #define THREAD_PROC void *
00148 #endif
00149 
00150 #ifdef _MSC_VER
00151 typedef unsigned thread_id;
00152 #else
00153 typedef pthread_t thread_id;
00154 #endif
00155 
00156 bool thread_spawn( THREAD_START_ROUTINE func, void* var, thread_id& thread );
00157 bool thread_spawn( THREAD_START_ROUTINE func, void* var );
00158 void thread_join( thread_id thread );
00159 void thread_detach( thread_id thread );
00160 thread_id thread_self();
00161 
00162 void process_sleep( double s );
00163 
00164 std::string file_separator();
00165 void file_mkdir( const char* path );
00166 FILE* file_fopen( const char* path, const char* mode );
00167 void file_fclose( FILE* file );
00168 bool file_exists( const char* path );
00169 void file_unlink( const char* path );
00170 int file_rename( const char* oldpath, const char* newpath );
00171 std::string file_appendpath( const std::string& path, const std::string& file );
00172 }
00173 
00174 #if( _MSC_VER >= 1400 )
00175 #define HAVE_FSCANF_S 1
00176 #define FILE_FSCANF fscanf_s
00177 #else
00178 #define FILE_FSCANF fscanf
00179 #endif
00180 
00181 #if( _MSC_VER >= 1400 )
00182 #define HAVE_SPRINTF_S 1
00183 #define STRING_SPRINTF sprintf_s
00184 #else
00185 #define STRING_SPRINTF sprintf
00186 #endif
00187 
00188 #if (!defined(_MSC_VER) || (_MSC_VER >= 1300)) && !defined(HAVE_STLPORT)
00189 using std::abort;
00190 using std::sprintf;
00191 using std::atoi;
00192 using std::atol;
00193 using std::atof;
00194 using std::isdigit;
00195 using std::strcmp;
00196 using std::strftime;
00197 using std::strlen;
00198 using std::abs;
00199 using std::labs;
00200 using std::memcpy;
00201 using std::memset;
00202 using std::exit;
00203 using std::strtod;
00204 using std::strtol;
00205 using std::strerror;
00206 #endif
00207 
00208 #endif

Generated on Mon Jun 23 2014 23:49:38 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001