OnixS C++ CME iLink 3 Binary Order Entry Handler  1.18.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 
25 
30 
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 const Char* typeName() const ONIXS_ILINK3_NOTHROW = 0;
45 
46  /// Outputs the text presentation of the value
47  /// stored in the given container into the given string.
48  virtual void toStr(std::string&, const ValueContainer&) const
49  {
50  }
51 
52  /// \return the text presentation of the value.
53  virtual StrRef toStr(Char*, size_t, const ValueContainer&) const
54  {
55  throwBadConversion(typeName());
56  }
57 
58  /// Tries to convert the value into a string reference.
59  ///
60  /// \return Indicates whether the conversion successful.
61  virtual bool convert(StrRef&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
62  {
63  return false;
64  }
65 
66  /// Tries to convert the value into a character.
67  ///
68  /// \return Indicates whether the conversion successful.
69  virtual bool convert(Char&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
70  {
71  return false;
72  }
73 
74  /// Tries to convert the value into an integer.
75  ///
76  /// \return Indicates whether the conversion successful.
77  virtual bool convert(Int8&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
78  {
79  return false;
80  }
81 
82  /// Tries to convert the value into an integer.
83  ///
84  /// \return Indicates whether the conversion successful.
85  virtual bool convert(UInt8&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
86  {
87  return false;
88  }
89 
90  /// Tries to convert the value into an integer.
91  ///
92  /// \return Indicates whether the conversion successful.
93  virtual bool convert(Int16&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
94  {
95  return false;
96  }
97 
98  /// Tries to convert the value into an integer.
99  ///
100  /// \return Indicates whether the conversion successful.
101  virtual bool convert(UInt16&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
102  {
103  return false;
104  }
105 
106  /// Tries to convert the value into an integer.
107  ///
108  /// \return Indicates whether the conversion successful.
109  virtual bool convert(Int32&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
110  {
111  return false;
112  }
113 
114  /// Tries to convert the value into an integer.
115  ///
116  /// \return Indicates whether the conversion successful.
117  virtual bool convert(UInt32&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
118  {
119  return false;
120  }
121 
122  /// Tries to convert the value into an integer.
123  ///
124  /// \return Indicates whether the conversion successful.
125  virtual bool convert(Int64&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
126  {
127  return false;
128  }
129 
130  /// Tries to convert the value into an integer.
131  ///
132  /// \return Indicates whether the conversion successful.
133  virtual bool convert(UInt64&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
134  {
135  return false;
136  }
137 
138  /// Tries to convert the value into a Decimal.
139  ///
140  /// \return Indicates whether the conversion successful.
141  virtual bool convert(Decimal&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
142  {
143  return false;
144  }
145 
146  /// Tries to convert the value into a timestamp.
147  ///
148  /// \return Indicates whether the conversion successful.
149  virtual bool convert(Timestamp&, const ValueContainer&) const
150  {
151  return false;
152  }
153 
154  /// Tries to convert the value into a month-year.
155  ///
156  /// \return Indicates whether the conversion successful.
157  virtual bool convert(MaturityMonthYear&, const ValueContainer&) const ONIXS_ILINK3_NOTHROW
158  {
159  return false;
160  }
161 
162 protected:
164 };
165 
168 {
170  {
171  return "Null";
172  }
173 
175 
176 protected:
178 };
179 
180 /// Implements the value conversion for text fields.
183 {
185 
187  {
188  return "String";
189  }
190 
191  void
193  std::string& str,
194  const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
195  {
196  const
197  StrRef&
198  ref =
199  container.get<StrRef>();
200 
201  str.
202  assign(
203  ref.data(),
204  ref.size());
205  }
206 
207  StrRef
209  Char*, size_t, const ValueContainer& container) const ONIXS_ILINK3_NOTHROW ONIXS_ILINK3_OVERRIDE
210  {
211  return container.get<StrRef>();
212  }
213 
214  bool
216  StrRef& ref,
218  {
219  ref = container.get<StrRef>();
220 
221  return true;
222  }
223 
224  bool
226  Char& value,
228  {
229  const
230  StrRef&
231  str =
232  container.get<StrRef>();
233 
234  if (1 == str.size())
235  {
236  value = str[0];
237 
238  return true;
239  }
240  else if (str.empty())
241  {
242  value = 0;
243 
244  return true;
245  }
246 
247  return false;
248  }
249 
250  bool
252  Int8& value,
254  {
255  const
256  StrRef&
257  str =
258  container.get<StrRef>();
259 
260  return
261  fromStr(
262  value,
263  str.data(),
264  str.size());
265  }
266 
267  bool
269  UInt8& value,
271  {
272  const
273  StrRef&
274  str =
275  container.get<StrRef>();
276 
277  return
278  fromStr(
279  value,
280  str.data(),
281  str.size());
282  }
283 
284  bool
286  Int16& value,
288  {
289  const
290  StrRef&
291  str =
292  container.get<StrRef>();
293 
294  return
295  fromStr(
296  value,
297  str.data(),
298  str.size());
299  }
300 
301  bool
303  UInt16& value,
305  {
306  const
307  StrRef&
308  str =
309  container.get<StrRef>();
310 
311  return
312  fromStr(
313  value,
314  str.data(),
315  str.size());
316  }
317 
318  bool
320  Int32& value,
322  {
323  const
324  StrRef&
325  str =
326  container.get<StrRef>();
327 
328  return
329  fromStr(
330  value,
331  str.data(),
332  str.size());
333  }
334 
335  bool
337  UInt32& value,
339  {
340  const
341  StrRef&
342  str =
343  container.get<StrRef>();
344 
345  return
346  fromStr(
347  value,
348  str.data(),
349  str.size());
350  }
351 
352  bool
354  Int64& value,
356  {
357  const
358  StrRef&
359  str =
360  container.get<StrRef>();
361 
362  return
363  fromStr(
364  value,
365  str.data(),
366  str.size());
367  }
368 
369  bool
371  UInt64& value,
373  {
374  const
375  StrRef&
376  str =
377  container.get<StrRef>();
378 
379  return
380  fromStr(
381  value,
382  str.data(),
383  str.size());
384  }
385 
386  bool
388  Decimal& value,
390  {
391  const
392  StrRef&
393  str =
394  container.get<StrRef>();
395 
396  return
397  fromStr(
398  value,
399  str.data(),
400  str.size());
401  }
402 
403  bool
405  Timestamp& value,
406  const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
407  {
408  const
409  StrRef&
410  str =
411  container.get<StrRef>();
412 
413  return
414  fromStr(
415  value,
416  str.data(),
417  str.size());
418  }
419 
420  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
421 
422 protected:
424 };
425 
426 //
427 
428 /// Implements the value conversion for
429 /// fields whose values represent a single character.
432 {
434 
436  {
437  return "Char";
438  }
439 
440  void
442  std::string& str,
443  const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
444  {
445  str.append(
446  1,
447  container.get<Char>());
448  }
449 
450  StrRef
452  Char*, size_t, const ValueContainer& container) const ONIXS_ILINK3_NOTHROW ONIXS_ILINK3_OVERRIDE
453  {
454  return
455  StrRef(
456  &container.get<Char>(),
457  1);
458  }
459 
460  bool
462  StrRef& ref,
464  {
465  ref =
466  StrRef(
467  &container.get<Char>(),
468  1);
469 
470  return true;
471  }
472 
473  bool
475  Char& value,
477  {
478  value = container.get<Char>();
479 
480  return true;
481  }
482 
483  bool
485  Int8& value,
487  {
488  return
489  charToDigit(
490  value,
491  container.get<Char>());
492  }
493 
494  bool
496  UInt8& value,
498  {
499  return
500  charToDigit(
501  value,
502  container.get<Char>());
503  }
504 
505  bool
507  Int16& value,
509  {
510  return
511  charToDigit(
512  value,
513  container.get<Char>());
514  }
515 
516  bool
518  UInt16& value,
520  {
521  return
522  charToDigit(
523  value,
524  container.get<Char>());
525  }
526 
527  bool
529  Int32& value,
531  {
532  return
533  charToDigit(
534  value,
535  container.get<Char>());
536  }
537 
538  bool
540  UInt32& value,
542  {
543  return
544  charToDigit(
545  value,
546  container.get<Char>());
547  }
548 
549  bool
551  Int64& value,
553  {
554  return
555  charToDigit(
556  value,
557  container.get<Char>());
558  }
559 
560  bool
562  UInt64& value,
564  {
565  return
566  charToDigit(
567  value,
568  container.get<Char>());
569  }
570 
571  bool
573  Decimal& value,
575  {
576  Decimal::Mantissa mantissa;
577 
578  if (charToDigit(
579  mantissa,
580  container.get<Char>()))
581  {
582  value = Decimal(mantissa, 0);
583 
584  return true;
585  }
586 
587  return false;
588  }
589 
590  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
591 
592 protected:
594 
595 private:
596  template
597  <
598  class Integer
599  >
600  static
601  bool
602  charToDigit(
603  Integer& converted,
604  Char original) ONIXS_ILINK3_NOTHROW
605  {
606  if ('0' <= original &&
607  '9' >= original)
608  {
609  converted =
610  static_cast
611  <Integer>
612  (original - '0');
613 
614  return true;
615  }
616 
617  return false;
618  }
619 };
620 
621 /// Implements the value conversion for integer fields.
622 template
623 <
624  class Integer
625 >
626 class
628 : public ValueConverter
629 {
630  template
631  <
632  class Integral,
633  bool IsSigned
634  >
635  struct
636  FitsToChar
637  {
638  bool
639  operator ()(
640  Integral value) const ONIXS_ILINK3_NOTHROW
641  {
642  return (
643  0 <= value &&
644  value < 10
645  );
646  }
647  };
648 
649  template
650  <
651  class Integral
652  >
653  struct
654  FitsToChar
655  <
656  Integral,
657  false
658  >
659  {
660  bool
661  operator ()(
662  Integral value) const ONIXS_ILINK3_NOTHROW
663  {
664  return (value < 10);
665  }
666  };
667 
668  typedef
669  FitsToChar
670  <
671  Integer,
672  !(
673  static_cast<Integer>(-1) >
674  static_cast<Integer>(0)
675  )
676  >
677  CanFitToChar;
678 
679 public:
681 
682  void
684  std::string& str,
685  const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
686  {
688  str,
689  container.get<Integer>());
690  }
691 
692  StrRef
694  Char* buf, size_t size, const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
695  {
696  assert(buf);
697 
698  const size_t converted =
700  container.get<Integer>(),
701  buf,
702  size);
703 
704  assert(converted < size);
705  assert(converted != 0);
706 
707  return
708  StrRef(buf, converted);
709  }
710 
711  bool
713  Char& value,
715  {
716  const
717  Integer
718  actual =
719  container.get<Integer>();
720 
721  if (CanFitToChar()(actual))
722  {
723  value =
724  static_cast
725  <Char>
726  ('0' + actual);
727 
728  return true;
729  }
730 
731  return false;
732  }
733 
734  bool
736  Int8& value,
738  {
739  value =
740  numericCast<Int8>(
741  container.get<Integer>());
742 
743  return true;
744  }
745 
746  bool
748  UInt8& value,
750  {
751  value =
752  numericCast<UInt8>(
753  container.get<Integer>());
754 
755  return true;
756  }
757 
758  bool
760  Int16& value,
762  {
763  value =
764  numericCast<Int16>(
765  container.get<Integer>());
766 
767  return true;
768  }
769 
770  bool
772  UInt16& value,
774  {
775  value =
776  numericCast<UInt16>(
777  container.get<Integer>());
778 
779  return true;
780  }
781 
782  bool
784  Int32& value,
786  {
787  value =
788  numericCast<Int32>(
789  container.get<Integer>());
790 
791  return true;
792  }
793 
794  bool
796  UInt32& value,
798  {
799  value =
800  numericCast<UInt32>(
801  container.get<Integer>());
802 
803  return true;
804  }
805 
806  bool
808  Int64& value,
810  {
811  value =
812  numericCast<Int64>(
813  container.get<Integer>());
814 
815  return true;
816  }
817 
818  bool
820  UInt64& value,
822  {
823  value =
824  numericCast<UInt64>(
825  container.get<Integer>());
826 
827  return true;
828  }
829 
830  bool
832  Decimal& value,
834  {
835  value =
836  Decimal
837  (
838  numericCast<Decimal::Mantissa>(
839  container.get<Integer>()),
840  0
841  );
842 
843  return true;
844  }
845 
846  bool
848  Timestamp& value,
850  {
851  value =
853  numericCast<UInt64>(
854  container.get<Integer>()));
855 
856  return true;
857  }
858 
859 protected:
861 };
862 
863 /// Implements the value conversion for integer fields.
867 <
868  Int8
869 >
870 {
872  {
873  return "Int8";
874  }
875 
876  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
877 
878 protected:
880 };
881 
882 /// Implements the value conversion for integer fields.
886 <
887  UInt8
888 >
889 {
891  {
892  return "UInt8";
893  }
894 
895  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
896 
897 protected:
899 };
900 
901 /// Implements the value conversion for integer fields.
905 <
906  Int16
907 >
908 {
910  {
911  return "Int16";
912  }
913 
914  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
915 
916 protected:
918 };
919 
920 /// Implements the value conversion for integer fields.
924 <
925  UInt16
926 >
927 {
929  {
930  return "UInt16";
931  }
932 
933  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
934 
935 protected:
937 };
938 
939 /// Implements the value conversion for integer fields.
943 <
944  Int32
945 >
946 {
948  {
949  return "Int32";
950  }
951 
952  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
953 
954 protected:
956 };
957 
958 /// Implements the value conversion for integer fields.
962 <
963  UInt32
964 >
965 {
967  {
968  return "UInt32";
969  }
970 
971  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
972 
973 protected:
975 };
976 
977 /// Implements the value conversion for integer fields.
981 <
982  Int64
983 >
984 {
986  {
987  return "Int64";
988  }
989 
990  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
991 
992 protected:
994 };
995 
996 /// Implements the value conversion for integer fields.
1000 <
1001  UInt64
1002 >
1003 {
1005  {
1006  return "UInt64";
1007  }
1008 
1009  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
1010 
1011 protected:
1013 };
1014 
1015 /// Implements the value conversion the Decimal fields.
1018 {
1020 
1022  {
1023  return "Decimal";
1024  }
1025 
1026  void
1028  std::string& str,
1029  const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
1030  {
1032  str,
1033  container.get<Decimal>());
1034  }
1035 
1036  StrRef
1038  Char* buf, size_t size, const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
1039  {
1040  assert(buf);
1041 
1042  const size_t converted =
1044  container.get<Decimal>(),
1045  buf,
1046  size);
1047 
1048  assert(converted != 0);
1049  assert(converted < size);
1050 
1051  return
1052  StrRef(buf, converted);
1053  }
1054 
1055  bool
1057  Decimal& value,
1059  {
1060  value = container.get<Decimal>();
1061 
1062  return true;
1063  }
1064 
1065  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
1066 
1067 protected:
1069 };
1070 
1071 //
1072 
1073 /// Implements the value conversion for Timestamp fields.
1076 {
1078 
1080  {
1081  return "Timestamp";
1082  }
1083 
1084  void
1086  std::string& str,
1087  const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
1088  {
1090  str,
1091  container.get<Timestamp>());
1092  }
1093 
1094  StrRef
1096  Char* buf, size_t size, const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
1097  {
1098  assert(buf);
1099 
1100  const size_t converted =
1102  container.get<Timestamp>(),
1103  buf,
1104  size);
1105 
1106  assert(converted < size);
1107  assert(converted != 0);
1108 
1109  return
1110  StrRef(buf, converted);
1111  }
1112 
1113  bool
1115  Int64& value,
1117  {
1118  value =
1119  numericCast<Int64>
1120  (
1121  container.
1122  get<Timestamp>().
1123  sinceEpoch()
1124  );
1125 
1126  return true;
1127  }
1128 
1129  bool
1131  UInt64& value,
1133  {
1134  value =
1135  container.
1136  get<Timestamp>().
1137  sinceEpoch();
1138 
1139  return true;
1140  }
1141 
1142  bool
1144  Timestamp& value,
1146  {
1147  value = container.get<Timestamp>();
1148 
1149  return true;
1150  }
1151 
1152  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
1153 
1154 protected:
1156 };
1157 
1158 /// Implements the value conversion for month-year fields.
1162 {
1164  using ValueConverter::toStr;
1165 
1167  {
1168  return "MaturityMonthYear";
1169  }
1170 
1171  void
1173  std::string& str,
1174  const ValueContainer& container) const ONIXS_ILINK3_OVERRIDE
1175  {
1177  str,
1178  container.get<MaturityMonthYear>());
1179  }
1180 
1181  bool
1183  MaturityMonthYear& value,
1185  {
1186  value =
1187  container.
1188  get
1190  ();
1191 
1192  return true;
1193  }
1194 
1195  static const ValueConverter& self() ONIXS_ILINK3_NOTHROW;
1196 
1197 protected:
1199 };
1200 
1201 /// Identifies the kind of the field value.
1203 {
1204  enum Enum
1205  {
1208  Bits
1209  };
1210 };
1211 
1212 /// Traits class used to identify a field value.
1213 template
1214 <
1215  class Value
1216 >
1218 {
1219  typedef
1220  char
1221  Ordinary[1];
1222 
1223  typedef
1224  char
1225  Enumeration[2];
1226 
1227  typedef
1228  char
1229  Bits[3];
1230 
1231  template
1232  <
1233  class Other
1234  >
1235  static
1236  Bits&
1237  kind(
1238  typename
1239  Other::Bits*);
1240 
1241  template
1242  <
1243  class Other
1244  >
1245  static
1246  Enumeration&
1247  kind(
1248  typename
1249  Other::Enum*);
1250 
1251  template
1252  <
1253  class Other
1254  >
1255  static
1256  Ordinary&
1257  kind(
1258  ...);
1259 
1260 public:
1261  enum
1262  {
1263  /// The kind of the given field value by its type.
1264  Kind =
1265  (
1266  sizeof(Bits) ==
1267  sizeof(kind<Value>(ONIXS_ILINK3_NULLPTR))
1268  ? ValueKinds::Bits
1269  : (
1270  sizeof(Enumeration) ==
1271  sizeof(kind<Value>(ONIXS_ILINK3_NULLPTR))
1272  ? ValueKinds::Enumeration
1273  : ValueKinds::Ordinary
1274  )
1275  )
1276  };
1277 };
1278 
1279 /// Field value traits used in conversion operations.
1280 template
1281 <
1282  class Value,
1283  int
1284 >
1285 struct
1287 {
1288  /// Type of the conversion output.
1289  typedef Value Result;
1290 
1291  /// Converters the given value by using the
1292  /// specified value converter.
1293  ///
1294  /// \return The result of the conversion.
1295  ///
1296  /// \throw An exception in case of a conversion failure.
1297  static Result convert(const ValueConverter& converter, const ValueContainer& container)
1298  {
1299  Result result;
1300 
1301  if (!converter.
1302  convert(
1303  result,
1304  container))
1305  {
1306  throwBadConversion(
1307  converter.typeName());
1308  }
1309 
1310  return result;
1311  }
1312 
1313  /// Tries to convert the given value using
1314  /// the given value converter and puts the
1315  /// result of the conversion into the given
1316  /// variable.
1317  ///
1318  /// \return the conversion status.
1319  static bool convert(Result& result, const ValueConverter& converter, const ValueContainer& container)
1320  {
1321  return
1322  converter.
1323  convert(
1324  result,
1325  container);
1326  }
1327 };
1328 
1329 /// Field value traits used in conversion operations.
1330 ///
1331 /// Specialization for enumerations.
1332 template
1333 <
1334  class Enumeration
1335 >
1336 struct
1338 <
1339  Enumeration,
1340  ValueKinds::Enumeration
1341 >
1342 {
1343  /// Type of the conversion output.
1344  typedef
1345  typename
1346  Enumeration::Enum
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
1358  converter,
1359  const
1361  container)
1362  {
1363  typename
1364  Enumeration::Base
1365  result;
1366 
1367  if (!converter.
1368  convert(
1369  result,
1370  container))
1371  {
1372  throwBadConversion(
1373  converter.typeName());
1374  }
1375 
1376  return
1377  static_cast
1378  <Result>
1379  (result);
1380  }
1381 
1382  /// Tries to convert the given value using
1383  /// the given value converter and puts the
1384  /// result of the conversion into the given
1385  /// variable. Returns conversion status.
1386  static
1387  bool
1389  Result& result,
1390  const
1392  converter,
1393  const
1395  container)
1396  {
1397  typename
1398  Enumeration::Base
1399  base;
1400 
1401  if (converter.
1402  convert(
1403  base,
1404  container))
1405  {
1406  result =
1407  static_cast
1408  <Result>
1409  (base);
1410 
1411  return true;
1412  }
1413 
1414  return false;
1415  }
1416 };
1417 
1418 /// The field value traits used in
1419 /// conversion related operations.
1420 ///
1421 /// Specialization for bit sets.
1422 template
1423 <
1424  class BitSet
1425 >
1426 struct
1428 <
1429  BitSet,
1430  ValueKinds::Bits
1431 >
1432 {
1433  /// Type of the conversion output.
1434  typedef BitSet Result;
1435 
1436  /// Converters the given value by using the
1437  /// specified value converter and returns the
1438  /// result of conversion. Throws an exception
1439  /// in case of conversion failure.
1440  static
1441  BitSet
1443  const
1445  converter,
1446  const
1448  container)
1449  {
1450  typename
1451  BitSet::Bits
1452  bits;
1453 
1454  if (!converter.
1455  convert(
1456  bits,
1457  container))
1458  {
1459  throwBadConversion(
1460  converter.typeName());
1461  }
1462 
1463  return BitSet(bits);
1464  }
1465 
1466  /// Tries to convert the given value using
1467  /// the given value converter and puts the
1468  /// result of the conversion into the given
1469  /// variable. Returns conversion status.
1470  static
1471  bool
1473  BitSet& result,
1474  const
1476  converter,
1477  const
1479  container)
1480  {
1481  typename
1482  BitSet::Bits
1483  bits;
1484 
1485  if (converter.
1486  convert(
1487  bits,
1488  container))
1489  {
1490  result = BitSet(bits);
1491 
1492  return true;
1493  }
1494 
1495  return false;
1496  }
1497 };
1498 
1499 /// Implements value conversion operations
1500 /// through value conversion traits.
1501 template
1502 <
1503  class Value
1504 >
1505 struct
1507 {
1508  /// Conversion traits.
1509  typedef
1511  <
1512  Value,
1514  >
1516 
1517  /// Conversion output type.
1518  typedef
1519  typename
1522 
1523  /// Converts the given value into a value of target
1524  /// type. Throws an exception in case of failure.
1525  typename
1527  operator ()(
1528  const ValueConverter& converter,
1529  const ValueContainer& container) const
1530  {
1531  return
1532  Traits::
1533  convert(
1534  converter,
1535  container);
1536  }
1537 
1538  /// Converts the given value into a value
1539  /// of target type. Returns conversion status.
1540  bool
1541  operator ()(
1542  typename
1543  Traits::Result& result,
1544  const ValueConverter& converter,
1545  const ValueContainer& container) const
1546  {
1547  return
1548  Traits::
1549  convert(
1550  result,
1551  converter,
1552  container);
1553  }
1554 };
1555 
bool convert(UInt8 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
#define ONIXS_ILINK3_NULLPTR
Definition: Compiler.h:182
virtual bool convert(UInt16 &, const ValueContainer &) const noexcept
Tries to convert the value into an integer.
bool convert(Int64 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
StrRef toStr(Char *, size_t, const ValueContainer &container) const noexceptoverride
std::string toStr(const FixedPointDecimal< Mantissa, Exponent > &)
Serializes a fixed-point decimal into a string.
Timestamp makeTimestamp(Timestamp::Ticks ticks) noexcept
Make Timestamp helper.
Definition: Time.h:660
Implements the value conversion the Decimal fields.
std::basic_string_view< Char > StrRef
Definition: StrRef.h:46
bool convert(StrRef &ref, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a string reference.
bool convert(UInt16 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
Identifies the kind of the field value.
char Char
Character type alias.
Definition: String.h:30
bool convert(Int32 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool convert(UInt32 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
FloatingPointDecimal< Int64, Int32 > Decimal
Universal decimal type.
bool convert(Char &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a character.
bool convert(UInt32 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
virtual void toStr(std::string &, const ValueContainer &) const
Outputs the text presentation of the value stored in the given container into the given string...
bool convert(Int16 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
A real number with a floating exponent.
Definition: Decimal.h:32
#define ONIXS_ILINK3_OVERRIDE
Definition: Compiler.h:180
bool convert(Int16 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool convert(UInt16 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool convert(Int8 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
Implements the value conversion for integer fields.
static BitSet convert(const ValueConverter &converter, const ValueContainer &container)
Converters the given value by using the specified value converter and returns the result of conversio...
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
bool convert(UInt8 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
virtual bool convert(Int64 &, const ValueContainer &) const noexcept
Tries to convert the value into an integer.
static bool convert(Result &result, const ValueConverter &converter, const ValueContainer &container)
Tries to convert the given value using the given value converter and puts the result of the conversio...
Implements the value conversion for integer fields.
virtual bool convert(Int32 &, const ValueContainer &) const noexcept
Tries to convert the value into an integer.
#define ONIXS_ILINK3_MESSAGING_TAGBASED_NAMESPACE_END
Definition: ABI.h:153
bool convert(MaturityMonthYear &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a month-year.
bool convert(Timestamp &value, const ValueContainer &container) const override
Tries to convert the value into a timestamp.
StrRef toStr(Char *, size_t, const ValueContainer &container) const noexceptoverride
StrRef toStr(Char *buf, size_t size, const ValueContainer &container) const override
virtual bool convert(UInt64 &, const ValueContainer &) const noexcept
Tries to convert the value into an integer.
void toStr(std::string &str, const ValueContainer &container) const override
Outputs the text presentation of the value stored in the given container into the given string...
bool convert(UInt64 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool convert(Int16 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
MantissaType Mantissa
Mantissa component type.
Definition: Decimal.h:56
bool convert(Decimal &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a Decimal.
void toStr(std::string &str, const ValueContainer &container) const override
Outputs the text presentation of the value stored in the given container into the given string...
UInt16 UInt16
uInt16.
Definition: Fields.h:296
bool convert(UInt64 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool convert(Timestamp &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a timestamp.
virtual bool convert(MaturityMonthYear &, const ValueContainer &) const noexcept
Tries to convert the value into a month-year.
virtual StrRef toStr(Char *, size_t, const ValueContainer &) const
bool convert(UInt16 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool fromStr(Decimal &, const Char *, size_t) noexcept
Deserializes a decimal number from the given text presentation.
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
bool convert(StrRef &ref, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a string reference.
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
Implements the value conversion for integer fields.
bool convert(Int32 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool convert(UInt64 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
Implements the value conversion for Timestamp fields.
virtual bool convert(Char &, const ValueContainer &) const noexcept
Tries to convert the value into a character.
#define ONIXS_ILINK3_DEFAULT
Definition: Compiler.h:202
bool convert(Timestamp &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a timestamp.
void toStr(std::string &str, const ValueContainer &container) const override
Outputs the text presentation of the value stored in the given container into the given string...
void toStr(std::string &str, const ValueContainer &container) const override
Outputs the text presentation of the value stored in the given container into the given string...
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
virtual bool convert(Int16 &, const ValueContainer &) const noexcept
Tries to convert the value into an integer.
static bool convert(BitSet &result, const ValueConverter &converter, const ValueContainer &container)
Tries to convert the given value using the given value converter and puts the result of the conversio...
ValueConversionTraits< Value, ValueKind< Value >::Kind > Traits
Conversion traits.
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
static Result convert(const ValueConverter &converter, const ValueContainer &container)
Converters the given value by using the specified value converter and returns the result of conversio...
Implements value conversion operations through value conversion traits.
virtual bool convert(UInt8 &, const ValueContainer &) const noexcept
Tries to convert the value into an integer.
Implements the value conversion for fields whose values represent a single character.
virtual bool convert(StrRef &, const ValueContainer &) const noexcept
Tries to convert the value into a string reference.
Implements the value conversion for integer fields.
bool convert(Int32 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool convert(Int64 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool convert(Char &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a character.
void toStr(std::string &str, const ValueContainer &container) const override
Outputs the text presentation of the value stored in the given container into the given string...
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
virtual bool convert(UInt32 &, const ValueContainer &) const noexcept
Tries to convert the value into an integer.
virtual bool convert(Int8 &, const ValueContainer &) const noexcept
Tries to convert the value into an integer.
virtual const Char * typeName() const noexcept=0
The name of the type whose values are manipulated through the given converter.
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
Implements the value conversion for integer fields.
bool convert(UInt64 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
Field value traits used in conversion operations.
bool convert(Decimal &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a Decimal.
#define ONIXS_ILINK3_FINAL
Definition: Compiler.h:181
Implements the value conversion for integer fields.
Implements the value conversion for text fields.
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
bool convert(Char &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a character.
bool convert(Decimal &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a Decimal.
UInt64 UInt64
uInt64.
Definition: Fields.h:308
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
virtual bool convert(Timestamp &, const ValueContainer &) const
Tries to convert the value into a timestamp.
bool convert(Decimal &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into a Decimal.
#define ONIXS_ILINK3_EXPORTED_STRUCT
Definition: ABI.h:48
Implements the value conversion for integer fields.
bool convert(Int64 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
UInt32 UInt32
uInt32.
Definition: Fields.h:302
Implements the value conversion for month-year fields.
bool convert(UInt8 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
Implements the value conversion for integer fields.
static bool convert(Result &result, const ValueConverter &converter, const ValueContainer &container)
Tries to convert the given value using the given value converter and puts the result of the conversio...
Traits class used to identify a field value.
bool convert(UInt32 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
bool convert(Int8 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
The time point without the time-zone information.
Definition: Time.h:467
#define ONIXS_ILINK3_MESSAGING_TAGBASED_NAMESPACE_BEGIN
Definition: ABI.h:149
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
Implements the value conversion for integer fields.
Abstraction gathering operations over a value of a particular type stored as a field in a message...
static Result convert(const ValueConverter &converter, const ValueContainer &container)
Converters the given value by using the specified value converter.
bool convert(Int8 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
#define ONIXS_ILINK3_NODISCARD
Definition: Compiler.h:185
void toStr(std::string &str, const ValueContainer &container) const override
Outputs the text presentation of the value stored in the given container into the given string...
bool convert(Int64 &value, const ValueContainer &container) const noexceptoverride
Tries to convert the value into an integer.
#define ONIXS_ILINK3_NOTHROW
Definition: Compiler.h:176
virtual bool convert(Decimal &, const ValueContainer &) const noexcept
Tries to convert the value into a Decimal.
StrRef toStr(Char *buf, size_t size, const ValueContainer &container) const override
const Char * typeName() const noexceptoverride
The name of the type whose values are manipulated through the given converter.
void convert(FixedPointDecimal< MantissaType, ExponentType > &res, const Decimal &number)
StrRef toStr(Char *buf, size_t size, const ValueContainer &container) const override