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 #include <sys/time.h>
78 #include <sys/stat.h>
79 #include <netinet/in.h>
80 #include <netinet/tcp.h>
81 #include <arpa/inet.h>
82 #include <netdb.h>
83 #include <fcntl.h>
84 #include <unistd.h>
85 #include <pthread.h>
86 #include <signal.h>
87 #include <errno.h>
88 #include <time.h>
89 #include <stdlib.h>
91 #endif
92 
93 #include <string>
94 #include <cstring>
95 #include <cctype>
96 #include <ctime>
97 #include <cstdio>
98 #include <cstdlib>
99 #include <memory>
100 
101 #if defined(HAVE_STD_SHARED_PTR)
102  namespace ptr = std;
103 #elif defined(HAVE_STD_TR1_SHARED_PTR)
104  #include <tr1/memory>
105  namespace ptr = std::tr1;
106 #else
107  namespace ptr = std;
108 #endif
109 
110 namespace FIX
111 {
112 void string_replace( const std::string& oldValue,
113  const std::string& newValue,
114  std::string& value );
115 
116 std::string string_toLower( const std::string& value );
117 std::string string_toUpper( const std::string& value );
118 std::string string_strip( const std::string& value );
119 
120 void socket_init();
121 void socket_term();
122 int socket_createAcceptor( int port, bool reuse = false );
124 int socket_connect( int s, const char* address, int port );
125 int socket_accept( int s );
126 ssize_t socket_send( int s, const char* msg, size_t length );
127 void socket_close( int s );
128 bool socket_fionread( int s, int& bytes );
129 bool socket_disconnected( int s );
130 int socket_setsockopt( int s, int opt );
131 int socket_setsockopt( int s, int opt, int optval );
132 int socket_getsockopt( int s, int opt, int& optval );
133 #ifndef _MSC_VER
134 int socket_fcntl( int s, int opt, int arg );
135 int socket_getfcntlflag( int s, int arg );
136 int socket_setfcntlflag( int s, int arg );
137 #endif
138 void socket_setnonblock( int s );
139 bool socket_isValid( int socket );
140 #ifndef _MSC_VER
141 bool socket_isBad( int s );
142 #endif
143 void socket_invalidate( int& socket );
144 short socket_hostport( int socket );
145 const char* socket_hostname( int socket );
146 const char* socket_hostname( const char* name );
147 const char* socket_peername( int socket );
148 std::pair<int, int> socket_createpair();
149 
150 tm time_gmtime( const time_t* t );
151 tm time_localtime( const time_t* t );
152 
153 #ifdef _MSC_VER
154 typedef unsigned int (_stdcall THREAD_START_ROUTINE)(void *);
155 #define THREAD_PROC unsigned int _stdcall
156 #else
157 extern "C" { typedef void * (THREAD_START_ROUTINE)(void *); }
158 #define THREAD_PROC void *
159 #endif
160 
161 #ifdef _MSC_VER
162 typedef unsigned thread_id;
163 #else
164 typedef pthread_t thread_id;
165 #endif
166 
167 bool thread_spawn( THREAD_START_ROUTINE func, void* var, thread_id& thread );
168 bool thread_spawn( THREAD_START_ROUTINE func, void* var );
169 void thread_join( thread_id thread );
170 void thread_detach( thread_id thread );
171 thread_id thread_self();
172 
173 void process_sleep( double s );
174 
175 std::string file_separator();
176 void file_mkdir( const char* path );
177 FILE* file_fopen( const char* path, const char* mode );
178 void file_fclose( FILE* file );
179 bool file_exists( const char* path );
180 void file_unlink( const char* path );
181 int file_rename( const char* oldpath, const char* newpath );
182 std::string file_appendpath( const std::string& path, const std::string& file );
183 }
184 
185 #if( _MSC_VER >= 1400 )
186 #define HAVE_FSCANF_S 1
187 #define FILE_FSCANF fscanf_s
188 #else
189 #define FILE_FSCANF fscanf
190 #endif
191 
192 #if( _MSC_VER >= 1400 )
193 #define HAVE_SPRINTF_S 1
194 #define STRING_SPRINTF sprintf_s
195 #else
196 #define STRING_SPRINTF sprintf
197 #endif
198 
199 #if (!defined(_MSC_VER) || (_MSC_VER >= 1300)) && !defined(HAVE_STLPORT)
200 using std::abort;
201 using std::sprintf;
202 using std::atoi;
203 using std::atol;
204 using std::atof;
205 using std::isdigit;
206 using std::strcmp;
207 using std::strftime;
208 using std::strlen;
209 using std::abs;
210 using std::labs;
211 using std::memcpy;
212 using std::memset;
213 using std::exit;
214 using std::strtod;
215 using std::strtol;
216 using std::strerror;
217 #endif
218 
219 #endif
void thread_join(thread_id thread)
Definition: Utility.cpp:415
int socket_getsockopt(int s, int opt, int &optval)
Definition: Utility.cpp:211
int socket_connect(int socket, const char *address, int port)
Definition: Utility.cpp:131
int socket_accept(int s)
Definition: Utility.cpp:147
bool socket_isValid(int socket)
Definition: Utility.cpp:255
bool socket_disconnected(int s)
Definition: Utility.cpp:180
std::string string_toLower(const std::string &value)
Definition: Utility.cpp:60
void socket_init()
Definition: Utility.cpp:81
tm time_localtime(const time_t *t)
Definition: Utility.cpp:378
void socket_term()
Definition: Utility.cpp:96
short socket_hostport(int socket)
Definition: Utility.cpp:282
void thread_detach(thread_id thread)
Definition: Utility.cpp:425
int socket_createConnector()
Definition: Utility.cpp:126
void process_sleep(double s)
Definition: Utility.cpp:444
int socket_getfcntlflag(int s, int arg)
Definition: Utility.cpp:233
bool socket_fionread(int s, int &bytes)
Definition: Utility.cpp:168
bool thread_spawn(THREAD_START_ROUTINE func, void *var, thread_id &thread)
Definition: Utility.cpp:394
std::string file_appendpath(const std::string &path, const std::string &file)
Definition: Utility.cpp:529
int socket_setfcntlflag(int s, int arg)
Definition: Utility.cpp:238
tm time_gmtime(const time_t *t)
Definition: Utility.cpp:362
int socket_setsockopt(int s, int opt)
Definition: Utility.cpp:186
void socket_invalidate(int &socket)
Definition: Utility.cpp:273
int socket_fcntl(int s, int opt, int arg)
Definition: Utility.cpp:228
void file_fclose(FILE *file)
Definition: Utility.cpp:498
Definition: Acceptor.cpp:34
std::string file_separator()
Definition: Utility.cpp:458
std::string string_toUpper(const std::string &value)
Definition: Utility.cpp:53
void file_mkdir(const char *path)
Definition: Utility.cpp:467
const char * socket_hostname(int socket)
Definition: Utility.cpp:292
int file_rename(const char *oldpath, const char *newpath)
Definition: Utility.cpp:524
std::string string_strip(const std::string &value)
Definition: Utility.cpp:67
void socket_setnonblock(int socket)
Definition: Utility.cpp:246
void file_unlink(const char *path)
Definition: Utility.cpp:515
std::pair< int, int > socket_createpair()
Definition: Utility.cpp:344
bool socket_isBad(int s)
Definition: Utility.cpp:265
int socket_createAcceptor(int port, bool reuse)
Definition: Utility.cpp:103
FILE * file_fopen(const char *path, const char *mode)
Definition: Utility.cpp:487
pthread_t thread_id
Definition: Utility.h:164
ssize_t socket_send(int s, const char *msg, size_t length)
Definition: Utility.cpp:153
thread_id thread_self()
Definition: Utility.cpp:435
void string_replace(const std::string &oldValue, const std::string &newValue, std::string &value)
Definition: Utility.cpp:40
void socket_close(int s)
Definition: Utility.cpp:158
void *() THREAD_START_ROUTINE(void *)
Definition: Utility.h:157
const char * socket_peername(int socket)
Definition: Utility.cpp:331
bool file_exists(const char *path)
Definition: Utility.cpp:503

Generated on Thu Sep 5 2019 11:07:58 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001