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();
133 ~
Future()
override =
default;
141 const T GetValue()
const;
144 void SetValue(
const T& value);
146 Impl& GetPImpl()
override 148 return *(this->pImpl);
151 const Impl& GetPImpl()
const override 153 return *(this->pImpl);
157 std::shared_ptr<Impl> pImpl{std::make_shared<Impl>()};
165 result.pImpl->isCreatedByPromise =
true;
173 this->CheckForValueAndException();
174 return this->GetPImpl().value;
181 this->GetPImpl().value = value;
182 this->GetPImpl().valueHasBeenSet.store(
true);
194 friend Internal::Promise<void>;
195 using Impl = ImplBase;
197 static Future CreateByPromise();
207 ~
Future()
override =
default;
216 void GetValue()
const;
221 Impl& GetPImpl()
override;
222 const Impl& GetPImpl()
const override;
225 std::shared_ptr<Impl> pImpl;
const T GetValue() const
Returns the value set by the associated Promise
Definition: Future.hpp:171
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