SXEval 1.0.3
A generic s-expression interpreter library.
Loading...
Searching...
No Matches
EncapsulatedVariable.hpp
Go to the documentation of this file.
1#ifndef SXEVAL_ENCASPULATED_VARIABLE_HPP
2#define SXEVAL_ENCASPULATED_VARIABLE_HPP
3
4#include "sxeval/IOperand.hpp"
5#include <functional>
6
7namespace sxeval {
8
17template <typename T>
18class EncapsulatedVariable : public virtual IOperand<T> {
19public:
27 inline EncapsulatedVariable(const std::function<T(void)> get,
28 const std::string& name) : _get(get), _name(name) {}
29
35 inline T& getResult() override { return _var; }
36
40 inline void retrieve() { _var = _get(); }
41
47 inline std::string toString() const override { return _name; }
48
49private:
50 T _var;
51 const std::function<T(void)> _get;
52 const std::string _name;
53
54};
55
56} /* namespace sxeval */
57#endif /* SXEVAL_ENCASPULATED_VARIABLE_HPP */
The EncapsulatedVariable class represents a variable that can be encapsulated in an unaccessible Obje...
Definition EncapsulatedVariable.hpp:18
std::string toString() const override
String representation of the encapsulated variable.
Definition EncapsulatedVariable.hpp:47
void retrieve()
Retrieve the value of the encapsulated variable.
Definition EncapsulatedVariable.hpp:40
EncapsulatedVariable(const std::function< T(void)> get, const std::string &name)
Default constructor.
Definition EncapsulatedVariable.hpp:27
T & getResult() override
Get a reference to the variable.
Definition EncapsulatedVariable.hpp:35
The IOperand class is an interface for operands.
Definition IOperand.hpp:16
Definition AOperation.hpp:8