OnixS C++ B3 Binary UMDF Market Data Handler  1.3.3
API documentation
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 
30 /// Forward declarations
31 template <class MantissaType, class ExponentType> class FixedPointDecimal;
32 template<class Mantissa, class Exponent> std::string toStr(const FixedPointDecimal <Mantissa, Exponent>&);
33 
34 /// A real number with a constant exponent.
35 template
36 <
37  class MantissaType,
38  class ExponentType
39 >
41 {
42  // Only mantissa is stored.
43  MantissaType mantissa_;
44 
45 public:
46  /// \private
47  /// Init traits.
48  struct MemberTraits
49  {
50  enum { Count = 1 };
51 
52  typedef MantissaType FirstArgType;
53  };
54 
55  /// Mantissa component type.
56  typedef MantissaType Mantissa;
57 
58  /// Exponent component type.
59  typedef ExponentType Exponent;
60 
61  /// Traits.
62  enum
63  {
64  /// Size of the class in bytes.
65  Size = sizeof(Mantissa)
66  };
67 
68  /// \return a human-readable presentation.
69  ONIXS_B3_UMDF_MD_NODISCARD
70  std::string toString() const
71  {
72  return toStr(*this);
73  }
74 
75  /// Default (zero) initialization.
78  : mantissa_()
79  {
80  }
81 
82  /// Explicitly initializes the instance from the mantissa value.
84  : mantissa_(mantissa)
85  {
86  }
87 
88  /// \return mantissa.
90  {
91  return mantissa_;
92  }
93 
94  /// \return exponent.
96  {
97  return Exponent();
98  }
99 
100  /// Serialize to the given data buffer.
101  void serialize(void* addr) const ONIXS_B3_UMDF_MD_NOTHROW
102  {
103  assert(addr);
104 
105  std::memcpy(addr, &mantissa_, sizeof(mantissa_));
106  }
107 };
108 
109 /// A nullable real number with a constant exponent.
110 template
111 <
112  class MantissaType,
113  class ExponentType,
114  class NullMantissaType
115 >
116 class NullableFixedPointDecimal : public FixedPointDecimal<MantissaType, ExponentType>
117 {
118 public:
119  /// Default (zero) initialization.
122  : FixedPointDecimal<MantissaType, ExponentType>()
123  {
124  }
125 
126  /// Explicitly initializes the instance from the mantissa value.
129  {
130  }
131 
133  static NullMantissaType nullMantissa() ONIXS_B3_UMDF_MD_NOTHROW
134  {
135  return NullMantissaType();
136  }
137 
140  {
141  return NullableFixedPointDecimal(nullMantissa());
142  }
143 
144 
145  /// \return whether the value is `Null`.
146  bool isNull() const { return nullMantissa() == this->mantissa(); }
147 };
148 
ONIXS_B3_UMDF_MD_NODISCARD std::string toString() const
Definition: Decimal.h:70
ExponentType Exponent
Exponent component type.
Definition: Decimal.h:59
FixedPointDecimal()
Default (zero) initialization.
Definition: Decimal.h:77
#define ONIXS_B3_UMDF_MD_NOTHROW
Definition: Compiler.h:114
#define ONIXS_B3_UMDF_MD_CONSTEXPR
Definition: Compiler.h:120
NullableFixedPointDecimal()
Default (zero) initialization.
Definition: Decimal.h:121
NullableFixedPointDecimal(MantissaType mantissa)
Explicitly initializes the instance from the mantissa value.
Definition: Decimal.h:127
void serialize(void *addr) const
Serialize to the given data buffer.
Definition: Decimal.h:101
std::string toStr(const FixedPointDecimal< Mantissa, Exponent > &)
Serializes a fixed-point decimal into a string.
#define ONIXS_B3_UMDF_MD_MESSAGING_NAMESPACE_END
Definition: ABI.h:151
FixedPointDecimal(Mantissa mantissa)
Explicitly initializes the instance from the mantissa value.
Definition: Decimal.h:83
A nullable real number with a constant exponent.
Definition: Decimal.h:116
#define ONIXS_B3_UMDF_MD_MESSAGING_NAMESPACE_BEGIN
Definition: ABI.h:146
MantissaType Mantissa
Mantissa component type.
Definition: Decimal.h:56