OnixS C++ CME MDP Premium Market Data Handler  5.8.7
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 <typename Type>
45 inline void* toOpaquePtr(Type* ptr)
46 {
47  return static_cast<void*>(ptr);
48 }
49 
50 /// Makes pointer as opaque one.
51 template <typename Type>
52 inline const void* toOpaquePtr(const Type* ptr)
53 {
54  return static_cast<const void*>(ptr);
55 }
56 
57 /// Reinterprets pointer to one
58 /// referencing to byte block.
59 template <typename Type>
60 inline Byte* toByteBlock(Type* ptr)
61 {
62  return static_cast<Byte*>(toOpaquePtr(ptr));
63 }
64 
65 /// Reinterprets pointer to one
66 /// referencing to byte block.
67 template <typename Type>
68 inline const Byte* toByteBlock(const Type* ptr)
69 {
70  return static_cast<const Byte*>(toOpaquePtr(ptr));
71 }
72 
73 /// Advances given pointer to a given offset (distance) in bytes.
74 template <typename Type>
75 inline Type* advanceByBytes(Type* pointer, ptrdiff_t distance)
76 {
77  return reinterpret_cast<Type*>(toByteBlock(pointer) + distance);
78 }
79 
80 /// Returns pointer which is lower than
81 /// given one to a given number of bytes.
82 template <typename Type>
83 inline Type* advanceBackByBytes(Type* pointer, ptrdiff_t distance)
84 {
85  return reinterpret_cast<Type*>(toByteBlock(pointer) - distance);
86 }
87 
88 /// Returns distance in bytes between two pointers.
89 template <typename Left, typename Right>
90 inline ptrdiff_t byteDistance(Left* left, Right* right)
91 {
92  return (toByteBlock(left) - toByteBlock(right));
93 }
94 
UInt8 Byte
Alias for Byte.
Definition: Memory.h:30
UInt32 UInt32
uInt32.
Definition: Fields.h:192
UInt64 QWord
Alias for Quad Word.
Definition: Memory.h:39
UInt8 UInt8
uInt8.
Definition: Fields.h:198
UInt64 UInt64
uInt64.
Definition: Fields.h:195
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:67
const Byte * toByteBlock(const Type *ptr)
Reinterprets pointer to one referencing to byte block.
Definition: Memory.h:68
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition: Memory.h:75
UInt16 UInt16
uInt16 optional.
Definition: Fields.h:189
Type * advanceBackByBytes(Type *pointer, ptrdiff_t distance)
Returns pointer which is lower than given one to a given number of bytes.
Definition: Memory.h:83
const void * toOpaquePtr(const Type *ptr)
Makes pointer as opaque one.
Definition: Memory.h:52
ptrdiff_t byteDistance(Left *left, Right *right)
Returns distance in bytes between two pointers.
Definition: Memory.h:90
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68