OnixS C++ EuroTLX GTP Market Data Handler  1.4.0
API documentation
BinaryMessage.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 <cassert>
24 
25 #include <OnixS/EuroTLX/MarketData/GTP/Export.h>
30 
31 
32 namespace OnixS
33 {
34  namespace EuroTLX
35  {
36  namespace MarketData
37  {
38  namespace GTP
39  {
40 
41  /// Exposes base services to access fields stored in
42  /// little Endian block of memory. Class represents an
43  /// abstraction, instance construction available through
44  /// descendants implementing actual access to encoded data.
45  template <class Block, class BlockSize>
47  {
48  /// Instance of block providing
49  /// actual access to encoded data.
50  const Block& block() const
52  {
53  return *static_cast<const Block*>(this);
54  }
55 
56  protected:
57  /// Returns value of a field by its offset.
58  template <class FieldValue>
59  FieldValue ordinary(BlockSize offset) const
61  {
62  assert(block().binarySize() >= (offset + sizeof(FieldValue)));
63 
64  return
65  unalignedCopy<FieldValue>(advanceByBytes(block().binary(), offset));
66  }
67 
68  /// Returns value of a field by its offset.
69  template <class FieldValue>
70  const FieldValue& ordinaryRef(BlockSize offset) const
72  {
73  assert(block().binarySize() >= (offset + sizeof(FieldValue)));
74 
75  return
76  *static_cast <const FieldValue*>(advanceByBytes(block().binary(), offset));
77  }
78 
79  /// Returns value of a field by its offset.
80  ///
81  /// Given function serves as specialization of
82  /// general case for fields of enumeration type.
83  template <class Enumeration>
84  typename Enumeration::Enum enumeration(BlockSize offset) const
86  {
87  typedef typename Enumeration::Base Base;
88 
89  typedef typename Enumeration::Enum Enum;
90 
91  return static_cast<Enum>(ordinary<Base>(offset));
92  }
93 
94  /// Provides access to string field by its offset.
95  ///
96  /// Given function serves as specialization
97  /// of general case for fields of string type.
98  template <BlockSize Size>
99  StrRef fixedStr(BlockSize offset) const
101  {
102  typedef Char Str[Size];
103 
104  return StrRef(ordinaryRef<Str>(offset), strnlen(ordinaryRef<Str>(offset), Size));
105  }
106  };
107 
108  /// Encapsulates services for manipulating little endian encoded messages.
109  class ONIXS_EUROTLX_GTP_API BinaryMessage : public BinaryFields<BinaryMessage, MessageSize>
110  {
111  const void* data_;
112  MessageSize size_;
113 
114  public:
115  /// Length of message binary data.
117 
118  /// Initializes blank instance referencing to nothing.
121  : data_(ONIXS_EUROTLX_GTP_NULLPTR)
122  , size_(0)
123  {
124  }
125 
126  /// Initializes instance over given memory block.
128  const void* data,
129  MessageSize size)
131  : data_(data)
132  , size_(size)
133  {
134  }
135 
136  /// Initializes instance as copy of the other one.
138  const BinaryMessage& other)
140  : data_(other.data_)
141  , size_(other.size_)
142  {
143  }
144 
145  /// Indicates whether instance refers to a valid message.
147  operator bool() const
149  {
150  return (ONIXS_EUROTLX_GTP_NULLPTR != data_);
151  }
152 
153  /// Message content.
154  const void* binary() const
156  {
157  return data_;
158  }
159 
160  /// Size of message.
163  {
164  return size_;
165  }
166 
167  /// Re-initializes instance as a copy of the other one.
169  operator =(
170  const BinaryMessage& other)
172  {
173  if (this == &other)
174  return *this;
175 
176  data_ = other.data_;
177  size_ = other.size_;
178 
179  return *this;
180  }
181 
182 #if defined(ONIXS_EUROTLX_GTP_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_EUROTLX_GTP_COMPILER_CXX_RVALUE_REFERENCES
183 
186  : data_(std::move(other.data_))
187  , size_(std::move(other.size_))
188  {
189  }
190 
192  operator=(
193  BinaryMessage&& other)
195  {
196  if (this == &other)
197  return *this;
198 
199  data_ = std::move(other.data_);
200  size_ = std::move(other.size_);
201 
202  return *this;
203  }
204 #endif
205 
206  };
207 
208  ONIXS_EUROTLX_GTP_API
209  void throwIncorrectSize(const std::string& messageName, MessageSize receivedSize, MessageSize expectedSize);
210 
211  }
212  }
213  }
214 }
#define ONIXS_EUROTLX_GTP_EXPLICIT
Definition: Compiler.h:33
BinaryMessage() ONIXS_EUROTLX_GTP_NOTHROW
Initializes blank instance referencing to nothing.
#define ONIXS_EUROTLX_GTP_NOTHROW
Definition: Compiler.h:27
MessageSize binarySize() const ONIXS_EUROTLX_GTP_NOTHROW
Size of message.
const void * binary() const ONIXS_EUROTLX_GTP_NOTHROW
Message content.
UInt16 MessageSize
Aliases message length type.
Definition: Defines.h:141
ONIXS_EUROTLX_GTP_API void throwIncorrectSize(const std::string &messageName, MessageSize receivedSize, MessageSize expectedSize)
FixedPointDecimal< UInt64, IntegralConstant< Int8,-8 > > Size
Little-Endian encoded 64 bit unsigned integer with eight implied decimal places.
Definition: Defines.h:111
char Char
Character type alias.
Definition: String.h:42
FieldValue ordinary(BlockSize offset) const ONIXS_EUROTLX_GTP_NOTHROW
Returns value of a field by its offset.
Definition: BinaryMessage.h:59
const FieldValue & ordinaryRef(BlockSize offset) const ONIXS_EUROTLX_GTP_NOTHROW
Returns value of a field by its offset.
Definition: BinaryMessage.h:70
BinaryMessage(const BinaryMessage &other) ONIXS_EUROTLX_GTP_NOTHROW
Initializes instance as copy of the other one.
StrRef fixedStr(BlockSize offset) const ONIXS_EUROTLX_GTP_NOTHROW
Definition: BinaryMessage.h:99
Enumeration::Enum enumeration(BlockSize offset) const ONIXS_EUROTLX_GTP_NOTHROW
Definition: BinaryMessage.h:84
Encapsulates services for manipulating little endian encoded messages.
Provides efficient way of accessing text-based FIX field values.
Definition: String.h:45
MessageSize BinarySize
Length of message binary data.
BinaryMessage(const void *data, MessageSize size) ONIXS_EUROTLX_GTP_NOTHROW
Initializes instance over given memory block.
Type * advanceByBytes(Type *pointer, ptrdiff_t distance) ONIXS_EUROTLX_GTP_NOTHROW
Advances given pointer to a given offset (distance) in bytes.
Definition: Memory.h:109