OnixS C++ SGX Titan ITCH Market Data Handler  1.2.2
API documentation
Price.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 #include <climits>
25 
27 
28 ONIXS_SGXTITAN_ITCH_NAMESPACE_BEGIN
29 
30 /// Price type
31 class ONIXS_SGXTITAN_ITCH_API Price
32 {
33 public:
34  /// Aliases value component type.
35  typedef Int32 Value;
36 
37  /// Default (zero) initialization.
39  : value_(0)
40  {
41  }
42 
43  /// Explicitly initializes instance from its value value.
44  explicit Price(
45  Value value)
46  : value_(value)
47  {
48  }
49 
50  /// Initializes instance as copy of the other one.
52  const Price& other)
53  : value_(other.value_)
54  {
55  }
56 
57  /// Returns value of given price.
58  Value value() const
59  {
60  return value_;
61  }
62 
63  /// Re-initializes instance as copy of the other one.
64  Price&
65  operator =(
66  const Price& other)
67  {
68  value_ = other.value_;
69 
70  return *this;
71  }
72 
73  /// Check whether the value is nullPrice
74  bool isNull() const;
75 
76 private:
77  Value value_;
78 };
79 
80 //
81 
82 inline
83 bool
85  const Price& left,
86  const Price& right)
87 {
88  return left.value() == right.value();
89 }
90 
91 inline
92 bool
94  const Price& left,
95  const Price& right)
96 {
97  return left.value() != right.value();
98 }
99 
100 inline
101 bool
103  const Price& left,
104  const Price& right)
105 {
106  return left.value() < right.value();
107 }
108 
109 
110 inline
111 bool
113  const Price& left,
114  const Price& right)
115 {
116  return left.value() <= right.value();
117 }
118 
119 
120 inline
121 bool
123  const Price& left,
124  const Price& right)
125 {
126  return (right < left);
127 }
128 
129 inline
130  bool
132  const Price& left,
133  const Price& right)
134 {
135  return (right <= left);
136 }
137 
138 
139 /// Serializes price presented by
140 /// value and exponent into a string.
141 ONIXS_SGXTITAN_ITCH_API
142 void
143 priceToStr(
144  std::string&,
145  Int32);
146 
147 inline
148 void
150  std::string& str,
151  const Price& number)
152 {
153  priceToStr
154  (
155  str,
156  number.value()
157  );
158 }
159 
160 inline
161 std::string
163  const Price& number)
164 {
165  std::string str;
166 
167  toStr(str, number);
168 
169  return str;
170 }
171 
172 inline std::ostream& operator << (std::ostream& stream, const Price& msg)
173 {
174  stream << toStr(msg);
175  return stream;
176 }
177 
178 
179 /// Null values definition for optional price field.
180 struct NullPrice
181 {
182  /// Null value.
184 
185  /// Compares price data to NULL.
186  bool
188  const Price& other) const
189  {
190  return (
191  NullValue() ==
192  other.value()
193  );
194  }
195 
196  /// Compares price data to NULL.
197  bool
199  const Price& other) const
200  {
201  return !(*this == other);
202  }
203 };
204 
205 
206 inline
207 bool Price::isNull() const
208 {
209  return NullPrice() == *this;
210 }
211 
212 ONIXS_SGXTITAN_ITCH_NAMESPACE_END
Null values definition for optional price field.
Definition: Price.h:180
ONIXS_SGXTITAN_ITCH_API void priceToStr(std::string &, Int32)
Definition: Price.cpp:30
bool operator>(const Price &left, const Price &right)
Definition: Price.h:122
bool operator>=(const Price &left, const Price &right)
Definition: Price.h:131
Price(Value value)
Explicitly initializes instance from its value value.
Definition: Price.h:44
Value value() const
Returns value of given price.
Definition: Price.h:58
std::ostream & operator<<(std::ostream &stream, const Price &msg)
Definition: Price.h:172
Int32 Value
Aliases value component type.
Definition: Price.h:35
bool operator!=(const Price &left, const Price &right)
Definition: Price.h:93
bool operator<(const Price &left, const Price &right)
Definition: Price.h:102
IntegralConstant< Int32, INT_MIN > NullValue
Null value.
Definition: Price.h:183
bool operator<=(const Price &left, const Price &right)
Definition: Price.h:112
bool operator==(const Price &left, const Price &right)
Definition: Price.h:84
Price(const Price &other)
Initializes instance as copy of the other one.
Definition: Price.h:51
Price()
Default (zero) initialization.
Definition: Price.h:38
std::string toStr(const Price &number)
Definition: Price.h:162