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;
00070 typedef int ssize_t;
00072 #else
00073 
00074 #include <sys/types.h>
00075 #include <sys/socket.h>
00076 #include <sys/ioctl.h>
00077 #include <sys/time.h>
00078 #include <sys/stat.h>
00079 #include <netinet/in.h>
00080 #include <netinet/tcp.h>
00081 #include <arpa/inet.h>
00082 #include <netdb.h>
00083 #include <fcntl.h>
00084 #include <unistd.h>
00085 #include <pthread.h>
00086 #include <signal.h>
00087 #include <errno.h>
00088 #include <time.h>
00089 #include <stdlib.h>
00091 #endif
00092 
00093 #include <string>
00094 #include <cstring>
00095 #include <cctype>
00096 #include <ctime>
00097 #include <cstdio>
00098 #include <cstdlib>
00099 #include <memory>
00100 
00101 #if defined(HAVE_STD_SHARED_PTR)
00102   namespace ptr = std;
00103 #elif defined(HAVE_STD_TR1_SHARED_PTR)
00104   #include <tr1/memory>
00105   namespace ptr = std::tr1;
00106 #else
00107   namespace ptr = std;
00108 #endif
00109 
00110 namespace FIX
00111 {
00112 void string_replace( const std::string& oldValue,
00113                      const std::string& newValue,
00114                      std::string& value );
00115 
00116 std::string string_toLower( const std::string& value );
00117 std::string string_toUpper( const std::string& value );
00118 std::string string_strip( const std::string& value );
00119 
00120 void socket_init();
00121 void socket_term();
00122 int socket_createAcceptor( int port, bool reuse = false );
00123 int socket_createConnector();
00124 int socket_connect( int s, const char* address, int port );
00125 int socket_accept( int s );
00126 ssize_t socket_send( int s, const char* msg, size_t length );
00127 void socket_close( int s );
00128 bool socket_fionread( int s, int& bytes );
00129 bool socket_disconnected( int s );
00130 int socket_setsockopt( int s, int opt );
00131 int socket_setsockopt( int s, int opt, int optval );
00132 int socket_getsockopt( int s, int opt, int& optval );
00133 #ifndef _MSC_VER
00134 int socket_fcntl( int s, int opt, int arg );
00135 int socket_getfcntlflag( int s, int arg );
00136 int socket_setfcntlflag( int s, int arg );
00137 #endif
00138 void socket_setnonblock( int s );
00139 bool socket_isValid( int socket );
00140 #ifndef _MSC_VER
00141 bool socket_isBad( int s );
00142 #endif
00143 void socket_invalidate( int& socket );
00144 short socket_hostport( int socket );
00145 const char* socket_hostname( int socket );
00146 const char* socket_hostname( const char* name );
00147 const char* socket_peername( int socket );
00148 std::pair<int, int> socket_createpair();
00149 
00150 tm time_gmtime( const time_t* t );
00151 tm time_localtime( const time_t* t );
00152 
00153 #ifdef _MSC_VER
00154 typedef unsigned int (_stdcall THREAD_START_ROUTINE)(void *);
00155 #define  THREAD_PROC unsigned int _stdcall
00156 #else
00157 extern "C" { typedef void * (THREAD_START_ROUTINE)(void *); }
00158 #define THREAD_PROC void *
00159 #endif
00160 
00161 #ifdef _MSC_VER
00162 typedef unsigned thread_id;
00163 #else
00164 typedef pthread_t thread_id;
00165 #endif
00166 
00167 bool thread_spawn( THREAD_START_ROUTINE func, void* var, thread_id& thread );
00168 bool thread_spawn( THREAD_START_ROUTINE func, void* var );
00169 void thread_join( thread_id thread );
00170 void thread_detach( thread_id thread );
00171 thread_id thread_self();
00172 
00173 void process_sleep( double s );
00174 
00175 std::string file_separator();
00176 void file_mkdir( const char* path );
00177 FILE* file_fopen( const char* path, const char* mode );
00178 void file_fclose( FILE* file );
00179 bool file_exists( const char* path );
00180 void file_unlink( const char* path );
00181 int file_rename( const char* oldpath, const char* newpath );
00182 std::string file_appendpath( const std::string& path, const std::string& file );
00183 }
00184 
00185 #if( _MSC_VER >= 1400 )
00186 #define HAVE_FSCANF_S 1
00187 #define FILE_FSCANF fscanf_s
00188 #else
00189 #define FILE_FSCANF fscanf
00190 #endif
00191 
00192 #if( _MSC_VER >= 1400 )
00193 #define HAVE_SPRINTF_S 1
00194 #define STRING_SPRINTF sprintf_s
00195 #else
00196 #define STRING_SPRINTF sprintf
00197 #endif
00198 
00199 #if (!defined(_MSC_VER) || (_MSC_VER >= 1300)) && !defined(HAVE_STLPORT)
00200 using std::abort;
00201 using std::sprintf;
00202 using std::atoi;
00203 using std::atol;
00204 using std::atof;
00205 using std::isdigit;
00206 using std::strcmp;
00207 using std::strftime;
00208 using std::strlen;
00209 using std::abs;
00210 using std::labs;
00211 using std::memcpy;
00212 using std::memset;
00213 using std::exit;
00214 using std::strtod;
00215 using std::strtol;
00216 using std::strerror;
00217 #endif
00218 
00219 #endif

Generated on Mon Sep 15 2014 01:23:55 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001