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