File: Setting.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (121 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (6)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "Setting.h"

#include "i18n.h"
#include "iregistry.h"
#include "gamelib.h"

namespace difficulty
{

namespace
{
	const std::string GKEY_APPTYPE_IGNORE("/difficulty/appTypeIgnore");
}

Setting::Setting() :
	id(++_highestId),
	isDefault(false)
{}

std::string Setting::getArgumentKeyValue() const {
	std::string returnValue(argument);

	switch (appType) {
		case EAssign: break;
		case EAdd:
			returnValue = "+" + returnValue;
			break;
		case EMultiply:
			returnValue = "*" + returnValue;
			break;
		case EIgnore:
			returnValue = game::current::getValue<std::string>(GKEY_APPTYPE_IGNORE);
			break;
		default:
			break;
	};

	return returnValue;
}

std::string Setting::getDescString() const {
	std::string returnValue(argument);

	switch (appType) {
		case EAssign:
			returnValue = " = " + returnValue;
			break;
		case EAdd:
			returnValue = " += " + returnValue;
			break;
		case EMultiply:
			returnValue = " *= " + returnValue;
			break;
		case EIgnore:
			returnValue = " = [IGNORE]";
			break;
		default:
			break;
	};

	returnValue = spawnArg + returnValue;
	return returnValue;
}

bool Setting::operator==(const Setting& rhs) const {
	return className == rhs.className &&
			spawnArg == rhs.spawnArg &&
			argument == rhs.argument &&
			appType == rhs.appType;
}

bool Setting::operator!=(const Setting& rhs) const {
	return !operator==(rhs);
}

Setting& Setting::operator=(const Setting& rhs) {
	className = rhs.className;
	spawnArg = rhs.spawnArg;
	argument = rhs.argument;
	appType = rhs.appType;
	isDefault = rhs.isDefault;

	return *this;
}

void Setting::parseAppType() {
	appType = EAssign;

	if (!argument.empty())
	{
		// Check for ignore argument
		if (argument == game::current::getValue<std::string>(GKEY_APPTYPE_IGNORE))
		{
			appType = EIgnore;
			argument.clear(); // clear the argument
		}
		// Check for special modifiers
		else if (argument[0] == '+')
		{
			appType = EAdd;
			// Remove the first character
			argument = argument.substr(1);
		}
		else if (argument[0] == '*')
		{
			appType = EMultiply;
			// Remove the first character
			argument = argument.substr(1);
		}
		else if (argument[0] == '-')
		{
			appType = EAdd;
			// Leave the "-" sign, it will be the sign of the parsed int
		}
	}
}

// Initialise the static member
int Setting::_highestId = 0;

} // namespace difficulty