Chrysalis - Pattern
Loading...
Searching...
No Matches
BinaryFunctionArgument.h
Go to the documentation of this file.
1#ifndef CHRYSALIS_BINARYFUNCTIONARGUMENT_H
2#define CHRYSALIS_BINARYFUNCTIONARGUMENT_H
3
5
6#define BINARY_FUNCTIONS (Add)(Subtract)(Multiply)(Divide)(Min)(Max)
7
11namespace Chrysalis {
14 protected:
15 explicit BinaryFunctionArgument(args::number&& operand1, args::number&& operand2);
16 public:
17 #define FORWARD_DECLARE(r, data, Name) class Name;
18 BOOST_PP_SEQ_FOR_EACH(FORWARD_DECLARE, _, BINARY_FUNCTIONS)
19 #undef FORWARD_DECLARE
20 protected:
21 std::expected<double, Error> calculate() const override;
22 virtual std::expected<double, Error> evaluate(double a, double b) const = 0;
23
28 };
29
30 #define DECLARE_BINARY_FUNCTION(r, data, Name) \
31 class BinaryFunctionArgument::Name: public BinaryFunctionArgument { \
32 PROVIDE_SERIALIZATION_ACCESS(BinaryFunctionArgument::Name) \
33 public: \
34 explicit Name(args::number&& operand1, args::number&& operand2) \
35 : BinaryFunctionArgument(std::move(operand1), std::move(operand2)) {} \
36 protected: \
37 std::expected<double, Error> evaluate(double a, double b) const override; \
38 }; \
39 SERIALIZE_DERIVED_CONSTRUCTION(BinaryFunctionArgument::Name, BinaryFunctionArgument, operand1_, operand2_);
40 BOOST_PP_SEQ_FOR_EACH(DECLARE_BINARY_FUNCTION, _, BINARY_FUNCTIONS)
41 #undef DECLARE_BINARY_FUNCTION
42}
44
45#endif //CHRYSALIS_BINARYFUNCTIONARGUMENT_H
#define BINARY_FUNCTIONS
Definition BinaryFunctionArgument.h:6
#define FORWARD_DECLARE(r, data, Name)
Definition BinaryFunctionArgument.h:17
#define DECLARE_BINARY_FUNCTION(r, data, Name)
Definition BinaryFunctionArgument.h:30
args::number operand2_
Definition BinaryFunctionArgument.h:27
args::number operand1_
Definition BinaryFunctionArgument.h:25
std::expected< double, Error > calculate() const override
Definition BinaryFunctionArgument.cpp:8
virtual std::expected< double, Error > evaluate(double a, double b) const =0
BinaryFunctionArgument(args::number &&operand1, args::number &&operand2)
Definition BinaryFunctionArgument.cpp:5
std::unique_ptr< BaseArgument< double > > number
Definition BaseArgument.h:25
Definition Argument.h:9
#define SERIALIZE_DERIVED_FROM(Base,...)
Definition serialization.h:71