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
void Array::reserve(size_t capacity)
23
_values.reserve(capacity);
26
Array Array::copy() const
28
std::vector<Value> values;
30
for(const Value & v : _values)
31
values.push_back(v.copy());
33
return { _common_type, _dimensions, values };
36
void Array::add(const Value & value)
38
_values.push_back(value);
43
assert(!_values.empty());
47
const Value & Array::getValueByIndex(const std::vector<index_t> & index) const
49
if (_dimensions.size() != index.size())
50
throw bormental::DrBormental("Array::getValueByIndex", inout::fmt("Out of indexes count"));
52
if (index.size() != 1)
53
throw bormental::DrBormental("Array::getValueByIndex", inout::fmt("Unsupported"));
55
if (index[0] >= _values.size())
56
throw bormental::DrBormental("Array::getValueByIndex", inout::fmt("Out of index"));
58
return _values[index[0]];
61
VariableRef Array::getRefByIndex(const std::vector<index_t> & index) const
63
return VariableRef(getValueByIndex(index));