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/inout/format/fmt.h"
15
namespace simodo::variable
17
Array::Array(const std::vector<Value> & values)
18
: _dimensions({static_cast<index_t>(values.size())}), _values(values)
21
Array Array::copy() const
23
std::vector<Value> values;
25
for(const Value & v : _values)
26
values.push_back(v.copy());
28
return { _common_type, _dimensions, values };
31
const Value & Array::getValueByIndex(const std::vector<index_t> & index) const
33
if (_dimensions.size() != index.size())
34
throw bormental::DrBormental("Array::getValueByIndex", inout::fmt("Out of indexes count"));
36
if (index.size() != 1)
37
throw bormental::DrBormental("Array::getValueByIndex", inout::fmt("Unsupported"));
39
if (index[0] >= _values.size())
40
throw bormental::DrBormental("Array::getValueByIndex", inout::fmt("Out of index"));
42
return _values[index[0]];
45
VariableRef Array::getRefByIndex(const std::vector<index_t> & index) const
47
return VariableRef(getValueByIndex(index));