OnixS C++ CME iLink 3 Binary Order Entry Handler 1.18.9
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
30{
31public:
34 : value_()
35 , converter_(&NullConverter::self())
36 {
37 }
38
42 {
43 return (converter_ != &NullConverter::self());
44 }
45
47 ONIXS_ILINK3_EXPLICIT ONIXS_ILINK3_NODISCARD operator std::string() const
48 {
49 return toString();
50 }
51
54 ONIXS_ILINK3_NODISCARD bool operator == (const StrRef& r) const
55 {
56 ONIXS_ILINK3_CONST_OR_CONSTEXPR size_t bufSize = 512;
57 Char buffer[bufSize];
58
59 return this->toString(buffer, bufSize) == r;
60 }
61
63 ONIXS_ILINK3_NODISCARD bool operator != (const StrRef& r) const
64 {
65 return !this->operator==(r);
66 }
67
78 template
79 <
80 class Value
81 >
83 typename
85 {
87
88 assert(converter_);
89
90 return convert(*converter_, value_);
91 }
92
97 {
98 assert(converter_);
99
100 return converter_->convert(str, value_);
101 }
102
108 {
109 assert(converter_);
110
111 return converter_->convert(value, value_);
112 }
113
119 {
120 assert(converter_);
121
122 return converter_->convert(value, value_);
123 }
124
130 {
131 assert(converter_);
132
133 return converter_->convert(value, value_);
134 }
135
141 {
142 assert(converter_);
143
144 return converter_->convert(value, value_);
145 }
146
152 {
153 assert(converter_);
154
155 return converter_->convert(value, value_);
156 }
157
163 {
164 assert(converter_);
165
166 return converter_->convert(value, value_);
167 }
168
174 {
175 assert(converter_);
176
177 return converter_->convert(value, value_);
178 }
179
185 {
186 assert(converter_);
187
188 return converter_->convert(value, value_);
189 }
190
196 {
197 assert(converter_);
198
199 return converter_->convert(value, value_);
200 }
201
207 {
208 assert(converter_);
209
210 return converter_->convert(value, value_);
211 }
212
218 {
219 assert(converter_);
220
221 return converter_->convert(value, value_);
222 }
223
229 {
230 assert(converter_);
231
232 return converter_->convert(value, value_);
233 }
234
239 template<class Enumeration>
240 ONIXS_ILINK3_NODISCARD bool toEnumeration(typename Enumeration::Enum& value) const
241 {
242 typename Enumeration::Base integral;
243
244 assert(converter_);
245
246 if (converter_->convert(integral,value_))
247 {
248 value = static_cast<typename Enumeration::Enum>(integral);
249
250 return true;
251 }
252
253 return false;
254 }
255
260 template <class BitSet>
262 {
263 typename BitSet::Bits bits;
264
265 assert(converter_);
266
267 if (converter_->convert(bits, value_))
268 {
269 value = BitSet(bits);
270
271 return true;
272 }
273
274 return false;
275 }
276
279 {
280 std::string str;
281
282 toString(str);
283
284 return str;
285 }
286
288 void toString(std::string& str) const
289 {
290 assert(converter_);
291
292 converter_->toStr(str, value_);
293 }
294
297 StrRef toString(Char* buf, size_t size) const
298 {
299 assert(converter_);
300
301 return converter_->toStr(buf, size, value_);
302 }
303
304protected:
306 explicit Field(const ValueConverter& converter) ONIXS_ILINK3_NOTHROW
307 : value_()
308 , converter_(&converter)
309 {
310 }
311
314 {
315 return value_;
316 }
317
320 {
321 return value_;
322 }
323
324private:
325 ValueContainer value_;
326 const ValueConverter* converter_;
327};
328
329inline bool operator == (const Field& ref, const std::string& str)
330{
331 return ref == StrRef(str);
332}
333
334inline bool operator != (const Field& ref, const std::string& str)
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 std::string& str, const Field& ref)
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 Field& ref, const char* str)
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
364inline bool operator != (const char* str, const Field& ref)
365{
366 return ref != StrRef(str);
367}
368
370inline std::ostream& operator<<(std::ostream& stream, const Field& field)
371{
372 return stream << field.toString();
373}
374
#define ONIXS_ILINK3_LTWT_CLASS
Definition ABI.h:84
#define ONIXS_ILINK3_MESSAGING_TAGBASED_NAMESPACE_END
Definition ABI.h:153
#define ONIXS_ILINK3_MESSAGING_TAGBASED_NAMESPACE_BEGIN
Definition ABI.h:149
#define ONIXS_ILINK3_EXPLICIT
Definition Compiler.h:177
#define ONIXS_ILINK3_NODISCARD
Definition Compiler.h:185
#define ONIXS_ILINK3_CONST_OR_CONSTEXPR
Definition Compiler.h:178
#define ONIXS_ILINK3_NOTHROW
Definition Compiler.h:176
A field in a tag-based message.
Definition Field.h:30
bool toNumber(Int8 &value) const
Tries to cast the stored value into a value of the Int8 type.
Definition Field.h:118
bool toStringRef(StrRef &str) const
Tries to cast the stored value into a value of the StrRef type.
Definition Field.h:96
bool operator==(const StrRef &r) const
Compares the presentation for equality with the given text reference.
Definition Field.h:54
bool toNumber(Decimal &value) const
Tries to cast the stored value into a value of the Decimal type.
Definition Field.h:206
Field()
Initializes a field with no value.
Definition Field.h:33
bool toNumber(UInt8 &value) const
Tries to cast the stored value into a value of the UInt8 type.
Definition Field.h:129
bool toNumber(Int64 &value) const
Tries to cast the stored value into a value of the Int64 type.
Definition Field.h:184
bool toNumber(UInt32 &value) const
Tries to cast the stored value into a value of the UInt32 type.
Definition Field.h:173
void toString(std::string &str) const
Outputs the text representation into the given string.
Definition Field.h:288
Field(const ValueConverter &converter) noexcept
Initializes the field.
Definition Field.h:306
bool toTimestamp(Timestamp &value) const
Tries to cast the stored value into a value of the Timestamp type.
Definition Field.h:217
bool toBitSet(BitSet &value) const
Tries to cast the stored value into a value of the type representing a BitSet.
Definition Field.h:261
const ValueContainer & value() const noexcept
Exposes the value storage for further value manipulations.
Definition Field.h:313
ValueContainer & value() noexcept
Exposes the value storage for further value manipulations.
Definition Field.h:319
bool toNumber(Int32 &value) const
Tries to cast the stored value into a value of the Int32 type.
Definition Field.h:162
bool toNumber(UInt64 &value) const
Tries to cast the stored value into a value of the UInt64 type.
Definition Field.h:195
bool toMaturityMonthYear(MaturityMonthYear &value) const
Tries to cast the stored value into a value of the MaturityMonthYear type.
Definition Field.h:228
bool toNumber(Int16 &value) const
Tries to cast the stored value into a value of the Int16 type.
Definition Field.h:140
bool toEnumeration(typename Enumeration::Enum &value) const
Tries to cast the stored value into a value of the given Enumeration type.
Definition Field.h:240
bool toNumber(UInt16 &value) const
Tries to cast the stored value into a value of the UInt16 type.
Definition Field.h:151
ValueConversion< Value >::Result cast() const
Casts the stored value to the requested type.
Definition Field.h:84
bool toChar(Char &value) const
Tries to cast the stored value into a value of the Char type.
Definition Field.h:107
StrRef toString(Char *buf, size_t size) const
Definition Field.h:297
The time point without the time-zone information.
Definition Time.h:468
std::ostream & operator<<(std::ostream &stream, const Field &field)
Serializes into the given stream.
Definition Field.h:370
FloatingPointDecimal< Int64, Int32 > Decimal
Universal decimal type.
char Char
Character type alias.
Definition String.h:30
std::basic_string_view< Char > StrRef
Definition StrRef.h:46
void convert(FixedPointDecimal< MantissaType, ExponentType > &res, const Decimal &number)
static const ValueConverter & self() noexcept
Implements value conversion operations through value conversion traits.
Abstraction gathering operations over a value of a particular type stored as a field in a message.