OnixS C++ CME MDP Streamlined Market Data Handler  1.2.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 
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 /// Casts data of source type to the data
44 /// of target type using C casting rules.
45 template
46 <
47  typename Target,
48  typename Source
49 >
50 inline Target c_cast(Source src)
51 {
52  return (Target)src;
53 }
54 
55 /// Makes pointer as opaque one.
56 template
57 <
58  typename Type
59 >
60 inline
61 void*
62 toOpaquePtr(Type* ptr)
63 {
64  return static_cast<void*>(ptr);
65 }
66 
67 /// Makes pointer as opaque one.
68 template
69 <
70  typename Type
71 >
72 inline
73 const void*
75  const Type* ptr)
76 {
77  return static_cast<const void*>(ptr);
78 }
79 
80 /// Reinterprets pointer to one
81 /// referencing to byte block.
82 template
83 <
84  typename Type
85 >
86 inline
87 Byte*
89  Type* ptr)
90 {
91  return
92  static_cast
93  <Byte*>
94  (toOpaquePtr(ptr));
95 }
96 
97 /// Reinterprets pointer to one
98 /// referencing to byte block.
99 template
100 <
101  typename Type
102 >
103 inline
104 const Byte*
106  const Type* ptr)
107 {
108  return
109  static_cast
110  <const Byte*>
111  (toOpaquePtr(ptr));
112 }
113 
114 /// Advances given pointer to a given offset (distance) in bytes.
115 template
116 <
117  typename Type
118 >
119 inline
120 Type*
122  Type* pointer,
123  ptrdiff_t distance)
124 {
125  return
126  reinterpret_cast<Type*>
127  (
128  toByteBlock(pointer) + distance
129  );
130 }
131 
132 /// Returns pointer which is lower than
133 /// given one to a given number of bytes.
134 template
135 <
136  typename Type
137 >
138 inline
139 Type*
141  Type* pointer,
142  ptrdiff_t distance)
143 {
144  return
145  reinterpret_cast<Type*>
146  (
147  toByteBlock(pointer) - distance
148  );
149 }
150 
151 /// Returns distance in bytes between two pointers.
152 template
153 <
154  typename Left,
155  typename Right
156 >
157 inline
158 ptrdiff_t
160  Left* left,
161  Right* right)
162 {
163  return (
164  toByteBlock(left) -
165  toByteBlock(right)
166  );
167 }
168 
UInt64 UInt64
uInt64.
Definition: Fields.h:187
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition: Memory.h:121
Target c_cast(Source src)
Casts data of source type to the data of target type using C casting rules.
Definition: Memory.h:50
const void * toOpaquePtr(const Type *ptr)
Makes pointer as opaque one.
Definition: Memory.h:74
UInt16 UInt16
uInt16.
Definition: Fields.h:179
UInt8 Byte
Alias for Byte.
Definition: Memory.h:30
Type * advanceBackByBytes(Type *pointer, ptrdiff_t distance)
Returns pointer which is lower than given one to a given number of bytes.
Definition: Memory.h:140
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_END
Definition: Bootstrap.h:173
const Byte * toByteBlock(const Type *ptr)
Reinterprets pointer to one referencing to byte block.
Definition: Memory.h:105
UInt16 Word
Alias for Word.
Definition: Memory.h:33
UInt64 QWord
Alias for Quad Word.
Definition: Memory.h:39
ptrdiff_t byteDistance(Left *left, Right *right)
Returns distance in bytes between two pointers.
Definition: Memory.h:159
UInt32 DWord
Alias for Double Word.
Definition: Memory.h:36
UInt32 UInt32
uInt32.
Definition: Fields.h:183
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:169