OnixS C++ CME Market Data Handler  5.4.0
API documentation
ValueContainer.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 <new>
24 
25 #include <OnixS/CME/MDH/Memory.h>
27 
29 
30 /// Container for a value of any supported kinds.
33 {
34  enum
35  {
36  // Capacity of the storage for a value.
37  //
38  // The storage must be capacious enough
39  // to store all integer types, string refs,
40  // time-related typed and the Decimal.
41  Capacity = 16
42  };
43 
44  Byte bytes_[Capacity];
45 
46  // This is to make G++ happy with the
47  // concept of storing value in the array.
48  void* place()
49  {
50  return static_cast<void*>(bytes_);
51  }
52 
53  // This is to make G++ happy with the
54  // concept of storing value in the array.
55  const void* place() const
56  {
57  return static_cast<const void*>(bytes_);
58  }
59 
60 public:
61  /// Initializes the container.
63  {
64  }
65 
66  /// Provides access to the value stored
67  /// in the container assuming the value
68  /// is of the specified type.
69  template
70  <
71  typename Value
72  >
73  Value& get()
74  {
76  (
77  sizeof(Value) <= Capacity,
78  "Capacity isn't sufficient for "
79  "storing values of the given type. "
80  );
81 
82  return *
83  static_cast
84  <Value*>
85  (place());
86  }
87 
88  /// Provides access to the value stored
89  /// in the container assuming the value
90  /// is of the specified type.
91  template
92  <
93  typename Value
94  >
95  const Value& get() const
96  {
98  (
99  sizeof(Value) <= Capacity,
100  "Capacity of the storage isn't "
101  "sufficient to store values "
102  "of the specified type. "
103  );
104 
105  return *
106  static_cast
107  <const Value*>
108  (place());
109  }
110 
111  /// Stores the given value in the container.
112  template
113  <
114  class Value
115  >
118  const Value& value)
119  {
121  (
122  sizeof(Value) <= Capacity,
123  "Capacity of the storage isn't "
124  "sufficient to store values "
125  "of the specified type. "
126  );
127 
128  new (place()) Value(value);
129 
130  return *this;
131  }
132 };
133 
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
UInt8 Byte
Alias for Byte.
Definition: Memory.h:30
ValueContainer()
Initializes the container.
#define ONIXS_CMEMDHFIX_NAMESPACE_BEGIN
Definition: Bootstrap.h:160
bool value(Number &number, const MultiContainer &container, Tag tag)
#define ONIXS_CMEMDHFIX_NAMESPACE_END
Definition: Bootstrap.h:164
ValueContainer & assign(const Value &value)
Stores the given value in the container.
#define ONIXS_SASSERT_MSG(expression, message)
Definition: Assertion.h:34
Container for a value of any supported kinds.