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