Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_expected.hpp
1#pragma once
2
3#include <string>
4#include <utility>
5
6#include "structure/container/spk_task_result.hpp"
7
8namespace spk
9{
10 template <typename TType, typename TReportStatusType = size_t>
24 {
25 public:
30
31 private:
32 TType _value{};
33 ReportStatus _reportStatus;
34
35 public:
39 Expected() = default;
46 explicit Expected(const TType &p_value, const TReportStatusType &p_reportStatusID, const std::wstring &p_reportStatusMessage) :
47 _value(p_value),
48 _reportStatus(p_reportStatusID, p_reportStatusMessage)
49 {
50 }
51
57 explicit Expected(TType &&p_value, const TReportStatusType &p_reportStatusID, const std::wstring &p_reportStatusMessage) :
58 _value(std::move(p_value)),
59 _reportStatus(p_reportStatusID, p_reportStatusMessage)
60 {
61 }
62
69 static Expected generateReport(const TReportStatusType &p_reportStatusID, const std::wstring &p_reportStatusMessage)
70 {
71 return (Expected({}, p_reportStatusID, p_reportStatusMessage));
72 }
73
78 TType &value()
79 {
80 return _value;
81 }
82
87 const TType &value() const
88 {
89 return _value;
90 }
91
97 {
98 return (_reportStatus);
99 }
100
106 {
107 return (_reportStatus);
108 }
109 };
110}
Expected()=default
Builds a default-initialized expected value.
const ReportStatus & reportStatus() const
Returns a const reference to the report status.
Definition spk_expected.hpp:105
const TType & value() const
Returns a const reference to the stored value.
Definition spk_expected.hpp:87
TaskResult< TReportStatusType > ReportStatus
Report status container type.
Definition spk_expected.hpp:29
Expected(const TType &p_value, const TReportStatusType &p_reportStatusID, const std::wstring &p_reportStatusMessage)
Builds an expected value with a report status.
Definition spk_expected.hpp:46
Expected(TType &&p_value, const TReportStatusType &p_reportStatusID, const std::wstring &p_reportStatusMessage)
Builds an expected value by moving the payload and adding a report status.
Definition spk_expected.hpp:57
ReportStatus & reportStatus()
Returns a mutable reference to the report status.
Definition spk_expected.hpp:96
TType & value()
Returns a mutable reference to the stored value.
Definition spk_expected.hpp:78
static Expected generateReport(const TReportStatusType &p_reportStatusID, const std::wstring &p_reportStatusMessage)
Creates an expected value with a default-initialized payload and report status.
Definition spk_expected.hpp:69
Wraps a value with an optional status message for task reporting.
Definition spk_task_result.hpp:21
STL namespace.