OnixS C++ EuroTLX GTP Market Data Handler  1.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 #include <cstring>
25 
27 
28 namespace OnixS
29 {
30  namespace EuroTLX
31  {
32  namespace MarketData
33  {
34  namespace GTP
35  {
36  /// Alias for Byte.
37  typedef UInt8 Byte;
38 
39  /// Makes pointer as opaque one.
40  template
41  <
42  typename Type
43  >
44  inline
45  void*
46  toOpaquePtr(Type* ptr)
48  {
49  return static_cast<void*>(ptr);
50  }
51 
52  /// Makes pointer as opaque one.
53  template
54  <
55  typename Type
56  >
57  inline
58  const void*
60  const Type* ptr)
62  {
63  return static_cast<const void*>(ptr);
64  }
65 
66  /// Reinterprets pointer to one
67  /// referencing to byte block.
68  template
69  <
70  typename Type
71  >
72  inline
73  Byte*
75  Type* ptr)
77  {
78  return
79  static_cast
80  <Byte*>
81  (toOpaquePtr(ptr));
82  }
83 
84  /// Reinterprets pointer to one
85  /// referencing to byte block.
86  template
87  <
88  typename Type
89  >
90  inline
91  const Byte*
93  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)
113  {
114  return
115  reinterpret_cast<Type*>
116  (
117  toByteBlock(pointer) + distance
118  );
119  }
120 
121  /// Returns pointer which is lower than
122  /// given one to a given number of bytes.
123  template
124  <
125  typename Type
126  >
127  inline
128  Type*
130  Type* pointer,
131  ptrdiff_t distance)
133  {
134  return
135  reinterpret_cast<Type*>
136  (
137  toByteBlock(pointer) - distance
138  );
139  }
140 
141  /// Returns distance in bytes between two pointers.
142  template
143  <
144  typename Left,
145  typename Right
146  >
147  inline
148  ptrdiff_t
150  Left* left,
151  Right* right)
153  {
154  return (
155  toByteBlock(left) -
156  toByteBlock(right)
157  );
158  }
159 
160  template
161  <
162  class FieldValue
163  >
164  inline
165  FieldValue
166  unalignedCopy(const void* p)
168  {
169  FieldValue value;
170  memcpy(&value, p, sizeof(FieldValue));
171  return value;
172  }
173  }
174  }
175  }
176 }
Type * advanceBackByBytes(Type *pointer, ptrdiff_t distance) ONIXS_EUROTLX_GTP_NOTHROW
Definition: Memory.h:129
#define ONIXS_EUROTLX_GTP_NOTHROW
Definition: Compiler.h:27
ptrdiff_t byteDistance(Left *left, Right *right) ONIXS_EUROTLX_GTP_NOTHROW
Returns distance in bytes between two pointers.
Definition: Memory.h:149
FieldValue unalignedCopy(const void *p) ONIXS_EUROTLX_GTP_NOTHROW
Definition: Memory.h:166
UInt8 Byte
Alias for Byte.
Definition: Memory.h:37
Type * advanceByBytes(Type *pointer, ptrdiff_t distance) ONIXS_EUROTLX_GTP_NOTHROW
Advances given pointer to a given offset (distance) in bytes.
Definition: Memory.h:109
void * toOpaquePtr(Type *ptr) ONIXS_EUROTLX_GTP_NOTHROW
Makes pointer as opaque one.
Definition: Memory.h:46
Byte * toByteBlock(Type *ptr) ONIXS_EUROTLX_GTP_NOTHROW
Definition: Memory.h:74