OnixS C++ CBOE CFE Binary Order Entry (BOE) Handler 1.12.0
API documentation
Loading...
Searching...
No Matches
Memory.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 <cstddef>
24#include <cstring>
25
27
28namespace OnixS
29{
30 namespace CboeCFE
31 {
32 namespace Trading
33 {
34 namespace BOE
35 {
37 typedef UInt8 Byte;
38
40 typedef UInt16 Word;
41
43 typedef UInt32 DWord;
44
46 typedef UInt64 QWord;
47
50 template
51 <
52 typename Target,
53 typename Source
54 >
55 inline Target c_cast(Source src)
56 {
57 return (Target)src;
58 }
59
61 template
62 <
63 typename Type
64 >
65 inline
66 void*
67 toOpaquePtr(Type* ptr)
68 {
69 return static_cast<void*>(ptr);
70 }
71
73 template
74 <
75 typename Type
76 >
77 inline
78 const void*
80 const Type* ptr)
81 {
82 return static_cast<const void*>(ptr);
83 }
84
87 template
88 <
89 typename Type
90 >
91 inline
92 Byte*
94 Type* ptr)
95 {
96 return
97 static_cast
98 <Byte*>
99 (toOpaquePtr(ptr));
100 }
101
104 template
105 <
106 typename Type
107 >
108 inline
109 const Byte*
111 const Type* ptr)
112 {
113 return
114 static_cast
115 <const Byte*>
116 (toOpaquePtr(ptr));
117 }
118
120 template
121 <
122 typename Type
123 >
124 inline
125 Type*
127 Type* pointer,
128 ptrdiff_t distance)
129 {
130 return
131 reinterpret_cast<Type*>
132 (
133 toByteBlock(pointer) + distance
134 );
135 }
136
139 template
140 <
141 typename Type
142 >
143 inline
144 Type*
146 Type* pointer,
147 ptrdiff_t distance)
148 {
149 return
150 reinterpret_cast<Type*>
151 (
152 toByteBlock(pointer) - distance
153 );
154 }
155
157 template
158 <
159 typename Left,
160 typename Right
161 >
162 inline
163 ptrdiff_t
165 Left* left,
166 Right* right)
167 {
168 return (
169 toByteBlock(left) -
170 toByteBlock(right)
171 );
172 }
173
174 template
175 <
176 class FieldValue
177 >
178 inline
179 FieldValue
180 unalignedCopy(const void* p) ONIXS_BATS_BOE_NOTHROW
181 {
182 FieldValue value;
183 memcpy(&value, p, sizeof(FieldValue));
184 return value;
185 }
186 }
187 }
188 }
189}
void * toOpaquePtr(Type *ptr)
Makes pointer as opaque one.
Definition Memory.h:67
ptrdiff_t byteDistance(Left *left, Right *right)
Returns distance in bytes between two pointers.
Definition Memory.h:164
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition Memory.h:126
Type * advanceBackByBytes(Type *pointer, ptrdiff_t distance)
Definition Memory.h:145
UInt16 Word
Alias for Word.
Definition Memory.h:40
UInt64 QWord
Alias for Quad Word.
Definition Memory.h:46
FieldValue unalignedCopy(const void *p) ONIXS_BATS_BOE_NOTHROW
Definition Memory.h:180
UInt32 DWord
Alias for Double Word.
Definition Memory.h:43
Byte * toByteBlock(Type *ptr)
Definition Memory.h:93
Target c_cast(Source src)
Definition Memory.h:55
UInt8 Byte
Alias for Byte.
Definition Memory.h:37