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
64 #include <Winsock2.h>
66 #include <process.h>
67 #include <direct.h>
68 #include <time.h>
69 typedef int socklen_t;
70 typedef int ssize_t;
72 #else
73 #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 
131 namespace FIX
132 {
133 void string_replace( const std::string& oldValue,
134  const std::string& newValue,
135  std::string& value );
136 
137 std::string string_toLower( const std::string& value );
138 std::string string_toUpper( const std::string& value );
139 std::string string_strip( const std::string& value );
140 
141 void socket_init();
142 void socket_term();
143 int socket_bind( int socket, const char* hostname, int port );
144 int socket_createAcceptor( int port, bool reuse = false );
146 int socket_connect( int s, const char* address, int port );
147 int socket_accept( int s );
148 ssize_t socket_recv( int s, char* buf, size_t length );
149 ssize_t socket_send( int s, const char* msg, size_t length );
150 void socket_close( int s );
151 bool socket_fionread( int s, int& bytes );
152 bool socket_disconnected( int s );
153 int socket_setsockopt( int s, int opt );
154 int socket_setsockopt( int s, int opt, int optval );
155 int socket_getsockopt( int s, int opt, int& optval );
156 #ifndef _MSC_VER
157 int socket_fcntl( int s, int opt, int arg );
158 int socket_getfcntlflag( int s, int arg );
159 int socket_setfcntlflag( int s, int arg );
160 #endif
161 void socket_setnonblock( int s );
162 bool socket_isValid( int socket );
163 #ifndef _MSC_VER
164 bool socket_isBad( int s );
165 #endif
166 void socket_invalidate( int& socket );
167 short socket_hostport( int socket );
168 const char* socket_hostname( int socket );
169 const char* socket_hostname( const char* name );
170 const char* socket_peername( int socket );
171 std::pair<int, int> socket_createpair();
172 
173 tm time_gmtime( const time_t* t );
174 tm time_localtime( const time_t* t );
175 
176 #if(_MSC_VER >= 1900)
177 typedef _beginthreadex_proc_type THREAD_START_ROUTINE;
178 #define THREAD_PROC unsigned int _stdcall
179 #elif(_MSC_VER > 0)
180 typedef unsigned int (_stdcall * THREAD_START_ROUTINE)(void *);
181 #define THREAD_PROC unsigned int _stdcall
182 #else
183 extern "C" { typedef void * (THREAD_START_ROUTINE)(void *); }
184 #define THREAD_PROC void *
185 #endif
186 
187 #ifdef _MSC_VER
188 typedef unsigned thread_id;
189 #else
190 typedef pthread_t thread_id;
191 #endif
192 
193 bool thread_spawn( THREAD_START_ROUTINE func, void* var, thread_id& thread );
194 bool thread_spawn( THREAD_START_ROUTINE func, void* var );
195 void thread_join( thread_id thread );
196 void thread_detach( thread_id thread );
198 
199 void process_sleep( double s );
200 
201 std::string file_separator();
202 void file_mkdir( const char* path );
203 FILE* file_fopen( const char* path, const char* mode );
204 void file_fclose( FILE* file );
205 bool file_exists( const char* path );
206 void file_unlink( const char* path );
207 int file_rename( const char* oldpath, const char* newpath );
208 std::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)
226 using std::abort;
227 using std::sprintf;
228 using std::atoi;
229 using std::atol;
230 using std::atof;
231 using std::isdigit;
232 using std::strcmp;
233 using std::strftime;
234 using std::strlen;
235 using std::abs;
236 using std::labs;
237 using std::memcpy;
238 using std::memset;
239 using std::exit;
240 using std::strtod;
241 using std::strtol;
242 using std::strerror;
243 #endif
244 
245 #endif
FIX::thread_id
pthread_t thread_id
Definition: Utility.h:190
FIX::file_appendpath
std::string file_appendpath(const std::string &path, const std::string &file)
Definition: Utility.cpp:568
FIX::time_localtime
tm time_localtime(const time_t *t)
Definition: Utility.cpp:417
FIX::string_toUpper
std::string string_toUpper(const std::string &value)
Definition: Utility.cpp:70
FIX::file_fclose
void file_fclose(FILE *file)
Definition: Utility.cpp:537
FIX::socket_setsockopt
int socket_setsockopt(int s, int opt)
Definition: Utility.cpp:225
FIX::socket_fcntl
int socket_fcntl(int s, int opt, int arg)
Definition: Utility.cpp:267
FIX::socket_init
void socket_init()
Definition: Utility.cpp:98
FIX::socket_connect
int socket_connect(int socket, const char *address, int port)
Definition: Utility.cpp:165
FIX::string_strip
std::string string_strip(const std::string &value)
Definition: Utility.cpp:84
FIX::thread_detach
void thread_detach(thread_id thread)
Definition: Utility.cpp:464
FIX::socket_getsockopt
int socket_getsockopt(int s, int opt, int &optval)
Definition: Utility.cpp:250
FIX::socket_term
void socket_term()
Definition: Utility.cpp:113
FIX::file_rename
int file_rename(const char *oldpath, const char *newpath)
Definition: Utility.cpp:563
FIX::socket_isValid
bool socket_isValid(int socket)
Definition: Utility.cpp:294
FIX::file_exists
bool file_exists(const char *path)
Definition: Utility.cpp:542
FIX::socket_recv
ssize_t socket_recv(int s, char *buf, size_t length)
Definition: Utility.cpp:187
FIX::socket_bind
int socket_bind(int socket, const char *hostname, int port)
Definition: Utility.cpp:120
FIX::socket_isBad
bool socket_isBad(int s)
Definition: Utility.cpp:304
FIX::socket_disconnected
bool socket_disconnected(int s)
Definition: Utility.cpp:219
FIX::socket_accept
int socket_accept(int s)
Definition: Utility.cpp:181
FIX::socket_hostport
short socket_hostport(int socket)
Definition: Utility.cpp:321
FIX::socket_send
ssize_t socket_send(int s, const char *msg, size_t length)
Definition: Utility.cpp:192
FIX::socket_createConnector
int socket_createConnector()
Definition: Utility.cpp:160
FIX::time_gmtime
tm time_gmtime(const time_t *t)
Definition: Utility.cpp:401
FIX::file_separator
std::string file_separator()
Definition: Utility.cpp:497
FIX::string_replace
void string_replace(const std::string &oldValue, const std::string &newValue, std::string &value)
Definition: Utility.cpp:57
FIX::socket_getfcntlflag
int socket_getfcntlflag(int s, int arg)
Definition: Utility.cpp:272
FIX::file_unlink
void file_unlink(const char *path)
Definition: Utility.cpp:554
Allocator.h
FIX::process_sleep
void process_sleep(double s)
Definition: Utility.cpp:483
FIX::THREAD_START_ROUTINE
void *() THREAD_START_ROUTINE(void *)
Definition: Utility.h:183
FIX::socket_setnonblock
void socket_setnonblock(int socket)
Definition: Utility.cpp:285
FIX::file_mkdir
void file_mkdir(const char *path)
Definition: Utility.cpp:506
FIX
Definition: Acceptor.cpp:34
FIX::socket_createAcceptor
int socket_createAcceptor(int port, bool reuse)
Definition: Utility.cpp:137
FIX::socket_invalidate
void socket_invalidate(int &socket)
Definition: Utility.cpp:312
FIX::socket_hostname
const char * socket_hostname(int socket)
Definition: Utility.cpp:331
FIX::socket_close
void socket_close(int s)
Definition: Utility.cpp:197
FIX::file_fopen
FILE * file_fopen(const char *path, const char *mode)
Definition: Utility.cpp:526
FIX::thread_self
thread_id thread_self()
Definition: Utility.cpp:474
FIX::thread_join
void thread_join(thread_id thread)
Definition: Utility.cpp:454
FIX::socket_fionread
bool socket_fionread(int s, int &bytes)
Definition: Utility.cpp:207
FIX::thread_spawn
bool thread_spawn(THREAD_START_ROUTINE func, void *var, thread_id &thread)
Definition: Utility.cpp:433
FIX::string_toLower
std::string string_toLower(const std::string &value)
Definition: Utility.cpp:77
FIX::socket_createpair
std::pair< int, int > socket_createpair()
Definition: Utility.cpp:383
FIX::socket_peername
const char * socket_peername(int socket)
Definition: Utility.cpp:370
FIX::socket_setfcntlflag
int socket_setfcntlflag(int s, int arg)
Definition: Utility.cpp:277

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001