OnixS C++ CME MDP Premium Market Data Handler 5.10.3
Users' manual and API documentation
Loading...
Searching...
No Matches
Future.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 <exception>
24#include <future>
25#include <type_traits>
26#include <utility>
27
28#include <OnixS/CME/MDH/ABI.h>
29
30namespace OnixS {
31
32namespace System {
33class FutureSharedState;
34}
35
36} // namespace OnixS
37
39
40namespace Implementation {
41
42class FutureHelper;
43
46{
47public:
51 bool valid() const noexcept
52 {
53 return state_ != nullptr;
54 }
55
61
66
71
76 ONIXS_CMEMDH_EXPORTED std::exception_ptr get_exception_ptr() const;
77
78 enum
79 {
81 };
82
94 ONIXS_CMEMDH_EXPORTED std::future_status wait(int timeoutInMs = InfiniteTimeout) const;
95
96protected:
97 FutureBase() noexcept = default;
98
100
101 ONIXS_CMEMDH_EXPORTED FutureBase& operator=(const FutureBase& other) noexcept;
102
104
105 ONIXS_CMEMDH_EXPORTED FutureBase& operator=(FutureBase&& other) noexcept;
106
108
110 ONIXS_CMEMDH_EXPORTED FutureBase(const System::FutureSharedState* state) noexcept;
111
113 ONIXS_CMEMDH_EXPORTED FutureBase(const System::FutureSharedState* state, moving_init_t) noexcept;
114
120
121 ONIXS_CMEMDH_EXPORTED void swap(FutureBase& other) noexcept;
122
124
126
127private:
128 const System::FutureSharedState* state_ = nullptr;
129
130 friend class FutureHelper;
131};
132
133template <typename T>
135{
136 typedef const T& Type;
137};
138
139template <>
140struct FutureGetReturn<void>
141{
142 typedef void Type;
143};
144
145} // namespace Implementation
146
158template <typename T>
160{
161 static_assert(!std::is_reference<T>::value, "SharedFuture does not support reference result types");
162
163public:
164 SharedFuture() noexcept = default;
165
167 SharedFuture(const SharedFuture& other) noexcept = default;
168
170 SharedFuture& operator=(const SharedFuture& other) noexcept = default;
171
172 SharedFuture(SharedFuture&& other) noexcept = default;
173
174 SharedFuture& operator=(SharedFuture&& other) noexcept = default;
175
182 typename Implementation::FutureGetReturn<T>::Type get() const
183 {
184 return *reinterpret_cast<const T*>(getValuePtr());
185 }
186
188 void swap(SharedFuture<T>& other) noexcept
189 {
190 FutureBase::swap(other);
191 }
192
193private:
195 SharedFuture(const System::FutureSharedState* state) noexcept
196 : FutureBase(state)
197 {}
198
200 SharedFuture(const System::FutureSharedState* state, moving_init_t t) noexcept
201 : FutureBase(state, t)
202 {}
203
204 friend class Implementation::FutureHelper;
205};
206
209
211template <>
212inline void SharedFuture<void>::get() const
213{
214 getVoid();
215}
216
#define ONIXS_CME_MDH_THREADING_NAMESPACE_BEGIN
Definition Bootstrap.h:66
#define ONIXS_CME_MDH_THREADING_NAMESPACE_END
Definition Bootstrap.h:67
#define ONIXS_CMEMDH_EXPORTED
Definition Compiler.h:148
FutureBase(const System::FutureSharedState *state) noexcept
Initializes the instance and adds a reference to the shared state.
FutureBase(const System::FutureSharedState *state, moving_init_t) noexcept
Initializes the instance from a detached shared state reference.
std::future_status wait(int timeoutInMs=InfiniteTimeout) const
void swap(SharedFuture< T > &other) noexcept
Swaps two SharedFuture objects.
Definition Future.h:188
Implementation::FutureGetReturn< void >::Type get() const
Definition Future.h:182
SharedFuture< void > Event
Completion signal for an asynchronous operation that does not produce a value.
Definition Future.h:208