OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.0.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  inline
63  const char*
64  duplicate(
65  AccumulatingAllocator& allocator,
66  const char* buffer,
67  size_t bufferSize)
68  {
69  return CORE::clone(
70  allocator,
71  OnixS::ConstStringRef(buffer, bufferSize)).
72  chars();
73  }
74 }
75 
76 inline
77 void
78 Message::construct()
79 {
80  allocator_ = constructAllocator(allocatorImpl_);
81  message_ = new (impl_) CORE::Message(*allocator_);
82 }
83 
84 inline
85 void
86 Message::destruct()
87 {
88  destructAllocator(allocator_);
89 }
90 
91 Message::Message(const void* impl)
92  : FieldSet(this, impl_)
93  , allocator_(NULL)
94  , message_(NULL)
95 {
97  sizeof(impl_) ==
98  (sizeof(CORE::Message) + sizeof(size_t) - 1) / sizeof(size_t) * sizeof(size_t)
99  );
100 
102  sizeof(allocatorImpl_) ==
103  (sizeof(CORE::Allocator) + sizeof(size_t) - 1) / sizeof(size_t) * sizeof(size_t));
104 
105 
106  allocator_ = constructAllocator(allocatorImpl_);
107 
108  message_ = new (impl_) CORE::Message(
109  *static_cast<const CORE::Message*>(impl), CORE::CopyStrategy::Deep
110  );
111 }
112 
114 {
115  destruct();
116 }
117 
119  : FieldSet(this, impl_)
120  , allocator_(NULL)
121  , message_(NULL)
122 {
123  construct();
124 
126 
127  CORE::Message::deepCopy(
128  MessageOperator::getCore(*this),
129  MessageOperator::getCore(other));
130 
132 }
133 
134 bool
135 Message::operator ==(const Message& other) const
136 {
137  const bool thisIsConstructed = static_cast<bool>(*this);
138  const bool otherIsConstructed = static_cast<bool>(other);
139 
140  if (thisIsConstructed && otherIsConstructed)
141  {
142  return CORE::Extras::SerialEqual()(
143  MessageOperator::getCore(*this),
144  MessageOperator::getCore(other));
145  }
146 
147  return !thisIsConstructed && !otherIsConstructed;
148 }
149 
150 bool
151 Message::operator !=(const Message& other) const
152 {
153  return !(*this == other);
154 }
155 
156 Message&
158  const Message& other)
159 {
161 
162  if (this != &other)
163 {
164  CORE::Message& impl =
166 
167  impl.allocator().reset();
168 
169  CORE::Message::deepCopy(
170  impl,
171  MessageOperator::getCore(other));
172  }
173 
174  return *this;
175 
177 }
178 
179 // Field/info access.
180 
183 {
184  return MessageOperator::
186  *this,
187  Tags::MsgType);
188 }
189 
192 {
193  CORE::SeqNumber seqNumber;
194 
195  if (MessageOperator::getCore(*this)
196  [Tags::MsgSeqNum].convertTo(seqNumber))
197  {
198  return seqNumber;
199  }
200 
201  return 0;
202 }
203 
206 {
207  return get(Tags::SenderCompID);
208 }
209 
210 // Serialization.
211 
212 void
214  std::string& str,
215  char delimiter,
216  MessageStringingFlags flags) const
217 {
218  const CORE::Message& message =
220 
221  if (message)
222  {
223  const
224  CORE::Extras::Stringing::FieldDelimiter
225  fieldDelimiterPresenter(delimiter);
226 
227  switch (flags)
228  {
230  {
231  CORE::Extras::toString(
232  message,
233  CORE::Extras::Stringing::ValuePresenter(),
234  fieldDelimiterPresenter,
235  str);
236  }
237  break;
238 
240  {
241  CORE::Extras::toString(
242  message,
243  CORE::Extras::Stringing::TagValuePresenter(),
244  fieldDelimiterPresenter,
245  str);
246  }
247  break;
248 
250  {
251  CORE::Extras::toString(
252  message,
253  CORE::Extras::Stringing::NamedFieldPresenter(
254  message.dictionary().fields()),
255  fieldDelimiterPresenter,
256  str);
257  }
258  break;
259 
262  {
263  CORE::Extras::toString(
264  message,
265  CORE::Extras::Stringing::EnhancedNamedFieldPresenter(
266  message.dictionary().fields()),
267  fieldDelimiterPresenter,
268  str);
269  }
270  break;
271  }
272  }
273 }
274 
275 std::ostream&
277  std::ostream& os,
278  const Message& message)
279 {
280  OnixS::
281  PreallocatedCharArray<512>
282  serialMessage;
283 
284  CORE::serialize(
285  MessageOperator::getCore(message),
286  serialMessage);
287 
288  os.write(
289  serialMessage.chars(),
290  serialMessage.size());
291 
292  return os;
293 }
294 
295 }}}
unsigned int SequenceNumber
Alias for sequence numbers.
FieldValueRef type() const
Returns the message type (MsgType(35) field value).
Definition: Message.cpp:182
SequenceNumber seqNum() const
Definition: Message.cpp:191
#define END_TRASLATE_EXCEPTION_WITH_ROLLBACK(action)
Definition: Message.cpp:35
BOOST_STATIC_ASSERT(sizeof(HeartbeatMsgData)==16)
update side from pdf to ensure no differences with EOBILayouts.h
unsigned MessageStringingFlags
Collection of message stringing flags.
STL namespace.
bool operator==(const Message &) const
Definition: Message.cpp:135
#define END_TRANSLATE_EXCEPTION
Definition: Message.cpp:30
FieldValueRef senderCompId() const
Definition: Message.cpp:205
Definition: Group.h:25
bool operator!=(const Message &) const
Definition: Message.cpp:151
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:118
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:157
static FieldValueRef constructField(const FieldSet &fieldSet, Tag tag)