OnixS C++ CME MDP Premium Market Data Handler  5.8.3
API Documentation
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 
28 /// Represents the field in the FIX message.
29 ///
30 /// Exposes operations to access value
31 /// and make a compatible conversion.
33 {
34  ValueContainer value_;
35  const ValueConverter* converter_;
36 
37 protected:
38  /// Initializes the field.
39  Field(const ValueConverter& converter)
40  : value_()
41  , converter_(&converter)
42  {
43  }
44 
45  /// Exposes value storage for further value manipulations.
46  const ValueContainer& value() const
47  {
48  return value_;
49  }
50 
51  /// Exposes value storage for further value manipulations.
53  {
54  return value_;
55  }
56 
57 public:
58  /// Initializes the field with no value.
60  : value_()
61  , converter_(&NullConverter::self())
62  {
63  }
64 
65  /// Initializes as the copy of the other field.
66  Field(const Field& other)
67  : value_(other.value_)
68  , converter_(other.converter_)
69  {
70  }
71 
72  /// Tells whether the field has
73  /// an associated (non-null) value.
74  operator bool() const
75  {
76  return (converter_ != &NullConverter::self());
77  }
78 
79  /// Casts the stored value to the requested type.
80  ///
81  /// The value may be converted into the value of the
82  /// requested type if a conversion is possible. Otherwise,
83  /// an exception is thrown. For example, if the field value
84  /// represents a reference to a string (e.g. instance of the
85  /// StrRef class), then it can be successfully converted into
86  /// a number if the string referred represents a number.
87  template <class Value>
89  {
90  ValueConversion<Value> convert;
91 
92  return convert(*converter_, value_);
93  }
94 
95  /// Tries to cast the stored value into a
96  /// value of the StrRef type. Returned value
97  /// indicates whether the casting succeeded.
98  bool tryCast(StrRef& str) const
99  {
100  return converter_->convert(str, value_);
101  }
102 
103  /// Tries to cast the stored value into a
104  /// value of the Char type. Returned value
105  /// indicates whether the casting succeeded.
106  bool tryCast(Char& value) const
107  {
108  return converter_->convert(value, value_);
109  }
110 
111  /// Tries to cast the stored value into a
112  /// value of the Int8 type. Returned value
113  /// indicates whether the casting succeeded.
114  bool tryCast(Int8& value) const
115  {
116  return converter_->convert(value, value_);
117  }
118 
119  /// Tries to cast the stored value into a
120  /// value of the UInt8 type. Returned value
121  /// indicates whether the casting succeeded.
122  bool tryCast(UInt8& value) const
123  {
124  return converter_->convert(value, value_);
125  }
126 
127  /// Tries to cast the stored value into a
128  /// value of the Int16 type. Returned value
129  /// indicates whether the casting succeeded.
130  bool tryCast(Int16& value) const
131  {
132  return converter_->convert(value, value_);
133  }
134 
135  /// Tries to cast the stored value into a
136  /// value of the UInt16 type. Returned value
137  /// indicates whether the casting succeeded.
138  bool tryCast(UInt16& value) const
139  {
140  return converter_->convert(value, value_);
141  }
142 
143  /// Tries to cast the stored value into a
144  /// value of the Int32 type. Returned value
145  /// indicates whether the casting succeeded.
146  bool tryCast(Int32& value) const
147  {
148  return converter_->convert(value, value_);
149  }
150 
151  /// Tries to cast the stored value into a
152  /// value of the UInt32 type. Returned value
153  /// indicates whether the casting succeeded.
154  bool tryCast(UInt32& value) const
155  {
156  return converter_->convert(value, value_);
157  }
158 
159  /// Tries to cast the stored value into a
160  /// value of the Int64 type. Returned value
161  /// indicates whether the casting succeeded.
162  bool tryCast(Int64& value) const
163  {
164  return converter_->convert(value, value_);
165  }
166 
167  /// Tries to cast the stored value into a
168  /// value of the UInt64 type. Returned value
169  /// indicates whether the casting succeeded.
170  bool tryCast(UInt64& value) const
171  {
172  return converter_->convert(value, value_);
173  }
174 
175  /// Tries to cast the stored value into a
176  /// value of the Timestamp type. Returned value
177  /// indicates whether the casting succeeded.
178  bool tryCast(Timestamp& value) const
179  {
180  return converter_->convert(value, value_);
181  }
182 
183  /// Tries to cast the stored value into a value
184  /// of the MaturityMonthYear type. Returned value
185  /// indicates whether the casting succeeded.
187  {
188  return converter_->convert(value, value_);
189  }
190 
191  /// Tries to cast the stored value into a value
192  /// of the given Enumeration type. Returned value
193  /// indicates whether the casting succeeded.
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 
209  /// Tries to cast the stored value into a value
210  /// of the type representing a BitSet. Returned
211  /// value indicates whether the casting succeeded.
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 
227  /// Returns the text representation.
228  std::string toStr() const
229  {
230  std::string str;
231 
232  toStr(str);
233 
234  return str;
235  }
236 
237  /// Outputs the text representation into the given string.
238  void toStr(std::string& str) const
239  {
240  converter_->toStr(str, value_);
241  }
242 
243  /// Re-initializes the field as a copy of the other one.
244  Field& operator=(const Field& other)
245  {
246  value_ = other.value_;
247  converter_ = other.converter_;
248 
249  return *this;
250  }
251 };
252 
Int32 Int32
int32.
Definition: Fields.h:60
Field()
Initializes the field with no value.
Definition: Field.h:59
bool tryCast(Char &value) const
Tries to cast the stored value into a value of the Char type.
Definition: Field.h:106
UInt32 UInt32
uInt32.
Definition: Fields.h:192
#define ONIXS_CMEMDH_NULLPTR
Definition: Compiler.h:145
#define ONIXS_CMEMDHFIX_NAMESPACE_BEGIN
Definition: Bootstrap.h:70
Represents time point without time-zone information.
Definition: Time.h:387
bool tryCast(Timestamp &value) const
Tries to cast the stored value into a value of the Timestamp type.
Definition: Field.h:178
Field(const Field &other)
Initializes as the copy of the other field.
Definition: Field.h:66
void toStr(std::string &str) const
Outputs the text representation into the given string.
Definition: Field.h:238
const ValueContainer & value() const
Exposes value storage for further value manipulations.
Definition: Field.h:46
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
ValueConversion< Value >::Result cast() const
Casts the stored value to the requested type.
Definition: Field.h:88
bool tryCast(MaturityMonthYear &value) const
Tries to cast the stored value into a value of the MaturityMonthYear type.
Definition: Field.h:186
Implements value conversion operations through value conversion traits.
UInt8 UInt8
uInt8.
Definition: Fields.h:198
char Char
Character type alias.
Definition: String.h:36
UInt64 UInt64
uInt64.
Definition: Fields.h:195
bool value(Number &number, const MultiContainer &container, Tag tag)
Finds a tag-value entry in the given collection by the given tag and returns its value component tran...
void toStr(std::string &str, const Message &message)
Serializes FIX message into tag=value format.
Definition: Message.h:318
Year, Month and Date.
Definition: Composites.h:87
#define ONIXS_CMEMDHFIX_NAMESPACE_END
Definition: Bootstrap.h:71
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
Int16 Int16
int16.
Definition: Fields.h:57
Field(const ValueConverter &converter)
Initializes the field.
Definition: Field.h:39
Provides efficient way of accessing text-based values without copying content of the text being refer...
Definition: String.h:41
bool tryCast(Int32 &value) const
Tries to cast the stored value into a value of the Int32 type.
Definition: Field.h:146
Traits::Result Result
Conversion output type.
bool tryCast(Int8 &value) const
Tries to cast the stored value into a value of the Int8 type.
Definition: Field.h:114
virtual void toStr(std::string &, const ValueContainer &) const
Outputs the text presentation of the FIX value stored in the given container into the given string...
bool tryCast(UInt8 &value) const
Tries to cast the stored value into a value of the UInt8 type.
Definition: Field.h:122
Field & operator=(const Field &other)
Re-initializes the field as a copy of the other one.
Definition: Field.h:244
bool tryCast(StrRef &str) const
Tries to cast the stored value into a value of the StrRef type.
Definition: Field.h:98
bool tryCast(UInt64 &value) const
Tries to cast the stored value into a value of the UInt64 type.
Definition: Field.h:170
virtual bool convert(StrRef &, const ValueContainer &) const
Tries to convert the value stored in the given container into the string reference.
std::string toStr() const
Returns the text representation.
Definition: Field.h:228
UInt16 UInt16
uInt16 optional.
Definition: Fields.h:189
ValueContainer & value()
Exposes value storage for further value manipulations.
Definition: Field.h:52
bool tryCast(Int64 &value) const
Tries to cast the stored value into a value of the Int64 type.
Definition: Field.h:162
Int8 Int8
int8.
Definition: Fields.h:63
bool tryCast(UInt16 &value) const
Tries to cast the stored value into a value of the UInt16 type.
Definition: Field.h:138
bool tryCast(Int16 &value) const
Tries to cast the stored value into a value of the Int16 type.
Definition: Field.h:130
bool tryCast(UInt32 &value) const
Tries to cast the stored value into a value of the UInt32 type.
Definition: Field.h:154
Container for a value of any supported kinds.
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
Abstraction gathering operations over a value of a particular type stored as a field in a message...
Represents the field in the FIX message.
Definition: Field.h:32