OnixS C++ CME MDP Premium Market Data Handler 5.10.2
Users' manual and API documentation
Loading...
Searching...
No Matches
Field.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
25
27
29class Field
30{
31public:
34 : value_()
35 , converter_(&NullConverter::self())
36 {
37 }
38
41 explicit ONIXS_CMEMDH_NODISCARD operator bool() const noexcept
42 {
43 return (converter_ != &NullConverter::self());
44 }
45
47 explicit ONIXS_CMEMDH_NODISCARD operator std::string() const
48 {
49 return toString();
50 }
51
55 {
56 constexpr size_t bufSize = 512;
57 Char buffer[bufSize];
58
59 return this->toString(buffer, bufSize) == r;
60 }
61
64 {
65 return !this->operator==(r);
66 }
67
78 template <class Value>
80 {
82
83 assert(converter_);
84
85 return convert(*converter_, value_);
86 }
87
92 {
93 assert(converter_);
94
95 return converter_->convert(str, value_);
96 }
97
103 {
104 assert(converter_);
105
106 return converter_->convert(value, value_);
107 }
108
114 {
115 assert(converter_);
116
117 return converter_->convert(value, value_);
118 }
119
125 {
126 assert(converter_);
127
128 return converter_->convert(value, value_);
129 }
130
136 {
137 assert(converter_);
138
139 return converter_->convert(value, value_);
140 }
141
147 {
148 assert(converter_);
149
150 return converter_->convert(value, value_);
151 }
152
158 {
159 assert(converter_);
160
161 return converter_->convert(value, value_);
162 }
163
169 {
170 assert(converter_);
171
172 return converter_->convert(value, value_);
173 }
174
180 {
181 assert(converter_);
182
183 return converter_->convert(value, value_);
184 }
185
191 {
192 assert(converter_);
193
194 return converter_->convert(value, value_);
195 }
196
202 {
203 assert(converter_);
204
205 return converter_->convert(value, value_);
206 }
207
213 {
214 assert(converter_);
215
216 return converter_->convert(value, value_);
217 }
218
224 {
225 assert(converter_);
226
227 return converter_->convert(value, value_);
228 }
229
234 template <class Enumeration>
235 ONIXS_CMEMDH_NODISCARD bool toEnumeration(typename Enumeration::Enum& value) const
236 {
237 typename Enumeration::Base integral;
238
239 assert(converter_);
240
241 if (converter_->convert(integral, value_))
242 {
243 value = static_cast<typename Enumeration::Enum>(integral);
244
245 return true;
246 }
247
248 return false;
249 }
250
255 template <class BitSet>
257 {
258 typename BitSet::Bits bits;
259
260 assert(converter_);
261
262 if (converter_->convert(bits, value_))
263 {
264 value = BitSet(bits);
265
266 return true;
267 }
268
269 return false;
270 }
271
274 {
275 std::string str;
276
277 toString(str);
278
279 return str;
280 }
281
283 void toString(std::string& str) const
284 {
285 assert(converter_);
286
287 converter_->toStr(str, value_);
288 }
289
292 StrRef toString(Char* buf, size_t size) const
293 {
294 assert(converter_);
295
296 return converter_->toStr(buf, size, value_);
297 }
298
299protected:
301 explicit Field(const ValueConverter& converter) noexcept
302 : value_()
303 , converter_(&converter)
304 {
305 }
306
308 const ValueContainer& value() const noexcept
309 {
310 return value_;
311 }
312
315 {
316 return value_;
317 }
318
319private:
320 ValueContainer value_;
321 const ValueConverter* converter_;
322};
323
324inline bool operator==(const Field& ref, const std::string& str)
325{
326 return ref == StrRef(str);
327}
328
329inline bool operator!=(const Field& ref, const std::string& str)
330{
331 return ref != StrRef(str);
332}
333
334inline bool operator==(const std::string& str, const Field& ref)
335{
336 return ref == StrRef(str);
337}
338
339inline bool operator!=(const std::string& str, const Field& ref)
340{
341 return ref != StrRef(str);
342}
343
344inline bool operator==(const Field& ref, const char* str)
345{
346 return ref == StrRef(str);
347}
348
349inline bool operator!=(const Field& ref, const char* str)
350{
351 return ref != StrRef(str);
352}
353
354inline bool operator==(const char* str, const Field& ref)
355{
356 return ref == StrRef(str);
357}
358
359inline bool operator!=(const char* str, const Field& ref)
360{
361 return ref != StrRef(str);
362}
363
365inline std::ostream& operator<<(std::ostream& stream, const Field& field)
366{
367 return stream << field.toString();
368}
369
#define ONIXS_CMEMDH_MESSAGING_TAGBASED_NAMESPACE_BEGIN
Definition Bootstrap.h:60
#define ONIXS_CMEMDH_MESSAGING_TAGBASED_NAMESPACE_END
Definition Bootstrap.h:61
#define ONIXS_CMEMDH_NODISCARD
Definition Compiler.h:150
A field in a tag-based message.
Definition Field.h:30
bool toNumber(Int8 &value) const
Definition Field.h:113
bool toStringRef(StrRef &str) const
Definition Field.h:91
bool operator==(const StrRef &r) const
Definition Field.h:54
bool toNumber(Decimal &value) const
Definition Field.h:201
Field()
Initializes a field with no value.
Definition Field.h:33
bool toNumber(UInt8 &value) const
Definition Field.h:124
bool toNumber(Int64 &value) const
Definition Field.h:179
bool toNumber(UInt32 &value) const
Definition Field.h:168
void toString(std::string &str) const
Outputs the text representation into the given string.
Definition Field.h:283
Field(const ValueConverter &converter) noexcept
Initializes the field.
Definition Field.h:301
bool toTimestamp(Timestamp &value) const
Definition Field.h:212
bool toBitSet(BitSet &value) const
Definition Field.h:256
const ValueContainer & value() const noexcept
Exposes the value storage for further value manipulations.
Definition Field.h:308
ValueContainer & value() noexcept
Exposes the value storage for further value manipulations.
Definition Field.h:314
bool toNumber(Int32 &value) const
Definition Field.h:157
bool toNumber(UInt64 &value) const
Definition Field.h:190
bool toMaturityMonthYear(MaturityMonthYear &value) const
Definition Field.h:223
bool toNumber(Int16 &value) const
Definition Field.h:135
bool operator!=(const StrRef &r) const
Compares the presentation for not equality with given text reference.
Definition Field.h:63
bool toEnumeration(typename Enumeration::Enum &value) const
Definition Field.h:235
bool toNumber(UInt16 &value) const
Definition Field.h:146
ValueConversion< Value >::Result cast() const
Definition Field.h:79
bool toChar(Char &value) const
Definition Field.h:102
StrRef toString(Char *buf, size_t size) const
Definition Field.h:292
The time point without the time-zone information.
Definition Time.h:425
std::ostream & operator<<(std::ostream &stream, const Field &field)
Serializes into the given stream.
Definition Field.h:365
bool operator==(const Field &ref, const std::string &str)
Definition Field.h:324
bool operator!=(const Field &ref, const std::string &str)
Definition Field.h:329
std::uint32_t UInt32
uInt32.
Definition Integral.h:35
std::int8_t Int8
int8.
Definition Integral.h:30
char Char
Character type alias.
Definition String.h:30
std::uint16_t UInt16
uInt16.
Definition Integral.h:33
std::int32_t Int32
int32.
Definition Integral.h:34
std::basic_string_view< Char > StrRef
Definition StrRef.h:46
FloatingPointDecimal< DecimalMantissa, DecimalExponent > Decimal
Universal decimal type.
void convert(FixedPointDecimal< MantissaType, ExponentType > &res, const Decimal &number)
std::uint64_t UInt64
uInt64.
Definition Integral.h:37
std::uint8_t UInt8
uInt8.
Definition Integral.h:31
std::int16_t Int16
int16.
Definition Integral.h:32
static const ValueConverter & self() noexcept
Traits::Result Result
Conversion output type.