OnixS C++ CME Market Data Handler  5.4.0
API documentation
ValueConverters.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
23 #include <stdexcept>
24 
25 #include <OnixS/CME/MDH/String.h>
26 #include <OnixS/CME/MDH/Time.h>
27 
28 #include <OnixS/CME/MDH/Decimal.h>
29 #include <OnixS/CME/MDH/Integral.h>
31 
33 
35 
36 /// Abstraction gathering operations
37 /// over a value of a particular type
38 /// stored as a field in a message.
41 {
42  /// The name of the type whose values are
43  /// manipulated through the given converter.
44  virtual
45  const Char*
46  typeName() const = 0;
47 
48  /// Outputs the text presentation of the FIX value
49  /// stored in the given container into the given string.
50  virtual
51  void
53  std::string&,
54  const ValueContainer&) const
55  {
56  }
57 
58  /// Tries to convert the value stored in the given
59  /// container into the string reference. The returned
60  /// value indicates whether the conversion successful.
61  virtual
62  bool
64  StrRef&,
65  const ValueContainer&) const
66  {
67  return false;
68  }
69 
70  /// Tries to convert the value stored in the given
71  /// container into a character. The returned value
72  /// indicates whether the conversion successful.
73  virtual
74  bool
76  Char&,
77  const ValueContainer&) const
78  {
79  return false;
80  }
81 
82  /// Tries to convert the value stored in the
83  /// given container into an integer. The returned
84  /// value indicates whether the conversion successful.
85  virtual
86  bool
88  Int8&,
89  const ValueContainer&) const
90  {
91  return false;
92  }
93 
94  /// Tries to convert the value stored in the
95  /// given container into an integer. The returned
96  /// value indicates whether the conversion successful.
97  virtual
98  bool
100  UInt8&,
101  const ValueContainer&) const
102  {
103  return false;
104  }
105 
106  /// Tries to convert the value stored in the
107  /// given container into an integer. The returned
108  /// value indicates whether the conversion successful.
109  virtual
110  bool
112  Int16&,
113  const ValueContainer&) const
114  {
115  return false;
116  }
117 
118  /// Tries to convert the value stored in the
119  /// given container into an integer. The returned
120  /// value indicates whether the conversion successful.
121  virtual
122  bool
124  UInt16&,
125  const ValueContainer&) const
126  {
127  return false;
128  }
129 
130  /// Tries to convert the value stored in the
131  /// given container into an integer. The returned
132  /// value indicates whether the conversion successful.
133  virtual
134  bool
136  Int32&,
137  const ValueContainer&) const
138  {
139  return false;
140  }
141 
142  /// Tries to convert the value stored in the
143  /// given container into an integer. The returned
144  /// value indicates whether the conversion successful.
145  virtual
146  bool
148  UInt32&,
149  const ValueContainer&) const
150  {
151  return false;
152  }
153 
154  /// Tries to convert the value stored in the
155  /// given container into an integer. The returned
156  /// value indicates whether the conversion successful.
157  virtual
158  bool
160  Int64&,
161  const ValueContainer&) const
162  {
163  return false;
164  }
165 
166  /// Tries to convert the value stored in the
167  /// given container into an integer. The returned
168  /// value indicates whether the conversion successful.
169  virtual
170  bool
172  UInt64&,
173  const ValueContainer&) const
174  {
175  return false;
176  }
177 
178  /// Tries to convert the value stored in the
179  /// given container into a decimal. The returned
180  /// value indicates whether the conversion successful.
181  virtual
182  bool
184  Decimal&,
185  const ValueContainer&) const
186  {
187  return false;
188  }
189 
190  /// Tries to convert the value stored in the
191  /// given container into a timestamp. The returned
192  /// value indicates whether the conversion successful.
193  virtual
194  bool
196  Timestamp&,
197  const ValueContainer&) const
198  {
199  return false;
200  }
201 
202  /// Tries to convert the value stored in the
203  /// given container into a month-year. The returned
204  /// value indicates whether the conversion successful.
205  virtual
206  bool
209  const ValueContainer&) const
210  {
211  return false;
212  }
213 };
214 
217 {
218  const Char*
219  typeName() const
220  {
221  return "Null";
222  }
223 
224  static
225  const
227  self()
228  {
229  static
230  const
232  self_;
233 
234  return self_;
235  }
236 };
237 
238 //
239 
240 /// Implements the value conversion
241 /// abstraction for the text fields.
244 {
245  const Char*
246  typeName() const
247  {
248  return "String";
249  }
250 
251  void
253  std::string& str,
254  const ValueContainer& container) const
255  {
256  const
257  StrRef&
258  ref =
259  container.get<StrRef>();
260 
261  str.
262  assign(
263  ref.items(),
264  ref.size());
265  }
266 
267  bool
269  StrRef& ref,
270  const ValueContainer& container) const
271  {
272  ref = container.get<StrRef>();
273 
274  return true;
275  }
276 
277  bool
279  Char& value,
280  const ValueContainer& container) const
281  {
282  const
283  StrRef&
284  str =
285  container.get<StrRef>();
286 
287  if (1 == str.size())
288  {
289  value = str[0];
290 
291  return true;
292  }
293  else if (str.empty())
294  {
295  value = 0;
296 
297  return true;
298  }
299 
300  return false;
301  }
302 
303  bool
305  Int8& value,
306  const ValueContainer& container) const
307  {
308  const
309  StrRef&
310  str =
311  container.get<StrRef>();
312 
313  return
314  fromStr(
315  value,
316  str.items(),
317  str.size());
318  }
319 
320  bool
322  UInt8& value,
323  const ValueContainer& container) const
324  {
325  const
326  StrRef&
327  str =
328  container.get<StrRef>();
329 
330  return
331  fromStr(
332  value,
333  str.items(),
334  str.size());
335  }
336 
337  bool
339  Int16& value,
340  const ValueContainer& container) const
341  {
342  const
343  StrRef&
344  str =
345  container.get<StrRef>();
346 
347  return
348  fromStr(
349  value,
350  str.items(),
351  str.size());
352  }
353 
354  bool
356  UInt16& value,
357  const ValueContainer& container) const
358  {
359  const
360  StrRef&
361  str =
362  container.get<StrRef>();
363 
364  return
365  fromStr(
366  value,
367  str.items(),
368  str.size());
369  }
370 
371  bool
373  Int32& value,
374  const ValueContainer& container) const
375  {
376  const
377  StrRef&
378  str =
379  container.get<StrRef>();
380 
381  return
382  fromStr(
383  value,
384  str.items(),
385  str.size());
386  }
387 
388  bool
390  UInt32& value,
391  const ValueContainer& container) const
392  {
393  const
394  StrRef&
395  str =
396  container.get<StrRef>();
397 
398  return
399  fromStr(
400  value,
401  str.items(),
402  str.size());
403  }
404 
405  bool
407  Int64& value,
408  const ValueContainer& container) const
409  {
410  const
411  StrRef&
412  str =
413  container.get<StrRef>();
414 
415  return
416  fromStr(
417  value,
418  str.items(),
419  str.size());
420  }
421 
422  bool
424  UInt64& value,
425  const ValueContainer& container) const
426  {
427  const
428  StrRef&
429  str =
430  container.get<StrRef>();
431 
432  return
433  fromStr(
434  value,
435  str.items(),
436  str.size());
437  }
438 
439  bool
441  Decimal& value,
442  const ValueContainer& container) const
443  {
444  const
445  StrRef&
446  str =
447  container.get<StrRef>();
448 
449  return
450  fromStr(
451  value,
452  str.items(),
453  str.size());
454  }
455 
456  bool
458  Timestamp& value,
459  const ValueContainer& container) const
460  {
461  const
462  StrRef&
463  str =
464  container.get<StrRef>();
465 
466  return
467  fromStr(
468  value,
469  str.items(),
470  str.size());
471  }
472 
473  static
474  const
476  self()
477  {
478  static
479  const
481  self_;
482 
483  return self_;
484  }
485 };
486 
487 //
488 
489 /// Implements the value conversion abstraction for
490 /// fields whose values represent a single character.
493 {
494  const Char*
495  typeName() const
496  {
497  return "Char";
498  }
499 
500  void
502  std::string& str,
503  const ValueContainer& container) const
504  {
505  str.append(
506  1,
507  container.get<Char>());
508  }
509 
510  bool
512  StrRef& ref,
513  const ValueContainer& container) const
514  {
515  ref =
516  StrRef(
517  &container.get<Char>(),
518  1);
519 
520  return true;
521  }
522 
523  bool
525  Char& value,
526  const ValueContainer& container) const
527  {
528  value = container.get<Char>();
529 
530  return true;
531  }
532 
533  bool
535  Int8& value,
536  const ValueContainer& container) const
537  {
538  return
539  charToDigit(
540  value,
541  container.get<Char>());
542  }
543 
544  bool
546  UInt8& value,
547  const ValueContainer& container) const
548  {
549  return
550  charToDigit(
551  value,
552  container.get<Char>());
553  }
554 
555  bool
557  Int16& value,
558  const ValueContainer& container) const
559  {
560  return
561  charToDigit(
562  value,
563  container.get<Char>());
564  }
565 
566  bool
568  UInt16& value,
569  const ValueContainer& container) const
570  {
571  return
572  charToDigit(
573  value,
574  container.get<Char>());
575  }
576 
577  bool
579  Int32& value,
580  const ValueContainer& container) const
581  {
582  return
583  charToDigit(
584  value,
585  container.get<Char>());
586  }
587 
588  bool
590  UInt32& value,
591  const ValueContainer& container) const
592  {
593  return
594  charToDigit(
595  value,
596  container.get<Char>());
597  }
598 
599  bool
601  Int64& value,
602  const ValueContainer& container) const
603  {
604  return
605  charToDigit(
606  value,
607  container.get<Char>());
608  }
609 
610  bool
612  UInt64& value,
613  const ValueContainer& container) const
614  {
615  return
616  charToDigit(
617  value,
618  container.get<Char>());
619  }
620 
621  bool
623  Decimal& value,
624  const ValueContainer& container) const
625  {
626  Decimal::Mantissa mantissa;
627 
628  if (charToDigit(
629  mantissa,
630  container.get<Char>()))
631  {
632  value = Decimal(mantissa, 0);
633 
634  return true;
635  }
636 
637  return false;
638  }
639 
640  bool
642  Timestamp&,
643  const ValueContainer&) const
644  {
645  return false;
646  }
647 
648  static
649  const
651  self()
652  {
653  static
654  const
656  self_;
657 
658  return self_;
659  }
660 
661 private:
662  template
663  <
664  class Integer
665  >
666  static
667  bool
668  charToDigit(
669  Integer& converted,
670  Char original)
671  {
672  if ('0' <= original &&
673  '9' >= original)
674  {
675  converted =
676  static_cast
677  <Integer>
678  (original - '0');
679 
680  return true;
681  }
682 
683  return false;
684  }
685 };
686 
687 //
688 
689 /// Implements the value conversion
690 /// abstraction for the integer fields.
691 template
692 <
693  class Integer,
694  class Descendant
695 >
696 class
698 : public ValueConverter
699 {
700  template
701  <
702  class Integral,
703  bool IsSigned
704  >
705  struct
706  FitsToChar
707  {
708  bool
709  operator ()(
710  Integral value) const
711  {
712  return (
713  0 <= value &&
714  value < 10
715  );
716  }
717  };
718 
719  template
720  <
721  class Integral
722  >
723  struct
724  FitsToChar
725  <
726  Integral,
727  false
728  >
729  {
730  bool
731  operator ()(
732  Integral value) const
733  {
734  return (value < 10);
735  }
736  };
737 
738  typedef
739  FitsToChar
740  <
741  Integer,
742  !(
743  static_cast<Integer>(-1) >
744  static_cast<Integer>(0)
745  )
746  >
747  CanFitToChar;
748 
749 public:
750 
751  void
753  std::string& str,
754  const ValueContainer& container) const
755  {
757  str,
758  container.get<Integer>());
759  }
760 
761  bool
763  Char& value,
764  const ValueContainer& container) const
765  {
766  const
767  Integer
768  actual =
769  container.get<Integer>();
770 
771  if (CanFitToChar()(actual))
772  {
773  value =
774  static_cast
775  <Char>
776  ('0' + actual);
777 
778  return true;
779  }
780 
781  return false;
782  }
783 
784  bool
786  Int8& value,
787  const ValueContainer& container) const
788  {
789  value =
790  static_cast
791  <Int8>
792  (container.get<Integer>());
793 
794  return true;
795  }
796 
797  bool
799  UInt8& value,
800  const ValueContainer& container) const
801  {
802  value =
803  static_cast
804  <UInt8>
805  (container.get<Integer>());
806 
807  return true;
808  }
809 
810  bool
812  Int16& value,
813  const ValueContainer& container) const
814  {
815  value =
816  static_cast
817  <Int16>
818  (container.get<Integer>());
819 
820  return true;
821  }
822 
823  bool
825  UInt16& value,
826  const ValueContainer& container) const
827  {
828  value =
829  static_cast
830  <UInt16>
831  (container.get<Integer>());
832 
833  return true;
834  }
835 
836  bool
838  Int32& value,
839  const ValueContainer& container) const
840  {
841  value =
842  static_cast
843  <Int32>
844  (container.get<Integer>());
845 
846  return true;
847  }
848 
849  bool
851  UInt32& value,
852  const ValueContainer& container) const
853  {
854  value =
855  static_cast
856  <UInt32>
857  (container.get<Integer>());
858 
859  return true;
860  }
861 
862  bool
864  Int64& value,
865  const ValueContainer& container) const
866  {
867  value =
868  static_cast
869  <Int64>
870  (container.get<Integer>());
871 
872  return true;
873  }
874 
875  bool
877  UInt64& value,
878  const ValueContainer& container) const
879  {
880  value =
881  static_cast
882  <UInt64>
883  (container.get<Integer>());
884 
885  return true;
886  }
887 
888  bool
890  Decimal& value,
891  const ValueContainer& container) const
892  {
893  value =
894  Decimal
895  (
896  static_cast<Decimal::Mantissa>
897  (container.get<Integer>()),
898  0
899  );
900 
901  return true;
902  }
903 
904  static
905  const
907  self()
908  {
909  static
910  const
911  Descendant
912  self_;
913 
914  return self_;
915  }
916 };
917 
918 /// Implements the value conversion
919 /// abstraction for the integer fields.
923 <
924  Int8,
926 >
927 {
928  const Char*
929  typeName() const
930  {
931  return "Int8";
932  }
933 };
934 
935 /// Implements the value conversion
936 /// abstraction for the integer fields.
940 <
941  UInt8,
943 >
944 {
945  const Char*
946  typeName() const
947  {
948  return "UInt8";
949  }
950 };
951 
952 /// Implements the value conversion
953 /// abstraction for the integer fields.
957 <
958  Int16,
960 >
961 {
962  const Char*
963  typeName() const
964  {
965  return "Int16";
966  }
967 };
968 
969 /// Implements the value conversion
970 /// abstraction for the integer fields.
974 <
975  UInt16,
977 >
978 {
979  const Char*
980  typeName() const
981  {
982  return "UInt16";
983  }
984 };
985 
986 /// Implements the value conversion
987 /// abstraction for the integer fields.
991 <
992  Int32,
994 >
995 {
996  const Char*
997  typeName() const
998  {
999  return "Int32";
1000  }
1001 };
1002 
1003 /// Implements the value conversion
1004 /// abstraction for the integer fields.
1008 <
1009  UInt32,
1011 >
1012 {
1013  const Char*
1014  typeName() const
1015  {
1016  return "UInt32";
1017  }
1018 };
1019 
1020 /// Implements the value conversion
1021 /// abstraction for the integer fields.
1025 <
1026  Int64,
1028 >
1029 {
1030  const Char*
1031  typeName() const
1032  {
1033  return "Int64";
1034  }
1035 };
1036 
1037 /// Implements the value conversion
1038 /// abstraction for the integer fields.
1042 <
1043  UInt64,
1045 >
1046 {
1047  const Char*
1048  typeName() const
1049  {
1050  return "UInt64";
1051  }
1052 };
1053 
1054 //
1055 
1056 /// Implements the value conversion
1057 /// abstraction for the decimal fields.
1060 {
1061  const Char*
1062  typeName() const
1063  {
1064  return "Decimal";
1065  }
1066 
1067  void
1069  std::string& str,
1070  const ValueContainer& container) const
1071  {
1073  str,
1074  container.get<Decimal>());
1075  }
1076 
1077  bool
1079  Decimal& value,
1080  const ValueContainer& container) const
1081  {
1082  value = container.get<Decimal>();
1083 
1084  return true;
1085  }
1086 
1087  static
1088  const
1089  ValueConverter&
1090  self()
1091  {
1092  static
1093  const
1095  self_;
1096 
1097  return self_;
1098  }
1099 };
1100 
1101 //
1102 
1103 /// Implements the value conversion
1104 /// abstraction for the timestamp fields.
1107 {
1108  const Char*
1109  typeName() const
1110  {
1111  return "Timestamp";
1112  }
1113 
1114  void
1116  std::string& str,
1117  const ValueContainer& container) const
1118  {
1120  str,
1121  container.get<Timestamp>());
1122  }
1123 
1124  bool
1126  Int64& value,
1127  const ValueContainer& container) const
1128  {
1129  value =
1130  static_cast
1131  <Int64>
1132  (
1133  container.
1134  get<Timestamp>().
1135  sinceEpoch()
1136  );
1137 
1138  return true;
1139  }
1140 
1141  bool
1143  UInt64& value,
1144  const ValueContainer& container) const
1145  {
1146  value =
1147  container.
1148  get<Timestamp>().
1149  sinceEpoch();
1150 
1151  return true;
1152  }
1153 
1154  bool
1156  Timestamp& value,
1157  const ValueContainer& container) const
1158  {
1159  value = container.get<Timestamp>();
1160 
1161  return true;
1162  }
1163 
1164  static
1165  const
1166  ValueConverter&
1167  self()
1168  {
1169  static
1170  const
1172  self_;
1173 
1174  return self_;
1175  }
1176 };
1177 
1178 //
1179 
1180 /// Implements the value conversion
1181 /// abstraction for the month-year fields.
1185 {
1186  const Char*
1187  typeName() const
1188  {
1189  return "MaturityMonthYear";
1190  }
1191 
1192  void
1194  std::string& str,
1195  const ValueContainer& container) const
1196  {
1198  str,
1199  container.get<MaturityMonthYear>());
1200  }
1201 
1202  bool
1205  const ValueContainer& container) const
1206  {
1207  value =
1208  container.
1209  get
1211  ();
1212 
1213  return true;
1214  }
1215 
1216  static
1217  const
1218  ValueConverter&
1219  self()
1220  {
1221  static
1222  const
1224  self_;
1225 
1226  return self_;
1227  }
1228 };
1229 
1230 //
1231 
1232 inline
1233 void
1235  const Char* typeName)
1236 {
1237  std::string issue;
1238 
1239  issue += "Cannot transform ";
1240 
1241  issue +=
1242  typeName
1243  ? typeName
1244  : "Unknown type";
1245 
1246  issue +=
1247  " value to the value of the requested "
1248  "type because either conversion between "
1249  "types does not exist or the value cannot "
1250  "be fit to the value of the target type. ";
1251 
1252  throw std::domain_error(issue);
1253 }
1254 
1255 //
1256 
1257 /// Identifies kinds of FIX field values.
1259 {
1260  /// Identifies kinds of FIX field values.
1261  enum Enum
1262  {
1265  Bits
1266  };
1267 };
1268 
1269 /// Traits class used identify a field value kind.
1270 template
1271 <
1272  class Value
1273 >
1275 {
1276  typedef
1277  char
1278  Ordinary[1];
1279 
1280  typedef
1281  char
1282  Enumeration[2];
1283 
1284  typedef
1285  char
1286  Bits[3];
1287 
1288  template
1289  <
1290  class Other
1291  >
1292  static
1293  Bits&
1294  kind(
1295  typename
1296  Other::Bits*);
1297 
1298  template
1299  <
1300  class Other
1301  >
1302  static
1303  Enumeration&
1304  kind(
1305  typename
1306  Other::Enum*);
1307 
1308  template
1309  <
1310  class Other
1311  >
1312  static
1313  Ordinary&
1314  kind(
1315  ...);
1316 
1317 public:
1318  enum
1319  {
1320  /// The kind of the given field value by its type.
1321  Kind =
1322  (
1323  sizeof(Bits) ==
1324  sizeof(kind<Value>(NULL))
1325  ? ValueKinds::Bits
1326  : (
1327  sizeof(Enumeration) ==
1328  sizeof(kind<Value>(NULL))
1329  ? ValueKinds::Enumeration
1330  : ValueKinds::Ordinary
1331  )
1332  )
1333  };
1334 };
1335 
1336 /// The field value traits used in
1337 /// conversion related operations.
1338 template
1339 <
1340  class Value,
1341  int
1342 >
1343 struct
1345 {
1346  /// Type of the conversion output.
1347  typedef Value Result;
1348 
1349  /// Converters the given value by using the
1350  /// specified value converter and returns the
1351  /// result of conversion. Throws an exception
1352  /// in case of conversion failure.
1353  static
1354  Result
1356  const
1357  ValueConverter&
1358  converter,
1359  const
1360  ValueContainer&
1361  container)
1362  {
1363  Result result;
1364 
1365  if (!converter.
1366  convert(
1367  result,
1368  container))
1369  {
1371  converter.typeName());
1372  }
1373 
1374  return result;
1375  }
1376 
1377  /// Tries to convert the given value using
1378  /// the given value converter and puts the
1379  /// result of the conversion into the given
1380  /// variable. Returns conversion status.
1381  static
1382  bool
1384  Result& result,
1385  const
1386  ValueConverter&
1387  converter,
1388  const
1389  ValueContainer&
1390  container)
1391  {
1392  return
1393  converter.
1394  convert(
1395  result,
1396  container);
1397  }
1398 };
1399 
1400 /// The field value traits used in
1401 /// conversion related operations.
1402 ///
1403 /// Specialization for enumerations.
1404 template
1405 <
1406  class Enumeration
1407 >
1408 struct
1410 <
1411  Enumeration,
1412  ValueKinds::Enumeration
1413 >
1414 {
1415  /// Type of the conversion output.
1416  typedef
1417  typename
1418  Enumeration::Enum
1420 
1421  /// Converters the given value by using the
1422  /// specified value converter and returns the
1423  /// result of conversion. Throws an exception
1424  /// in case of conversion failure.
1425  static
1426  Result
1428  const
1429  ValueConverter&
1430  converter,
1431  const
1432  ValueContainer&
1433  container)
1434  {
1435  typename
1436  Enumeration::Base
1437  result;
1438 
1439  if (!converter.
1440  convert(
1441  result,
1442  container))
1443  {
1445  converter.typeName());
1446  }
1447 
1448  return
1449  static_cast
1450  <Result>
1451  (result);
1452  }
1453 
1454  /// Tries to convert the given value using
1455  /// the given value converter and puts the
1456  /// result of the conversion into the given
1457  /// variable. Returns conversion status.
1458  static
1459  bool
1461  Result& result,
1462  const
1463  ValueConverter&
1464  converter,
1465  const
1466  ValueContainer&
1467  container)
1468  {
1469  typename
1470  Enumeration::Base
1471  base;
1472 
1473  if (converter.
1474  convert(
1475  base,
1476  container))
1477  {
1478  result =
1479  static_cast
1480  <Result>
1481  (base);
1482 
1483  return true;
1484  }
1485 
1486  return false;
1487  }
1488 };
1489 
1490 /// The field value traits used in
1491 /// conversion related operations.
1492 ///
1493 /// Specialization for bit sets.
1494 template
1495 <
1496  class BitSet
1497 >
1498 struct
1500 <
1501  BitSet,
1502  ValueKinds::Bits
1503 >
1504 {
1505  /// Type of the conversion output.
1506  typedef BitSet Result;
1507 
1508  /// Converters the given value by using the
1509  /// specified value converter and returns the
1510  /// result of conversion. Throws an exception
1511  /// in case of conversion failure.
1512  static
1513  BitSet
1515  const
1516  ValueConverter&
1517  converter,
1518  const
1519  ValueContainer&
1520  container)
1521  {
1522  typename
1523  BitSet::Bits
1524  bits;
1525 
1526  if (!converter.
1527  convert(
1528  bits,
1529  container))
1530  {
1532  converter.typeName());
1533  }
1534 
1535  return BitSet(bits);
1536  }
1537 
1538  /// Tries to convert the given value using
1539  /// the given value converter and puts the
1540  /// result of the conversion into the given
1541  /// variable. Returns conversion status.
1542  static
1543  bool
1545  BitSet& result,
1546  const
1547  ValueConverter&
1548  converter,
1549  const
1550  ValueContainer&
1551  container)
1552  {
1553  typename
1554  BitSet::Bits
1555  bits;
1556 
1557  if (converter.
1558  convert(
1559  bits,
1560  container))
1561  {
1562  result = BitSet(bits);
1563 
1564  return true;
1565  }
1566 
1567  return false;
1568  }
1569 };
1570 
1571 /// Implements value conversion operations
1572 /// through value conversion traits.
1573 template
1574 <
1575  class Value
1576 >
1577 struct
1579 {
1580  /// Conversion traits.
1581  typedef
1583  <
1584  Value,
1586  >
1588 
1589  /// Conversion output type.
1590  typedef
1591  typename
1594 
1595  /// Converts the given value into a value of target
1596  /// type. Throws an exception in case of failure.
1597  typename
1599  operator ()(
1600  const ValueConverter& converter,
1601  const ValueContainer& container) const
1602  {
1603  return
1604  Traits::
1605  convert(
1606  converter,
1607  container);
1608  }
1609 
1610  /// Converts the given value into a value
1611  /// of target type. Returns conversion status.
1612  bool
1613  operator ()(
1614  typename
1615  Traits::Result& result,
1616  const ValueConverter& converter,
1617  const ValueContainer& container) const
1618  {
1619  return
1620  Traits::
1621  convert(
1622  result,
1623  converter,
1624  container);
1625  }
1626 };
1627 
virtual bool convert(UInt16 &, const ValueContainer &) const
bool convert(Int16 &value, const ValueContainer &container) const
ONIXS_CMEMDH_EXPORTED bool fromStr(Decimal &, const Char *, size_t)
bool convert(Decimal &value, const ValueContainer &container) const
virtual bool convert(Timestamp &, const ValueContainer &) const
bool convert(Int8 &value, const ValueContainer &container) const
Int32 Int32
int32.
Definition: Fields.h:69
virtual bool convert(Int16 &, const ValueContainer &) const
DecimalMantissa Mantissa
Aliases mantissa component type.
Definition: Decimal.h:240
bool empty() const
Indicates whether the referenced text is empty.
Definition: String.h:80
bool convert(UInt8 &value, const ValueContainer &container) const
virtual bool convert(Char &, const ValueContainer &) const
static Result convert(const ValueConverter &converter, const ValueContainer &container)
Enum
Identifies kinds of FIX field values.
bool convert(Int8 &value, const ValueContainer &container) const
UInt32 UInt32
uInt32.
Definition: Fields.h:247
bool convert(StrRef &ref, const ValueContainer &container) const
virtual bool convert(MaturityMonthYear &, const ValueContainer &) const
#define ONIXS_CMEMDHFIX_NAMESPACE_BEGIN
Definition: Bootstrap.h:160
void toStr(std::string &str, const ValueContainer &container) const
bool convert(UInt64 &value, const ValueContainer &container) const
bool convert(StrRef &ref, const ValueContainer &container) const
Represents time point without time-zone information.
Definition: Time.h:471
static bool convert(BitSet &result, const ValueConverter &converter, const ValueContainer &container)
bool convert(Int64 &value, const ValueContainer &container) const
virtual bool convert(UInt8 &, const ValueContainer &) const
bool convert(Int32 &value, const ValueContainer &container) const
void toStr(std::string &str, const ValueContainer &container) const
static bool convert(Result &result, const ValueConverter &converter, const ValueContainer &container)
void toStr(std::string &str, const ValueContainer &container) const
virtual const Char * typeName() const =0
static bool convert(Result &result, const ValueConverter &converter, const ValueContainer &container)
bool convert(Int32 &value, const ValueContainer &container) const
virtual bool convert(Decimal &, const ValueContainer &) const
bool convert(UInt64 &value, const ValueContainer &container) const
bool convert(Decimal &value, const ValueContainer &container) const
static BitSet convert(const ValueConverter &converter, const ValueContainer &container)
bool convert(Int8 &value, const ValueContainer &container) const
UInt8 UInt8
uInt8.
Definition: Fields.h:255
bool convert(UInt8 &value, const ValueContainer &container) const
char Char
Character type alias.
Definition: String.h:36
bool convert(UInt16 &value, const ValueContainer &container) const
ValueConversionTraits< Value, ValueKind< Value >::Kind > Traits
Conversion traits.
UInt64 UInt64
uInt64.
Definition: Fields.h:251
bool value(Number &number, const MultiContainer &container, Tag tag)
bool convert(Timestamp &value, const ValueContainer &container) const
Identifies kinds of FIX field values.
bool convert(Int32 &value, const ValueContainer &container) const
bool convert(UInt64 &value, const ValueContainer &container) const
virtual bool convert(Int64 &, const ValueContainer &) const
void toStr(std::string &str, const ValueContainer &container) const
#define ONIXS_CMEMDHFIX_NAMESPACE_END
Definition: Bootstrap.h:164
Traits class used identify a field value kind.
virtual bool convert(UInt64 &, const ValueContainer &) const
Int16 Int16
int16.
Definition: Fields.h:65
const Char * items() const
Read-only content.
Definition: String.h:86
bool convert(Timestamp &value, const ValueContainer &container) const
A real number with floating exponent.
Definition: Decimal.h:231
virtual bool convert(Int32 &, const ValueContainer &) const
bool convert(Int64 &value, const ValueContainer &container) const
Traits::Result Result
Conversion output type.
bool convert(UInt32 &value, const ValueContainer &container) const
void toStr(std::string &str, const ValueContainer &container) const
bool convert(UInt8 &value, const ValueContainer &container) const
bool convert(Char &value, const ValueContainer &container) const
bool convert(UInt16 &value, const ValueContainer &container) const
virtual void toStr(std::string &, const ValueContainer &) const
Value Result
Type of the conversion output.
bool convert(MaturityMonthYear &value, const ValueContainer &container) const
virtual bool convert(UInt32 &, const ValueContainer &) const
void toStr(std::string &str, const ValueContainer &container) const
bool convert(Timestamp &, const ValueContainer &) const
bool convert(UInt16 &value, const ValueContainer &container) const
bool convert(Decimal &value, const ValueContainer &container) const
bool convert(Decimal &value, const ValueContainer &container) const
virtual bool convert(StrRef &, const ValueContainer &) const
UInt16 UInt16
uInt16 optional.
Definition: Fields.h:243
bool convert(UInt32 &value, const ValueContainer &container) const
bool convert(Int64 &value, const ValueContainer &container) const
Int8 Int8
int8.
Definition: Fields.h:73
static Result convert(const ValueConverter &converter, const ValueContainer &container)
void throwBadConversion(const Char *typeName)
size_t size() const
Number of chars.
Definition: String.h:92
bool convert(Int64 &value, const ValueContainer &container) const
bool convert(Int16 &value, const ValueContainer &container) const
bool convert(Int16 &value, const ValueContainer &container) const
#define ONIXS_CMEMDH_EXPORTED_STRUCT
Definition: Bootstrap.h:58
bool convert(Char &value, const ValueContainer &container) const
Container for a value of any supported kinds.
bool convert(UInt32 &value, const ValueContainer &container) const
bool convert(UInt64 &value, const ValueContainer &container) const
ONIXS_CMEMDH_EXPORTED void toStr(std::string &, BookState::Enum)
Serializes book state value into a string.
virtual bool convert(Int8 &, const ValueContainer &) const
bool convert(Char &value, const ValueContainer &container) const