9 #include "Arp/System/Core/Exception.hpp" 10 #include "Arp/System/Core/TypeName.hxx" 15 namespace Arp {
namespace System {
namespace Nm {
namespace Internal
31 class IExceptionWrapper
34 virtual ~IExceptionWrapper() =
default;
35 virtual void ReThrowException() = 0;
41 template<
typename ExceptionType>
42 class ExceptionWrapper :
public IExceptionWrapper
45 explicit ExceptionWrapper(
const ExceptionType& e) : exception(e)
49 ~ExceptionWrapper()
override =
default;
51 void ReThrowException()
override 53 throw this->exception;
57 ExceptionType exception;
65 bool isCreatedByPromise =
false;
66 std::atomic<bool> valueHasBeenSet;
67 std::unique_ptr<IExceptionWrapper> exception;
80 const bool IsValid()
const;
83 const bool HasValue()
const;
86 const bool HasException()
const;
89 virtual ImplBase& GetPImpl() = 0;
90 virtual const ImplBase& GetPImpl()
const = 0;
91 void CheckForValueAndException()
const;
93 template<
typename ExceptionType>
94 void SetException(
const ExceptionType& e);
96 void Clear(
bool isValid);
100 template<
typename ExceptionType>
101 void FutureBase::SetException(
const ExceptionType& e)
103 this->GetPImpl().exception =
104 std::unique_ptr<IExceptionWrapper>(
new ExceptionWrapper<ExceptionType>(e));
105 this->GetPImpl().valueHasBeenSet.store(
true);
117 friend Internal::Promise<T>;
119 struct Impl :
public ImplBase
124 static Future CreateByPromise();
134 ~
Future()
override =
default;
142 const T GetValue()
const;
145 void SetValue(
const T& value);
147 Impl& GetPImpl()
override 149 return *(this->pImpl);
152 const Impl& GetPImpl()
const override 154 return *(this->pImpl);
158 std::shared_ptr<Impl> pImpl;
166 result.pImpl->isCreatedByPromise =
true;
180 this->CheckForValueAndException();
181 return this->GetPImpl().value;
188 this->GetPImpl().value = value;
189 this->GetPImpl().valueHasBeenSet.store(
true);
201 friend Internal::Promise<void>;
202 using Impl = ImplBase;
204 static Future CreateByPromise();
214 ~
Future()
override =
default;
223 void GetValue()
const;
228 Impl& GetPImpl()
override;
229 const Impl& GetPImpl()
const override;
232 std::shared_ptr<Impl> pImpl;
Future()
Constructs an invalid Future
Definition: Future.hpp:172
Namespace of the C++ standard library
Root namespace for the PLCnext API
Future object as proxy for return value an asynchronous function call
Definition: Future.hpp:114
System components used by the System, Device, Plc or Io domains.
Base class with common behavior for Future<T> and Future<void>
Definition: Future.hpp:26