OnixS C++ SGX Titan OUCH Trading Handler  1.2.0
API documentation
MutableBinaryMessage.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 
25 
27 
28 
29 /// Exposes base services to access fields stored in
30 /// little Endian block of memory. Class represents an
31 /// abstraction, instance construction available through
32 /// descendants implementing actual access to encoded data.
33 template <template<class> class Block, class FieldAccessor>
34 class MutableBinaryFields : public BinaryFields<Block, FieldAccessor>
35 {
36  typedef MessageSize BlockSize;
37 
38  /// Instance of block providing
39  /// actual access to encoded data.
40  Block<FieldAccessor>& block()
41  ONIXS_SGX_OUCH_NOTHROW
42  {
43  return *static_cast<Block<FieldAccessor>*>(this);
44  }
45 
46 protected:
47  /// Assigns value of a field by its offset.
48  template<class FieldValue>
49  void setOrdinary(BlockSize offset, FieldValue value)
50  ONIXS_SGX_OUCH_NOTHROW
51  {
52  assert(block().binarySize() >= (offset + sizeof(FieldValue)));
53 
54  void* const fieldPos = advanceByBytes(block().binary(), offset);
55 
56  FieldAccessor::set(fieldPos, value);
57  }
58 
59  /// Assigns value of a field by its offset.
60  template <class FieldValue>
61  void setOrdinaryRef(BlockSize offset, FieldValue value)
62  ONIXS_SGX_OUCH_NOTHROW
63  {
64  assert(block().binarySize() >= (offset + sizeof(FieldValue)));
65  assert(sizeof(FieldValue) == 1);
66 
67  *static_cast <FieldValue*>(advanceByBytes(block().binary(), offset)) = value;
68  }
69 
70  /// Returns value of a field by its offset.
71  template<class Enumeration>
72  void setEnumeration(BlockSize offset, typename Enumeration::Enum value)
73  ONIXS_SGX_OUCH_NOTHROW
74  {
75  typedef typename Enumeration::Base Base;
76  setOrdinaryRef<Base>(offset, static_cast<Base>(value));
77  }
78 
79  template<BlockSize Size>
80  void setFixedStr(BlockSize offset, const StrRef& value)
81  ONIXS_SGX_OUCH_NOTHROW
82  {
83  assert(block().binarySize() >= (offset + Size));
84 
85  void* const fieldPos = advanceByBytes(block().binary(), offset);
86 
87  const BlockSize size = std::min(Size, static_cast<BlockSize>(value.size()));
88 
89  memcpy(fieldPos, value.items(), size);
90  memset(advanceByBytes(fieldPos, size), ' ', Size - size);
91  }
92 };
93 
94 /// Encapsulates services for manipulating little endian encoded messages.
95 template <typename Accessor>
97  : public MutableBinaryFields<MutableBinaryMessage, Accessor>
98 {
99  void* data_;
100  MessageSize size_;
101 
102 public:
103  /// Length of message binary data.
105 
106  typedef Accessor FieldAccessor;
107 
108  /// Message content.
109  const void* binary() const
110  ONIXS_SGX_OUCH_NOTHROW
111  {
112  return data_;
113  }
114 
115  void* binary()
116  ONIXS_SGX_OUCH_NOTHROW
117  {
118  return data_;
119  }
120 
121  /// Size of message.
123  ONIXS_SGX_OUCH_NOTHROW
124  {
125  return size_;
126  }
127 
128  /// Re-initializes instance as a copy of the other one.
130  operator =(
131  const MutableBinaryMessage& other)
132  ONIXS_SGX_OUCH_NOTHROW
133  {
134  data_ = other.data_;
135  size_ = other.size_;
136 
137  return *this;
138  }
139 
140 protected:
141  /// Initializes instance over given memory block.
143  void* data,
144  MessageSize size)
145  ONIXS_SGX_OUCH_NOTHROW
146  : data_(data)
147  , size_(size)
148  {
149  }
150 
151 #if defined(ONIXS_SGX_OUCH_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_SGX_OUCH_COMPILER_CXX_RVALUE_REFERENCES
152 
153 private:
155  {}
156 
158  {
159  return *this;
160  };
161 
162 #endif
163 };
164 
void setEnumeration(BlockSize offset, typename Enumeration::Enum value)
Returns value of a field by its offset.
MutableBinaryMessage(void *data, MessageSize size)
Initializes instance over given memory block.
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition: Memory.h:119
Binary2 MessageSize
Aliases message length type.
Definition: Defines.h:47
void setOrdinaryRef(BlockSize offset, FieldValue value)
Assigns value of a field by its offset.
MessageSize binarySize() const
Size of message.
MessageSize BinarySize
Length of message binary data.
Encapsulates services for manipulating little endian encoded messages.
Provides efficient way of accessing text-based FIX field values.
Definition: String.h:41
#define ONIXS_SGXTITAN_OUCH_NAMESPACE_END
Definition: Bootstrap.h:31
void setFixedStr(BlockSize offset, const StrRef &value)
#define ONIXS_SGXTITAN_OUCH_NAMESPACE_BEGIN
Definition: Bootstrap.h:27
void setOrdinary(BlockSize offset, FieldValue value)
Assigns value of a field by its offset.