SXEval 1.0.3
A generic s-expression interpreter library.
Loading...
Searching...
No Matches
AOperation.hpp
Go to the documentation of this file.
1#ifndef SXEVAL_AOPERATION_HPP
2#define SXEVAL_AOPERATION_HPP
3
5#include <vector>
6
7
8namespace sxeval {
9
21template <typename T>
22class AOperation : public virtual IInstruction<T> {
23public:
27 static constexpr const int UNLIMITED_ARITY = -1;
28
32 static constexpr const char* KEY = "AOperation";
33
37 static constexpr const int ARITY_MIN = 0;
38
42 static constexpr const int ARITY_MAX = UNLIMITED_ARITY;
43
47 AOperation(const std::vector<IInstruction<T>*>& args);
48
54 inline AOperation(const AOperation& other)
55 : _result(other._result), _args(other._args) {}
56
60 virtual ~AOperation() override = default;
61
67 inline T& getResult() override { return _result; }
68
75 virtual void execute() = 0;
76
77protected:
79 std::vector<std::reference_wrapper<T>> _args;
80
81};
82
83} /* namespace sxeval */
84
85
86/* IMPLEMENTATIONS */
87
88template <typename T>
90 for (const auto& arg : args) {
91 _args.push_back(arg->getResult());
92 }
93}
94
95#endif /* SXEVAL_AOPERATION_HPP */
The AOperation class is an abstract base class for operations in the SXEval library.
Definition AOperation.hpp:22
std::vector< std::reference_wrapper< T > > _args
Definition AOperation.hpp:79
T & getResult() override
Get the result of the operation.
Definition AOperation.hpp:67
static constexpr const int ARITY_MAX
Default maximum number of arguments for the operation.
Definition AOperation.hpp:42
static constexpr const char * KEY
Default key for the operation.
Definition AOperation.hpp:32
static constexpr const int ARITY_MIN
Default minimum number of arguments for the operation.
Definition AOperation.hpp:37
AOperation(const std::vector< IInstruction< T > * > &args)
Constructor that initializes the operation.
Definition AOperation.hpp:89
AOperation(const AOperation &other)
Copy constructor.
Definition AOperation.hpp:54
virtual ~AOperation() override=default
Default destructor.
virtual void execute()=0
Execute the operation.
T _result
Definition AOperation.hpp:78
static constexpr const int UNLIMITED_ARITY
The value for an unlimited number of arguments.
Definition AOperation.hpp:27
The IInstruction class is an interface for any instructions.
Definition IInstruction.hpp:21
Definition AOperation.hpp:8