/
graphics_config_condition.cpp
66 lines (60 loc) · 2.65 KB
/
graphics_config_condition.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
66
/************************************************************************/
/* */
/* This file is part of VDrift. */
/* */
/* VDrift is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* VDrift is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with VDrift. If not, see <http://www.gnu.org/licenses/>. */
/* */
/************************************************************************/
#include <sstream>
#include "graphics_config_condition.h"
void GRAPHICS_CONFIG_CONDITION::Parse(const std::string & str)
{
std::stringstream parser(str);
while (parser)
{
std::string condition;
parser >> condition;
if (!condition.empty())
{
if (condition[0] == '!')
{
if (condition.size() > 1)
{
std::string cond = condition.substr(1);
if (positive_conditions.find(cond) == positive_conditions.end())
negated_conditions.insert(cond);
else
positive_conditions.erase(cond);
}
}
else
if (negated_conditions.find(condition) == negated_conditions.end())
positive_conditions.insert(condition);
else
negated_conditions.erase(condition);
}
}
}
bool GRAPHICS_CONFIG_CONDITION::Satisfied(const std::set <std::string> & conditions) const
{
// If we don't find all of our positive conditions in the conditions set, return false.
for (std::set <std::string>::const_iterator i = positive_conditions.begin(); i != positive_conditions.end(); i++)
if (conditions.find(*i) == conditions.end())
return false;
// If we find any of our negative conditions in the conditions set, return false.
for (std::set <std::string>::const_iterator i = negated_conditions.begin(); i != negated_conditions.end(); i++)
if (conditions.find(*i) != conditions.end())
return false;
return true;
}