OnixS C++ ICE Binary Order Entry Handler 1.0.0
API Documentation
Loading...
Searching...
No Matches
Future.h
Go to the documentation of this file.
1/*
2* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3*
4* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5* and international copyright treaties.
6*
7* Access to and use of the software is governed by the terms of the applicable OnixS Software
8* Services Agreement (the Agreement) and Customer end user license agreements granting
9* a non-assignable, non-transferable and non-exclusive license to use the software
10* for it's own data processing purposes under the terms defined in the Agreement.
11*
12* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13* of this source code or associated reference material to any other location for further reproduction
14* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15*
16* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17* the terms of the Agreement is a violation of copyright law.
18*/
19
20#pragma once
21
22#include <OnixS/ICE/BOE/ABI.h>
23
24#include <exception>
25
26namespace OnixS { namespace System { class FutureSharedState; }}
27
29namespace Threading {
30
33{
43};
44
45namespace Implementation {
46
47class FutureHelper;
48
51{
52public:
56 bool valid() const noexcept {
57 return state_ != nullptr;
58 }
59
71
77
83
88 ONIXS_ICEBOE_EXPORTED std::exception_ptr get_exception_ptr() const;
89
90 enum { InfiniteTimeout = -1 };
91
99
100protected:
102 : state_() {}
103
105
107
109
111
112 struct moving_init_t {};
113
115 ONIXS_ICEBOE_EXPORTED FutureBase(const System::FutureSharedState * state) noexcept;
116
118 ONIXS_ICEBOE_EXPORTED FutureBase(const System::FutureSharedState * state, moving_init_t) noexcept;
119
124
125 ONIXS_ICEBOE_EXPORTED void swap(FutureBase & other) noexcept;
126
127 ONIXS_ICEBOE_EXPORTED const void * getValuePtr() const;
128
130
131private:
132 const System::FutureSharedState * state_;
133
134 friend class FutureHelper;
135};
136
137template<typename T>
139 typedef const T & Type;
140};
141
142template<>
143struct FutureGetReturn<void> {
144 typedef void Type;
145};
146
147}
148
173template <typename T>
175{
176public:
177 SharedFuture() noexcept
178 : FutureBase() {}
179
181 SharedFuture(const SharedFuture<T> & other) noexcept
182 : FutureBase(other) {}
183
185 SharedFuture<T> & operator=(const SharedFuture<T> & other) noexcept {
186 FutureBase::operator=(other);
187 return *this;
188 }
189
190 SharedFuture(SharedFuture<T> && other) noexcept
191 : FutureBase(std::move(other)) {}
192
193 FutureBase & operator=(SharedFuture<T> && other) noexcept {
194 FutureBase::operator=(std::move(other));
195 return *this;
196 }
197
204 return *reinterpret_cast<const T *>(getValuePtr());
205 }
206
208 void swap(SharedFuture<T> & other) noexcept {
209 FutureBase::swap(other);
210 }
211
212private:
214 SharedFuture(const System::FutureSharedState * state)
215 : FutureBase(state) {}
216
218 SharedFuture(const System::FutureSharedState * state, moving_init_t t) noexcept
219 : FutureBase(state, t) {}
220
221 friend class Implementation::FutureHelper;
222};
223
224template<>
225inline void SharedFuture<void>::get() const {
226 getVoid();
227}
228
229}
#define ONIXS_ICEBOE_NAMESPACE_BEGIN
Definition ABI.h:94
#define ONIXS_ICEBOE_NAMESPACE_END
Definition ABI.h:98
#define ONIXS_ICEBOE_EXPORTED
Definition Compiler.h:153
Base implementation of SharedFuture<T>.
Definition Future.h:51
FutureBase & operator=(const FutureBase &other) noexcept
bool has_exception() const
Returns true if the asynchronous result associated with this Future has a stored exception,...
FutureStatus::Enum wait(int timeoutInMs) const
Waits for the result to become available during the timeout.
FutureBase(const FutureBase &other) noexcept
FutureBase(const System::FutureSharedState *state) noexcept
Initializes the instance with shared state.
bool has_value() const
Returns true if the asynchronous result associated with this Future has a stored value,...
bool valid() const noexcept
Check if a future instance is associated with an asynchronous result.
Definition Future.h:56
~FutureBase() noexcept
Destroys a future object.
FutureBase(const System::FutureSharedState *state, moving_init_t) noexcept
Initializes the instance with shared state.
std::exception_ptr get_exception_ptr() const
Returns the stored exception.
bool is_ready() const
Returns true if the asynchronous result associated with this Future is ready (has a value or exceptio...
FutureBase & operator=(FutureBase &&other) noexcept
Represents a future result of an asynchronous operation - a result that will eventually appear in the...
Definition Future.h:175
void swap(SharedFuture< T > &other) noexcept
swaps two SharedFuture objects
Definition Future.h:208
SharedFuture(const SharedFuture< T > &other) noexcept
Copy constructor.
Definition Future.h:181
SharedFuture(SharedFuture< T > &&other) noexcept
Definition Future.h:190
FutureBase & operator=(SharedFuture< T > &&other) noexcept
Definition Future.h:193
Implementation::FutureGetReturn< T >::Type get() const
Returns the result.
Definition Future.h:203
SharedFuture< T > & operator=(const SharedFuture< T > &other) noexcept
Copy assignment.
Definition Future.h:185
State of a SharedFuture object (similar to std::future_status,.
Definition Future.h:33
@ timeout
the shared state did not become ready before specified timeout duration has passed.
Definition Future.h:39
@ ready
the shared state is ready.
Definition Future.h:37
@ deferred
the shared state contains a deferred function, so the result will be computed only when explicitly re...
Definition Future.h:41