MFClient  1.3.0
 All Classes Functions Variables Enumerations
PriceSize.hpp
1 #ifndef _MFPRICESIZE_H
2 #define _MFPRICESIZE_H
3 
4 #include<sstream>
5 #include<cmath>
6 
7 #include <sbe/sbe.hpp>
8 
12 class PriceSize
13 {
14 private:
15  sbe_int64_t price;
16  sbe_int64_t quantity;
17 
18 public:
19 
21  static const int64_t QTY_EXPONENT = 5;
22 
24  static const int64_t PRICE_EXPONENT = 9;
25 
27  PriceSize() { price = 0; quantity = 0; }
28 
33  PriceSize(sbe_int64_t price_, sbe_int64_t quantity_) {
34  price = price_;
35  quantity = quantity_;
36  }
37 
41  PriceSize(const PriceSize &p2) { price = p2.price; quantity = p2.quantity; }
42 
46  void setPrice(sbe_int64_t price_) {
47  price = price_;
48  }
49 
53  void setQuantity(sbe_int64_t quantity_) {
54  quantity = quantity_;
55  }
56 
58  std::string toString()
59  {
60  std::string returnString;
61 
62  double pricen = std::pow(10.0, -9) * price;
63  double qtyn = std::pow(10.0, -5) * quantity;
64 
65  // returnString = std::to_string(pricen) +
66  returnString = ToString(pricen) +
67  " x " +
68  ToString(qtyn/1000000) + "M";
69 
70  return returnString;
71  }
72 
74  std::string toRawString() {
75  std::string returnString;
76 
77  returnString = "price: " +
78  // std::to_string(price) +
79  ToString(price) +
80  ", quantity:" +
81  // std::to_string(quantity);
82  ToString(quantity);
83 
84  return returnString;
85  }
86 
88  double priceToDouble()
89  {
90  return std::pow(10.0, (-1 * PRICE_EXPONENT)) * price;
91  }
92 
95  {
96  return std::pow(10.0, (-1 * QTY_EXPONENT)) * quantity;
97  }
98 
100  template <typename T>
101  std::string ToString(T val)
102  {
103  std::stringstream stream;
104  stream << val;
105  return stream.str();
106  }
107 };
108 
109 #endif
110 
double quantityToDouble()
Get the double representation of quantity.
Definition: PriceSize.hpp:94
PriceSize(const PriceSize &p2)
A deep copy Copy Constructor
Definition: PriceSize.hpp:41
void setPrice(sbe_int64_t price_)
Set a new price value
Definition: PriceSize.hpp:46
std::string ToString(T val)
Stringize a type using the standard sstream formatting.
Definition: PriceSize.hpp:101
static const int64_t QTY_EXPONENT
The number of decimal places in the quantity type.
Definition: PriceSize.hpp:21
std::string toString()
Stringize PriceSize showing stringized decimals.
Definition: PriceSize.hpp:58
double priceToDouble()
Get the double representation of price.
Definition: PriceSize.hpp:88
static const int64_t PRICE_EXPONENT
The number of decimal places in the price type.
Definition: PriceSize.hpp:24
PriceSize(sbe_int64_t price_, sbe_int64_t quantity_)
The constructor that initializes price and quantity to the passed values.
Definition: PriceSize.hpp:33
void setQuantity(sbe_int64_t quantity_)
Set a new quantity value
Definition: PriceSize.hpp:53
std::string toRawString()
Stringize PriceSize showing the raw data member price and quantity values.
Definition: PriceSize.hpp:74
PriceSize()
Default constructor that initializes price and quantity to 0.
Definition: PriceSize.hpp:27
Definition: PriceSize.hpp:12