OnixS C++ CBOE CFE Binary Order Entry (BOE) Handler  1.11.0
API documentation
Defines.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 part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #pragma once
21 
27 
28 #include <string>
29 #include <ostream>
30 
31 namespace OnixS
32 {
33  namespace CboeCFE
34  {
35  namespace Trading
36  {
37  namespace BOE
38  {
39  typedef unsigned short Port;
40 
41 
42  /// String helpers
43  struct ONIXS_CBOE_CFE_BOE_API StringTraits
44  {
45  static void fillBufferAndAddSpaces(Byte* buffer, size_t size, Byte filler, const char* data, size_t dataSize);
46 
47  static void fillBufferAndAddSpaces(Byte* buffer, size_t size, Byte filler, StrRef data)
48  {
49  fillBufferAndAddSpaces(buffer, size, filler, data.items(), data.size());
50  }
51 
52  static void fillBufferAndAddSpaces(Byte* buffer, size_t size, Byte filler, Byte value);
53  };
54 
55  /// ASCII encoded, right-padded with filler.
56  template <size_t N, Byte FILLER = 0>
57  struct ONIXS_CBOE_CFE_BOE_API String
58  {
59  Byte data[N];
60 
61  ///
62  size_t size() const
63  {
64  return N;
65  }
66 
68  {
70  }
71 
72  String(const std::string& value)
73  {
74  StringTraits::fillBufferAndAddSpaces(data, N, FILLER, value);
75  }
76 
77  String(Byte value)
78  {
79  StringTraits::fillBufferAndAddSpaces(data, N, FILLER, value);
80  }
81 
82  /// Returns string representation.
83  std::string toString () const
84  {
85  return std::string ((const char*)data, strnlen((const char*)data, N));
86  }
87 
88  /// Constructs StrRef instance.
89  StrRef toStrRef() const ONIXS_BATS_BOE_NOEXCEPT
90  {
91  return StrRef((const char*)data, strnlen((const char*)data, N));
92  }
93 
94  /// Cast to StrRef operator
95  operator StrRef() const ONIXS_BATS_BOE_NOEXCEPT
96  {
97  return toStrRef();
98  }
99 
100  /// Sets value from StrRef
101  String<N>& operator =(const StrRef value)
102  {
103  StringTraits::fillBufferAndAddSpaces(data, N, FILLER, value.items(), value.size());
104 
105  return *this;
106  }
107 
108  /// Compares with another instance.
109  bool operator == (const String<N>& other) const
110  {
111  return ( 0 == memcmp(data, other.data, N));
112  }
113 
114  /// Compares with another instance.
115  bool operator != (const String<N>& other) const
116  {
117  return ( 0 != memcmp(data, other.data, N));
118  }
119  };
120 
121  template <size_t N>
122  bool operator == (const String<N>& ref, const std::string& str)
123  {
124  return ref == String<N>(str);
125  }
126 
127  template <size_t N>
128  bool operator != (const String<N>& ref, const std::string& str)
129  {
130  return ref != String<N>(str);
131  }
132 
133  template <size_t N>
134  bool operator == (const String<N>& ref, Byte ch)
135  {
136  return ref.size() == 1 && ref == String<N>(ch);
137  }
138 
139  template <size_t N>
140  bool operator != (const String<N>& ref, Byte ch)
141  {
142  return ref.size() != 1 || ref != String<N>(ch);
143  }
144 
145  template <size_t N>
146  std::ostream& operator << (std::ostream& stream, const String<N>& value)
147  {
148  stream << '\'' << value.toString () << '\'';
149  return stream;
150  }
151 
152  /// Serializes given string into a string.
153  template <size_t N>
154  void toStr(std::string& str, const String<N>& value)
155  {
156  str.append((const char*)value.data, strnlen((const char*)value.data, N));
157  }
158 
159  /// Serializes given string into a string.
160  template <size_t N>
161  inline std::string toStr(const String<N>& value)
162  {
163  std::string str;
164 
165  toStr(str, value);
166 
167  return str;
168  }
169 
170  typedef UInt8 Binary1;
171  typedef UInt16 Binary2;
172  typedef UInt32 Binary4;
173  typedef UInt64 Binary8;
174 
175  typedef Int32 SignedBinary4;
176 
177  /// Binary Price.
178  typedef
180  <
181  Int64,
182  IntegralConstant<Int8, -4>
183  >
185 
186  template <size_t N>
187  struct ONIXS_CBOE_CFE_BOE_API Alpha : public String<N>
188  {
189  using String<N>::operator=;
190  };
191 
192  template <size_t N>
193  struct ONIXS_CBOE_CFE_BOE_API Alphanumeric : public String<N>
194  {
195  using String<N>::operator=;
196  };
197 
198  template <size_t N>
199  struct ONIXS_CBOE_CFE_BOE_API Text : public String<N>
200  {
201  using String<N>::operator=;
202  };
203 
204  typedef UInt64 DateTime;
205  typedef UInt32 Date;
206 
207  struct ONIXS_CBOE_CFE_BOE_API Unit
208  {
209  Unit();
210  Unit(Binary1 number, Binary4 sequence);
211 
212  Binary1 number() const
213  {
214  return number_;
215  }
216 
217  Binary4 sequence() const
218  {
219  return sequence_;
220  }
221 
222  Binary1 number_;
223  Binary4 sequence_;
224 
225  size_t serializeTo(unsigned char*) const ONIXS_BATS_BOE_NOEXCEPT;
226  };
227 
229 
230  struct NotImplementedException : public std::runtime_error
231  {
233  : std::runtime_error("Not implemented")
234  {}
235  };
236 
237  typedef Binary4 SeqNumber;
238 
240  {
241  static const SeqNumber InvalidValue = SeqNumber(-1);
242  };
243  }
244  }
245  }
246 }
247 
ASCII encoded, right-padded with filler.
Definition: Defines.h:57
StrRef constructStrRef(const char(&value)[Size])
Definition: String.h:404
static void fillBufferAndAddSpaces(Byte *buffer, size_t size, Byte filler, const char *data, size_t dataSize)
StrRef toStrRef() const ONIXS_BATS_BOE_NOEXCEPT
Constructs StrRef instance.
Definition: Defines.h:89
Provides efficient way of accessing text-based field values.
Definition: String.h:45
STL namespace.
String(const std::string &value)
Definition: Defines.h:72
void toStr(std::string &str, const FixedPointDecimal< Mantissa, Exponent > &number)
Serializes fixed-point decimal into a string.
Definition: Decimal.h:156
#define ONIXS_CBOE_CFE_BOE_DECLARE_T0_STR_FUNCTIONS(Type)
Definition: ABI.h:38
std::string toString() const
Returns string representation.
Definition: Defines.h:83
FixedPointDecimal< Int64, IntegralConstant< Int8,-4 > > BinaryPrice
Binary Price.
Definition: Defines.h:184
UInt8 Byte
Alias for Byte.
Definition: Memory.h:37
bool operator==(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:110
const Char * items() const ONIXS_BATS_BOE_NOEXCEPT
Read-only content.
Definition: String.h:97
bool operator!=(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:117
unsigned short Port
Definition: Defines.h:39
StrRef toStrRef(const std::string &str)
Constructs StrRef instance over std::string content.
Definition: String.h:184
static void fillBufferAndAddSpaces(Byte *buffer, size_t size, Byte filler, StrRef data)
Definition: Defines.h:47
size_t size() const ONIXS_BATS_BOE_NOEXCEPT
Number of chars.
Definition: String.h:103