4
Copyright (c) 2022 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
6
https://bmstu.codes/lsx/simodo/loom
9
#include "simodo/variable/Variable.h"
10
#include "simodo/bormental/DrBormental.h"
11
#include "simodo/variable/FunctionWrapper.h"
12
#include "simodo/inout/format/fmt.h"
16
namespace simodo::variable
18
Object Object::copy() const
22
for(const Variable & member : _variables)
23
record.variables().push_back(member.copyVariable());
28
bool Object::exists(const std::u16string & name) const
30
auto it = find_if(_variables.begin(), _variables.end(), [name](const Variable & v){
31
return v.name() == name;
34
return it != _variables.end();
37
const Value & Object::find(const std::u16string & name) const
39
static const Value undef {};
41
auto it = find_if(_variables.begin(), _variables.end(), [name](const Variable & v){
42
return v.name() == name;
45
if (it == _variables.end())
51
Value & Object::find(const std::u16string & name)
53
static Value undef {};
55
auto it = find_if(_variables.begin(), _variables.end(), [name](const Variable & v){
56
return v.name() == name;
59
if (it == _variables.end())
65
const Variable & Object::getVariableByName(const std::u16string & name) const
67
static const Variable undef {};
69
auto it = find_if(_variables.begin(), _variables.end(), [name](const Variable & v){
70
return v.name() == name;
73
if (it == _variables.end())
79
Variable & Object::getVariableByName_mutable(const std::u16string & name)
81
return const_cast<Variable &>(getVariableByName(name));
84
const Variable & Object::getVariableByIndex(index_t index) const
86
if (index >= _variables.size())
87
throw bormental::DrBormental("Object::getVariableByIndex", inout::fmt("Out of index"));
89
return _variables[index];
92
Value Object::invoke(const std::u16string & method_name, const VariableSet_t & arguments)
94
const Variable & function = getVariableByName(method_name);
95
if (function.type() == variable::ValueType::Null)
98
if (function.type() != variable::ValueType::Function)
103
FunctionWrapper func(function);
104
VariableSet_t args_mutable = arguments;
105
VariableSetWrapper_mutable args(args_mutable);
107
return func.invoke(args);
109
catch(const std::exception & e)