OnixS C++ LSE GTP Market Data Handler 1.0.6
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
23#include <string>
24
27
28namespace OnixS
29{
30 namespace LSE
31 {
32 namespace MarketData
33 {
34 namespace GTP
35 {
36
44 template<class MantissaType, class ExponentType>
45 class ONIXS_LSE_GTP_API FixedPointDecimal
46 {
47 // Only mantissa is stored.
48 MantissaType mantissa_;
49
50 public:
52 typedef MantissaType Mantissa;
53
55 typedef ExponentType Exponent;
56
58 enum
59 {
66 Size = sizeof(Mantissa)
67 };
68
72 : mantissa_()
73 {
74 }
75
77 explicit
83
87 : mantissa_(other.mantissa_)
88 {
89 }
90
91#if defined(ONIXS_LSE_GTP_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_LSE_GTP_COMPILER_CXX_RVALUE_REFERENCES
92
95 : mantissa_(std::move(other.mantissa_))
96 {
97 }
98
99 FixedPointDecimal&
100 operator=(
101 FixedPointDecimal&& other)
103 {
104 if (this == &other)
105 return *this;
106
107 mantissa_ = std::move(other.mantissa_);
108
109 return *this;
110 }
111#endif
112
116 {
117 return mantissa_;
118 }
119
123 {
124 return Exponent();
125 }
126
128 FixedPointDecimal& operator =(const FixedPointDecimal& other)
130 {
131 mantissa_ = other.mantissa_;
132
133 return *this;
134 }
135 };
136
138 template<class Mantissa, class Exponent>
142 {
143 return left.mantissa() == right.mantissa();
144 }
145
147 template <class Mantissa, class Exponent>
151 {
152 return left.mantissa() != right.mantissa();
153 }
154
156 template<class Mantissa, class Exponent>
160 {
161 return left.mantissa() < right.mantissa();
162 }
163
165 template<class Mantissa, class Exponent>
169 {
170 return left.mantissa() > right.mantissa();
171 }
172
174 template<class Mantissa, class Exponent>
178 {
179 return left.mantissa() <= right.mantissa();
180 }
181
183 template<class Mantissa, class Exponent>
187 {
188 return left.mantissa() >= right.mantissa();
189 }
190
193 ONIXS_LSE_GTP_API void decimalToStr(std::string&, Int64, Int32);
194
196 template <class Mantissa, class Exponent>
197 inline void toStr(std::string& str, const FixedPointDecimal<Mantissa, Exponent>& number)
198 {
199 decimalToStr(str, number.mantissa(), static_cast<Int32>(number.exponent().value()));
200 }
201
203 template<class Mantissa, class Exponent>
204 inline std::string toStr(const FixedPointDecimal<Mantissa, Exponent>& number)
205 {
206 std::string str;
207
208 toStr(str, number);
209
210 return str;
211 }
212
213 // Serializes fixed-point decimal to stream
214 template<class Mantissa, class Exponent>
215 std::ostream& operator << (std::ostream& stream, const FixedPointDecimal<Mantissa, Exponent>& number)
216 {
217 return stream << toStr(number);
218 }
219 }
220 }
221 }
222}
#define ONIXS_LSE_GTP_NOTHROW
Definition Compiler.h:118
FixedPointDecimal(const FixedPointDecimal &other) ONIXS_LSE_GTP_NOTHROW
Initializes instance as copy of the other one.
Definition Decimal.h:85
ExponentType Exponent
Aliases exponent component type.
Definition Decimal.h:55
FixedPointDecimal(Mantissa mantissa) ONIXS_LSE_GTP_NOTHROW
Explicitly initializes instance from its mantissa value.
Definition Decimal.h:78
Exponent exponent() const ONIXS_LSE_GTP_NOTHROW
Returns exponent of given decimal.
Definition Decimal.h:121
MantissaType Mantissa
Aliases mantissa component type.
Definition Decimal.h:52
FixedPointDecimal() ONIXS_LSE_GTP_NOTHROW
Default (zero) initialization.
Definition Decimal.h:70
bool operator==(const TimeSpan &left, const TimeSpan &right)
Compares with other instance for equality.
Definition Time.h:326
bool operator>=(const Timestamp &left, const Timestamp &right)
Establishes order between two instances.
Definition Time.h:777
bool operator>(const TimeSpan &left, const TimeSpan &right)
Checks whether left time interval greater than right one.
Definition Time.h:356
bool operator<=(const Timestamp &left, const Timestamp &right)
Establishes order between two instances.
Definition Time.h:751
ONIXS_LSE_GTP_API void decimalToStr(std::string &, Int64, Int32)
bool operator<(const TimeSpan &left, const TimeSpan &right)
Checks whether left time interval less than right one.
Definition Time.h:346
ONIXS_LSE_GTP_API std::ostream & operator<<(std::ostream &stream, const ServiceDescriptor &descriptor)
ONIXS_LSE_GTP_API void toStr(std::string &, EventCode::Enum)
Appends string presentation of object.
bool operator!=(const TimeSpan &left, const TimeSpan &right)
Compares with other instance for in-equality.
Definition Time.h:336