Utility.h
Go to the documentation of this file.
1/* -*- C++ -*- */
2
3/****************************************************************************
4** Copyright (c) 2001-2014
5**
6** This file is part of the QuickFIX FIX Engine
7**
8** This file may be distributed under the terms of the quickfixengine.org
9** license as defined by quickfixengine.org and appearing in the file
10** LICENSE included in the packaging of this file.
11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14**
15** See http://www.quickfixengine.org/LICENSE for licensing information.
16**
17** Contact ask@quickfixengine.org if any conditions of this licensing are
18** not clear to you.
19**
20****************************************************************************/
21
22#ifndef FIX_UTILITY_H
23#define FIX_UTILITY_H
24
25#ifdef _MSC_VER
26#pragma warning( disable : 4503 4355 4786 4290 )
27#endif
28
29#ifndef _MSC_VER
30#include "Allocator.h"
31#endif
32
33#ifdef HAVE_STLPORT
34 #define ALLOCATOR std::allocator
35#elif ENABLE_DEBUG_ALLOCATOR
36 #include <ext/debug_allocator.h>
37 #define ALLOCATOR __gnu_cxx::debug_allocator
38#elif ENABLE_NEW_ALLOCATOR
39 #include <ext/new_allocator.h>
40 #define ALLOCATOR __gnu_cxx::new_allocator
41#elif ENABLE_BOOST_FAST_POOL_ALLOCATOR
42 #include <boost/pool/pool_alloc.hpp>
43 #define ALLOCATOR boost::fast_pool_allocator
44#elif ENABLE_MT_ALLOCATOR
45 #include <ext/mt_allocator.h>
46 #define ALLOCATOR __gnu_cxx::__mt_alloc
47#elif ENABLE_BOOST_POOL_ALLOCATOR
48 #include <boost/pool/pool_alloc.hpp>
49 #define ALLOCATOR boost::pool_allocator
50#elif ENABLE_POOL_ALLOCATOR
51 #include <ext/pool_allocator.h>
52 #define ALLOCATOR __gnu_cxx::__pool_alloc
53#elif ENABLE_BITMAP_ALLOCATOR
54 #include <ext/bitmap_allocator.h>
55 #define ALLOCATOR __gnu_cxx::bitmap_allocator
56#elif ENABLE_TBB_ALLOCATOR
57 #include <tbb/scalable_allocator.h>
58 #define ALLOCATOR tbb::scalable_allocator
59#else
60 #define ALLOCATOR std::allocator
61#endif
62
63#ifdef _MSC_VER
65#include <Winsock2.h>
66#include <process.h>
67#include <direct.h>
68#include <time.h>
69typedef int socklen_t;
70typedef int ssize_t;
72#else
74#include <sys/types.h>
75#include <sys/socket.h>
76#include <sys/ioctl.h>
77#if defined(__SUNPRO_CC)
78#include <sys/filio.h>
79#endif
80#include <sys/time.h>
81#include <sys/stat.h>
82#include <netinet/in.h>
83#include <netinet/tcp.h>
84#include <arpa/inet.h>
85#include <netdb.h>
86#include <fcntl.h>
87#include <unistd.h>
88#include <pthread.h>
89#include <signal.h>
90#include <errno.h>
91#include <time.h>
92#include <stdlib.h>
94#endif
95
96#include <string>
97#include <cstring>
98#include <cctype>
99#include <ctime>
100#include <cstdio>
101#include <cstdlib>
102#include <memory>
103
104#if !defined(HAVE_STD_UNIQUE_PTR)
105#define SmartPtr std::auto_ptr
106#else
107#include <memory>
108#define SmartPtr std::unique_ptr
109#endif
110
111#if defined(HAVE_STD_SHARED_PTR)
112 namespace ptr = std;
113#elif defined(HAVE_STD_TR1_SHARED_PTR)
114 #include <tr1/memory>
115 namespace ptr = std::tr1;
116#elif defined(HAVE_BOOST_SHARED_PTR)
117 #include <boost/shared_ptr.hpp>
118 namespace ptr = boost;
119#elif defined(__SUNPRO_CC)
120 #if (__SUNPRO_CC <= 0x5140)
121 #include "./wx/sharedptr.h"
122 namespace ptr = wxWidgets;
123 #endif
124#elif defined(__TOS_AIX__)
125 #include <memory>
126 namespace ptr = std::tr1;
127#else
128 namespace ptr = std;
129#endif
130
131namespace FIX
132{
133void string_replace( const std::string& oldValue,
134 const std::string& newValue,
135 std::string& value );
136
137std::string string_toLower( const std::string& value );
138std::string string_toUpper( const std::string& value );
139std::string string_strip( const std::string& value );
140
141void socket_init();
142void socket_term();
143int socket_bind( int socket, const char* hostname, int port );
144int socket_createAcceptor( int port, bool reuse = false );
146int socket_connect( int s, const char* address, int port );
147int socket_accept( int s );
148ssize_t socket_recv( int s, char* buf, size_t length );
149ssize_t socket_send( int s, const char* msg, size_t length );
150void socket_close( int s );
151bool socket_fionread( int s, int& bytes );
152bool socket_disconnected( int s );
153int socket_setsockopt( int s, int opt );
154int socket_setsockopt( int s, int opt, int optval );
155int socket_getsockopt( int s, int opt, int& optval );
156#ifndef _MSC_VER
157int socket_fcntl( int s, int opt, int arg );
158int socket_getfcntlflag( int s, int arg );
159int socket_setfcntlflag( int s, int arg );
160#endif
161void socket_setnonblock( int s );
162bool socket_isValid( int socket );
163#ifndef _MSC_VER
164bool socket_isBad( int s );
165#endif
166void socket_invalidate( int& socket );
167short socket_hostport( int socket );
168const char* socket_hostname( int socket );
169const char* socket_hostname( const char* name );
170const char* socket_peername( int socket );
171std::pair<int, int> socket_createpair();
172
173tm time_gmtime( const time_t* t );
174tm time_localtime( const time_t* t );
175
176#if(_MSC_VER >= 1900)
177typedef _beginthreadex_proc_type THREAD_START_ROUTINE;
178#define THREAD_PROC unsigned int _stdcall
179#elif(_MSC_VER > 0)
180typedef unsigned int (_stdcall * THREAD_START_ROUTINE)(void *);
181#define THREAD_PROC unsigned int _stdcall
182#else
183extern "C" { typedef void * (THREAD_START_ROUTINE)(void *); }
184#define THREAD_PROC void *
185#endif
186
187#ifdef _MSC_VER
188typedef unsigned thread_id;
189#else
190typedef pthread_t thread_id;
191#endif
192
193bool thread_spawn( THREAD_START_ROUTINE func, void* var, thread_id& thread );
194bool thread_spawn( THREAD_START_ROUTINE func, void* var );
195void thread_join( thread_id thread );
196void thread_detach( thread_id thread );
198
199void process_sleep( double s );
200
201std::string file_separator();
202void file_mkdir( const char* path );
203FILE* file_fopen( const char* path, const char* mode );
204void file_fclose( FILE* file );
205bool file_exists( const char* path );
206void file_unlink( const char* path );
207int file_rename( const char* oldpath, const char* newpath );
208std::string file_appendpath( const std::string& path, const std::string& file );
209}
210
211#if( _MSC_VER >= 1400 )
212#define HAVE_FSCANF_S 1
213#define FILE_FSCANF fscanf_s
214#else
215#define FILE_FSCANF fscanf
216#endif
217
218#if( _MSC_VER >= 1400 )
219#define HAVE_SPRINTF_S 1
220#define STRING_SPRINTF sprintf_s
221#else
222#define STRING_SPRINTF sprintf
223#endif
224
225#if (!defined(_MSC_VER) || (_MSC_VER >= 1300)) && !defined(HAVE_STLPORT)
226using std::abort;
227using std::sprintf;
228using std::atoi;
229using std::atol;
230using std::atof;
231using std::isdigit;
232using std::strcmp;
233using std::strftime;
234using std::strlen;
235using std::abs;
236using std::labs;
237using std::memcpy;
238using std::memset;
239using std::exit;
240using std::strtod;
241using std::strtol;
242using std::strerror;
243#endif
244
245#endif
std::string string_strip(const std::string &value)
Definition Utility.cpp:67
void socket_setnonblock(int socket)
Definition Utility.cpp:268
int socket_accept(int s)
Definition Utility.cpp:164
int socket_setsockopt(int s, int opt)
Definition Utility.cpp:208
bool socket_fionread(int s, int &bytes)
Definition Utility.cpp:190
int socket_getfcntlflag(int s, int arg)
Definition Utility.cpp:255
void thread_detach(thread_id thread)
Definition Utility.cpp:447
bool socket_isBad(int s)
Definition Utility.cpp:287
int socket_createConnector()
Definition Utility.cpp:143
int socket_setfcntlflag(int s, int arg)
Definition Utility.cpp:260
void file_unlink(const char *path)
Definition Utility.cpp:537
int file_rename(const char *oldpath, const char *newpath)
Definition Utility.cpp:546
pthread_t thread_id
Definition Utility.h:190
bool thread_spawn(THREAD_START_ROUTINE func, void *var, thread_id &thread)
Definition Utility.cpp:416
const char * socket_hostname(int socket)
Definition Utility.cpp:314
tm time_localtime(const time_t *t)
Definition Utility.cpp:400
thread_id thread_self()
Definition Utility.cpp:457
bool socket_disconnected(int s)
Definition Utility.cpp:202
void socket_invalidate(int &socket)
Definition Utility.cpp:295
ssize_t socket_recv(int s, char *buf, size_t length)
Definition Utility.cpp:170
short socket_hostport(int socket)
Definition Utility.cpp:304
void *() THREAD_START_ROUTINE(void *)
Definition Utility.h:183
tm time_gmtime(const time_t *t)
Definition Utility.cpp:384
void socket_close(int s)
Definition Utility.cpp:180
void process_sleep(double s)
Definition Utility.cpp:466
void file_mkdir(const char *path)
Definition Utility.cpp:489
std::pair< int, int > socket_createpair()
Definition Utility.cpp:366
void string_replace(const std::string &oldValue, const std::string &newValue, std::string &value)
Definition Utility.cpp:40
std::string string_toLower(const std::string &value)
Definition Utility.cpp:60
void thread_join(thread_id thread)
Definition Utility.cpp:437
int socket_getsockopt(int s, int opt, int &optval)
Definition Utility.cpp:233
int socket_connect(int socket, const char *address, int port)
Definition Utility.cpp:148
int socket_bind(int socket, const char *hostname, int port)
Definition Utility.cpp:103
std::string file_separator()
Definition Utility.cpp:480
void socket_init()
Definition Utility.cpp:81
std::string string_toUpper(const std::string &value)
Definition Utility.cpp:53
ssize_t socket_send(int s, const char *msg, size_t length)
Definition Utility.cpp:175
bool file_exists(const char *path)
Definition Utility.cpp:525
void socket_term()
Definition Utility.cpp:96
bool socket_isValid(int socket)
Definition Utility.cpp:277
int socket_createAcceptor(int port, bool reuse)
Definition Utility.cpp:120
void file_fclose(FILE *file)
Definition Utility.cpp:520
int socket_fcntl(int s, int opt, int arg)
Definition Utility.cpp:250
FILE * file_fopen(const char *path, const char *mode)
Definition Utility.cpp:509
std::string file_appendpath(const std::string &path, const std::string &file)
Definition Utility.cpp:551
const char * socket_peername(int socket)
Definition Utility.cpp:353

Generated on Thu Feb 29 2024 22:38:19 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001