OnixS C++ CME MDP Premium Market Data Handler 5.9.0
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
33{
34 ValueContainer value_;
35 const ValueConverter* converter_;
36
37protected:
39 Field(const ValueConverter& converter)
40 : value_()
41 , converter_(&converter)
42 {
43 }
44
46 const ValueContainer& value() const
47 {
48 return value_;
49 }
50
53 {
54 return value_;
55 }
56
57public:
60 : value_()
61 , converter_(&NullConverter::self())
62 {
63 }
64
66 Field(const Field& other)
67 : value_(other.value_)
68 , converter_(other.converter_)
69 {
70 }
71
74 operator bool() const
75 {
76 return (converter_ != &NullConverter::self());
77 }
78
87 template <class Value>
89 {
91
92 return convert(*converter_, value_);
93 }
94
98 bool tryCast(StrRef& str) const
99 {
100 return converter_->convert(str, value_);
101 }
102
106 bool tryCast(Char& value) const
107 {
108 return converter_->convert(value, value_);
109 }
110
114 bool tryCast(Int8& value) const
115 {
116 return converter_->convert(value, value_);
117 }
118
122 bool tryCast(UInt8& value) const
123 {
124 return converter_->convert(value, value_);
125 }
126
130 bool tryCast(Int16& value) const
131 {
132 return converter_->convert(value, value_);
133 }
134
138 bool tryCast(UInt16& value) const
139 {
140 return converter_->convert(value, value_);
141 }
142
146 bool tryCast(Int32& value) const
147 {
148 return converter_->convert(value, value_);
149 }
150
154 bool tryCast(UInt32& value) const
155 {
156 return converter_->convert(value, value_);
157 }
158
162 bool tryCast(Int64& value) const
163 {
164 return converter_->convert(value, value_);
165 }
166
170 bool tryCast(UInt64& value) const
171 {
172 return converter_->convert(value, value_);
173 }
174
179 {
180 return converter_->convert(value, value_);
181 }
182
187 {
188 return converter_->convert(value, value_);
189 }
190
194 template <class Enumeration>
195 bool tryCast(typename Enumeration::Enum& value) const
196 {
197 typename Enumeration::Base integral;
198
199 if (converter_->convert(integral, value_))
200 {
201 value = static_cast<typename Enumeration::Enum>(integral);
202
203 return true;
204 }
205
206 return false;
207 }
208
212 template <class BitSet>
213 bool tryCast(BitSet& value, typename BitSet::Bits* = ONIXS_CMEMDH_NULLPTR) const
214 {
215 typename BitSet::Bits bits;
216
217 if (converter_->convert(bits, value_))
218 {
219 value = BitSet(bits);
220
221 return true;
222 }
223
224 return false;
225 }
226
228 std::string toStr() const
229 {
230 std::string str;
231
232 toStr(str);
233
234 return str;
235 }
236
238 void toStr(std::string& str) const
239 {
240 converter_->toStr(str, value_);
241 }
242
244 Field& operator=(const Field& other)
245 {
246 value_ = other.value_;
247 converter_ = other.converter_;
248
249 return *this;
250 }
251};
252
#define ONIXS_CMEMDHFIX_NAMESPACE_BEGIN
Definition Bootstrap.h:70
#define ONIXS_CMEMDH_LTWT
Definition Bootstrap.h:46
#define ONIXS_CMEMDHFIX_NAMESPACE_END
Definition Bootstrap.h:71
#define ONIXS_CMEMDH_NULLPTR
Definition Compiler.h:178
const ValueContainer & value() const
Exposes value storage for further value manipulations.
Definition Field.h:46
bool tryCast(Int16 &value) const
Tries to cast the stored value into a value of the Int16 type.
Definition Field.h:130
bool tryCast(Int8 &value) const
Tries to cast the stored value into a value of the Int8 type.
Definition Field.h:114
bool tryCast(MaturityMonthYear &value) const
Tries to cast the stored value into a value of the MaturityMonthYear type.
Definition Field.h:186
Field()
Initializes the field with no value.
Definition Field.h:59
Field(const Field &other)
Initializes as the copy of the other field.
Definition Field.h:66
bool tryCast(UInt64 &value) const
Tries to cast the stored value into a value of the UInt64 type.
Definition Field.h:170
Field & operator=(const Field &other)
Re-initializes the field as a copy of the other one.
Definition Field.h:244
bool tryCast(Char &value) const
Tries to cast the stored value into a value of the Char type.
Definition Field.h:106
std::string toStr() const
Returns the text representation.
Definition Field.h:228
bool tryCast(StrRef &str) const
Tries to cast the stored value into a value of the StrRef type.
Definition Field.h:98
bool tryCast(UInt8 &value) const
Tries to cast the stored value into a value of the UInt8 type.
Definition Field.h:122
bool tryCast(Timestamp &value) const
Tries to cast the stored value into a value of the Timestamp type.
Definition Field.h:178
ValueContainer & value()
Exposes value storage for further value manipulations.
Definition Field.h:52
bool tryCast(UInt16 &value) const
Tries to cast the stored value into a value of the UInt16 type.
Definition Field.h:138
bool tryCast(BitSet &value, typename BitSet::Bits *=nullptr) const
Tries to cast the stored value into a value of the type representing a BitSet.
Definition Field.h:213
bool tryCast(UInt32 &value) const
Tries to cast the stored value into a value of the UInt32 type.
Definition Field.h:154
bool tryCast(Int64 &value) const
Tries to cast the stored value into a value of the Int64 type.
Definition Field.h:162
bool tryCast(typename Enumeration::Enum &value) const
Tries to cast the stored value into a value of the given Enumeration type.
Definition Field.h:195
void toStr(std::string &str) const
Outputs the text representation into the given string.
Definition Field.h:238
ValueConversion< Value >::Result cast() const
Casts the stored value to the requested type.
Definition Field.h:88
bool tryCast(Int32 &value) const
Tries to cast the stored value into a value of the Int32 type.
Definition Field.h:146
Field(const ValueConverter &converter)
Initializes the field.
Definition Field.h:39
Container for a value of any supported kinds.
Provides efficient way of accessing text-based values without copying content of the text being refer...
Definition String.h:42
Represents time point without time-zone information.
Definition Time.h:388
Int8 Int8
int8.
Definition Fields.h:63
UInt64 UInt64
uInt64.
Definition Fields.h:205
Int32 Int32
int32.
Definition Fields.h:60
char Char
Character type alias.
Definition String.h:36
UInt32 UInt32
uInt32.
Definition Fields.h:202
Int16 Int16
int16.
Definition Fields.h:57
UInt8 UInt8
uInt8.
Definition Fields.h:208
UInt16 UInt16
uInt16.
Definition Fields.h:199
static const ValueConverter & self()
Implements value conversion operations through value conversion traits.
Traits::Result Result
Conversion output type.
Abstraction gathering operations over a value of a particular type stored as a field in a message.