OnixS C++ CME MDP Premium Market Data Handler 5.10.2
Users' manual and 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 <cstdint>
24#include <string>
25
27
29
30using Int8 = std::int8_t;
31using UInt8 = std::uint8_t;
32using Int16 = std::int16_t;
33using UInt16 = std::uint16_t;
34using Int32 = std::int32_t;
35using UInt32 = std::uint32_t;
36using Int64 = std::int64_t;
37using UInt64 = std::uint64_t;
38
39static_assert(sizeof(Int8) == 1, "Size of Int8 must be 1");
40static_assert(sizeof(UInt8) == 1, "Size of UInt8 must be 1");
41static_assert(sizeof(Int16) == 2, "Size of Int16 must be 2");
42static_assert(sizeof(UInt16) == 2, "Size of UInt16 must be 2");
43static_assert(sizeof(Int32) == 4, "Size of Int32 must be 4");
44static_assert(sizeof(UInt32) == 4, "Size of UInt32 must be 4");
45static_assert(sizeof(Int64) == 8, "Size of Int64 must be 8");
46static_assert(sizeof(UInt64) == 8, "Size of UInt64 must be 8");
47
48//
49
51template <typename Type, Type Constant>
53{
55 typedef Type Value;
56
58 constexpr operator Value() const noexcept
59 {
60 return Constant;
61 }
62
64 constexpr Value operator()() const noexcept
65 {
66 return Constant;
67 }
68
70 static constexpr Value value() noexcept
71 {
72 return Constant;
73 }
74};
75
76template <typename T>
78
79template <typename Type, Type Constant>
80struct UnwrapType<IntegralConstant<Type, Constant>>
81{
82 typedef Type Value;
83};
84
87void toStr(std::string&, Int8);
88
90inline std::string toStr(Int8 number)
91{
92 std::string str;
93
94 toStr(str, number);
95
96 return str;
97}
98
101void toStr(std::string&, UInt8);
102
104inline std::string toStr(UInt8 number)
105{
106 std::string str;
107
108 toStr(str, number);
109
110 return str;
111}
112
115void toStr(std::string&, Int16);
116
118inline std::string toStr(Int16 number)
119{
120 std::string str;
121
122 toStr(str, number);
123
124 return str;
125}
126
129void toStr(std::string&, UInt16);
130
132inline std::string toStr(UInt16 number)
133{
134 std::string str;
135
136 toStr(str, number);
137
138 return str;
139}
140
143void toStr(std::string&, Int32);
144
146inline std::string toStr(Int32 number)
147{
148 std::string str;
149
150 toStr(str, number);
151
152 return str;
153}
154
157void toStr(std::string&, UInt32);
158
160inline std::string toStr(UInt32 number)
161{
162 std::string str;
163
164 toStr(str, number);
165
166 return str;
167}
168
171void toStr(std::string&, Int64);
172
174inline std::string toStr(Int64 number)
175{
176 std::string str;
177
178 toStr(str, number);
179
180 return str;
181}
182
185void toStr(std::string&, UInt64);
186
188inline std::string toStr(UInt64 number)
189{
190 std::string str;
191
192 toStr(str, number);
193
194 return str;
195}
196
198template <typename Type, Type Constant>
199inline void toStr(std::string& str, IntegralConstant<Type, Constant> constant)
200{
201 toStr(str, constant());
202}
203
205template <typename Type, Type Constant>
206inline std::string toStr(IntegralConstant<Type, Constant> constant)
207{
208 std::string str;
209
210 toStr(str, constant);
211
212 return str;
213}
214
222bool fromStr(Int8&, const Char*, size_t);
223
231bool fromStr(UInt8&, const Char*, size_t);
232
240bool fromStr(Int16&, const Char*, size_t);
241
249bool fromStr(UInt16&, const Char*, size_t);
250
258bool fromStr(Int32&, const Char*, size_t);
259
267bool fromStr(UInt32&, const Char*, size_t);
268
276bool fromStr(Int64&, const Char*, size_t);
277
285bool fromStr(UInt64&, const Char*, size_t);
286
291template <typename T>
293bool fromStr(T& value, const std::string& str, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr) noexcept
294{
295 return fromStr(value, str.c_str(), str.size());
296}
297
301size_t toStr(Int8, Char*, size_t);
302
306size_t toStr(UInt8, Char*, size_t);
307
311size_t toStr(Int16, Char*, size_t);
312
316size_t toStr(UInt16, Char*, size_t);
317
321size_t toStr(Int32, Char*, size_t);
322
326size_t toStr(UInt32, Char*, size_t);
327
331size_t toStr(Int64, Char*, size_t);
332
336size_t toStr(UInt64, Char*, size_t);
337
#define ONIXS_CMEMDH_MESSAGING_NAMESPACE_BEGIN
Definition Bootstrap.h:57
#define ONIXS_CMEMDH_MESSAGING_NAMESPACE_END
Definition Bootstrap.h:58
#define ONIXS_CMEMDH_EXPORTED
Definition Compiler.h:148
#define ONIXS_CMEMDH_NODISCARD
Definition Compiler.h:150
bool fromStr(Int8 &, const Char *, size_t)
std::uint32_t UInt32
uInt32.
Definition Integral.h:35
std::int8_t Int8
int8.
Definition Integral.h:30
char Char
Character type alias.
Definition String.h:30
std::uint16_t UInt16
uInt16.
Definition Integral.h:33
std::int32_t Int32
int32.
Definition Integral.h:34
std::uint64_t UInt64
uInt64.
Definition Integral.h:37
void toStr(std::string &, Int8)
Serializes given integer into a string.
std::uint8_t UInt8
uInt8.
Definition Integral.h:31
std::int16_t Int16
int16.
Definition Integral.h:32
constexpr Value operator()() const noexcept
Returns value of the constant.
Definition Integral.h:64
static constexpr Value value() noexcept
Returns value of the constant.
Definition Integral.h:70