quickfix_ruby_ud 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/ext/quickfix/Acceptor.cpp +257 -0
  3. data/ext/quickfix/Acceptor.h +127 -0
  4. data/ext/quickfix/Allocator.h +9 -0
  5. data/ext/quickfix/Application.h +137 -0
  6. data/ext/quickfix/DOMDocument.h +70 -0
  7. data/ext/quickfix/DataDictionary.cpp +679 -0
  8. data/ext/quickfix/DataDictionary.h +607 -0
  9. data/ext/quickfix/DataDictionaryProvider.cpp +66 -0
  10. data/ext/quickfix/DataDictionaryProvider.h +67 -0
  11. data/ext/quickfix/DatabaseConnectionID.h +98 -0
  12. data/ext/quickfix/DatabaseConnectionPool.h +84 -0
  13. data/ext/quickfix/Dictionary.cpp +157 -0
  14. data/ext/quickfix/Dictionary.h +89 -0
  15. data/ext/quickfix/Event.h +89 -0
  16. data/ext/quickfix/Except.h +39 -0
  17. data/ext/quickfix/Exceptions.h +257 -0
  18. data/ext/quickfix/Field.h +654 -0
  19. data/ext/quickfix/FieldConvertors.cpp +86 -0
  20. data/ext/quickfix/FieldConvertors.h +800 -0
  21. data/ext/quickfix/FieldMap.cpp +254 -0
  22. data/ext/quickfix/FieldMap.h +327 -0
  23. data/ext/quickfix/FieldNumbers.h +44 -0
  24. data/ext/quickfix/FieldTypes.cpp +62 -0
  25. data/ext/quickfix/FieldTypes.h +817 -0
  26. data/ext/quickfix/Fields.h +30 -0
  27. data/ext/quickfix/FileLog.cpp +176 -0
  28. data/ext/quickfix/FileLog.h +110 -0
  29. data/ext/quickfix/FileStore.cpp +369 -0
  30. data/ext/quickfix/FileStore.h +131 -0
  31. data/ext/quickfix/FixCommonFields.h +13 -0
  32. data/ext/quickfix/FixFieldNumbers.h +6132 -0
  33. data/ext/quickfix/FixFields.h +6133 -0
  34. data/ext/quickfix/FixValues.h +5790 -0
  35. data/ext/quickfix/Group.cpp +44 -0
  36. data/ext/quickfix/Group.h +78 -0
  37. data/ext/quickfix/HostDetailsProvider.cpp +79 -0
  38. data/ext/quickfix/HostDetailsProvider.h +44 -0
  39. data/ext/quickfix/HtmlBuilder.h +178 -0
  40. data/ext/quickfix/HttpConnection.cpp +914 -0
  41. data/ext/quickfix/HttpConnection.h +74 -0
  42. data/ext/quickfix/HttpMessage.cpp +229 -0
  43. data/ext/quickfix/HttpMessage.h +112 -0
  44. data/ext/quickfix/HttpParser.cpp +49 -0
  45. data/ext/quickfix/HttpParser.h +49 -0
  46. data/ext/quickfix/HttpServer.cpp +152 -0
  47. data/ext/quickfix/HttpServer.h +76 -0
  48. data/ext/quickfix/Initiator.cpp +310 -0
  49. data/ext/quickfix/Initiator.h +151 -0
  50. data/ext/quickfix/Log.cpp +71 -0
  51. data/ext/quickfix/Log.h +254 -0
  52. data/ext/quickfix/Message.cpp +617 -0
  53. data/ext/quickfix/Message.h +419 -0
  54. data/ext/quickfix/MessageCracker.h +171 -0
  55. data/ext/quickfix/MessageSorters.cpp +101 -0
  56. data/ext/quickfix/MessageSorters.h +185 -0
  57. data/ext/quickfix/MessageStore.cpp +182 -0
  58. data/ext/quickfix/MessageStore.h +164 -0
  59. data/ext/quickfix/Mutex.h +120 -0
  60. data/ext/quickfix/MySQLConnection.h +187 -0
  61. data/ext/quickfix/MySQLLog.cpp +262 -0
  62. data/ext/quickfix/MySQLLog.h +158 -0
  63. data/ext/quickfix/MySQLStore.cpp +323 -0
  64. data/ext/quickfix/MySQLStore.h +161 -0
  65. data/ext/quickfix/MySQLStubs.h +203 -0
  66. data/ext/quickfix/NullStore.cpp +40 -0
  67. data/ext/quickfix/NullStore.h +89 -0
  68. data/ext/quickfix/OdbcConnection.h +241 -0
  69. data/ext/quickfix/OdbcLog.cpp +230 -0
  70. data/ext/quickfix/OdbcLog.h +109 -0
  71. data/ext/quickfix/OdbcStore.cpp +313 -0
  72. data/ext/quickfix/OdbcStore.h +124 -0
  73. data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
  74. data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
  75. data/ext/quickfix/Parser.cpp +111 -0
  76. data/ext/quickfix/Parser.h +50 -0
  77. data/ext/quickfix/PostgreSQLConnection.h +163 -0
  78. data/ext/quickfix/PostgreSQLLog.cpp +263 -0
  79. data/ext/quickfix/PostgreSQLLog.h +157 -0
  80. data/ext/quickfix/PostgreSQLStore.cpp +327 -0
  81. data/ext/quickfix/PostgreSQLStore.h +160 -0
  82. data/ext/quickfix/PostgreSQLStubs.h +203 -0
  83. data/ext/quickfix/Queue.h +66 -0
  84. data/ext/quickfix/QuickfixRuby.cpp +131900 -0
  85. data/ext/quickfix/QuickfixRuby.h +56 -0
  86. data/ext/quickfix/Responder.h +41 -0
  87. data/ext/quickfix/SSLSocketAcceptor.cpp +409 -0
  88. data/ext/quickfix/SSLSocketAcceptor.h +186 -0
  89. data/ext/quickfix/SSLSocketConnection.cpp +434 -0
  90. data/ext/quickfix/SSLSocketConnection.h +221 -0
  91. data/ext/quickfix/SSLSocketInitiator.cpp +558 -0
  92. data/ext/quickfix/SSLSocketInitiator.h +203 -0
  93. data/ext/quickfix/SSLStubs.h +129 -0
  94. data/ext/quickfix/Session.cpp +1437 -0
  95. data/ext/quickfix/Session.h +343 -0
  96. data/ext/quickfix/SessionFactory.cpp +314 -0
  97. data/ext/quickfix/SessionFactory.h +84 -0
  98. data/ext/quickfix/SessionID.h +136 -0
  99. data/ext/quickfix/SessionSettings.cpp +165 -0
  100. data/ext/quickfix/SessionSettings.h +283 -0
  101. data/ext/quickfix/SessionState.h +260 -0
  102. data/ext/quickfix/Settings.cpp +160 -0
  103. data/ext/quickfix/Settings.h +56 -0
  104. data/ext/quickfix/SharedArray.h +274 -0
  105. data/ext/quickfix/SocketAcceptor.cpp +216 -0
  106. data/ext/quickfix/SocketAcceptor.h +77 -0
  107. data/ext/quickfix/SocketConnection.cpp +256 -0
  108. data/ext/quickfix/SocketConnection.h +102 -0
  109. data/ext/quickfix/SocketConnector.cpp +112 -0
  110. data/ext/quickfix/SocketConnector.h +76 -0
  111. data/ext/quickfix/SocketInitiator.cpp +241 -0
  112. data/ext/quickfix/SocketInitiator.h +76 -0
  113. data/ext/quickfix/SocketMonitor.h +26 -0
  114. data/ext/quickfix/SocketMonitor_UNIX.cpp +238 -0
  115. data/ext/quickfix/SocketMonitor_UNIX.h +101 -0
  116. data/ext/quickfix/SocketMonitor_WIN32.cpp +248 -0
  117. data/ext/quickfix/SocketMonitor_WIN32.h +99 -0
  118. data/ext/quickfix/SocketServer.cpp +163 -0
  119. data/ext/quickfix/SocketServer.h +100 -0
  120. data/ext/quickfix/ThreadedSSLSocketAcceptor.cpp +436 -0
  121. data/ext/quickfix/ThreadedSSLSocketAcceptor.h +209 -0
  122. data/ext/quickfix/ThreadedSSLSocketConnection.cpp +364 -0
  123. data/ext/quickfix/ThreadedSSLSocketConnection.h +191 -0
  124. data/ext/quickfix/ThreadedSSLSocketInitiator.cpp +434 -0
  125. data/ext/quickfix/ThreadedSSLSocketInitiator.h +193 -0
  126. data/ext/quickfix/ThreadedSocketAcceptor.cpp +242 -0
  127. data/ext/quickfix/ThreadedSocketAcceptor.h +95 -0
  128. data/ext/quickfix/ThreadedSocketConnection.cpp +227 -0
  129. data/ext/quickfix/ThreadedSocketConnection.h +89 -0
  130. data/ext/quickfix/ThreadedSocketInitiator.cpp +238 -0
  131. data/ext/quickfix/ThreadedSocketInitiator.h +78 -0
  132. data/ext/quickfix/TimeRange.cpp +227 -0
  133. data/ext/quickfix/TimeRange.h +215 -0
  134. data/ext/quickfix/Utility.cpp +639 -0
  135. data/ext/quickfix/Utility.h +255 -0
  136. data/ext/quickfix/UtilitySSL.cpp +1612 -0
  137. data/ext/quickfix/UtilitySSL.h +274 -0
  138. data/ext/quickfix/Values.h +63 -0
  139. data/ext/quickfix/config-all.h +10 -0
  140. data/ext/quickfix/config.h +10 -0
  141. data/ext/quickfix/config_unix.h +178 -0
  142. data/ext/quickfix/config_windows.h +0 -0
  143. data/ext/quickfix/dirent_windows.h +838 -0
  144. data/ext/quickfix/double-conversion/bignum-dtoa.cc +641 -0
  145. data/ext/quickfix/double-conversion/bignum-dtoa.h +84 -0
  146. data/ext/quickfix/double-conversion/bignum.cc +766 -0
  147. data/ext/quickfix/double-conversion/bignum.h +144 -0
  148. data/ext/quickfix/double-conversion/cached-powers.cc +176 -0
  149. data/ext/quickfix/double-conversion/cached-powers.h +64 -0
  150. data/ext/quickfix/double-conversion/diy-fp.cc +57 -0
  151. data/ext/quickfix/double-conversion/diy-fp.h +118 -0
  152. data/ext/quickfix/double-conversion/double-conversion.cc +994 -0
  153. data/ext/quickfix/double-conversion/double-conversion.h +543 -0
  154. data/ext/quickfix/double-conversion/fast-dtoa.cc +665 -0
  155. data/ext/quickfix/double-conversion/fast-dtoa.h +88 -0
  156. data/ext/quickfix/double-conversion/fixed-dtoa.cc +404 -0
  157. data/ext/quickfix/double-conversion/fixed-dtoa.h +56 -0
  158. data/ext/quickfix/double-conversion/ieee.h +402 -0
  159. data/ext/quickfix/double-conversion/strtod.cc +557 -0
  160. data/ext/quickfix/double-conversion/strtod.h +45 -0
  161. data/ext/quickfix/double-conversion/utils.h +374 -0
  162. data/ext/quickfix/extconf.rb +76 -0
  163. data/ext/quickfix/index.h +37 -0
  164. data/ext/quickfix/pugiconfig.hpp +77 -0
  165. data/ext/quickfix/pugixml.cpp +13237 -0
  166. data/ext/quickfix/pugixml.hpp +1516 -0
  167. data/ext/quickfix/scope_guard.hpp +215 -0
  168. data/ext/quickfix/stdint_msvc.h +254 -0
  169. data/ext/quickfix/strptime.h +7 -0
  170. data/lib/quickfix40.rb +274 -0
  171. data/lib/quickfix41.rb +351 -0
  172. data/lib/quickfix42.rb +1184 -0
  173. data/lib/quickfix43.rb +3504 -0
  174. data/lib/quickfix44.rb +14040 -0
  175. data/lib/quickfix50.rb +20051 -0
  176. data/lib/quickfix50sp1.rb +23596 -0
  177. data/lib/quickfix50sp2.rb +412444 -0
  178. data/lib/quickfix_fields.rb +79393 -0
  179. data/lib/quickfix_ruby.rb +82 -0
  180. data/lib/quickfixt11.rb +65 -0
  181. data/spec/FIX40.xml +862 -0
  182. data/spec/FIX41.xml +1282 -0
  183. data/spec/FIX42.xml +2743 -0
  184. data/spec/FIX43.xml +4230 -0
  185. data/spec/FIX44.xml +6600 -0
  186. data/spec/FIX50.xml +8142 -0
  187. data/spec/FIX50SP1.xml +9506 -0
  188. data/spec/FIX50SP2.xml +26069 -0
  189. data/spec/FIXT11.xml +252 -0
  190. data/test/DataDictionaryTestCase.rb +268 -0
  191. data/test/DictionaryTestCase.rb +112 -0
  192. data/test/FieldBaseTestCase.rb +24 -0
  193. data/test/MessageStoreTestCase.rb +19 -0
  194. data/test/MessageTestCase.rb +368 -0
  195. data/test/SessionSettingsTestCase.rb +41 -0
  196. metadata +236 -0
@@ -0,0 +1,817 @@
1
+ /* -*- C++ -*- */
2
+
3
+ /****************************************************************************
4
+ ** Copyright (c) 2001-2014
5
+ **
6
+ ** This file is part of the QuickFIX FIX Engine
7
+ **
8
+ **
9
+ ** This file may be distributed under the terms of the quickfixengine.org
10
+ ** license as defined by quickfixengine.org and appearing in the file
11
+ ** LICENSE included in the packaging of this file.
12
+ **
13
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15
+ **
16
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
17
+ **
18
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
19
+ ** not clear to you.
20
+ **
21
+ ****************************************************************************/
22
+
23
+ #ifndef FIX_FIELDTYPES_H
24
+ #define FIX_FIELDTYPES_H
25
+
26
+ #ifdef _MSC_VER
27
+ #pragma warning(disable : 4503 4355 4786 4290)
28
+ #endif
29
+
30
+ #if defined(_MSC_VER) && (_MSC_VER < 1600)
31
+ #include "stdint_msvc.h"
32
+ #else
33
+ #include <stdint.h> /* integer types int8_t .. uint64_t, intptr_t */
34
+ #endif
35
+
36
+ #include "Utility.h"
37
+ #include <string>
38
+ #include <time.h>
39
+
40
+ namespace FIX {
41
+ /*! \addtogroup user
42
+ * @{
43
+ */
44
+
45
+ /// Date and Time stored as a Julian day number and number of
46
+ /// nanoseconds since midnight. Does not perform any timezone
47
+ /// calculations. All magic numbers and related calculations
48
+ /// have been taken from:
49
+ ///
50
+ /// \sa http://www.faqs.org/faqs/calendars.faq
51
+ /// \sa http://scienceworld.wolfram.com/astronomy/JulianDate.html
52
+ /// \sa http://scienceworld.wolfram.com/astronomy/GregorianCalendar.html
53
+ /// \sa http://scienceworld.wolfram.com/astronomy/Weekday.html
54
+ ///
55
+ /// \author Caleb Epstein <caleb.epstein at gmail dot com>
56
+
57
+ // Precision factor of timestamp. [0] - second, [9] - nanosecond
58
+ static const int PRECISION_FACTOR[10] = {1000000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1};
59
+
60
+ struct DateTime {
61
+ int m_date;
62
+ int64_t m_time;
63
+
64
+ /// Magic numbers
65
+ static const int64_t SECONDS_PER_DAY = 86400;
66
+ static const int64_t SECONDS_PER_HOUR = 3600;
67
+ static const int64_t SECONDS_PER_MIN = 60;
68
+ static const int64_t MINUTES_PER_HOUR = 60;
69
+
70
+ static const int64_t NANOS_PER_DAY = 86400000000000;
71
+ static const int64_t NANOS_PER_HOUR = 3600000000000;
72
+ static const int64_t NANOS_PER_MIN = 60000000000;
73
+ static const int64_t NANOS_PER_SEC = 1000000000;
74
+
75
+ // time_t epoch (1970-01-01) as a Julian date
76
+ static const int64_t JULIAN_19700101 = 2440588;
77
+
78
+ /// Default constructor - initializes to zero
79
+ DateTime()
80
+ : m_date(0),
81
+ m_time(0) {}
82
+
83
+ /// Construct from a Julian day number and time in millis
84
+ DateTime(int date, int64_t time)
85
+ : m_date(date),
86
+ m_time(time) {}
87
+
88
+ /// Construct from the specified components
89
+ DateTime(int year, int month, int day, int hour, int minute, int second, int millis) {
90
+ m_date = julianDate(year, month, day);
91
+ m_time = makeHMS(hour, minute, second, millis * PRECISION_FACTOR[3]);
92
+ }
93
+
94
+ /// Construct from the specified components
95
+ DateTime(int year, int month, int day, int hour, int minute, int second, int fraction, int precision) {
96
+ m_date = julianDate(year, month, day);
97
+ int nanos = convertToNanos(fraction, precision);
98
+ m_time = makeHMS(hour, minute, second, nanos);
99
+ }
100
+
101
+ virtual ~DateTime() {}
102
+
103
+ /// Return the year portion of the date
104
+ inline int getYear() const {
105
+ int y, m, d;
106
+ getYMD(y, m, d);
107
+ return y;
108
+ }
109
+
110
+ /// Return the month (1-12) portion of the date
111
+ inline int getMonth() const {
112
+ int y, m, d;
113
+ getYMD(y, m, d);
114
+ return m;
115
+ }
116
+
117
+ /// Return the day of the month portion of the date
118
+ inline int getDay() const {
119
+ int y, m, d;
120
+ getYMD(y, m, d);
121
+ return d;
122
+ }
123
+
124
+ /// Another name for the day of the month. Bad name, but used
125
+ /// because of the legacy UtcTimeStamp interface
126
+ inline int getDate() const { return getDay(); }
127
+
128
+ /// Return the internal julian date
129
+ inline int getJulianDate() const { return m_date; }
130
+
131
+ /// Return the hour portion of the time (0-23)
132
+ inline int getHour() const { return (int)(m_time / NANOS_PER_HOUR); }
133
+
134
+ /// Return the minute portion of the time (0-59)
135
+ inline int getMinute() const { return (m_time / NANOS_PER_MIN) % MINUTES_PER_HOUR; }
136
+
137
+ /// Return the second portion of the time (0-59)
138
+ inline int getSecond() const { return (m_time / NANOS_PER_SEC) % SECONDS_PER_MIN; }
139
+
140
+ /// Return the millisecond portion of the time (0-999)
141
+ inline int getMillisecond() const { return (getNanosecond() / PRECISION_FACTOR[3]); }
142
+
143
+ /// Return the microsecond portion of the time
144
+ inline int getMicrosecond() const { return (getNanosecond() / PRECISION_FACTOR[6]); }
145
+
146
+ /// Return the nanosecond portion of the time
147
+ inline unsigned int getNanosecond() const { return static_cast<uint64_t>(m_time) % NANOS_PER_SEC; }
148
+
149
+ /// Return the fraction portion of the time
150
+ inline int getFraction(int precision) const {
151
+ switch (precision) {
152
+ case 0:
153
+ return (getNanosecond() / PRECISION_FACTOR[0]);
154
+
155
+ case 1:
156
+ return (getNanosecond() / PRECISION_FACTOR[1]);
157
+
158
+ case 2:
159
+ return (getNanosecond() / PRECISION_FACTOR[2]);
160
+
161
+ case 3:
162
+ return (getNanosecond() / PRECISION_FACTOR[3]);
163
+
164
+ case 4:
165
+ return (getNanosecond() / PRECISION_FACTOR[4]);
166
+
167
+ case 5:
168
+ return (getNanosecond() / PRECISION_FACTOR[5]);
169
+
170
+ case 6:
171
+ return (getNanosecond() / PRECISION_FACTOR[6]);
172
+
173
+ case 7:
174
+ return (getNanosecond() / PRECISION_FACTOR[7]);
175
+
176
+ case 8:
177
+ return (getNanosecond() / PRECISION_FACTOR[8]);
178
+
179
+ case 9:
180
+ default:
181
+ return (getNanosecond() / PRECISION_FACTOR[9]);
182
+ }
183
+ }
184
+
185
+ /// Load the referenced values with the year, month and day
186
+ /// portions of the date in a single operation
187
+ inline void getYMD(int &year, int &month, int &day) const { getYMD(m_date, year, month, day); }
188
+
189
+ /// Load the referenced values with the hour, minute, second and
190
+ /// millisecond portions of the time in a single operation
191
+ inline void getHMS(int &hour, int &minute, int &second, int &millis) const {
192
+ int ticks = (int)(m_time / NANOS_PER_SEC);
193
+ hour = ticks / SECONDS_PER_HOUR;
194
+ minute = (ticks / SECONDS_PER_MIN) % MINUTES_PER_HOUR;
195
+ second = ticks % SECONDS_PER_MIN;
196
+ millis = getMillisecond();
197
+ }
198
+
199
+ /// Load the referenced values with the hour, minute, second and
200
+ /// fraction portions of the time in a single operation
201
+ inline void getHMS(int &hour, int &minute, int &second, int &fraction, int precision) const {
202
+ int ticks = (int)(m_time / NANOS_PER_SEC);
203
+ hour = ticks / SECONDS_PER_HOUR;
204
+ minute = (ticks / SECONDS_PER_MIN) % MINUTES_PER_HOUR;
205
+ second = ticks % SECONDS_PER_MIN;
206
+ fraction = getFraction(precision);
207
+ }
208
+
209
+ /// Calculate the weekday of the date (Sunday is 1, Saturday is 7)
210
+ inline int getWeekDay() const {
211
+ int Y, M, D;
212
+ getYMD(Y, M, D);
213
+ int m = M >= 3 ? M - 2 : M + 10;
214
+ int Yprime = M >= 3 ? Y : Y - 1;
215
+ int y = Yprime % 100;
216
+ int c = Yprime / 100;
217
+ int wd = (D + int(2.6 * m - 0.2) + y + int(y / 4) + int(c / 4) - (2 * c)) % 7;
218
+ return 1 + (wd < 0 ? 7 + wd : wd);
219
+ }
220
+
221
+ /// Convert the DateTime to a time_t. Note that this operation
222
+ /// can overflow on 32-bit platforms when we go beyond year 2038.
223
+ inline time_t getTimeT() const { return (SECONDS_PER_DAY * (m_date - JULIAN_19700101) + m_time / NANOS_PER_SEC); }
224
+
225
+ /// Convert the DateTime to a struct tm which is in UTC
226
+ tm getTmUtc() const {
227
+ int year, month, day;
228
+ int hour, minute, second, millis;
229
+ tm result = {0};
230
+
231
+ getYMD(year, month, day);
232
+ getHMS(hour, minute, second, millis);
233
+
234
+ result.tm_year = year - 1900;
235
+ result.tm_mon = month - 1;
236
+ result.tm_mday = day;
237
+ result.tm_hour = hour;
238
+ result.tm_min = minute;
239
+ result.tm_sec = second;
240
+ result.tm_isdst = -1;
241
+
242
+ return result;
243
+ }
244
+
245
+ /// Set the date portion of the DateTime
246
+ void setYMD(int year, int month, int day) { m_date = julianDate(year, month, day); }
247
+
248
+ /// Set the time portion of the DateTime
249
+ void setHMS(int hour, int minute, int second, int millis) {
250
+ m_time = makeHMS(hour, minute, second, millis * PRECISION_FACTOR[3]);
251
+ }
252
+
253
+ /// Set the time portion of the DateTime
254
+ void setHMS(int hour, int minute, int second, int fraction, int precision) {
255
+ int nanos = convertToNanos(fraction, precision);
256
+
257
+ m_time = makeHMS(hour, minute, second, nanos);
258
+ }
259
+
260
+ /// Set the hour portion of the time
261
+ void setHour(int hour) {
262
+ int old_hour, min, sec, millis;
263
+ getHMS(old_hour, min, sec, millis);
264
+ setHMS(hour, min, sec, millis);
265
+ }
266
+
267
+ /// Set the minute portion of the time
268
+ void setMinute(int min) {
269
+ int hour, old_min, sec, millis;
270
+ getHMS(hour, old_min, sec, millis);
271
+ setHMS(hour, min, sec, millis);
272
+ }
273
+
274
+ /// Set the seconds portion of the time
275
+ void setSecond(int sec) {
276
+ int hour, min, old_sec, millis;
277
+ getHMS(hour, min, old_sec, millis);
278
+ setHMS(hour, min, sec, millis);
279
+ }
280
+
281
+ /// Set the millisecond portion of the time
282
+ void setMillisecond(int millis) {
283
+ int hour, min, sec, old_millis;
284
+ getHMS(hour, min, sec, old_millis);
285
+ setHMS(hour, min, sec, millis);
286
+ }
287
+
288
+ /// Set the microsecond portion of the time
289
+ void setMicrosecond(int micros) {
290
+ int hour, min, sec, old_nanos;
291
+ getHMS(hour, min, sec, old_nanos, 9);
292
+ setHMS(hour, min, sec, micros, 6);
293
+ }
294
+
295
+ /// Set the nanosecond portion of the time
296
+ void setNanosecond(int nanos) {
297
+ int hour, min, sec, old_nanos;
298
+ getHMS(hour, min, sec, old_nanos, 9);
299
+ setHMS(hour, min, sec, nanos, 9);
300
+ }
301
+
302
+ /// Set the fraction portion of the time
303
+ void setFraction(int fraction, int precision) {
304
+ int hour, min, sec, old_nanos;
305
+ getHMS(hour, min, sec, old_nanos, 9);
306
+ setHMS(hour, min, sec, fraction, precision);
307
+ }
308
+
309
+ /// Clear the date portion of the DateTime
310
+ void clearDate() { m_date = 0; }
311
+
312
+ /// Clear the time portion of the DateTime
313
+ void clearTime() { m_time = 0; }
314
+
315
+ /// Set the internal date and time members
316
+ void set(int date, int64_t time) {
317
+ m_date = date;
318
+ m_time = time;
319
+ }
320
+
321
+ /// Initialize from another DateTime
322
+ void set(const DateTime &other) {
323
+ m_date = other.m_date;
324
+ m_time = other.m_time;
325
+ }
326
+
327
+ /// Add a number of seconds to this
328
+ void operator+=(int seconds) {
329
+ int daysToAdd = seconds / SECONDS_PER_DAY;
330
+ int secondsToAdd = seconds % SECONDS_PER_DAY;
331
+
332
+ m_date += daysToAdd;
333
+ m_time += secondsToAdd * NANOS_PER_SEC;
334
+
335
+ if (m_time >= NANOS_PER_DAY) {
336
+ m_date++;
337
+ m_time %= NANOS_PER_DAY;
338
+ } else if (m_time < 0) {
339
+ m_date--;
340
+ m_time += NANOS_PER_DAY;
341
+ }
342
+ }
343
+
344
+ /// Convert to internal nanos
345
+ static int convertToNanos(int fraction, int precision) {
346
+ int nanos;
347
+
348
+ switch (precision) {
349
+ case 0:
350
+ nanos = fraction * PRECISION_FACTOR[0];
351
+ break;
352
+
353
+ case 1:
354
+ nanos = fraction * PRECISION_FACTOR[1];
355
+ break;
356
+
357
+ case 2:
358
+ nanos = fraction * PRECISION_FACTOR[2];
359
+ break;
360
+
361
+ case 3:
362
+ nanos = fraction * PRECISION_FACTOR[3];
363
+ break;
364
+
365
+ case 4:
366
+ nanos = fraction * PRECISION_FACTOR[4];
367
+ break;
368
+
369
+ case 5:
370
+ nanos = fraction * PRECISION_FACTOR[5];
371
+ break;
372
+
373
+ case 6:
374
+ nanos = fraction * PRECISION_FACTOR[6];
375
+ break;
376
+
377
+ case 7:
378
+ nanos = fraction * PRECISION_FACTOR[7];
379
+ break;
380
+
381
+ case 8:
382
+ nanos = fraction * PRECISION_FACTOR[8];
383
+ break;
384
+
385
+ case 9:
386
+ default:
387
+ nanos = fraction * PRECISION_FACTOR[9];
388
+ break;
389
+ }
390
+
391
+ return nanos;
392
+ }
393
+
394
+ /// Helper method to convert a broken down time to a number of
395
+ /// nanoseconds since midnight
396
+ static int64_t makeHMS(int hour, int minute, int second, int nanos) {
397
+ return NANOS_PER_SEC * (SECONDS_PER_HOUR * hour + SECONDS_PER_MIN * minute + second) + nanos;
398
+ }
399
+
400
+ /// Return the current wall-clock time as a utc DateTime
401
+ static DateTime nowUtc();
402
+
403
+ /// Return the current wall-clock time as a local DateTime
404
+ static DateTime nowLocal();
405
+
406
+ /// Convert a time_t and optional milliseconds to a DateTime
407
+ static DateTime fromUtcTimeT(time_t t, int millis = 0) {
408
+ struct tm tm = time_gmtime(&t);
409
+ return fromTm(tm, millis);
410
+ }
411
+
412
+ static DateTime fromLocalTimeT(time_t t, int millis = 0) {
413
+ struct tm tm = time_localtime(&t);
414
+ return fromTm(tm, millis);
415
+ }
416
+
417
+ static DateTime fromUtcTimeT(time_t t, int fraction, int precision) {
418
+ struct tm tm = time_gmtime(&t);
419
+ return fromTm(tm, fraction, precision);
420
+ }
421
+
422
+ static DateTime fromLocalTimeT(time_t t, int fraction, int precision) {
423
+ struct tm tm = time_localtime(&t);
424
+ return fromTm(tm, fraction, precision);
425
+ }
426
+
427
+ /// Convert a tm and optional milliseconds to a DateTime. \note
428
+ /// the tm structure is assumed to contain a date specified in UTC
429
+ static DateTime fromTm(const tm &tm, int millis = 0) {
430
+ return DateTime(
431
+ julianDate(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday),
432
+ makeHMS(tm.tm_hour, tm.tm_min, tm.tm_sec, millis * PRECISION_FACTOR[3]));
433
+ }
434
+
435
+ /// Convert a tm and optional milliseconds to a DateTime. \note
436
+ /// the tm structure is assumed to contain a date specified in UTC
437
+ static DateTime fromTm(const tm &tm, int fraction, int precision) {
438
+ int nanos = convertToNanos(fraction, precision);
439
+ return DateTime(
440
+ julianDate(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday),
441
+ makeHMS(tm.tm_hour, tm.tm_min, tm.tm_sec, nanos));
442
+ }
443
+
444
+ /// Helper method to calculate a Julian day number.
445
+ static int julianDate(int year, int month, int day) {
446
+ int a = (14 - month) / 12;
447
+ int y = year + 4800 - a;
448
+ int m = month + 12 * a - 3;
449
+ return (day + int((153 * m + 2) / 5) + y * 365 + int(y / 4) - int(y / 100) + int(y / 400) - 32045);
450
+ }
451
+
452
+ /// Convert a Julian day number to a year, month and day
453
+ static void getYMD(int jday, int &year, int &month, int &day) {
454
+ int a = jday + 32044;
455
+ int b = (4 * a + 3) / 146097;
456
+ int c = a - int((b * 146097) / 4);
457
+ int d = (4 * c + 3) / 1461;
458
+ int e = c - int((1461 * d) / 4);
459
+ int m = (5 * e + 2) / 153;
460
+ day = e - int((153 * m + 2) / 5) + 1;
461
+ month = m + 3 - 12 * int(m / 10);
462
+ year = b * 100 + d - 4800 + int(m / 10);
463
+ }
464
+ };
465
+
466
+ inline bool operator==(const DateTime &lhs, const DateTime &rhs) {
467
+ return lhs.m_date == rhs.m_date && lhs.m_time == rhs.m_time;
468
+ }
469
+
470
+ inline bool operator!=(const DateTime &lhs, const DateTime &rhs) { return !(lhs == rhs); }
471
+
472
+ inline bool operator<(const DateTime &lhs, const DateTime &rhs) {
473
+ if (lhs.m_date < rhs.m_date) {
474
+ return true;
475
+ } else if (lhs.m_date > rhs.m_date) {
476
+ return false;
477
+ } else if (lhs.m_time < rhs.m_time) {
478
+ return true;
479
+ }
480
+ return false;
481
+ }
482
+
483
+ inline bool operator>(const DateTime &lhs, const DateTime &rhs) { return !(lhs == rhs || lhs < rhs); }
484
+
485
+ inline bool operator<=(const DateTime &lhs, const DateTime &rhs) { return lhs == rhs || lhs < rhs; }
486
+
487
+ inline bool operator>=(const DateTime &lhs, const DateTime &rhs) { return lhs == rhs || lhs > rhs; }
488
+
489
+ /// Calculate the difference between two DateTime values and return
490
+ /// the result as a number of seconds
491
+ inline int operator-(const DateTime &lhs, const DateTime &rhs) {
492
+ return (
493
+ DateTime::SECONDS_PER_DAY * (lhs.m_date - rhs.m_date) +
494
+ // Truncate the nanos before subtracting
495
+ (int)(lhs.m_time / DateTime::NANOS_PER_SEC) - (int)(rhs.m_time / DateTime::NANOS_PER_SEC));
496
+ }
497
+
498
+ /// Date and Time represented in UTC.
499
+ class UtcTimeStamp : public DateTime {
500
+ public:
501
+ static UtcTimeStamp now() { return UtcTimeStamp(DateTime::nowUtc()); }
502
+
503
+ /// Defaults to the current date and time
504
+ [[deprecated("Use UtcTimeStamp::now()")]]
505
+ UtcTimeStamp()
506
+ : DateTime(DateTime::nowUtc()) {}
507
+
508
+ UtcTimeStamp(DateTime dateTime)
509
+ : DateTime(std::move(dateTime)) {}
510
+
511
+ /// Defaults to the current date
512
+ UtcTimeStamp(int hour, int minute, int second, int millisecond = 0)
513
+ : DateTime(DateTime::nowUtc()) {
514
+ setHMS(hour, minute, second, millisecond);
515
+ }
516
+
517
+ UtcTimeStamp(int hour, int minute, int second, int fraction, int precision)
518
+ : DateTime(DateTime::nowUtc()) {
519
+ setHMS(hour, minute, second, fraction, precision);
520
+ }
521
+
522
+ UtcTimeStamp(int hour, int minute, int second, int date, int month, int year)
523
+ : DateTime(year, month, date, hour, minute, second, 0) {}
524
+
525
+ UtcTimeStamp(int hour, int minute, int second, int millisecond, int date, int month, int year)
526
+ : DateTime(year, month, date, hour, minute, second, millisecond) {}
527
+
528
+ UtcTimeStamp(int hour, int minute, int second, int fraction, int date, int month, int year, int precision)
529
+ : DateTime(year, month, date, hour, minute, second, fraction, precision) {}
530
+
531
+ explicit UtcTimeStamp(time_t time, int millisecond = 0)
532
+ : DateTime(fromUtcTimeT(time, millisecond)) {}
533
+
534
+ UtcTimeStamp(time_t time, int fraction, int precision)
535
+ : DateTime(fromUtcTimeT(time, fraction, precision)) {}
536
+
537
+ UtcTimeStamp(const tm *time, int millisecond = 0)
538
+ : DateTime(fromTm(*time, millisecond)) {}
539
+
540
+ UtcTimeStamp(const tm *time, int fraction, int precision)
541
+ : DateTime(fromTm(*time, fraction, precision)) {}
542
+
543
+ void setCurrent() { set(DateTime::nowUtc()); }
544
+ };
545
+
546
+ /// Date and Time represented in local time.
547
+ class LocalTimeStamp : public DateTime {
548
+ public:
549
+ /// Defaults to the current date and time
550
+ LocalTimeStamp()
551
+ : DateTime(DateTime::nowLocal()) {}
552
+
553
+ /// Defaults to the current date
554
+ LocalTimeStamp(int hour, int minute, int second, int millisecond = 0)
555
+ : DateTime(DateTime::nowLocal()) {
556
+ setHMS(hour, minute, second, millisecond);
557
+ }
558
+
559
+ LocalTimeStamp(int hour, int minute, int second, int fraction, int precision)
560
+ : DateTime(DateTime::nowLocal()) {
561
+ setHMS(hour, minute, second, fraction, precision);
562
+ }
563
+
564
+ LocalTimeStamp(int hour, int minute, int second, int date, int month, int year)
565
+ : DateTime(year, month, date, hour, minute, second, 0) {}
566
+
567
+ LocalTimeStamp(int hour, int minute, int second, int millisecond, int date, int month, int year)
568
+ : DateTime(year, month, date, hour, minute, second, millisecond) {}
569
+
570
+ LocalTimeStamp(int hour, int minute, int second, int fraction, int date, int month, int year, int precision)
571
+ : DateTime(year, month, date, hour, minute, second, fraction, precision) {}
572
+
573
+ explicit LocalTimeStamp(time_t time, int millisecond = 0)
574
+ : DateTime(fromLocalTimeT(time, millisecond)) {}
575
+
576
+ LocalTimeStamp(time_t time, int fraction, int precision)
577
+ : DateTime(fromLocalTimeT(time, fraction, precision)) {}
578
+
579
+ LocalTimeStamp(const tm *time, int millisecond = 0)
580
+ : DateTime(fromTm(*time, millisecond)) {}
581
+
582
+ LocalTimeStamp(const tm *time, int fraction, int precision)
583
+ : DateTime(fromTm(*time, fraction, precision)) {}
584
+
585
+ void setCurrent() { set(DateTime::nowLocal()); }
586
+ };
587
+
588
+ /// Time only represented in UTC.
589
+ class UtcTimeOnly : public DateTime {
590
+ public:
591
+ /// Defaults to the current time
592
+ UtcTimeOnly() { setCurrent(); }
593
+
594
+ UtcTimeOnly(const DateTime &val)
595
+ : DateTime(val) {
596
+ clearDate();
597
+ }
598
+
599
+ UtcTimeOnly(int hour, int minute, int second, int millisecond = 0) { setHMS(hour, minute, second, millisecond); }
600
+
601
+ UtcTimeOnly(int hour, int minute, int second, int fraction, int precision) {
602
+ setHMS(hour, minute, second, fraction, precision);
603
+ }
604
+
605
+ explicit UtcTimeOnly(time_t time, int millisecond = 0)
606
+ : DateTime(fromUtcTimeT(time, millisecond)) {
607
+ clearDate();
608
+ }
609
+
610
+ UtcTimeOnly(time_t time, int fraction, int precision)
611
+ : DateTime(fromUtcTimeT(time, fraction, precision)) {
612
+ clearDate();
613
+ }
614
+
615
+ UtcTimeOnly(const tm *time, int millisecond = 0)
616
+ : DateTime(fromTm(*time, millisecond)) {
617
+ clearDate();
618
+ }
619
+
620
+ UtcTimeOnly(const tm *time, int fraction, int precision)
621
+ : DateTime(fromTm(*time, fraction, precision)) {
622
+ clearDate();
623
+ }
624
+
625
+ /// Set to the current time.
626
+ void setCurrent() {
627
+ DateTime d = nowUtc();
628
+ m_time = d.m_time;
629
+ }
630
+ };
631
+
632
+ /// Time only represented in local time.
633
+ class LocalTimeOnly : public DateTime {
634
+ public:
635
+ /// Defaults to the current time
636
+ LocalTimeOnly() { setCurrent(); }
637
+
638
+ LocalTimeOnly(const DateTime &val)
639
+ : DateTime(val) {
640
+ clearDate();
641
+ }
642
+
643
+ LocalTimeOnly(int hour, int minute, int second, int millisecond = 0) { setHMS(hour, minute, second, millisecond); }
644
+
645
+ LocalTimeOnly(int hour, int minute, int second, int fraction, int precision) {
646
+ setHMS(hour, minute, second, fraction, precision);
647
+ }
648
+
649
+ explicit LocalTimeOnly(time_t time, int millisecond = 0)
650
+ : DateTime(fromLocalTimeT(time, millisecond)) {
651
+ clearDate();
652
+ }
653
+
654
+ LocalTimeOnly(time_t time, int fraction, int precision)
655
+ : DateTime(fromLocalTimeT(time, fraction, precision)) {
656
+ clearDate();
657
+ }
658
+
659
+ LocalTimeOnly(const tm *time, int millisecond = 0)
660
+ : DateTime(fromTm(*time, millisecond)) {
661
+ clearDate();
662
+ }
663
+
664
+ LocalTimeOnly(const tm *time, int fraction, int precision)
665
+ : DateTime(fromTm(*time, fraction, precision)) {
666
+ clearDate();
667
+ }
668
+
669
+ /// Set to the current time.
670
+ void setCurrent() {
671
+ DateTime d = nowLocal();
672
+ m_time = d.m_time;
673
+ }
674
+ };
675
+
676
+ /// Date only represented in UTC.
677
+ class UtcDate : public DateTime {
678
+ public:
679
+ /// Defaults to the current date
680
+ UtcDate() { setCurrent(); }
681
+
682
+ UtcDate(const DateTime &val)
683
+ : DateTime(val) {
684
+ clearTime();
685
+ }
686
+
687
+ UtcDate(int date, int month, int year)
688
+ : DateTime(year, month, date, 0, 0, 0, 0) {}
689
+
690
+ UtcDate(int sec)
691
+ : DateTime(sec / DateTime::SECONDS_PER_DAY, 0) {}
692
+
693
+ UtcDate(const tm *time)
694
+ : DateTime(fromTm(*time)) {
695
+ clearTime();
696
+ }
697
+
698
+ /// Set to the current time.
699
+ void setCurrent() {
700
+ DateTime d = nowUtc();
701
+ m_date = d.m_date;
702
+ }
703
+ };
704
+
705
+ /// Date only represented in local time.
706
+ class LocalDate : public DateTime {
707
+ public:
708
+ /// Defaults to the current date
709
+ LocalDate() { setCurrent(); }
710
+
711
+ LocalDate(const DateTime &val)
712
+ : DateTime(val) {
713
+ clearTime();
714
+ }
715
+
716
+ LocalDate(int date, int month, int year)
717
+ : DateTime(year, month, date, 0, 0, 0, 0) {}
718
+
719
+ LocalDate(int sec)
720
+ : DateTime(sec / DateTime::SECONDS_PER_DAY, 0) {}
721
+
722
+ LocalDate(const tm *time)
723
+ : DateTime(fromTm(*time)) {
724
+ clearTime();
725
+ }
726
+
727
+ /// Set to the current time.
728
+ void setCurrent() {
729
+ DateTime d = nowLocal();
730
+ m_date = d.m_date;
731
+ }
732
+ };
733
+
734
+ /*! @} */
735
+
736
+ typedef UtcDate UtcDateOnly;
737
+
738
+ typedef std::string STRING;
739
+ typedef char CHAR;
740
+ typedef double PRICE;
741
+ typedef int INT;
742
+ typedef int64_t INT64;
743
+ typedef double AMT;
744
+ typedef double QTY;
745
+ typedef std::string CURRENCY;
746
+ typedef std::string MULTIPLEVALUESTRING;
747
+ typedef std::string MULTIPLESTRINGVALUE;
748
+ typedef std::string MULTIPLECHARVALUE;
749
+ typedef std::string EXCHANGE;
750
+ typedef UtcTimeStamp UTCTIMESTAMP;
751
+ typedef bool BOOLEAN;
752
+ typedef std::string LOCALMKTTIME;
753
+ typedef std::string LOCALMKTDATE;
754
+ typedef std::string DATA;
755
+ typedef double FLOAT;
756
+ typedef double PRICEOFFSET;
757
+ typedef std::string MONTHYEAR;
758
+ typedef std::string DAYOFMONTH;
759
+ typedef UtcDate UTCDATE;
760
+ typedef UtcDateOnly UTCDATEONLY;
761
+ typedef UtcTimeOnly UTCTIMEONLY;
762
+ typedef int NUMINGROUP;
763
+ typedef double PERCENTAGE;
764
+ typedef uint64_t SEQNUM;
765
+ typedef int TAGNUM;
766
+ typedef int LENGTH;
767
+ typedef std::string COUNTRY;
768
+ typedef std::string TZTIMEONLY;
769
+ typedef std::string TZTIMESTAMP;
770
+ typedef std::string XMLDATA;
771
+ typedef std::string LANGUAGE;
772
+ typedef std::string XID;
773
+ typedef std::string XIDREF;
774
+
775
+ namespace TYPE {
776
+ enum Type {
777
+ Unknown,
778
+ String,
779
+ Char,
780
+ Price,
781
+ Int,
782
+ Amt,
783
+ Qty,
784
+ Currency,
785
+ MultipleValueString,
786
+ MultipleStringValue,
787
+ MultipleCharValue,
788
+ Exchange,
789
+ UtcTimeStamp,
790
+ Boolean,
791
+ LocalMktTime,
792
+ LocalMktDate,
793
+ Data,
794
+ Float,
795
+ PriceOffset,
796
+ MonthYear,
797
+ DayOfMonth,
798
+ UtcDate,
799
+ UtcDateOnly = UtcDate,
800
+ UtcTimeOnly,
801
+ NumInGroup,
802
+ Percentage,
803
+ SeqNum,
804
+ TagNum,
805
+ Length,
806
+ Country,
807
+ TzTimeOnly,
808
+ TzTimeStamp,
809
+ XmlData,
810
+ Language,
811
+ Xid,
812
+ XidRef
813
+ };
814
+ } // namespace TYPE
815
+ } // namespace FIX
816
+
817
+ #endif // FIX_FIELDTYPES_H