OnixS C++ CME MDP Premium Market Data Handler  5.8.3
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.
32 {
33  enum
34  {
35  // Capacity of the storage for a value.
36  //
37  // The storage must be capacious enough
38  // to store all integer types, string refs,
39  // time-related typed and the Decimal.
40  Capacity = 16
41  };
42 
43  Byte bytes_[Capacity];
44 
45  // This is to make G++ happy with the
46  // concept of storing value in the array.
47  void* place()
48  {
49  return static_cast<void*>(bytes_);
50  }
51 
52  // This is to make G++ happy with the
53  // concept of storing value in the array.
54  const void* place() const
55  {
56  return static_cast<const void*>(bytes_);
57  }
58 
59 public:
60  /// Initializes the container.
62 
63  /// Provides access to the value stored
64  /// in the container assuming the value
65  /// is of the specified type.
66  template <typename Value>
67  Value& get()
68  {
70  sizeof(Value) <= Capacity,
71  "Capacity isn't sufficient for "
72  "storing values of the given type. "
73  );
74 
75  return *static_cast<Value*>(place());
76  }
77 
78  /// Provides access to the value stored
79  /// in the container assuming the value
80  /// is of the specified type.
81  template <typename Value>
82  const Value& get() const
83  {
85  sizeof(Value) <= Capacity,
86  "Capacity of the storage isn't "
87  "sufficient to store values "
88  "of the specified type. "
89  );
90 
91  return *static_cast<const Value*>(place());
92  }
93 
94  /// Stores the given value in the container.
95  template <class Value>
96  ValueContainer& assign(const Value& value)
97  {
99  sizeof(Value) <= Capacity,
100  "Capacity of the storage isn't "
101  "sufficient to store values "
102  "of the specified type. "
103  );
104 
105  new (place()) Value(value);
106 
107  return *this;
108  }
109 };
110 
UInt8 Byte
Alias for Byte.
Definition: Memory.h:30
ValueContainer()
Initializes the container.
#define ONIXS_CMEMDHFIX_NAMESPACE_BEGIN
Definition: Bootstrap.h:70
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
bool value(Number &number, const MultiContainer &container, Tag tag)
Finds a tag-value entry in the given collection by the given tag and returns its value component tran...
#define ONIXS_CMEMDHFIX_NAMESPACE_END
Definition: Bootstrap.h:71
ValueContainer & assign(const Value &value)
Stores the given value in the container.
#define ONIXS_SASSERT_MSG(expression, message)
Definition: Assertion.h:36
Container for a value of any supported kinds.