OnixS C++ CME Market Data Handler  5.4.0
API documentation
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 
25 #include <OnixS/CME/MDH/Integral.h>
26 
28 
29 /// Alias for Byte.
30 typedef UInt8 Byte;
31 
32 /// Alias for Word.
33 typedef UInt16 Word;
34 
35 /// Alias for Double Word.
36 typedef UInt32 DWord;
37 
38 /// Alias for Quad Word.
39 typedef UInt64 QWord;
40 
41 //
42 
43 /// Makes pointer as opaque one.
44 template
45 <
46  typename Type
47 >
48 inline
49 void*
50 toOpaquePtr(Type* ptr)
51 {
52  return static_cast<void*>(ptr);
53 }
54 
55 /// Makes pointer as opaque one.
56 template
57 <
58  typename Type
59 >
60 inline
61 const void*
63  const Type* ptr)
64 {
65  return static_cast<const void*>(ptr);
66 }
67 
68 /// Reinterprets pointer to one
69 /// referencing to byte block.
70 template
71 <
72  typename Type
73 >
74 inline
75 Byte*
77  Type* ptr)
78 {
79  return
80  static_cast
81  <Byte*>
82  (toOpaquePtr(ptr));
83 }
84 
85 /// Reinterprets pointer to one
86 /// referencing to byte block.
87 template
88 <
89  typename Type
90 >
91 inline
92 const Byte*
94  const Type* ptr)
95 {
96  return
97  static_cast
98  <const Byte*>
99  (toOpaquePtr(ptr));
100 }
101 
102 /// Advances given pointer to a given offset (distance) in bytes.
103 template
104 <
105  typename Type
106 >
107 inline
108 Type*
110  Type* pointer,
111  ptrdiff_t distance)
112 {
113  return
114  reinterpret_cast<Type*>
115  (
116  toByteBlock(pointer) + distance
117  );
118 }
119 
120 /// Returns pointer which is lower than
121 /// given one to a given number of bytes.
122 template
123 <
124  typename Type
125 >
126 inline
127 Type*
129  Type* pointer,
130  ptrdiff_t distance)
131 {
132  return
133  reinterpret_cast<Type*>
134  (
135  toByteBlock(pointer) - distance
136  );
137 }
138 
139 /// Returns distance in bytes between two pointers.
140 template
141 <
142  typename Left,
143  typename Right
144 >
145 inline
146 ptrdiff_t
148  Left* left,
149  Right* right)
150 {
151  return (
152  toByteBlock(left) -
153  toByteBlock(right)
154  );
155 }
156 
UInt8 Byte
Alias for Byte.
Definition: Memory.h:30
UInt32 UInt32
uInt32.
Definition: Fields.h:247
UInt64 QWord
Alias for Quad Word.
Definition: Memory.h:39
UInt8 UInt8
uInt8.
Definition: Fields.h:255
UInt64 UInt64
uInt64.
Definition: Fields.h:251
UInt32 DWord
Alias for Double Word.
Definition: Memory.h:36
UInt16 Word
Alias for Word.
Definition: Memory.h:33
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:152
const Byte * toByteBlock(const Type *ptr)
Definition: Memory.h:93
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition: Memory.h:109
UInt16 UInt16
uInt16 optional.
Definition: Fields.h:243
Type * advanceBackByBytes(Type *pointer, ptrdiff_t distance)
Definition: Memory.h:128
const void * toOpaquePtr(const Type *ptr)
Makes pointer as opaque one.
Definition: Memory.h:62
ptrdiff_t byteDistance(Left *left, Right *right)
Returns distance in bytes between two pointers.
Definition: Memory.h:147
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:156