OnixS C++ B3 Binary UMDF Market Data Handler 1.10.0
Users' manual and API documentation
Loading...
Searching...
No Matches
Decimal.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
31template <class MantissaType, class ExponentType> class FixedPointDecimal;
32template<class Mantissa, class Exponent> std::string toStr(const FixedPointDecimal <Mantissa, Exponent>&);
33
35template
36<
37 class MantissaType,
38 class ExponentType
39>
41{
42 // Only mantissa is stored.
43 MantissaType mantissa_;
44
45public:
48 struct MemberTraits
49 {
50 enum { Count = 1 };
51
52 typedef MantissaType FirstArgType;
53 };
54
56 typedef MantissaType Mantissa;
57
59 typedef ExponentType Exponent;
60
62 enum
63 {
65 Size = sizeof(Mantissa)
66 };
67
69 ONIXS_B3_UMDF_MD_NODISCARD
70 std::string toString() const
71 {
72 return toStr(*this);
73 }
74
76 constexpr
78 : mantissa_()
79 {
80 }
81
84 : mantissa_(mantissa)
85 {
86 }
87
89 constexpr
91 {
92 return mantissa_;
93 }
94
96 constexpr
98 {
99 return Exponent();
100 }
101
103 void serialize(void* addr) const noexcept
104 {
105 assert(addr);
106
107 std::memcpy(addr, &mantissa_, sizeof(mantissa_));
108 }
109};
110
112template
113<
114 class MantissaType,
115 class ExponentType,
116 class NullMantissaType
117>
118class NullableFixedPointDecimal : public FixedPointDecimal<MantissaType, ExponentType>
119{
120public:
122 constexpr
124 : FixedPointDecimal<MantissaType, ExponentType>()
125 {
126 }
127
133
134 constexpr
135 static NullMantissaType nullMantissa() noexcept
136 {
137 return NullMantissaType();
138 }
139
140 constexpr
145
146
148 bool isNull() const { return nullMantissa() == this->mantissa(); }
149};
150
#define ONIXS_B3_UMDF_MD_MESSAGING_NAMESPACE_END
Definition ABI.h:158
#define ONIXS_B3_UMDF_MD_MESSAGING_NAMESPACE_BEGIN
Definition ABI.h:153
constexpr Exponent exponent() const noexcept
Definition Decimal.h:97
constexpr FixedPointDecimal(Mantissa mantissa) noexcept
Explicitly initializes the instance from the mantissa value.
Definition Decimal.h:83
void serialize(void *addr) const noexcept
Serialize to the given data buffer.
Definition Decimal.h:103
constexpr NullableFixedPointDecimal() noexcept
Default (zero) initialization.
Definition Decimal.h:123
constexpr NullableFixedPointDecimal(MantissaType mantissa) noexcept
Explicitly initializes the instance from the mantissa value.
Definition Decimal.h:129
static constexpr NullableFixedPointDecimal nullValue() noexcept
Definition Decimal.h:141
static constexpr NullMantissaType nullMantissa() noexcept
Definition Decimal.h:135
void toStr(std::string &str, Char character)
Appends the character to the given std::string instance.
Definition String.h:34