FieldConvertors.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863
  1. /* -*- C++ -*- */
  2. /****************************************************************************
  3. ** Copyright (c) 2001-2014
  4. **
  5. ** This file is part of the QuickFIX FIX Engine
  6. **
  7. ** This file may be distributed under the terms of the quickfixengine.org
  8. ** license as defined by quickfixengine.org and appearing in the file
  9. ** LICENSE included in the packaging of this file.
  10. **
  11. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  12. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. **
  14. ** See http://www.quickfixengine.org/LICENSE for licensing information.
  15. **
  16. ** Contact ask@quickfixengine.org if any conditions of this licensing are
  17. ** not clear to you.
  18. **
  19. ****************************************************************************/
  20. #ifndef FIX_FIELDCONVERTORS_H
  21. #define FIX_FIELDCONVERTORS_H
  22. #include "FieldTypes.h"
  23. #include "Exceptions.h"
  24. #include "Utility.h"
  25. #include <string>
  26. #include <sstream>
  27. #include <iomanip>
  28. #include <cstdio>
  29. #include <limits>
  30. namespace FIX
  31. {
  32. typedef int signed_int;
  33. typedef unsigned int unsigned_int;
  34. #define UNSIGNED_VALUE_OF( x ) unsigned_int( x < 0 ? -x : x )
  35. #define IS_SPACE( x ) ( x == ' ' )
  36. #define IS_DIGIT( x ) ( unsigned_int( x - '0' ) < 10 )
  37. inline int number_of_symbols_in( const signed_int value )
  38. {
  39. unsigned_int number = UNSIGNED_VALUE_OF( value );
  40. int symbols = 0;
  41. while( number > 9999 )
  42. {
  43. symbols += 4;
  44. number /= 10000;
  45. }
  46. // small tweak to make comparison times consistent
  47. // always 2 comparisons instead of [1 - 4]
  48. if( number > 99 )
  49. {
  50. if( number > 999 )
  51. symbols += 4;
  52. else
  53. symbols += 3;
  54. }
  55. else
  56. {
  57. if( number > 9 )
  58. symbols += 2;
  59. else
  60. symbols += 1;
  61. }
  62. if( value < 0 )
  63. symbols += 1;
  64. return symbols;
  65. }
  66. static const char digit_pairs[201] = {
  67. "00010203040506070809"
  68. "10111213141516171819"
  69. "20212223242526272829"
  70. "30313233343536373839"
  71. "40414243444546474849"
  72. "50515253545556575859"
  73. "60616263646566676869"
  74. "70717273747576777879"
  75. "80818283848586878889"
  76. "90919293949596979899"
  77. };
  78. inline char* integer_to_string( char* buf, const size_t len, signed_int t )
  79. {
  80. const bool isNegative = t < 0;
  81. char* p = buf + len;
  82. *--p = '\0';
  83. unsigned_int number = UNSIGNED_VALUE_OF( t );
  84. while( number > 99 )
  85. {
  86. unsigned_int pos = number % 100;
  87. number /= 100;
  88. p -= 2;
  89. *(short*)(p) = *(short*)(digit_pairs + 2 * pos);
  90. }
  91. if( number > 9 )
  92. {
  93. p -= 2;
  94. *(short*)(p) = *(short*)(digit_pairs + 2 * number);
  95. }
  96. else
  97. {
  98. *--p = '0' + char(number);
  99. }
  100. if( isNegative )
  101. *--p = '-';
  102. return p;
  103. }
  104. inline char* integer_to_string_padded
  105. ( char* buf, const size_t len, signed_int t,
  106. const size_t width = 0,
  107. const char paddingChar = '0')
  108. {
  109. char* p = integer_to_string( buf, len, t );
  110. if( !width )
  111. return p;
  112. const char* stop_p = buf + len - width - 1;
  113. if( stop_p < buf ) stop_p = buf;
  114. while( p > stop_p )
  115. *--p = paddingChar;
  116. return p;
  117. }
  118. /// Empty converter is a no-op.
  119. struct EmptyConvertor
  120. {
  121. static const std::string& convert( const std::string& value )
  122. { return value; }
  123. };
  124. typedef EmptyConvertor StringConvertor;
  125. /// Converts integer to/from a string
  126. struct IntConvertor
  127. {
  128. static std::string convert( signed_int value )
  129. {
  130. // buffer is big enough for significant digits and extra digit,
  131. // minus and null
  132. char buffer[std::numeric_limits<signed_int>::digits10 + 3];
  133. const char* const start
  134. = integer_to_string( buffer, sizeof (buffer), value );
  135. return std::string( start, buffer + sizeof (buffer) - start - 1 );
  136. }
  137. static bool convert(
  138. std::string::const_iterator str,
  139. std::string::const_iterator end,
  140. signed_int& result )
  141. {
  142. bool isNegative = false;
  143. signed_int x = 0;
  144. if( str == end )
  145. return false;
  146. if( *str == '-' )
  147. {
  148. isNegative = true;
  149. if( ++str == end )
  150. return false;
  151. }
  152. do
  153. {
  154. const unsigned_int c = *str - '0';
  155. if( c > 9 ) return false;
  156. x = 10 * x + c;
  157. } while ( ++str != end );
  158. if( isNegative )
  159. x = -x;
  160. result = x;
  161. return true;
  162. }
  163. static bool convert( const std::string& value, signed_int& result )
  164. {
  165. return convert( value.begin(), value.end(), result );
  166. }
  167. static signed_int convert( const std::string& value )
  168. throw( FieldConvertError )
  169. {
  170. signed_int result = 0;
  171. if( !convert( value.begin(), value.end(), result ) )
  172. throw FieldConvertError(value);
  173. else
  174. return result;
  175. }
  176. /// Converts only positive number e.g. FIX field ID: [1 ... 2147483647]
  177. /// No leading whitespace/zero/plus/sign symbols allowed
  178. /// Value is fixed to not make difference between 32bit and 64bit code
  179. static bool convertPositive(
  180. std::string::const_iterator str,
  181. std::string::const_iterator end,
  182. signed_int& result )
  183. {
  184. const int MAX_VALUE = 2147483647; // max value for 32-bit signed integer
  185. const int HIGH_MARK = MAX_VALUE / 10;
  186. const unsigned_int STOP_SYMBOL = MAX_VALUE % 10;
  187. const std::size_t MAX_DIGITS = 10; // integer can hold up to 10 digits
  188. const std::size_t length = std::distance( str, end );
  189. if( length < 1 || length > MAX_DIGITS)
  190. return false;
  191. if( length == MAX_DIGITS )
  192. {
  193. end = str;
  194. std::advance( end, length - 1 );
  195. }
  196. const unsigned_int ch = *str - '1';
  197. if( ch > 8 )
  198. return false;
  199. unsigned_int x = 0;
  200. do
  201. {
  202. const unsigned_int c = *str - '0';
  203. if( c > 9 ) return false;
  204. x = 10 * x + c;
  205. } while( ++str < end );
  206. // complete overflow condition check and value calculation
  207. // this saves about 25% of speed when executed out of the main loop
  208. if( length == MAX_DIGITS )
  209. {
  210. if( x > (unsigned int)HIGH_MARK )
  211. return false;
  212. const unsigned_int c = *str - '0';
  213. if( x == (unsigned int)HIGH_MARK && c > STOP_SYMBOL )
  214. return false;
  215. x = 10 * x + c;
  216. }
  217. result = x;
  218. return true;
  219. }
  220. static signed_int convertPositive( const std::string& value )
  221. throw( FieldConvertError )
  222. {
  223. signed_int result = 0;
  224. if( !convertPositive( value.begin(), value.end(), result ) )
  225. throw FieldConvertError(value);
  226. else
  227. return result;
  228. }
  229. };
  230. /// Converts checksum to/from a string
  231. struct CheckSumConvertor
  232. {
  233. static std::string convert( int value )
  234. throw( FieldConvertError )
  235. {
  236. if ( value > 255 || value < 0 ) throw FieldConvertError();
  237. char result[4];
  238. if( integer_to_string_padded(result, sizeof(result), value, 3) != result )
  239. {
  240. throw FieldConvertError();
  241. }
  242. return std::string( result, 3 );
  243. }
  244. static bool convert( const std::string& value, int& result )
  245. {
  246. return IntConvertor::convert( value, result );
  247. }
  248. static int convert( const std::string& value )
  249. throw( FieldConvertError )
  250. {
  251. return IntConvertor::convert( value );
  252. }
  253. };
  254. /// Converts double to/from a string
  255. struct DoubleConvertor
  256. {
  257. private:
  258. /*Simple and fast atof (ascii to float) function.
  259. Executes about 5x faster than standard MSCRT library atof().
  260. An attractive alternative if the number of calls is in the millions.
  261. Assumes input is a proper integer, fraction, or scientific format.
  262. Matches library atof() to 15 digits (except at extreme exponents).
  263. Follows atof() precedent of essentially no error checking.
  264. 09-May-2009 Tom Van Baak (tvb) www.LeapSecond.com */
  265. static double fast_atof (const char *p)
  266. {
  267. bool frac(false);
  268. double sign(1.), value(0.), scale(1.);
  269. while (IS_SPACE(*p))
  270. ++p;
  271. // Get sign, if any.
  272. if (*p == '-')
  273. {
  274. sign = -1.;
  275. ++p;
  276. }
  277. else if (*p == '+')
  278. ++p;
  279. // Get digits before decimal point or exponent, if any.
  280. while (IS_DIGIT(*p))
  281. {
  282. value = value * 10. + (*p - '0');
  283. ++p;
  284. }
  285. // Get digits after decimal point, if any.
  286. if (*p == '.')
  287. {
  288. ++p;
  289. double pow10(10.);
  290. while (IS_DIGIT(*p))
  291. {
  292. value += (*p - '0') / pow10;
  293. pow10 *= 10.;
  294. ++p;
  295. }
  296. }
  297. // Handle exponent, if any.
  298. if (toupper(*p) == 'E')
  299. {
  300. unsigned int expon(0);
  301. ++p;
  302. // Get sign of exponent, if any.
  303. if (*p == '-')
  304. {
  305. frac = true;
  306. ++p;
  307. }
  308. else if (*p == '+')
  309. ++p;
  310. // Get digits of exponent, if any.
  311. while (IS_DIGIT(*p))
  312. {
  313. expon = expon * 10 + (*p - '0');
  314. ++p;
  315. }
  316. if (expon > 308)
  317. expon = 308;
  318. // Calculate scaling factor.
  319. while (expon >= 50)
  320. {
  321. scale *= 1E50;
  322. expon -= 50;
  323. }
  324. while (expon >= 8)
  325. {
  326. scale *= 1E8;
  327. expon -= 8;
  328. }
  329. while (expon > 0)
  330. {
  331. scale *= 10.0;
  332. expon -= 1;
  333. }
  334. }
  335. // Return signed and scaled floating point result.
  336. return sign * (frac ? (value / scale) : (value * scale));
  337. }
  338. public:
  339. static std::string convert( double value, int padding = 0 )
  340. {
  341. char result[32];
  342. char *end = 0;
  343. int size;
  344. if( value == 0 || value > 0.0001 || value <= -0.0001 )
  345. {
  346. size = STRING_SPRINTF( result, "%.15g", value );
  347. if( padding > 0 )
  348. {
  349. char* point = result;
  350. end = result + size - 1;
  351. while( *point != '.' && *point != 0 )
  352. point++;
  353. if( *point == 0 )
  354. {
  355. end = point;
  356. *point = '.';
  357. size++;
  358. }
  359. int needed = padding - (int)(end - point);
  360. while( needed-- > 0 )
  361. {
  362. *(++end) = '0';
  363. size++;
  364. }
  365. *(end+1) = 0;
  366. }
  367. }
  368. else
  369. {
  370. size = STRING_SPRINTF( result, "%.15f", value );
  371. // strip trailing 0's
  372. end = result + size - 1;
  373. if( padding > 0 )
  374. {
  375. int discard = 15 - padding;
  376. while( (*end == '0') && (discard-- > 0) )
  377. {
  378. *(end--) = 0;
  379. size--;
  380. }
  381. }
  382. else
  383. {
  384. while( *end == '0' )
  385. {
  386. *(end--) = 0;
  387. size--;
  388. }
  389. }
  390. }
  391. return std::string( result, size );
  392. }
  393. static bool convert( const std::string& value, double& result )
  394. {
  395. const char * i = value.c_str();
  396. // Catch null strings
  397. if( !*i ) return false;
  398. // Eat leading '-' and recheck for null string
  399. if( *i == '-' && !*++i ) return false;
  400. bool haveDigit = false;
  401. if( IS_DIGIT(*i) )
  402. {
  403. haveDigit = true;
  404. while( IS_DIGIT (*++i) );
  405. }
  406. if( *i == '.' && IS_DIGIT(*++i) )
  407. {
  408. haveDigit = true;
  409. while( IS_DIGIT (*++i) );
  410. }
  411. if( *i || !haveDigit ) return false;
  412. result = fast_atof( value.c_str() );
  413. return true;
  414. }
  415. static double convert( const std::string& value )
  416. throw( FieldConvertError )
  417. {
  418. double result = 0.0;
  419. if( !convert( value, result ) )
  420. throw FieldConvertError(value);
  421. else
  422. return result;
  423. }
  424. };
  425. /// Converts character to/from a string
  426. struct CharConvertor
  427. {
  428. static std::string convert( char value )
  429. {
  430. if( value == '\0' ) return "";
  431. return std::string( 1, value );
  432. }
  433. static bool convert( const std::string& value, char& result )
  434. {
  435. if( value.size() != 1 ) return false;
  436. result = value[0];
  437. return true;
  438. }
  439. static char convert( const std::string& value )
  440. throw( FieldConvertError )
  441. {
  442. char result = '\0';
  443. if( !convert( value, result ) )
  444. throw FieldConvertError(value);
  445. else
  446. return result;
  447. }
  448. };
  449. /// Converts boolean to/from a string
  450. struct BoolConvertor
  451. {
  452. static std::string convert( bool value )
  453. {
  454. const char ch = value ? 'Y' : 'N';
  455. return std::string( 1, ch );
  456. }
  457. static bool convert( const std::string& value, bool& result )
  458. {
  459. if( value.size() != 1 ) return false;
  460. switch( value[0] )
  461. {
  462. case 'Y': result = true; break;
  463. case 'N': result = false; break;
  464. default: return false;
  465. }
  466. return true;
  467. }
  468. static bool convert( const std::string& value )
  469. throw( FieldConvertError )
  470. {
  471. bool result = false;
  472. if( !convert( value, result ) )
  473. throw FieldConvertError(value);
  474. else
  475. return result;
  476. }
  477. };
  478. /// Converts a UtcTimeStamp to/from a string
  479. struct UtcTimeStampConvertor
  480. {
  481. static std::string convert( const UtcTimeStamp& value,
  482. bool showMilliseconds = false )
  483. throw( FieldConvertError )
  484. {
  485. char result[ 18+4 ];
  486. int year, month, day, hour, minute, second, millis;
  487. value.getYMD( year, month, day );
  488. value.getHMS( hour, minute, second, millis );
  489. integer_to_string_padded( result, 5, year, 4 );
  490. integer_to_string_padded( result + 4, 3, month, 2 );
  491. integer_to_string_padded( result + 6, 3, day, 2 );
  492. result[8] = '-';
  493. integer_to_string_padded( result + 9, 3, hour, 2 );
  494. result[11] = ':';
  495. integer_to_string_padded( result + 12, 3, minute, 2 );
  496. result[14] = ':';
  497. integer_to_string_padded( result + 15, 3, second, 2 );
  498. if( showMilliseconds )
  499. {
  500. result[17] = '.';
  501. if( integer_to_string_padded ( result + 18, 4, millis, 3 )
  502. != result + 18 )
  503. {
  504. throw FieldConvertError();
  505. }
  506. }
  507. return result;
  508. }
  509. static UtcTimeStamp convert( const std::string& value,
  510. bool calculateDays = false )
  511. throw( FieldConvertError )
  512. {
  513. bool haveMilliseconds = false;
  514. switch( value.size() )
  515. {
  516. case 21: haveMilliseconds = true;
  517. case 17: break;
  518. default: throw FieldConvertError(value);
  519. }
  520. int i = 0;
  521. int c = 0;
  522. for( c = 0; c < 8; ++c )
  523. if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
  524. if (value[i++] != '-') throw FieldConvertError(value);
  525. for( c = 0; c < 2; ++c )
  526. if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
  527. if( value[i++] != ':' ) throw FieldConvertError(value);
  528. for( c = 0; c < 2; ++c )
  529. if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
  530. if( value[i++] != ':' ) throw FieldConvertError(value);
  531. for( c = 0; c < 2; ++c )
  532. if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
  533. if( haveMilliseconds )
  534. {
  535. if( value[i++] != '.' ) throw FieldConvertError(value);
  536. for( c = 0; c < 3; ++c )
  537. if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
  538. }
  539. int year, mon, mday, hour, min, sec, millis;
  540. i = 0;
  541. year = value[i++] - '0';
  542. year = 10 * year + value[i++] - '0';
  543. year = 10 * year + value[i++] - '0';
  544. year = 10 * year + value[i++] - '0';
  545. mon = value[i++] - '0';
  546. mon = 10 * mon + value[i++] - '0';
  547. if( mon < 1 || 12 < mon ) throw FieldConvertError(value);
  548. mday = value[i++] - '0';
  549. mday = 10 * mday + value[i++] - '0';
  550. if( mday < 1 || 31 < mday ) throw FieldConvertError(value);
  551. ++i; // skip '-'
  552. hour = value[i++] - '0';
  553. hour = 10 * hour + value[i++] - '0';
  554. // No check for >= 0 as no '-' are converted here
  555. if( 23 < hour ) throw FieldConvertError(value);
  556. ++i; // skip ':'
  557. min = value[i++] - '0';
  558. min = 10 * min + value[i++] - '0';
  559. // No check for >= 0 as no '-' are converted here
  560. if( 59 < min ) throw FieldConvertError(value);
  561. ++i; // skip ':'
  562. sec = value[i++] - '0';
  563. sec = 10 * sec + value[i++] - '0';
  564. // No check for >= 0 as no '-' are converted here
  565. if( 60 < sec ) throw FieldConvertError(value);
  566. if( haveMilliseconds )
  567. {
  568. millis = (100 * (value[i+1] - '0')
  569. + 10 * (value[i+2] - '0')
  570. + (value[i+3] - '0'));
  571. }
  572. else
  573. millis = 0;
  574. return UtcTimeStamp (hour, min, sec, millis,
  575. mday, mon, year);
  576. }
  577. };
  578. /// Converts a UtcTimeOnly to/from a string
  579. struct UtcTimeOnlyConvertor
  580. {
  581. static std::string convert( const UtcTimeOnly& value,
  582. bool showMilliseconds = false)
  583. throw( FieldConvertError )
  584. {
  585. char result[ 9+4 ];
  586. int hour, minute, second, millis;
  587. value.getHMS( hour, minute, second, millis );
  588. integer_to_string_padded ( result, 3, hour, 2 );
  589. result[2] = ':';
  590. integer_to_string_padded ( result + 3, 3, minute, 2 );
  591. result[5] = ':';
  592. integer_to_string_padded ( result + 6, 3, second, 2 );
  593. if( showMilliseconds )
  594. {
  595. result[8] = '.';
  596. if( integer_to_string_padded ( result + 9, 4, millis, 3 )
  597. != result + 9 )
  598. throw FieldConvertError();
  599. }
  600. return result;
  601. }
  602. static UtcTimeOnly convert( const std::string& value )
  603. throw( FieldConvertError )
  604. {
  605. bool haveMilliseconds = false;
  606. switch( value.size() )
  607. {
  608. case 12: haveMilliseconds = true;
  609. case 8: break;
  610. default: throw FieldConvertError(value);
  611. }
  612. int i = 0;
  613. int c = 0;
  614. for( c = 0; c < 2; ++c )
  615. if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
  616. if( value[i++] != ':' ) throw FieldConvertError(value);
  617. for( c = 0; c < 2; ++c )
  618. if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
  619. if( value[i++] != ':' ) throw FieldConvertError(value);
  620. for( c = 0; c < 2; ++c )
  621. if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
  622. if( haveMilliseconds )
  623. {
  624. // ++i instead of i++ skips the '.' separator
  625. for( c = 0; c < 3; ++c )
  626. if( !IS_DIGIT(value[++i]) ) throw FieldConvertError(value);
  627. }
  628. int hour, min, sec, millis;
  629. i = 0;
  630. hour = value[i++] - '0';
  631. hour = 10 * hour + value[i++] - '0';
  632. // No check for >= 0 as no '-' are converted here
  633. if( 23 < hour ) throw FieldConvertError(value);
  634. ++i; // skip ':'
  635. min = value[i++] - '0';
  636. min = 10 * min + value[i++] - '0';
  637. // No check for >= 0 as no '-' are converted here
  638. if( 59 < min ) throw FieldConvertError(value);
  639. ++i; // skip ':'
  640. sec = value[i++] - '0';
  641. sec = 10 * sec + value[i++] - '0';
  642. // No check for >= 0 as no '-' are converted here
  643. if( 60 < sec ) throw FieldConvertError(value);
  644. if( haveMilliseconds )
  645. {
  646. millis = (100 * (value[i+1] - '0')
  647. + 10 * (value[i+2] - '0')
  648. + (value[i+3] - '0'));
  649. }
  650. else
  651. millis = 0;
  652. return UtcTimeOnly( hour, min, sec, millis );
  653. }
  654. };
  655. /// Converts a UtcDate to/from a string
  656. struct UtcDateConvertor
  657. {
  658. static std::string convert( const UtcDate& value )
  659. throw( FieldConvertError )
  660. {
  661. char result[ 9 ];
  662. int year, month, day;
  663. value.getYMD( year, month, day );
  664. integer_to_string_padded( result, 5, year, 4 );
  665. integer_to_string_padded( result + 4, 3, month, 2 );
  666. integer_to_string_padded( result + 6, 3, day, 2 );
  667. return result;
  668. }
  669. static UtcDate convert( const std::string& value )
  670. throw( FieldConvertError )
  671. {
  672. if( value.size() != 8 ) throw FieldConvertError(value);
  673. int i = 0;
  674. for( int c=0; c<8; ++c )
  675. if( !IS_DIGIT(value[i++]) ) throw FieldConvertError(value);
  676. int year, mon, mday;
  677. i = 0;
  678. year = value[i++] - '0';
  679. year = 10 * year + value[i++] - '0';
  680. year = 10 * year + value[i++] - '0';
  681. year = 10 * year + value[i++] - '0';
  682. mon = value[i++] - '0';
  683. mon = 10 * mon + value[i++] - '0';
  684. if( mon < 1 || 12 < mon )
  685. throw FieldConvertError(value);
  686. mday = value[i++] - '0';
  687. mday = 10 * mday + value[i++] - '0';
  688. if( mday < 1 || 31 < mday )
  689. throw FieldConvertError(value);
  690. return UtcDateOnly( mday, mon, year );
  691. }
  692. };
  693. typedef UtcDateConvertor UtcDateOnlyConvertor;
  694. typedef StringConvertor STRING_CONVERTOR;
  695. typedef CharConvertor CHAR_CONVERTOR;
  696. typedef DoubleConvertor PRICE_CONVERTOR;
  697. typedef IntConvertor INT_CONVERTOR;
  698. typedef DoubleConvertor AMT_CONVERTOR;
  699. typedef DoubleConvertor QTY_CONVERTOR;
  700. typedef StringConvertor CURRENCY_CONVERTOR;
  701. typedef StringConvertor MULTIPLEVALUESTRING_CONVERTOR;
  702. typedef StringConvertor MULTIPLESTRINGVALUE_CONVERTOR;
  703. typedef StringConvertor MULTIPLECHARVALUE_CONVERTOR;
  704. typedef StringConvertor EXCHANGE_CONVERTOR;
  705. typedef UtcTimeStampConvertor UTCTIMESTAMP_CONVERTOR;
  706. typedef BoolConvertor BOOLEAN_CONVERTOR;
  707. typedef StringConvertor LOCALMKTDATE_CONVERTOR;
  708. typedef StringConvertor DATA_CONVERTOR;
  709. typedef DoubleConvertor FLOAT_CONVERTOR;
  710. typedef DoubleConvertor PRICEOFFSET_CONVERTOR;
  711. typedef StringConvertor MONTHYEAR_CONVERTOR;
  712. typedef StringConvertor DAYOFMONTH_CONVERTOR;
  713. typedef UtcDateConvertor UTCDATE_CONVERTOR;
  714. typedef UtcTimeOnlyConvertor UTCTIMEONLY_CONVERTOR;
  715. typedef IntConvertor NUMINGROUP_CONVERTOR;
  716. typedef DoubleConvertor PERCENTAGE_CONVERTOR;
  717. typedef IntConvertor SEQNUM_CONVERTOR;
  718. typedef IntConvertor LENGTH_CONVERTOR;
  719. typedef StringConvertor COUNTRY_CONVERTOR;
  720. typedef StringConvertor TZTIMEONLY_CONVERTOR;
  721. typedef StringConvertor TZTIMESTAMP_CONVERTOR;
  722. typedef StringConvertor XMLDATA_CONVERTOR;
  723. typedef StringConvertor LANGUAGE_CONVERTOR;
  724. typedef CheckSumConvertor CHECKSUM_CONVERTOR;
  725. }
  726. #endif //FIX_FIELDCONVERTORS_H