loom
1/*
2MIT License
3
4Copyright (c) 2022 МГТУ им. Н.Э. Баумана, кафедра ИУ-6, Михаил Фетисов,
5
6https://bmstu.codes/lsx/simodo/loom
7*/
8
9#include "simodo/variable/Variable.h"
10
11#include <cassert>
12
13using namespace simodo::variable;
14
15const Variable & Variable::origin() const
16{
17if (type() != ValueType::Ref)
18return *this;
19
20const Variable & o = _value.getRef().origin();
21
22assert(o.type() != ValueType::Ref);
23
24return o;
25}
26
27Variable & Variable::origin()
28{
29if (type() != ValueType::Ref)
30return *this;
31
32Variable & o = std::get<VariableRef>(_value.variant()).origin();
33
34assert(o.type() != ValueType::Ref);
35
36return o;
37}
38
39Variable Variable::copyVariable() const
40{
41return { _name, _value.copy(), _location,
42_spec.isNull()
43? Specification {}
44: Specification { spec().object()->copy() } };
45}
46
47VariableRef Variable::makeReference() const
48{
49if (type() == ValueType::Ref)
50return std::get<VariableRef>(variant());
51
52return VariableRef {*this};
53}
54
55