QuickFIX: /home/omiller/Development/autobuild/quickfix/src/C++/Utility.h Source File

Index Source Files Annotated Class List Alphabetical Class List Class Hierarchy Graphical Class Hierarchy

# Utility.h

Go to the documentation of this file.

    00001 /* -*- C++ -*- */
    00002
    00003 /****************************************************************************
    00004 ** Copyright (c) quickfixengine.org  All rights reserved.
    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 HAVE_BOOST_FAST_POOL_ALLOCATOR
    00042   #include <boost/pool/pool_alloc.hpp>
    00043   #define ALLOCATOR boost::fast_pool_allocator
    00044 #elif HAVE_MT_ALLOCATOR
    00045   #include <ext/mt_allocator.h>
    00046   #define ALLOCATOR __gnu_cxx::__mt_alloc
    00047 #elif HAVE_BOOST_POOL_ALLOCATOR
    00048   #include <boost/pool/pool_alloc.hpp>
    00049   #define ALLOCATOR boost::pool_allocator
    00050 #elif HAVE_POOL_ALLOCATOR
    00051   #include <ext/pool_allocator.h>
    00052   #define ALLOCATOR __gnu_cxx::__pool_alloc
    00053 #elif HAVE_BITMAP_ALLOCATOR
    00054   #include <ext/bitmap_allocator.h>
    00055   #define ALLOCATOR __gnu_cxx::bitmap_allocator
    00056 #else
    00057   #define ALLOCATOR std::allocator
    00058 #endif
    00059
    00060 #ifdef _MSC_VER
    00062 #include <Winsock2.h>
    00063 #include <process.h>
    00064 #include <direct.h>
    00065 #include <time.h>
    00066 typedef int socklen_t;
    00068 #else
    00070 #include <sys/types.h>
    00071 #include <sys/socket.h>
    00072 #include <sys/ioctl.h>
    00073 #include <sys/time.h>
    00074 #include <sys/stat.h>
    00075 #include <netinet/in.h>
    00076 #include <netinet/tcp.h>
    00077 #include <arpa/inet.h>
    00078 #include <netdb.h>
    00079 #include <fcntl.h>
    00080 #include <unistd.h>
    00081 #include <pthread.h>
    00082 #include <signal.h>
    00083 #include <errno.h>
    00084 #include <time.h>
    00085 #include <stdlib.h>
    00087 #endif
    00088
    00089 #include <string>
    00090 #include <cstring>
    00091 #include <cctype>
    00092 #include <ctime>
    00093 #include <cstdio>
    00094
    00095 namespace FIX
    00096 {
    00097 void string_replace( const std::string& oldValue,
    00098                      const std::string& newValue,
    00099                      std::string& value );
    00100
    00101 std::string string_toLower( const std::string& value );
    00102 std::string string_toUpper( const std::string& value );
    00103 std::string string_strip( const std::string& value );
    00104
    00105 void socket_init();
    00106 void socket_term();
    00107 int socket_createAcceptor( int port, bool reuse = false );
    00108 int socket_createConnector();
    00109 int socket_connect( int s, const char* address, int port );
    00110 int socket_accept( int s );
    00111 int socket_send( int s, const char* msg, int length );
    00112 void socket_close( int s );
    00113 bool socket_fionread( int s, int& bytes );
    00114 bool socket_disconnected( int s );
    00115 int socket_setsockopt( int s, int opt );
    00116 int socket_setsockopt( int s, int opt, int optval );
    00117 int socket_getsockopt( int s, int opt, int& optval );
    00118 #ifndef _MSC_VER
    00119 int socket_fcntl( int s, int opt, int arg );
    00120 int socket_getfcntlflag( int s, int arg );
    00121 int socket_setfcntlflag( int s, int arg );
    00122 #endif
    00123 void socket_setnonblock( int s );
    00124 bool socket_isValid( int socket );
    00125 #ifndef _MSC_VER
    00126 bool socket_isBad( int s );
    00127 #endif
    00128 void socket_invalidate( int& socket );
    00129 short socket_hostport( int socket );
    00130 const char* socket_hostname( int socket );
    00131 const char* socket_hostname( const char* name );
    00132 const char* socket_peername( int socket );
    00133 std::pair<int, int> socket_createpair();
    00134
    00135 tm time_gmtime( const time_t* t );
    00136 tm time_localtime( const time_t* t );
    00137
    00138 #ifdef _MSC_VER
    00139 typedef unsigned int (_stdcall THREAD_START_ROUTINE)(void *);
    00140 #define  THREAD_PROC unsigned int _stdcall
    00141 #else
    00142 extern "C" { typedef void * (THREAD_START_ROUTINE)(void *); }
    00143 #define THREAD_PROC void *
    00144 #endif
    00145
    00146 #ifdef _MSC_VER
    00147 typedef unsigned thread_id;
    00148 #else
    00149 typedef pthread_t thread_id;
    00150 #endif
    00151
    00152 bool thread_spawn( THREAD_START_ROUTINE func, void* var, thread_id& thread );
    00153 bool thread_spawn( THREAD_START_ROUTINE func, void* var );
    00154 void thread_join( thread_id thread );
    00155 void thread_detach( thread_id thread );
    00156 thread_id thread_self();
    00157
    00158 void process_sleep( double s );
    00159
    00160 std::string file_separator();
    00161 void file_mkdir( const char* path );
    00162 FILE* file_fopen( const char* path, const char* mode );
    00163 void file_fclose( FILE* file );
    00164 bool file_exists( const char* path );
    00165 void file_unlink( const char* path );
    00166 int file_rename( const char* oldpath, const char* newpath );
    00167 std::string file_appendpath( const std::string& path, const std::string& file );
    00168 }
    00169
    00170 #if( _MSC_VER >= 1400 )
    00171 #define HAVE_FSCANF_S 1
    00172 #define FILE_FSCANF fscanf_s
    00173 #else
    00174 #define FILE_FSCANF fscanf
    00175 #endif
    00176
    00177 #if( _MSC_VER >= 1400 )
    00178 #define HAVE_SPRINTF_S 1
    00179 #define STRING_SPRINTF sprintf_s
    00180 #else
    00181 #define STRING_SPRINTF sprintf
    00182 #endif
    00183
    00184 #if (!defined(_MSC_VER) || (_MSC_VER >= 1300)) && !defined(HAVE_STLPORT)
    00185 using std::abort;
    00186 using std::sprintf;
    00187 using std::atoi;
    00188 using std::atol;
    00189 using std::atof;
    00190 using std::isdigit;
    00191 using std::strcmp;
    00192 using std::strftime;
    00193 using std::strlen;
    00194 using std::abs;
    00195 using std::labs;
    00196 using std::memcpy;
    00197 using std::memset;
    00198 using std::exit;
    00199 using std::strtod;
    00200 using std::strtol;
    00201 using std::strerror;
    00202 #endif
    00203
    00204 #endif