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