OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.4.3
API documentation
Message.cpp
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 protected by copyright law
4 // and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable ONIXS Software
7 // Services Agreement (the Agreement) and Customer end user license agreements granting
8 // a non-assignable, non-transferable and non-exclusive license to use the software
9 // for it's own data processing purposes under the terms defined in the Agreement.
10 //
11 // Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
12 // of this source code or associated reference material to any other location for further reproduction
13 // or redistribution, and any amendments to this copyright notice, are expressly prohibited.
14 //
15 // Any reproduction or redistribution for sale or hiring of the Software not in accordance with
16 // the terms of the Agreement is a violation of copyright law.
17 //
18 
19 #include <boost/static_assert.hpp>
20 
21 #include "MessageOperator.h"
22 
23 
24 namespace OnixS {
25 namespace Eurex {
26 namespace MarketData {
27 
28 
29 #define BEGIN_TRANSLATE_EXCEPTION
30 #define END_TRANSLATE_EXCEPTION
31 
32 #define BEGIN_TRASLATE_EXCEPTION_WITH_ROLLBACK \
33  try {
34 
35 #define END_TRASLATE_EXCEPTION_WITH_ROLLBACK(action) \
36 } catch (...) { action; throw; }
37 
38 
39 using namespace std;
40 using namespace OnixS::FIX;
41 
43 
44 namespace
45 {
46  inline
47  AccumulatingAllocator*
48  constructAllocator(void* buffer)
49  {
50  return new (buffer) AccumulatingAllocator();
51  }
52 
53  inline
54  void
55  destructAllocator(void* buffer)
56  {
57  reinterpret_cast
58  <AccumulatingAllocator*>(buffer)->
59  ~AccumulatingAllocator();
60  }
61 }
62 
63 inline
64 void
65 Message::construct()
66 {
67  allocator_ = constructAllocator(allocatorImpl_);
68  message_ = new (impl_) CORE::Message(*allocator_);
69 }
70 
71 inline
72 void
73 Message::destruct()
74 {
75  destructAllocator(allocator_);
76 }
77 
78 Message::Message(const void* impl)
79  : FieldSet(this, impl_)
80  , allocator_(nullptr)
81  , message_(nullptr)
82 {
84  sizeof(impl_) ==
85  (sizeof(CORE::Message) + sizeof(size_t) - 1) / sizeof(size_t) * sizeof(size_t)
86  );
87 
89  sizeof(allocatorImpl_) ==
90  (sizeof(CORE::Allocator) + sizeof(size_t) - 1) / sizeof(size_t) * sizeof(size_t));
91 
92 
93  allocator_ = constructAllocator(allocatorImpl_);
94 
95  message_ = new (impl_) CORE::Message(
96  *static_cast<const CORE::Message*>(impl), CORE::CopyStrategy::Deep
97  );
98 }
99 
101 {
102  destruct();
103 }
104 
106  : FieldSet(this, impl_)
107  , allocator_(nullptr)
108  , message_(nullptr)
109 {
110  construct();
111 
113 
114  CORE::Message::deepCopy(
115  MessageOperator::getCore(*this),
116  MessageOperator::getCore(other));
117 
119 }
120 
121 bool
122 Message::operator ==(const Message& other) const
123 {
124  const bool thisIsConstructed = static_cast<bool>(*this);
125  const bool otherIsConstructed = static_cast<bool>(other);
126 
127  if (thisIsConstructed && otherIsConstructed)
128  {
129  return CORE::Extras::SerialEqual()(
130  MessageOperator::getCore(*this),
131  MessageOperator::getCore(other));
132  }
133 
134  return !thisIsConstructed && !otherIsConstructed;
135 }
136 
137 bool
138 Message::operator !=(const Message& other) const
139 {
140  return !(*this == other);
141 }
142 
143 Message&
145  const Message& other)
146 {
148 
149  if (this != &other)
150 {
151  CORE::Message& impl =
153 
154  impl.allocator().reset();
155 
156  CORE::Message::deepCopy(
157  impl,
158  MessageOperator::getCore(other));
159  }
160 
161  return *this;
162 
164 }
165 
166 // Field/info access.
167 
170 {
171  return MessageOperator::
173  *this,
174  Tags::MsgType);
175 }
176 
179 {
180  CORE::SeqNumber seqNumber;
181 
182  if (MessageOperator::getCore(*this)
183  [Tags::MsgSeqNum].convertTo(seqNumber))
184  {
185  return seqNumber;
186  }
187 
188  return 0;
189 }
190 
193 {
194  return get(Tags::SenderCompID);
195 }
196 
197 // Serialization.
198 
199 void
201  std::string& str,
202  char delimiter,
203  MessageStringingFlags flags) const
204 {
205  const CORE::Message& message =
207 
208  if (message)
209  {
210  const
211  CORE::Extras::Stringing::FieldDelimiter
212  fieldDelimiterPresenter(delimiter);
213 
214  switch (flags)
215  {
217  {
218  CORE::Extras::toString(
219  message,
220  CORE::Extras::Stringing::ValuePresenter(),
221  fieldDelimiterPresenter,
222  str);
223  }
224  break;
225 
227  {
228  CORE::Extras::toString(
229  message,
230  CORE::Extras::Stringing::TagValuePresenter(),
231  fieldDelimiterPresenter,
232  str);
233  }
234  break;
235 
237  {
238  CORE::Extras::toString(
239  message,
240  CORE::Extras::Stringing::NamedFieldPresenter(
241  message.dictionary().fields()),
242  fieldDelimiterPresenter,
243  str);
244  }
245  break;
246 
249  {
250  CORE::Extras::toString(
251  message,
252  CORE::Extras::Stringing::EnhancedNamedFieldPresenter(
253  message.dictionary().fields()),
254  fieldDelimiterPresenter,
255  str);
256  }
257  break;
258  }
259  }
260 }
261 
262 std::ostream&
264  std::ostream& os,
265  const Message& message)
266 {
267  OnixS::
268  PreallocatedCharArray<512>
269  serialMessage;
270 
271  CORE::serialize(
272  MessageOperator::getCore(message),
273  serialMessage);
274 
275  os.write(
276  serialMessage.chars(),
277  serialMessage.size());
278 
279  return os;
280 }
281 
282 }}}
unsigned int SequenceNumber
Alias for sequence numbers.
FieldValueRef type() const
Returns the message type (MsgType(35) field value).
Definition: Message.cpp:169
SequenceNumber seqNum() const
Definition: Message.cpp:178
#define END_TRASLATE_EXCEPTION_WITH_ROLLBACK(action)
Definition: Message.cpp:35
unsigned MessageStringingFlags
Collection of message stringing flags.
STL namespace.
bool operator==(const Message &) const
Definition: Message.cpp:122
#define END_TRANSLATE_EXCEPTION
Definition: Message.cpp:30
FieldValueRef senderCompId() const
Definition: Message.cpp:192
BOOST_STATIC_ASSERT(MarketData::Implementation::PacketHeaderForEobi::TemplateIdValue==13005)
Definition: Defines.h:30
bool operator!=(const Message &) const
Definition: Message.cpp:138
Field tag numbers are included during serialization.
ONIXS_EUREX_EMDI_API std::ostream & operator<<(std::ostream &stream, const FeedEngineSettings &settings)
Message(const Message &other)
Definition: Message.cpp:105
static const OnixS::FIX::Core::Messaging::FieldValue & getCore(const FieldValueRef &value)
std::string toString(char delimiter=0x1, MessageStringingFlags flags=MessageStringingFlag::IncludeFieldTagNumber) const
Definition: Message.h:175
#define BEGIN_TRANSLATE_EXCEPTION
Definition: Message.cpp:29
#define BEGIN_TRASLATE_EXCEPTION_WITH_ROLLBACK
Definition: Message.cpp:32
Message & operator=(const Message &)
Definition: Message.cpp:144
static FieldValueRef constructField(const FieldSet &fieldSet, Tag tag)