OnixS C++ CME MDP Premium Market Data Handler  5.8.9
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 
46 
47 /// Provides FIX-like access to the fields
48 /// stored in a SBE-encoded repeating group.
50 {
51  /// Provides FIX-like access to the fields
52  /// stored in a SBE-encoded repeating group.
53  virtual Field field(const GroupEntrySource&, Tag) const = 0;
54 };
55 
56 /// Provides FIX-like access to the fields
57 /// stored in a SBE-encoded repeating group.
59 {
60  GroupEntrySource binary_;
61  const GroupEntryAccessor* accessor_;
62 
63 protected:
65 
66  /// Full-initialized instances are
67  /// constructed through descendants.
68  GroupEntry(const GroupEntrySource& binary, const GroupEntryAccessor& accessor)
69  : binary_(binary)
70  , accessor_(&accessor)
71  {
72  }
73 
74 public:
75  /// Initializes the instance which refers to
76  /// nothing and thus represents a null instance.
78  : binary_()
79  , accessor_(ONIXS_CMEMDH_NULLPTR)
80  {
81  }
82 
83  /// Initializes the instance as
84  /// the copy of the other one.
85  GroupEntry(const GroupEntry& other)
86  : binary_(other.binary_)
87  , accessor_(other.accessor_)
88  {
89  }
90 
91  /// Indicates whether the instance refers
92  /// to a valid repeating group entry.
93  operator bool() const
94  {
95  return (ONIXS_CMEMDH_NULLPTR != accessor_);
96  }
97 
98  /// Returns field by its tag.
99  ///
100  /// The instance must refer to a valid group entry.
101  Field operator[](Tag tag) const
102  {
103  return this->field(tag);
104  }
105 
106  /// Returns field by its tag.
107  ///
108  /// The instance must refer to a valid group entry.
110  {
111  assert(ONIXS_CMEMDH_NULLPTR != accessor_);
112 
113  return accessor_->field(binary_, tag);
114  }
115 
116  /// Re-initializes as the
117  /// copy of the other instance.
119  {
120  binary_ = other.binary_;
121  accessor_ = other.accessor_;
122 
123  return *this;
124  }
125 };
126 
128 
129 /// Implements a FIX repeating group
130 /// over the SBE-encoded binary data.
132 {
133  GroupEntriesSource binary_;
134  const GroupEntryAccessor* accessor_;
135 
136 protected:
137  /// Initializes the instance over the binary data.
138  Group(const GroupEntriesSource& binary, const GroupEntryAccessor& accessor)
139  : binary_(binary)
140  , accessor_(&accessor)
141  {
142  }
143 
144 public:
145  /// Number of repeating group entries.
147 
148  /// Initializes the instance which refers to
149  /// nothing and thus represent a null instance.
151  : accessor_(ONIXS_CMEMDH_NULLPTR)
152  {
153  }
154 
155  /// Initializes as the copy of the other instance.
156  Group(const Group& other)
157  : binary_(other.binary_)
158  , accessor_(other.accessor_)
159  {
160  }
161 
162  /// Indicates whether the instance
163  /// refers to a valid repeating group.
164  operator bool() const
165  {
166  return (ONIXS_CMEMDH_NULLPTR != accessor_);
167  }
168 
169  /// Number of entries in the repeating group
170  /// being referred by the given instance.
171  Size size() const
172  {
173  return binary_.size();
174  }
175 
176  /// Provides access to the group
177  /// entry by its index in the group.
178  GroupEntry operator[](Size index) const
179  {
180  assert(ONIXS_CMEMDH_NULLPTR != accessor_);
181 
182  return GroupEntry(binary_[index], *accessor_);
183  }
184 
185  /// Re-initializes as the copy of the other instance.
186  Group& operator=(const Group& other)
187  {
188  binary_ = other.binary_;
189  accessor_ = other.accessor_;
190 
191  return *this;
192  }
193 };
194 
195 /// Implements FIX-like services
196 /// for the SBE-encoded message.
198 {
199  /// FIX message type.
200  virtual StrRef type() const = 0;
201 
202  /// Returns field value by its tag.
203  virtual Field field(const BinaryMessage&, Tag) const = 0;
204 
205  /// Accesses a repeating group by its tag.
206  virtual Group group(const BinaryMessage&, Tag) const = 0;
207 
208  /// Serializes the given message into
209  /// the FIX (tag=value) presentation.
210  virtual void toFix(std::string&, const BinaryMessage&) const = 0;
211 };
212 
213 /// Implements FIX-like interface
214 /// over the SBE-encoded message.
216 {
217  BinaryMessage binary_;
218  const MessageAccessor* accessor_;
219 
220 protected:
221  /// Initializes the instance from the SBE-encoded message.
222  Message(const BinaryMessage& binary, const MessageAccessor& accessor)
223  : binary_(binary)
224  , accessor_(&accessor)
225  {
226  }
227 
228 public:
229  /// Initializes the message which refers
230  /// to nothing and thus being a null-instance.
232  : binary_()
233  , accessor_(ONIXS_CMEMDH_NULLPTR)
234  {
235  }
236 
237  /// Initializes as the copy of the other instance.
238  Message(const Message& other)
239  : binary_(other.binary_)
240  , accessor_(other.accessor_)
241  {
242  }
243 
244  /// Indicates whether the instance refers to a valid message.
245  operator bool() const
246  {
247  return (ONIXS_CMEMDH_NULLPTR != accessor_);
248  }
249 
250  /// FIX message type.
251  StrRef type() const
252  {
253  assert(ONIXS_CMEMDH_NULLPTR != accessor_);
254 
255  return accessor_->type();
256  }
257 
258  /// Returns a field by its tag.
259  ///
260  /// If the message contains a field
261  /// with the requested tag, then the
262  /// returned instance of the Field class
263  /// refers to a valid data and thus further
264  /// manipulations with its value are possible.
265  /// Otherwise, the returned instance refers
266  /// to nothing.
267  Field operator[](Tag tag) const
268  {
269  return this->field(tag);
270  }
271 
272  /// Returns a field by its tag.
273  ///
274  /// If the message contains a field
275  /// with the requested tag, then the
276  /// returned instance of the Field class
277  /// refers to a valid data and thus further
278  /// manipulations with its value are possible.
279  /// Otherwise, the returned instance refers
280  /// to nothing.
282  {
283  assert(ONIXS_CMEMDH_NULLPTR != accessor_);
284 
285  return accessor_->field(binary_, tag);
286  }
287 
288  /// Accesses a repeating group by its tag.
289  ///
290  /// Returns a null instance if the requested
291  /// group is not available in the given message.
292  Group group(Tag tag) const
293  {
294  assert(ONIXS_CMEMDH_NULLPTR != accessor_);
295 
296  return accessor_->group(binary_, tag);
297  }
298 
299  /// Builds the FIX (tag=value) representation.
300  void toFix(std::string& str) const
301  {
302  assert(ONIXS_CMEMDH_NULLPTR != accessor_);
303 
304  accessor_->toFix(str, binary_);
305  }
306 
307  /// Re-initializes as the copy of the other instance.
308  Message& operator=(const Message& other)
309  {
310  binary_ = other.binary_;
311  accessor_ = other.accessor_;
312 
313  return *this;
314  }
315 };
316 
317 /// Serializes FIX message into tag=value format.
318 inline void toStr(std::string& str, const Message& message)
319 {
320  message.toFix(str);
321 }
322 
323 /// Serializes FIX message into tag=value format.
324 inline std::string toStr(const Message& message)
325 {
326  std::string str;
327 
328  toStr(str, message);
329 
330  return str;
331 }
332 
Group(const GroupEntriesSource &binary, const GroupEntryAccessor &accessor)
Initializes the instance over the binary data.
Definition: Message.h:138
GroupEntry(const GroupEntrySource &binary, const GroupEntryAccessor &accessor)
Full-initialized instances are constructed through descendants.
Definition: Message.h:68
Field field(Tag tag) const override
Returns field by its tag.
Definition: Message.h:109
#define ONIXS_CMEMDH_OVERRIDE
Definition: Compiler.h:165
virtual Field field(const BinaryMessage &, Tag) const =0
Returns field value by its tag.
#define ONIXS_CMEMDH_NULLPTR
Definition: Compiler.h:167
#define ONIXS_CMEMDHFIX_NAMESPACE_BEGIN
Definition: Bootstrap.h:70
void toFix(std::string &str) const
Builds the FIX (tag=value) representation.
Definition: Message.h:300
Implements FIX-like services for the SBE-encoded message.
Definition: Message.h:197
StrRef type() const
FIX message type.
Definition: Message.h:251
virtual Group group(const BinaryMessage &, Tag) const =0
Accesses a repeating group by its tag.
void toFix(std::string &str, AggressorFlag::Enum value)
Serializes object into FIX presentation.
Definition: Serialization.h:46
GroupEntry()
Initializes the instance which refers to nothing and thus represents a null instance.
Definition: Message.h:77
Group & operator=(const Group &other)
Re-initializes as the copy of the other instance.
Definition: Message.h:186
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
GroupEntry operator[](Size index) const
Provides access to the group entry by its index in the group.
Definition: Message.h:178
virtual Field field(const GroupEntrySource &, Tag) const =0
Provides FIX-like access to the fields stored in a SBE-encoded repeating group.
Group(const Group &other)
Initializes as the copy of the other instance.
Definition: Message.h:156
Message(const BinaryMessage &binary, const MessageAccessor &accessor)
Initializes the instance from the SBE-encoded message.
Definition: Message.h:222
Field operator[](Tag tag) const
Returns field by its tag.
Definition: Message.h:101
#define ONIXS_CMEMDHFIX_NAMESPACE_END
Definition: Bootstrap.h:71
The abstraction of a source of FIX information which provides access to the FIX fields by their tags...
Definition: Message.h:35
virtual void toFix(std::string &, const BinaryMessage &) const =0
Serializes the given message into the FIX (tag=value) presentation.
Provides efficient way of accessing text-based values without copying content of the text being refer...
Definition: String.h:41
GroupEntriesSource::Size Size
Number of repeating group entries.
Definition: Message.h:146
Implements a FIX repeating group over the SBE-encoded binary data.
Definition: Message.h:131
Message(const Message &other)
Initializes as the copy of the other instance.
Definition: Message.h:238
Encapsulates services for manipulating SBE-encoded messages.
Provides FIX-like access to the fields stored in a SBE-encoded repeating group.
Definition: Message.h:58
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:160
std::string toStr(const Message &message)
Serializes FIX message into tag=value format.
Definition: Message.h:324
#define ONIXS_CMEMDH_LTWT_CLASS_DECL(name)
Definition: Bootstrap.h:48
Implements FIX-like interface over the SBE-encoded message.
Definition: Message.h:215
Field field(Tag tag) const override
Returns a field by its tag.
Definition: Message.h:281
UInt32 Tag
The type whose values are used to locate fields in the FIX-like messages.
Definition: Tag.h:29
Field operator[](Tag tag) const
Returns a field by its tag.
Definition: Message.h:267
GroupEntry(const GroupEntry &other)
Initializes the instance as the copy of the other one.
Definition: Message.h:85
Provides FIX-like access to the fields stored in a SBE-encoded repeating group.
Definition: Message.h:49
GroupEntry & operator=(const GroupEntry &other)
Re-initializes as the copy of the other instance.
Definition: Message.h:118
Message()
Initializes the message which refers to nothing and thus being a null-instance.
Definition: Message.h:231
Group group(Tag tag) const
Accesses a repeating group by its tag.
Definition: Message.h:292
Group()
Initializes the instance which refers to nothing and thus represent a null instance.
Definition: Message.h:150
Size size() const
Number of entries in the repeating group being referred by the given instance.
Definition: Message.h:171
BinaryGroupEntries< GroupEntrySource, MessageSize, MessageSize, MessageSize > GroupEntriesSource
Definition: Message.h:127
BinaryGroupEntry< MessageSize > GroupEntrySource
Definition: Message.h:45
Message & operator=(const Message &other)
Re-initializes as the copy of the other instance.
Definition: Message.h:308
Represents the field in the FIX message.
Definition: Field.h:32
virtual StrRef type() const =0
FIX message type.