OnixS C++ Eurex T7 Market and Reference Data (EMDI, MDI, RDI, EOBI) Handlers 18.2.0
API documentation
Loading...
Searching...
No Matches
Numeric.h
Go to the documentation of this file.
1/*
2* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3*
4* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5* and international copyright treaties.
6*
7* Access to and use of the software is governed by the terms of the applicable OnixS Software
8* Services Agreement (the Agreement) and Customer end user license agreements granting
9* a non-assignable, non-transferable and non-exclusive license to use the software
10* for it's own data processing purposes under the terms defined in the Agreement.
11*
12* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13* of this source code or associated reference material to any other location for further reproduction
14* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15*
16* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17* the terms of the Agreement is a violation of copyright law.
18*/
19
20#pragma once
21
22#include <string>
23#include <stdexcept>
24#include <iosfwd>
25
27
28namespace OnixS
29{
30 namespace Eurex
31 {
32 namespace MarketData
33 {
34 typedef char Int8;
35 typedef unsigned char UInt8;
36
37 typedef short Int16;
38 typedef unsigned short UInt16;
39
40 typedef int Int32;
41 typedef unsigned int UInt32;
42
43#if defined (_MSC_VER)
44 typedef signed long long Int64;
45 typedef unsigned long long UInt64;
46#elif defined (__GNUC__)
47
48#if defined (__LP64__)
49 typedef signed long Int64;
50 typedef unsigned long UInt64;
51#else
52 typedef signed long long Int64;
53 typedef unsigned long long UInt64;
54#endif
55
56#endif
57 typedef double Double;
58
59 typedef Int64 DecimalMantissa;
61
63 class
64 ONIXS_EUREX_EMDI_API
66 {
67 public:
72
73 explicit Decimal (int);
74
77 explicit Decimal (Double value);
78
82 Decimal (Double value, size_t precision);
83
85 Decimal (const Decimal& other);
86
89
92
95
98
100 bool operator == (const Decimal&) const;
101
103 bool operator != (const Decimal&) const;
104
108 operator Int32() const;
109
113 operator UInt32() const;
114
118 operator Int64() const;
119
123 operator UInt64() const;
124
128 operator Double() const;
129
133 bool toNumber (Int32&) const;
134
138 bool toNumber (UInt32&) const;
139
143 bool toNumber (Int64&) const;
144
148 bool toNumber (UInt64&) const;
149
152 bool toNumber (Double&) const;
153
155 void toString (std::string&) const;
156
158 std::string toString() const;
159
161 Decimal&
162 operator = (
163 const Decimal& other);
164
168 static
169 bool
171 const char* buffer,
172 size_t bufferSize,
173 Decimal&);
174
177 static
178 Decimal
180 const char* buffer,
181 size_t bufferSize);
182
183 private:
185 DecimalMantissa mantissa_;
186
188 DecimalExponent exponent_;
189 };
190
191 bool operator < (const Decimal& l, const Decimal& r);
192 bool operator > (const Decimal& l, const Decimal& r);
193 bool operator <= (const Decimal& l, const Decimal& r);
194 bool operator >= (const Decimal& l, const Decimal& r);
195
196
197 inline
200 {
201 return mantissa_;
202 }
203
204 inline
205 void
207 DecimalMantissa value)
208 {
209 mantissa_ = value;
210 }
211
212 inline
215 {
216 return exponent_;
217 }
218
219 inline
220 void
222 DecimalExponent value)
223 {
224 exponent_ = value;
225 }
226
227 inline
228 Decimal::operator Int32() const
229 {
230 Int32 number;
231
232 if (toNumber (number) )
233 return number;
234
235 throw std::domain_error (
236 "Cannot cast value to target type. ");
237 }
238
239 inline
240 Decimal::operator UInt32() const
241 {
242 UInt32 number;
243
244 if (toNumber (number) )
245 return number;
246
247 throw std::domain_error (
248 "Cannot cast value to target type. ");
249 }
250
251 inline
252 Decimal::operator Int64() const
253 {
254 Int64 number;
255
256 if (toNumber (number) )
257 return number;
258
259 throw std::domain_error (
260 "Cannot cast value to target type. ");
261 }
262
263 inline
264 Decimal::operator UInt64() const
265 {
266 UInt64 number;
267
268 if (toNumber (number) )
269 return number;
270
271 throw std::domain_error (
272 "Cannot cast value to target type. ");
273 }
274
275 inline
276 Decimal::operator Double() const
277 {
278 Double number;
279
280 if (toNumber (number) )
281 return number;
282
283 throw std::domain_error (
284 "Cannot cast value to target type. ");
285 }
286
287 inline
288 std::string
290 {
291 std::string presentation;
292 toString (presentation);
293 return presentation;
294 }
295
297 struct ONIXS_EUREX_EMDI_API Number
298 {
299 static
300 bool
302 const char* buffer,
303 size_t bufferSize,
304 Int32& number);
305
306 static
307 bool
309 const char* buffer,
310 size_t bufferSize,
311 UInt32& number);
312
313 static
314 bool
316 const char* buffer,
317 size_t bufferSize,
318 Int64& number);
319
320 static
321 bool
323 const char* buffer,
324 size_t bufferSize,
325 UInt64& number);
326
327 static
328 bool
330 const char* buffer,
331 size_t bufferSize,
332 Double& number);
333
334 static
335 bool
337 const char* buffer,
338 size_t bufferSize,
339 Decimal& number);
340 };
341 }
342 }
343}
344
345namespace std
346{
347 // Outputs into standard stream.
348 ONIXS_EUREX_EMDI_API
349 std::ostream&
350 operator <<(std::ostream&,
352}
Decimal type for better precision.
Definition Numeric.h:66
Decimal(DecimalMantissa mantissa=0, DecimalExponent exponent=0)
Initializes instance from compound components.
std::string toString() const
Returns text presentation of decimal.
Definition Numeric.h:289
static Decimal parse(const char *buffer, size_t bufferSize)
Decimal(const Decimal &other)
Initializes as copy of given value.
DecimalExponent exponent() const
Returns exponent part of decimal.
Definition Numeric.h:214
static bool tryParse(const char *buffer, size_t bufferSize, Decimal &)
bool toNumber(Double &) const
Decimal(Double value, size_t precision)
void toString(std::string &) const
Appends text presentation to given string.
bool toNumber(UInt64 &) const
bool toNumber(UInt32 &) const
DecimalMantissa mantissa() const
Returns mantissa part of decimal.
Definition Numeric.h:199
bool operator>=(const Decimal &l, const Decimal &r)
unsigned int UInt32
Definition Numeric.h:41
bool operator<=(const Decimal &l, const Decimal &r)
bool operator==(const FieldValueRef &ref, const std::string &str)
unsigned char UInt8
Definition Numeric.h:35
bool operator<(const Decimal &l, const Decimal &r)
bool operator>(const Decimal &l, const Decimal &r)
unsigned short UInt16
Definition Numeric.h:38
bool operator!=(const FieldValueRef &ref, const std::string &str)
STL namespace.
std::ostream & operator<<(std::ostream &, const OnixS::Eurex::MarketData::Decimal &)
Helper class for conversion from string to number.
Definition Numeric.h:298
static bool tryParse(const char *buffer, size_t bufferSize, Int32 &number)
static bool tryParse(const char *buffer, size_t bufferSize, UInt32 &number)
static bool tryParse(const char *buffer, size_t bufferSize, UInt64 &number)
static bool tryParse(const char *buffer, size_t bufferSize, Decimal &number)
static bool tryParse(const char *buffer, size_t bufferSize, Double &number)
static bool tryParse(const char *buffer, size_t bufferSize, Int64 &number)