OnixS C++ Tullett Prebon SURF Handler  1.6.1
API documentation
Decimal.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
13  * part of this source code or associated reference material to any other location for further
14  * reproduction or redistribution, and any amendments to this copyright notice, are expressly
15  * prohibited.
16  *
17  * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
18  * the terms of the Agreement is a violation of copyright law.
19  */
20 
21 #pragma once
22 
23 #include <OnixS/SURF/MarketData/Export.h>
24 
25 #include <iosfwd>
26 #include <string>
27 
28 namespace OnixS { namespace SURF { namespace MarketData {
29 
30 ///
31 /// Decimal representation.
32 ///
33 struct ONIXS_TP_SURF_EXPORT Decimal
34 {
35  Decimal();
36 
37  Decimal(signed char);
38  Decimal(unsigned char);
39 
40  Decimal(signed short);
41  Decimal(unsigned short);
42 
43  Decimal(signed int);
44  Decimal(unsigned int);
45 
46  Decimal(signed long long);
47  Decimal(unsigned long long);
48 
49  Decimal(float value, size_t precision);
50 
51  Decimal(signed long long mantissa, signed int exponent);
52 
53  Decimal(
54  signed char sign,
55  unsigned long long mantissaHigh,
56  unsigned long long mantissaLow,
57  signed int exponent
58  );
59 
60  Decimal(const std::string&);
61  Decimal(const char* buffer, size_t bufferSize);
62 
63  Decimal(const Decimal& other);
64 
65  signed long long mantissa() const;
66  void mantissa(signed long long);
67 
68  signed int exponent() const;
69  void exponent(signed int);
70 
71  bool toNumber(signed char& converted) const;
72  bool toNumber(unsigned char& converted) const;
73 
74  bool toNumber(signed short& converted) const;
75  bool toNumber(unsigned short& converted) const;
76 
77  bool toNumber(signed int& converted) const;
78  bool toNumber(unsigned int& converted) const;
79 
80  bool toNumber(signed long long& converted) const;
81  bool toNumber(unsigned long long& converted) const;
82 
83  bool toNumber(float& converted) const;
84  bool toNumber(double& converted) const;
85 
86  operator signed int() const;
87  operator unsigned int() const;
88  operator signed long long() const;
89  operator unsigned long long() const;
90  operator double() const;
91 
92  bool operator==(const Decimal& other) const;
93  bool operator!=(const Decimal& other) const;
94 
95  Decimal& operator=(const Decimal& other);
96 
97  Decimal& operator+=(const Decimal& other);
98  Decimal& operator-=(const Decimal& other);
99 
100  Decimal& operator*=(const Decimal& other);
101  Decimal& operator/=(const Decimal& other);
102 
103  std::string toString() const;
104 
105 private:
106  void unpack(
107  signed char* sign,
108  unsigned long long* mantissaHigh,
109  unsigned long long* mantissaLow,
110  signed int* exponent
111  ) const;
112 
113 private:
114  unsigned char bytes[16];
115 };
116 
117 ONIXS_TP_SURF_EXPORT Decimal operator+(Decimal);
118 ONIXS_TP_SURF_EXPORT Decimal operator-(Decimal);
119 
120 ONIXS_TP_SURF_EXPORT Decimal operator+(Decimal, Decimal);
121 ONIXS_TP_SURF_EXPORT Decimal operator-(Decimal, Decimal);
122 
123 ONIXS_TP_SURF_EXPORT Decimal operator*(Decimal, Decimal);
124 ONIXS_TP_SURF_EXPORT Decimal operator/(Decimal, Decimal);
125 
126 ONIXS_TP_SURF_EXPORT bool operator<(Decimal, Decimal);
127 ONIXS_TP_SURF_EXPORT bool operator>(Decimal, Decimal);
128 
129 ONIXS_TP_SURF_EXPORT bool operator<=(Decimal, Decimal);
130 ONIXS_TP_SURF_EXPORT bool operator>=(Decimal, Decimal);
131 
132 ONIXS_TP_SURF_EXPORT std::ostream& operator<<(std::ostream&, const Decimal&);
133 
134 }}} // namespace OnixS::SURF::MarketData
bool operator>=(Decimal, Decimal)
bool operator<=(Decimal, Decimal)
bool operator<(Decimal, Decimal)
Decimal operator*(Decimal, Decimal)
Definition: Decimal.h:28
Decimal operator-(Decimal)
Decimal operator/(Decimal, Decimal)
Decimal operator+(Decimal)
std::ostream & operator<<(std::ostream &, const Decimal &)
bool operator>(Decimal, Decimal)