OnixS C++ B3 Binary UMDF Market Data Handler  1.4.2
API documentation
Integral.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 
26 #include <string>
27 
29 
30 #if defined (_MSC_VER)
31 
32 typedef signed char Int8;
33 typedef unsigned char UInt8;
34 
35 typedef signed short Int16;
36 typedef unsigned short UInt16;
37 
38 typedef signed int Int32;
39 typedef unsigned int UInt32;
40 
41 typedef signed long long Int64;
42 typedef unsigned long long UInt64;
43 
44 #elif defined (__GNUC__)
45 
46 typedef signed char Int8;
47 typedef unsigned char UInt8;
48 
49 typedef signed short Int16;
50 typedef unsigned short UInt16;
51 
52 #if defined (__LP64__)
53 
54 typedef signed int Int32;
55 typedef unsigned int UInt32;
56 
57 typedef signed long Int64;
58 typedef unsigned long UInt64;
59 
60 #else
61 
62 typedef signed int Int32;
63 typedef unsigned int UInt32;
64 
65 typedef signed long long Int64;
66 typedef unsigned long long UInt64;
67 
68 #endif
69 
70 #else
71 
72 // Compiler is not (yet) supported.
73 // Integral types must be defined explicitly.
74 
75 #error \
76  Cannot identify compiler toolset to define integral types. \
77  Please contact support@onixs.biz on further assistance.
78 
79 #endif
80 
81 /// Integral constant.
82 template
83 <
84  typename Type,
85  Type Constant
86 >
88 {
89  /// Type of the constant.
90  typedef Type Value;
91 
92  /// \return value of the constant.
94  operator Value() const ONIXS_B3_UMDF_MD_NOTHROW
95  {
96  return Constant;
97  }
98 
99  /// \return value of the constant.
102  {
103  return Constant;
104  }
105 
106  /// \return value of the constant.
109  {
110  return Constant;
111  }
112 };
113 
114 /// Serializes the given integer into a string.
116 void toStr(std::string&, Int8);
117 
118 /// Serializes the given integer into a string.
119 inline
120 ONIXS_B3_UMDF_MD_NODISCARD
121 std::string
123  Int8 number)
124 {
125  std::string str;
126 
127  toStr(str, number);
128 
129  return str;
130 }
131 
132 /// Serializes the given integer into a string.
134 void
135 toStr(
136  std::string&,
137  UInt8);
138 
139 /// Serializes the given integer into a string.
140 inline
141 ONIXS_B3_UMDF_MD_NODISCARD
142 std::string
144  UInt8 number)
145 {
146  std::string str;
147 
148  toStr(str, number);
149 
150  return str;
151 }
152 
153 /// Serializes the given integer into a string.
155 void
156 toStr(
157  std::string&,
158  Int16);
159 
160 /// Serializes the given integer into a string.
161 inline
162 ONIXS_B3_UMDF_MD_NODISCARD
163 std::string
165  Int16 number)
166 {
167  std::string str;
168 
169  toStr(str, number);
170 
171  return str;
172 }
173 
174 /// Serializes the given integer into a string.
176 void
177 toStr(
178  std::string&,
179  UInt16);
180 
181 /// Serializes the given integer into a string.
182 inline
183 ONIXS_B3_UMDF_MD_NODISCARD
184 std::string
186  UInt16 number)
187 {
188  std::string str;
189 
190  toStr(str, number);
191 
192  return str;
193 }
194 
195 /// Serializes the given integer into a string.
197 void
198 toStr(
199  std::string&,
200  Int32);
201 
202 /// Serializes the given integer into a string.
203 inline
204 ONIXS_B3_UMDF_MD_NODISCARD
205 std::string
207  Int32 number)
208 {
209  std::string str;
210 
211  toStr(str, number);
212 
213  return str;
214 }
215 
216 /// Serializes the given integer into a string.
218 void
219 toStr(
220  std::string&,
221  UInt32);
222 
223 /// Serializes the given integer into a string.
224 inline
225 ONIXS_B3_UMDF_MD_NODISCARD
226 std::string
228  UInt32 number)
229 {
230  std::string str;
231 
232  toStr(str, number);
233 
234  return str;
235 }
236 
237 /// Serializes the given integer into a string.
239 void
240 toStr(
241  std::string&,
242  Int64);
243 
244 /// Serializes the given integer into a string.
245 inline
246 ONIXS_B3_UMDF_MD_NODISCARD
247 std::string
249  Int64 number)
250 {
251  std::string str;
252 
253  toStr(str, number);
254 
255  return str;
256 }
257 
258 /// Serializes the given integer into a string.
260 void
261 toStr(
262  std::string&,
263  UInt64);
264 
265 /// Serializes the given integer into a string.
266 inline
267 ONIXS_B3_UMDF_MD_NODISCARD
268 std::string
270  UInt64 number)
271 {
272  std::string str;
273 
274  toStr(str, number);
275 
276  return str;
277 }
278 
279 /// Serializes the integer into the given buffer.
281 ONIXS_B3_UMDF_MD_NODISCARD
282 size_t
283 toStr(
284  Int8,
285  Char*,
286  size_t);
287 
288 
289 /// Serializes the integer into the given buffer.
291 ONIXS_B3_UMDF_MD_NODISCARD
292 size_t
293 toStr(
294  UInt8,
295  Char*,
296  size_t);
297 
298 /// Serializes the integer into the given buffer.
300 ONIXS_B3_UMDF_MD_NODISCARD
301 size_t
302 toStr(
303  Int16,
304  Char*,
305  size_t);
306 
307 
308 /// Serializes the integer into the given buffer.
310 ONIXS_B3_UMDF_MD_NODISCARD
311 size_t
312 toStr(
313  UInt16,
314  Char*,
315  size_t);
316 
317 
318 /// Serializes the integer into the given buffer.
320 ONIXS_B3_UMDF_MD_NODISCARD
321 size_t
322 toStr(
323  Int32,
324  Char*,
325  size_t);
326 
327 
328 /// Serializes the integer into the given buffer.
330 size_t
331 ONIXS_B3_UMDF_MD_NODISCARD
332 toStr(
333  UInt32,
334  Char*,
335  size_t);
336 
337 /// Serializes the integer into the given buffer.
339 ONIXS_B3_UMDF_MD_NODISCARD
340 size_t
341 toStr(
342  Int64,
343  Char*,
344  size_t);
345 
346 
347 /// Serializes the integer into the given buffer.
349 ONIXS_B3_UMDF_MD_NODISCARD
350 size_t
351 toStr(
352  UInt64,
353  Char*,
354  size_t);
355 
356 /// Serializes the given constant into a string.
357 template
358 <
359  typename Type,
360  Type Constant
361 >
362 inline
363 void
365  std::string& str,
367 {
368  toStr(str, constant());
369 }
370 
371 /// Serializes the given constant into a string.
372 template
373 <
374  typename Type,
375  Type Constant
376 >
377 inline
378 ONIXS_B3_UMDF_MD_NODISCARD
379 std::string
382  <Type, Constant> constant)
383 {
384  std::string str;
385 
386  toStr(str, constant);
387 
388  return str;
389 }
390 
391 /// Deserializes a numeric value from its text representation.
392 ///
393 /// \return `true` if the given buffer contains a valid representation
394 /// of a number. Otherwise, `false` is returned.
396 ONIXS_B3_UMDF_MD_NODISCARD
397 bool fromStr(Int8&, const Char*, size_t) ONIXS_B3_UMDF_MD_NOTHROW;
398 
399 /// Deserializes a numeric value from its text representation.
400 ///
401 /// \return `true` if the given buffer contains a valid representation
402 /// of a number. Otherwise, `false` is returned.
403 inline ONIXS_B3_UMDF_MD_NODISCARD
404 bool fromStr(Int8& value, const std::string& str) ONIXS_B3_UMDF_MD_NOTHROW
405 {
406  return
407  fromStr(
408  value,
409  str.c_str(),
410  str.size());
411 }
412 
413 /// Deserializes a numeric value from its text representation.
414 ///
415 /// \return `true` if the given buffer contains a valid representation
416 /// of a number. Otherwise, `false` is returned.
418 ONIXS_B3_UMDF_MD_NODISCARD
419 bool
420 fromStr(
421  UInt8&,
422  const Char*,
423  size_t) ONIXS_B3_UMDF_MD_NOTHROW;
424 
425 /// Deserializes a numeric value from its text representation.
426 ///
427 /// \return `true` if the given buffer contains a valid representation
428 /// of a number. Otherwise, `false` is returned.
429 inline
430 ONIXS_B3_UMDF_MD_NODISCARD
431 bool fromStr(
432  UInt8& value,
433  const std::string& str) ONIXS_B3_UMDF_MD_NOTHROW
434 {
435  return
436  fromStr(
437  value,
438  str.c_str(),
439  str.size());
440 }
441 
442 /// Deserializes a numeric value from its text representation.
443 ///
444 /// \return `true` if the given buffer contains a valid representation
445 /// of a number. Otherwise, `false` is returned.
447 ONIXS_B3_UMDF_MD_NODISCARD
448 bool
449 fromStr(
450  Int16&,
451  const Char*,
452  size_t) ONIXS_B3_UMDF_MD_NOTHROW;
453 
454 /// Deserializes a numeric value from its text representation.
455 ///
456 /// \return `true` if the given buffer contains a valid representation
457 /// of a number. Otherwise, `false` is returned.
458 inline
459 ONIXS_B3_UMDF_MD_NODISCARD
460 bool fromStr(
461  Int16& value,
462  const std::string& str) ONIXS_B3_UMDF_MD_NOTHROW
463 {
464  return
465  fromStr(
466  value,
467  str.c_str(),
468  str.size());
469 }
470 
471 /// Deserializes a numeric value from its text representation.
472 ///
473 /// \return `true` if the given buffer contains a valid representation
474 /// of a number. Otherwise, `false` is returned.
476 ONIXS_B3_UMDF_MD_NODISCARD
477 bool
478 fromStr(
479  UInt16&,
480  const Char*,
481  size_t) ONIXS_B3_UMDF_MD_NOTHROW;
482 
483 /// Deserializes a numeric value from its text representation.
484 ///
485 /// \return `true` if the given buffer contains a valid representation
486 /// of a number. Otherwise, `false` is returned.
487 inline ONIXS_B3_UMDF_MD_NODISCARD
488 bool fromStr(
489  UInt16& value,
490  const std::string& str) ONIXS_B3_UMDF_MD_NOTHROW
491 {
492  return
493  fromStr(
494  value,
495  str.c_str(),
496  str.size());
497 }
498 
499 /// Deserializes a numeric value from its text representation.
500 ///
501 /// \return `true` if the given buffer contains a valid representation
502 /// of a number. Otherwise, `false` is returned.
504 ONIXS_B3_UMDF_MD_NODISCARD
505 bool
506 fromStr(
507  Int32&,
508  const Char*,
509  size_t) ONIXS_B3_UMDF_MD_NOTHROW;
510 
511 /// Deserializes a numeric value from its text representation.
512 ///
513 /// \return `true` if the given buffer contains a valid representation
514 /// of a number. Otherwise, `false` is returned.
515 inline
516 ONIXS_B3_UMDF_MD_NODISCARD
517 bool fromStr(
518  Int32& value,
519  const std::string& str) ONIXS_B3_UMDF_MD_NOTHROW
520 {
521  return
522  fromStr(
523  value,
524  str.c_str(),
525  str.size());
526 }
527 
528 /// Deserializes a numeric value from its text representation.
529 ///
530 /// \return `true` if the given buffer contains a valid representation
531 /// of a number. Otherwise, `false` is returned.
533 ONIXS_B3_UMDF_MD_NODISCARD
534 bool
535 fromStr(
536  UInt32&,
537  const Char*,
538  size_t) ONIXS_B3_UMDF_MD_NOTHROW;
539 
540 /// Deserializes a numeric value from its text representation.
541 ///
542 /// \return `true` if the given buffer contains a valid representation
543 /// of a number. Otherwise, `false` is returned.
544 inline
545 ONIXS_B3_UMDF_MD_NODISCARD
546 bool fromStr(
547  UInt32& value,
548  const std::string& str) ONIXS_B3_UMDF_MD_NOTHROW
549 {
550  return
551  fromStr(
552  value,
553  str.c_str(),
554  str.size());
555 }
556 
557 /// Deserializes a numeric value from its text representation.
558 ///
559 /// \return `true` if the given buffer contains a valid representation
560 /// of a number. Otherwise, `false` is returned.
562 ONIXS_B3_UMDF_MD_NODISCARD
563 bool
564 fromStr(
565  Int64&,
566  const Char*,
567  size_t) ONIXS_B3_UMDF_MD_NOTHROW;
568 
569 /// Deserializes a numeric value from its text representation.
570 ///
571 /// \return `true` if the given buffer contains a valid representation
572 /// of a number. Otherwise, `false` is returned.
573 inline
574 ONIXS_B3_UMDF_MD_NODISCARD
575 bool fromStr(
576  Int64& value,
577  const std::string& str) ONIXS_B3_UMDF_MD_NOTHROW
578 {
579  return
580  fromStr(
581  value,
582  str.c_str(),
583  str.size());
584 }
585 
586 /// Deserializes a numeric value from its text representation.
587 ///
588 /// \return `true` if the given buffer contains a valid representation
589 /// of a number. Otherwise, `false` is returned.
591 ONIXS_B3_UMDF_MD_NODISCARD
592 bool
593 fromStr(
594  UInt64&,
595  const Char*,
596  size_t) ONIXS_B3_UMDF_MD_NOTHROW;
597 
598 /// Deserializes a numeric value from its text representation.
599 ///
600 /// \return `true` if the given buffer contains a valid representation
601 /// of a number. Otherwise, `false` is returned.
602 inline
603 ONIXS_B3_UMDF_MD_NODISCARD
604 bool fromStr(
605  UInt64& value,
606  const std::string& str) ONIXS_B3_UMDF_MD_NOTHROW
607 {
608  return
609  fromStr(
610  value,
611  str.c_str(),
612  str.size());
613 }
614 
#define ONIXS_B3_UMDF_MD_NOTHROW
Definition: Compiler.h:114
#define ONIXS_B3_UMDF_MD_CONSTEXPR
Definition: Compiler.h:120
Messaging::UInt64 UInt64
Definition: Integral.h:40
Messaging::UInt8 UInt8
Definition: Integral.h:31
Messaging::UInt16 UInt16
Definition: Integral.h:34
#define ONIXS_B3_UMDF_MD_EXPORTED
Definition: ABI.h:37
UInt16 UInt16
2-byte unsigned integer, from 0 to 65535..
Definition: Fields.h:54
Messaging::UInt32 UInt32
Definition: Integral.h:37
Int16 Int16
2-byte signed integer, from -32768 to 32767; if optional, null value is -32768..
Definition: Fields.h:38
Int8 Int8
1-byte signed integer, from -128 to 127; if optional, null value is -128..
Definition: Fields.h:34
Messaging::Int32 Int32
Definition: Integral.h:36
char Char
Character type alias.
Definition: String.h:30
UInt8 UInt8
1-byte unsigned integer, from 0 to 255..
Definition: Fields.h:50
#define ONIXS_B3_UMDF_MD_MESSAGING_NAMESPACE_END
Definition: ABI.h:151
ONIXS_B3_UMDF_MD_NODISCARD std::string toStr(IntegralConstant< Type, Constant > constant)
Serializes the given constant into a string.
Definition: Integral.h:380
Int32 Int32
4-byte signed integer, from -2147483648 to 2147483647; if optional, null value is -2147483648...
Definition: Fields.h:42
UInt64 UInt64
8-byte unsigned integer, from 0 to 18446744073709551615 (2^64-1)..
Definition: Fields.h:62
UInt32 UInt32
4-byte unsigned integer, from 0 to 4294967295 (2^32-1)..
Definition: Fields.h:58
#define ONIXS_B3_UMDF_MD_MESSAGING_NAMESPACE_BEGIN
Definition: ABI.h:146
Messaging::Int64 Int64
Definition: Integral.h:39
Messaging::Int16 Int16
Definition: Integral.h:33
Int64 Int64
8-byte signed integer, from -9223372036854775808 (-2^63) to 9223372036854775807 (2^63-1)..
Definition: Fields.h:46
Messaging::Int8 Int8
Definition: Integral.h:30
ONIXS_B3_UMDF_MD_NODISCARD bool fromStr(UInt64 &value, const std::string &str)
Deserializes a numeric value from its text representation.
Definition: Integral.h:604