OnixS C++ ICE Binary Order Entry Handler 1.2.3
API Documentation
Loading...
Searching...
No Matches
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
23#include <OnixS/ICE/BOE/ABI.h>
25
26#include <cstddef>
27#include <string>
28#include <type_traits>
29
31
32typedef int8_t Int8;
33typedef uint8_t UInt8;
34
35typedef int16_t Int16;
36typedef uint16_t UInt16;
37
38typedef int32_t Int32;
39typedef uint32_t UInt32;
40
41typedef int64_t Int64;
42typedef uint64_t UInt64;
43
45template
46<
47 typename Type,
48 Type Constant
49>
51{
53 typedef Type Value;
54
56 constexpr
57 operator Value() const noexcept
58 {
59 return Constant;
60 }
61
63 constexpr
64 Value operator()() const noexcept
65 {
66 return Constant;
67 }
68
70 constexpr
71 static Value value() noexcept
72 {
73 return Constant;
74 }
75};
76
77
80void toStr(std::string&, Int8);
81
83inline
85std::string
87 Int8 number)
88{
89 std::string str;
90
91 toStr(str, number);
92
93 return str;
94}
95
98void
100 std::string&,
101 UInt8);
102
104inline
106std::string
108 UInt8 number)
109{
110 std::string str;
111
112 toStr(str, number);
113
114 return str;
115}
116
119void
121 std::string&,
122 Int16);
123
125inline
127std::string
129 Int16 number)
130{
131 std::string str;
132
133 toStr(str, number);
134
135 return str;
136}
137
140void
142 std::string&,
143 UInt16);
144
146inline
148std::string
150 UInt16 number)
151{
152 std::string str;
153
154 toStr(str, number);
155
156 return str;
157}
158
161void
163 std::string&,
164 Int32);
165
167inline
169std::string
171 Int32 number)
172{
173 std::string str;
174
175 toStr(str, number);
176
177 return str;
178}
179
182void
184 std::string&,
185 UInt32);
186
188inline
190std::string
192 UInt32 number)
193{
194 std::string str;
195
196 toStr(str, number);
197
198 return str;
199}
200
203void
205 std::string&,
206 Int64);
207
209inline
211std::string
213 Int64 number)
214{
215 std::string str;
216
217 toStr(str, number);
218
219 return str;
220}
221
224void
226 std::string&,
227 UInt64);
228
230inline
232std::string
234 UInt64 number)
235{
236 std::string str;
237
238 toStr(str, number);
239
240 return str;
241}
242
246size_t
248 Int8,
249 Char*,
250 size_t);
251
252
256size_t
258 UInt8,
259 Char*,
260 size_t);
261
265size_t
267 Int16,
268 Char*,
269 size_t);
270
271
275size_t
277 UInt16,
278 Char*,
279 size_t);
280
281
285size_t
287 Int32,
288 Char*,
289 size_t);
290
291
294size_t
297 UInt32,
298 Char*,
299 size_t);
300
304size_t
306 Int64,
307 Char*,
308 size_t);
309
310
314size_t
316 UInt64,
317 Char*,
318 size_t);
319
321template
322<
323 typename Type,
324 Type Constant
325>
326inline
327void
329 std::string& str,
331{
332 toStr(str, constant());
333}
334
336template
337<
338 typename Type,
339 Type Constant
340>
341inline
343std::string
346 <Type, Constant> constant)
347{
348 std::string str;
349
350 toStr(str, constant);
351
352 return str;
353}
354
361bool fromStr(Int8&, const Char*, size_t) noexcept;
362
368bool fromStr(Int8& value, const std::string& str) noexcept
369{
370 return
371 fromStr(
372 value,
373 str.c_str(),
374 str.size());
375}
376
383bool
385 UInt8&,
386 const Char*,
387 size_t) noexcept;
388
393inline
396 UInt8& value,
397 const std::string& str) noexcept
398{
399 return
400 fromStr(
401 value,
402 str.c_str(),
403 str.size());
404}
405
412bool
414 Int16&,
415 const Char*,
416 size_t) noexcept;
417
422inline
425 Int16& value,
426 const std::string& str) noexcept
427{
428 return
429 fromStr(
430 value,
431 str.c_str(),
432 str.size());
433}
434
441bool
443 UInt16&,
444 const Char*,
445 size_t) noexcept;
446
453 UInt16& value,
454 const std::string& str) noexcept
455{
456 return
457 fromStr(
458 value,
459 str.c_str(),
460 str.size());
461}
462
469bool
471 Int32&,
472 const Char*,
473 size_t) noexcept;
474
479inline
482 Int32& value,
483 const std::string& str) noexcept
484{
485 return
486 fromStr(
487 value,
488 str.c_str(),
489 str.size());
490}
491
498bool
500 UInt32&,
501 const Char*,
502 size_t) noexcept;
503
508inline
511 UInt32& value,
512 const std::string& str) noexcept
513{
514 return
515 fromStr(
516 value,
517 str.c_str(),
518 str.size());
519}
520
527bool
529 Int64&,
530 const Char*,
531 size_t) noexcept;
532
537inline
540 Int64& value,
541 const std::string& str) noexcept
542{
543 return
544 fromStr(
545 value,
546 str.c_str(),
547 str.size());
548}
549
556bool
558 UInt64&,
559 const Char*,
560 size_t) noexcept;
561
566inline
569 UInt64& value,
570 const std::string& str) noexcept
571{
572 return
573 fromStr(
574 value,
575 str.c_str(),
576 str.size());
577}
578
581template <typename Type>
583 : std::integral_constant<bool,
584 std::is_integral<Type>::value
585 && !std::is_same<Type, bool>::value
586 && !std::is_same<Type, char>::value
587 && !std::is_same<Type, wchar_t>::value
588 && !std::is_same<Type, char16_t>::value
589 && !std::is_same<Type, char32_t>::value
590#if defined(__cpp_char8_t)
591 && !std::is_same<Type, char8_t>::value
592#endif
593 && !std::is_same<Type, Int8>::value && !std::is_same<Type, UInt8>::value
594 && !std::is_same<Type, Int16>::value && !std::is_same<Type, UInt16>::value
595 && !std::is_same<Type, Int32>::value && !std::is_same<Type, UInt32>::value
596 && !std::is_same<Type, Int64>::value && !std::is_same<Type, UInt64>::value>
597{
598};
599
601template <typename Type>
602using WideInteger = typename std::conditional<std::is_signed<Type>::value, Int64, UInt64>::type;
603
605template <typename Type, typename = typename std::enable_if<IsOtherInteger<Type>::value>::type>
606inline
607void
609 std::string& str,
610 Type number)
611{
612 toStr(str, static_cast<WideInteger<Type>>(number));
613}
614
616template <typename Type, typename = typename std::enable_if<IsOtherInteger<Type>::value>::type>
617inline
619std::string
621 Type number)
622{
623 return toStr(static_cast<WideInteger<Type>>(number));
624}
625
627template <typename Type, typename = typename std::enable_if<IsOtherInteger<Type>::value>::type>
628inline
630size_t
632 Type number,
633 Char* buffer,
634 size_t size)
635{
636 return toStr(static_cast<WideInteger<Type>>(number), buffer, size);
637}
638
643template <typename Type, typename = typename std::enable_if<IsOtherInteger<Type>::value>::type>
644inline
646bool
648 Type& value,
649 const Char* buffer,
650 size_t size) noexcept
651{
652 WideInteger<Type> parsed = 0;
653
654 if(!fromStr(parsed, buffer, size))
655 return false;
656
657 // Reject values that do not survive the conversion to `Type`.
658 if(static_cast<WideInteger<Type>>(static_cast<Type>(parsed)) != parsed)
659 return false;
660
661 value = static_cast<Type>(parsed);
662 return true;
663}
664
669template <typename Type, typename = typename std::enable_if<IsOtherInteger<Type>::value>::type>
670inline
672bool
674 Type& value,
675 const std::string& str) noexcept
676{
677 return fromStr(value, str.c_str(), str.size());
678}
679
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_BEGIN
Definition ABI.h:102
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_END
Definition ABI.h:106
#define ONIXS_ICEBOE_EXPORTED
Definition Compiler.h:154
#define ONIXS_ICEBOE_NODISCARD
Definition Compiler.h:155
constexpr std::enable_if<!details::HasMemberTraits< Value >::value, size_t >::type size() noexcept
Definition Memory.h:322
char Char
Character type alias.
Definition String.h:31
typename std::conditional< std::is_signed< Type >::value, Int64, UInt64 >::type WideInteger
The 64-bit type an other integer type is converted through.
Definition Integral.h:602
std::string toStr(const FixedPointDecimal< Mantissa, Exponent > &)
Serializes a fixed-point decimal into a string.
bool fromStr(Decimal &, const Char *, size_t) noexcept
Deserializes a decimal number from the given text presentation.
constexpr Value operator()() const noexcept
Definition Integral.h:64
static constexpr Value value() noexcept
Definition Integral.h:71
Whether Type is an integer type other than the fixed-width ones above, e.g.
Definition Integral.h:597