Chrysalis - Pattern
Toggle main menu visibility
Loading...
Searching...
No Matches
BaseCalculatedArgument.h
Go to the documentation of this file.
1
#ifndef CHRYSALIS_BASECACHABLEARGUMENT_H
2
#define CHRYSALIS_BASECACHABLEARGUMENT_H
3
4
#include <boost/optional/optional.hpp>
5
6
#include "
arguments/BaseArgument.h
"
7
11
namespace
Chrysalis
{
12
template
<
typename
T>
13
class
BaseCalculatedArgument
:
public
BaseArgument
<T> {
14
SERIALIZE_DERIVED_FROM
(
BaseArgument<T>
, value_)
15
protected
:
16
explicit
BaseCalculatedArgument
() =
default
;
17
explicit
BaseCalculatedArgument
(
const
T& value): value_(value) {}
18
19
virtual
std::expected<T, Error>
calculate
()
const
= 0;
20
public
:
21
std::expected<T, Error>
get
()
const override
{
22
if
(!value_.has_value()) {
23
std::expected<T, Error> value =
calculate
();
24
return
value.transform([&](T t) {
25
value_ = t;
26
return
t;
27
});
28
}
29
return
value_.get();
30
}
31
private
:
32
mutable
boost::optional<T> value_;
33
};
34
}
36
37
#endif
//CHRYSALIS_BASECACHABLEARGUMENT_H
BaseArgument.h
Chrysalis::BaseArgument::BaseArgument
BaseArgument()=default
Chrysalis::BaseCalculatedArgument::get
std::expected< T, Error > get() const override
Definition
BaseCalculatedArgument.h:21
Chrysalis::BaseCalculatedArgument::BaseCalculatedArgument
BaseCalculatedArgument(const T &value)
Definition
BaseCalculatedArgument.h:17
Chrysalis::BaseCalculatedArgument::BaseCalculatedArgument
BaseCalculatedArgument()=default
Chrysalis::BaseCalculatedArgument::calculate
virtual std::expected< T, Error > calculate() const =0
Chrysalis
Definition
Argument.h:9
SERIALIZE_DERIVED_FROM
#define SERIALIZE_DERIVED_FROM(Base,...)
Definition
serialization.h:71
pattern
include
arguments
BaseCalculatedArgument.h
Generated by
1.17.0