OnixS C++ CME Market Data Handler  5.5.1
API documentation
Message.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 
23 #include <cstdlib>
24 
26 
28 #include <OnixS/CME/MDH/FIX/Tag.h>
29 
31 
32 /// The abstraction of a source of FIX information
33 /// which provides access to the FIX fields by their
34 /// tags.
36 {
37  /// Returns field by its tag.
38  ///
39  /// If the source does not contain any
40  /// field with the given tag, the returned
41  /// instance represents a null field.
42  virtual Field field(Tag) const = 0;
43 };
44 
45 typedef
48 
49 /// Provides FIX-like access to the fields
50 /// stored in a SBE-encoded repeating group.
53 {
54  /// Provides FIX-like access to the fields
55  /// stored in a SBE-encoded repeating group.
56  virtual
57  Field
58  field(
59  const GroupEntrySource&,
60  Tag) const = 0;
61 };
62 
63 /// Provides FIX-like access to the fields
64 /// stored in a SBE-encoded repeating group.
66 GroupEntry : public FieldSet
67 {
68  GroupEntrySource binary_;
69  const GroupEntryAccessor* accessor_;
70 
71 protected:
72  friend
74  (
75  Group
76  );
77 
78  /// Full-initialized instances are
79  /// constructed through descendants.
80  GroupEntry(
81  const GroupEntrySource& binary,
82  const GroupEntryAccessor& accessor)
83  : binary_(binary)
84  , accessor_(&accessor)
85  {
86  }
87 
88 public:
89  /// Initializes the instance which refers to
90  /// nothing and thus represents a null instance.
91  GroupEntry()
92  : binary_()
93  , accessor_(NULL)
94  {
95  }
96 
97  /// Initializes the instance as
98  /// the copy of the other one.
99  GroupEntry(
100  const GroupEntry& other)
101  : binary_(other.binary_)
102  , accessor_(other.accessor_)
103  {
104  }
105 
106  /// Indicates whether the instance refers
107  /// to a valid repeating group entry.
108  operator bool() const
109  {
110  return (NULL != accessor_);
111  }
113  /// Returns field by its tag.
114  ///
115  /// The instance must refer to a valid group entry.
116  Field operator [](Tag tag) const
117  {
118  return this->field(tag);
119  }
121  /// Returns field by its tag.
122  ///
123  /// The instance must refer to a valid group entry.
124  Field field(Tag tag) const
125  {
126  assert(NULL != accessor_);
127 
128  return accessor_->field(binary_, tag);
129  }
131  /// Re-initializes as the
132  /// copy of the other instance.
133  GroupEntry&
134  operator =(
135  const GroupEntry& other)
136  {
137  binary_ = other.binary_;
138  accessor_ = other.accessor_;
139 
140  return *this;
141  }
142 };
143 
144 typedef
146 <
148  MessageSize,
149  MessageSize,
151 >
153 
154 /// Implements a FIX repeating group
155 /// over the SBE-encoded binary data.
157 {
158  GroupEntriesSource binary_;
159  const GroupEntryAccessor* accessor_;
160 
161 protected:
162  /// Initializes the instance over the binary data.
164  const GroupEntriesSource& binary,
165  const GroupEntryAccessor& accessor)
166  : binary_(binary)
167  , accessor_(&accessor)
168  {
169  }
170 
171 public:
172  /// Number of repeating group entries.
173  typedef
176 
177  /// Initializes the instance which refers to
178  /// nothing and thus represent a null instance.
180  : accessor_(NULL)
181  {
182  }
183 
184  /// Initializes as the copy of the other instance.
186  const Group& other)
187  : binary_(other.binary_)
188  , accessor_(other.accessor_)
189  {
190  }
191 
192  /// Indicates whether the instance
193  /// refers to a valid repeating group.
194  operator bool() const
195  {
196  return (NULL != accessor_);
197  }
198 
199  /// Number of entries in the repeating group
200  /// being referred by the given instance.
201  Size size() const
202  {
203  return binary_.size();
204  }
205 
206  /// Provides access to the group
207  /// entry by its index in the group.
208  GroupEntry
209  operator [](
210  Size index) const
211  {
212  assert(NULL != accessor_);
213 
214  return
215  GroupEntry(
216  binary_[index],
217  *accessor_);
218  }
219 
220  /// Re-initializes as the copy of the other instance.
221  Group&
222  operator =(
223  const Group& other)
224  {
225  binary_ = other.binary_;
226  accessor_ = other.accessor_;
227 
228  return *this;
229  }
230 };
231 
232 /// Implements FIX-like services
233 /// for the SBE-encoded message.
236 {
237  /// FIX message type.
238  virtual
239  StrRef
240  type() const = 0;
241 
242  /// Returns field value by its tag.
243  virtual
244  Field
245  field(
246  const BinaryMessage&,
247  Tag) const = 0;
248 
249  /// Accesses a repeating group by its tag.
250  virtual
251  Group
252  group(
253  const BinaryMessage&,
254  Tag) const = 0;
255 
256  /// Serializes the given message into
257  /// the FIX (tag=value) presentation.
258  virtual
259  void
260  toFix(
261  std::string&,
262  const BinaryMessage&) const = 0;
263 };
264 
265 /// Implements FIX-like interface
266 /// over the SBE-encoded message.
268 Message : public FieldSet
269 {
270  BinaryMessage binary_;
271  const MessageAccessor* accessor_;
272 
273 protected:
274  /// Initializes the instance from the SBE-encoded message.
276  const BinaryMessage& binary,
277  const MessageAccessor& accessor)
278  : binary_(binary), accessor_(&accessor)
279  {
280  }
281 
282 public:
283  /// Initializes the message which refers
284  /// to nothing and thus being a null-instance.
286  : binary_()
287  , accessor_(NULL)
288  {
289  }
290 
291  /// Initializes as the copy of the other instance.
293  const Message& other)
294  : binary_(other.binary_)
295  , accessor_(other.accessor_)
296  {
297  }
298 
299  /// Indicates whether the instance refers to a valid message.
300  operator bool() const
301  {
302  return (NULL != accessor_);
303  }
304 
305  /// FIX message type.
306  StrRef type() const
307  {
308  assert(NULL != accessor_);
309 
310  return accessor_->type();
311  }
312 
313  /// Returns a field by its tag.
314  ///
315  /// If the message contains a field
316  /// with the requested tag, then the
317  /// returned instance of the Field class
318  /// refers to a valid data and thus further
319  /// manipulations with its value are possible.
320  /// Otherwise, the returned instance refers
321  /// to nothing.
322  Field operator [](Tag tag) const
323  {
324  return this->field(tag);
325  }
326 
327  /// Returns a field by its tag.
328  ///
329  /// If the message contains a field
330  /// with the requested tag, then the
331  /// returned instance of the Field class
332  /// refers to a valid data and thus further
333  /// manipulations with its value are possible.
334  /// Otherwise, the returned instance refers
335  /// to nothing.
336  Field field(Tag tag) const
337  {
338  assert(NULL != accessor_);
339 
340  return accessor_->field(binary_, tag);
341  }
342 
343  /// Accesses a repeating group by its tag.
344  ///
345  /// Returns a null instance if the requested
346  /// group is not available in the given message.
347  Group group(Tag tag) const
348  {
349  assert(NULL != accessor_);
350 
351  return accessor_->group(binary_, tag);
352  }
353 
354  /// Builds the FIX (tag=value) representation.
355  void
357  std::string& str) const
358  {
359  assert(NULL != accessor_);
360 
361  accessor_->toFix(str, binary_);
362  }
363 
364  /// Re-initializes as the copy of the other instance.
365  Message&
366  operator =(
367  const Message& other)
368  {
369  binary_ = other.binary_;
370  accessor_ = other.accessor_;
371 
372  return *this;
373  }
374 };
375 
376 /// Serializes FIX message into tag=value format.
377 inline
378 void
380  std::string& str,
381  const Message& message)
382 {
383  message.toFix(str);
384 }
385 
386 /// Serializes FIX message into tag=value format.
387 inline
388 std::string
390  const Message& message)
391 {
392  std::string str;
393 
394  toStr(str, message);
395 
396  return str;
397 }
398 
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
Group(const GroupEntriesSource &binary, const GroupEntryAccessor &accessor)
Initializes the instance over the binary data.
Definition: Message.h:163
virtual StrRef type() const =0
FIX message type.
virtual Field field(const BinaryMessage &, Tag) const =0
Returns field value by its tag.
#define ONIXS_CMEMDHFIX_NAMESPACE_BEGIN
Definition: Bootstrap.h:160
Field field(Tag tag) const
Definition: Message.h:336
void toFix(std::string &str) const
Builds the FIX (tag=value) representation.
Definition: Message.h:356
StrRef type() const
FIX message type.
Definition: Message.h:306
void toFix(std::string &str, AggressorFlag::Enum value)
Serializes object into FIX presentation.
Definition: Serialization.h:55
Group(const Group &other)
Initializes as the copy of the other instance.
Definition: Message.h:185
Message(const BinaryMessage &binary, const MessageAccessor &accessor)
Initializes the instance from the SBE-encoded message.
Definition: Message.h:275
UInt16 MessageSize
Aliases message length type.
#define ONIXS_CMEMDHFIX_NAMESPACE_END
Definition: Bootstrap.h:164
GroupEntriesSource::Size Size
Number of repeating group entries.
Definition: Message.h:175
virtual Group group(const BinaryMessage &, Tag) const =0
Accesses a repeating group by its tag.
Message(const Message &other)
Initializes as the copy of the other instance.
Definition: Message.h:292
Encapsulates services for manipulating SBE-encoded messages.
std::string toStr(const Message &message)
Serializes FIX message into tag=value format.
Definition: Message.h:389
#define ONIXS_CMEMDH_LTWT_CLASS_DECL(name)
Definition: Bootstrap.h:106
virtual Field field(const GroupEntrySource &, Tag) const =0
UInt32 Tag
Definition: Tag.h:29
Group group(Tag tag) const
Definition: Message.h:347
virtual void toFix(std::string &, const BinaryMessage &) const =0
BinaryGroupEntries< GroupEntrySource, MessageSize, MessageSize, MessageSize > GroupEntriesSource
Definition: Message.h:152
Size size() const
Returns number of blocks.
#define ONIXS_CMEMDH_EXPORTED_STRUCT
Definition: Bootstrap.h:58
BinaryGroupEntry< MessageSize > GroupEntrySource
Definition: Message.h:47
Encapsulates operations over SBE-encoded repeating group entries.