-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRule.cpp
65 lines (55 loc) · 1.73 KB
/
Rule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include "Rule.h"
#include "Cmd.h"
#include "Parser.h"
#include <exception>
void Rule::setcmds(Commands&& newcmds) {
_commands = std::move(newcmds);
}
void Rule::readruleoptions(Lexer &lex) {
Token t = lex.nexttoken();
while (t.isdata()) {
if (t.getdata() == "invisible") { //!!!fix similarity of these
_drawsInvisibly = true;
} else if (t.getdata() == "nodraw") {
_doesNotDraw=true;
// } else if (t.getdata() == "rectwidth") {
// t = lex.nexttoken();
// assertdatatoken(t);
// _rectWidthExpression = parse(t.getdata());
} else if (t.getdata() == "localscale") {
t = lex.nexttoken();
assertdatatoken(t);
_localScaleExpression = parse(t);
_shouldFix = false;
} else if (t.getdata() == "nofix") {
_shouldFix = false;
} else
throw std::runtime_error("Unexpected option " + t.getdata());
t = lex.nexttoken();
}
}
void Rule::evaluateExpressions(const Context& cc) const {
for (auto & cmd : _commands)
cmd->evaluateExpressions(cc);
_localScale = _localScaleExpression ? _localScaleExpression->eval(cc) : 1.0;
}
double Rule::getLocalScale() const {
return _localScale;
}
const Commands & Rule::getCommands() const {
return _commands;
}
bool Rule::doesNotDraw() const {
return _doesNotDraw;
}
bool Rule::drawsInvisibly() const {
return _drawsInvisibly;
}
bool Rule::isFixed() const {
return _isFixed;
}
bool Rule::shouldFix() const {
return _shouldFix;
}