OnixS C++ CME MDP Conflated UDP Handler  1.1.2
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.
40  const
41  ValueConverter& converter)
42  : value_(), converter_(&converter)
43  {
44  }
45 
46  /// Exposes value storage for further value manipulations.
47  const ValueContainer& value() const
48  {
49  return value_;
50  }
51 
52  /// Exposes value storage for further value manipulations.
54  {
55  return value_;
56  }
57 
58 public:
59  /// Initializes the field with no value.
61  : value_()
62  , converter_
63  (
64  &NullConverter::
65  self()
66  )
67  {
68  }
69 
70  /// Initializes as the copy of the other field.
72  const Field& other)
73  : value_(other.value_)
74  , converter_(other.converter_)
75  {
76  }
77 
78  /// Tells whether the field has
79  /// an associated (non-null) value.
80  operator bool() const
81  {
82  return (
83  converter_ !=
84  &NullConverter::self()
85  );
86  }
87 
88  /// Casts the stored value to the requested type.
89  ///
90  /// The value may be converted into the value of the
91  /// requested type if a conversion is possible. Otherwise,
92  /// an exception is thrown. For example, if the field value
93  /// represents a reference to a string (e.g. instance of the
94  /// StrRef class), then it can be successfully converted into
95  /// a number if the string referred represents a number.
96  template
97  <
98  class Value
99  >
100  typename
102  cast() const
103  {
104  ValueConversion<Value> convert;
105 
106  return
107  convert
108  (
109  *converter_,
110  value_
111  );
112  }
113 
114  /// Tries to cast the stored value into a
115  /// value of the StrRef type. Returned value
116  /// indicates whether the casting succeeded.
117  bool
119  StrRef& str) const
120  {
121  return
122  converter_->convert
123  (
124  str,
125  value_
126  );
127  }
128 
129  /// Tries to cast the stored value into a
130  /// value of the Char type. Returned value
131  /// indicates whether the casting succeeded.
132  bool
134  Char& value) const
135  {
136  return
137  converter_->convert
138  (
139  value,
140  value_
141  );
142  }
143 
144  /// Tries to cast the stored value into a
145  /// value of the Int8 type. Returned value
146  /// indicates whether the casting succeeded.
147  bool
149  Int8& value) const
150  {
151  return
152  converter_->convert
153  (
154  value,
155  value_
156  );
157  }
158 
159  /// Tries to cast the stored value into a
160  /// value of the UInt8 type. Returned value
161  /// indicates whether the casting succeeded.
162  bool
164  UInt8& value) const
165  {
166  return
167  converter_->convert
168  (
169  value,
170  value_
171  );
172  }
173 
174  /// Tries to cast the stored value into a
175  /// value of the Int16 type. Returned value
176  /// indicates whether the casting succeeded.
177  bool
179  Int16& value) const
180  {
181  return
182  converter_->convert
183  (
184  value,
185  value_
186  );
187  }
188 
189  /// Tries to cast the stored value into a
190  /// value of the UInt16 type. Returned value
191  /// indicates whether the casting succeeded.
192  bool
194  UInt16& value) const
195  {
196  return
197  converter_->convert
198  (
199  value,
200  value_
201  );
202  }
203 
204  /// Tries to cast the stored value into a
205  /// value of the Int32 type. Returned value
206  /// indicates whether the casting succeeded.
207  bool
209  Int32& value) const
210  {
211  return
212  converter_->convert
213  (
214  value,
215  value_
216  );
217  }
218 
219  /// Tries to cast the stored value into a
220  /// value of the UInt32 type. Returned value
221  /// indicates whether the casting succeeded.
222  bool
224  UInt32& value) const
225  {
226  return
227  converter_->convert
228  (
229  value,
230  value_
231  );
232  }
233 
234  /// Tries to cast the stored value into a
235  /// value of the Int64 type. Returned value
236  /// indicates whether the casting succeeded.
237  bool
239  Int64& value) const
240  {
241  return
242  converter_->convert
243  (
244  value,
245  value_
246  );
247  }
248 
249  /// Tries to cast the stored value into a
250  /// value of the UInt64 type. Returned value
251  /// indicates whether the casting succeeded.
252  bool
254  UInt64& value) const
255  {
256  return
257  converter_->convert
258  (
259  value,
260  value_
261  );
262  }
263 
264  /// Tries to cast the stored value into a
265  /// value of the Timestamp type. Returned value
266  /// indicates whether the casting succeeded.
267  bool
269  Timestamp& value) const
270  {
271  return
272  converter_->convert
273  (
274  value,
275  value_
276  );
277  }
278 
279  /// Tries to cast the stored value into a value
280  /// of the MaturityMonthYear type. Returned value
281  /// indicates whether the casting succeeded.
282  bool
284  MaturityMonthYear& value) const
285  {
286  return
287  converter_->convert
288  (
289  value,
290  value_
291  );
292  }
293 
294  /// Tries to cast the stored value into a value
295  /// of the given Enumeration type. Returned value
296  /// indicates whether the casting succeeded.
297  template
298  <
299  class Enumeration
300  >
301  bool
303  typename
304  Enumeration::Enum& value) const
305  {
306  typename
307  Enumeration::Base
308  integral;
309 
310  if (converter_->
311  convert(
312  integral,
313  value_))
314  {
315  value =
316  static_cast
317  <
318  typename
319  Enumeration::Enum
320  >
321  (integral);
322 
323  return true;
324  }
325 
326  return false;
327  }
328 
329  /// Tries to cast the stored value into a value
330  /// of the type representing a BitSet. Returned
331  /// value indicates whether the casting succeeded.
332  template
333  <
334  class BitSet
335  >
336  bool
338  BitSet& value,
339  typename BitSet::Bits* = NULL) const
340  {
341  typename BitSet::Bits bits;
342 
343  if (converter_->
344  convert(
345  bits,
346  value_))
347  {
348  value = BitSet(bits);
349 
350  return true;
351  }
352 
353  return false;
354  }
355 
356  /// Returns the text representation.
357  std::string
358  toStr() const
359  {
360  std::string str;
361 
362  toStr(str);
363 
364  return str;
365  }
366 
367  /// Outputs the text representation into the given string.
368  void
370  std::string& str) const
371  {
372  converter_->toStr
373  (
374  str,
375  value_
376  );
377  }
378 
379  /// Re-initializes the field as a copy of the other one.
380  Field&
381  operator =(
382  const Field& other)
383  {
384  value_ = other.value_;
385  converter_ = other.converter_;
386 
387  return *this;
388  }
389 };
390 
Field(const Field &other)
Initializes as the copy of the other field.
Definition: Field.h:71
UInt64 UInt64
uInt64.
Definition: Fields.h:265
bool tryCast(StrRef &str) const
Definition: Field.h:118
Traits::Result Result
Conversion output type.
std::string toStr() const
Returns the text representation.
Definition: Field.h:358
bool tryCast(Int64 &value) const
Definition: Field.h:238
Container for a value of any supported kinds.
Int32 Int32
int32.
Definition: Fields.h:69
bool tryCast(Int32 &value) const
Definition: Field.h:208
Represents time point without time-zone information.
Definition: Time.h:471
bool tryCast(Char &value) const
Definition: Field.h:133
bool tryCast(MaturityMonthYear &value) const
Definition: Field.h:283
bool tryCast(Int8 &value) const
Definition: Field.h:148
bool tryCast(UInt16 &value) const
Definition: Field.h:193
const ValueContainer & value() const
Exposes value storage for further value manipulations.
Definition: Field.h:47
void toStr(std::string &str, const Message &message)
Serializes FIX message into tag=value format.
Definition: Message.h:379
bool tryCast(UInt8 &value) const
Definition: Field.h:163
UInt32 UInt32
uInt32.
Definition: Fields.h:261
Field(const ValueConverter &converter)
Initializes the field.
Definition: Field.h:39
void toStr(std::string &str) const
Outputs the text representation into the given string.
Definition: Field.h:369
ValueConversion< Value >::Result cast() const
Definition: Field.h:102
char Char
Character type alias.
Definition: String.h:36
#define ONIXS_CONFLATEDUDPFIX_NAMESPACE_END
Definition: Bootstrap.h:165
Int16 Int16
int16.
Definition: Fields.h:65
virtual void toStr(std::string &, const ValueContainer &) const
bool tryCast(BitSet &value, typename BitSet::Bits *=NULL) const
Definition: Field.h:337
bool tryCast(typename Enumeration::Enum &value) const
Definition: Field.h:302
virtual bool convert(StrRef &, const ValueContainer &) const
UInt16 UInt16
uInt16.
Definition: Fields.h:257
UInt8 UInt8
uInt8.
Definition: Fields.h:269
bool value(Number &number, const MultiContainer &container, Tag tag)
ValueContainer & value()
Exposes value storage for further value manipulations.
Definition: Field.h:53
bool tryCast(UInt64 &value) const
Definition: Field.h:253
#define ONIXS_CONFLATEDUDP_LTWT_CLASS
Definition: Bootstrap.h:95
bool tryCast(Int16 &value) const
Definition: Field.h:178
bool tryCast(UInt32 &value) const
Definition: Field.h:223
#define ONIXS_CONFLATEDUDPFIX_NAMESPACE_BEGIN
Definition: Bootstrap.h:161
Field()
Initializes the field with no value.
Definition: Field.h:60
bool tryCast(Timestamp &value) const
Definition: Field.h:268