OnixS C++ CME MDP Premium Market Data Handler 5.10.2
Users' manual and API documentation
Loading...
Searching...
No Matches
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 <OnixS/CME/MDH/ABI.h>
25
26#include <new>
27
29
32{
33 enum
34 {
40 Capacity = 16
41 };
42
43 Byte bytes_[Capacity];
44
47 void* place() noexcept
48 {
49 return static_cast<void*>(bytes_);
50 }
51
54 const void* place() const noexcept
55 {
56 return static_cast<const void*>(bytes_);
57 }
58
59public:
61 ValueContainer() = default;
62
64 template <typename Value>
65 ONIXS_CMEMDH_NODISCARD Value& get() noexcept
66 {
67 static_assert(
68 (sizeof(Value) <= static_cast<size_t>(Capacity)),
69 "Capacity is not sufficient for storing values of the given type."
70 );
71
72 return *static_cast<Value*>(place());
73 }
74
76 template <typename Value>
77 ONIXS_CMEMDH_NODISCARD const Value& get() const noexcept
78 {
79 static_assert(
80 (sizeof(Value) <= static_cast<size_t>(Capacity)),
81 "Capacity of the storage is not sufficient to store values of the specified type."
82 );
83
84 return *static_cast<const Value*>(place());
85 }
86
88 template <class Value>
89 ValueContainer& assign(const Value& value) noexcept
90 {
91 static_assert(
92 (sizeof(Value) <= static_cast<size_t>(Capacity)),
93 "Capacity of the storage is not sufficient to store values of the specified type."
94 );
95
96 static_assert(std::is_nothrow_copy_constructible<Value>::value, "must be noexcept");
97
98 new (place()) Value(value);
99
100 return *this;
101 }
102};
103
#define ONIXS_CMEMDH_MESSAGING_TAGBASED_NAMESPACE_BEGIN
Definition Bootstrap.h:60
#define ONIXS_CMEMDH_MESSAGING_TAGBASED_NAMESPACE_END
Definition Bootstrap.h:61
#define ONIXS_CMEMDH_NODISCARD
Definition Compiler.h:150
ValueContainer()=default
Initializes the container.
ValueContainer & assign(const Value &value) noexcept
Stores the given value.
bool value(Number &number, const MultiContainer &container, Tag tag)
UInt8 Byte
Alias for Byte.
Definition Memory.h:34