blob: 21105b495622c5e797fce40c57004814aa1247ef (
plain)
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
|
/*
core/cvar.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include "core/cvar.h"
#include "sys/sys.h"
#include <map>
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
namespace core {
Cvar_t::Cvar_t(unsigned int cvarflags)
{
cvar_flags = cvarflags;
}
Cvar_t & Cvar_t::operator=(const std::string &cvarvalue)
{
cvar_value = cvarvalue;
return (*this);
}
Cvar_t & Cvar_t::operator=(const char *cvarvalue)
{
cvar_value.assign(cvarvalue);
return (*this);
}
Cvar_t & Cvar_t::operator=(int cvarvalue)
{
std::stringstream s;
s << cvarvalue;
s >> cvar_value;
return (*this);
}
namespace cvar
{
std::map<std::string, Cvar> registry;
Cvar set(const char *cvarname, const char *cvarvalue, int cvarflags)
{
Cvar c = registry[std::string(cvarname)];
if (c) {
con_debug << "cvar::set " << cvarname << " already exist with value " << cvarvalue << std::endl;
} else {
con_debug << "cvar::set " << cvarname << " with value " << cvarvalue << std::endl;
c = new Cvar_t(cvarflags);
registry[std::string(cvarname)] = c;
(*c) = cvarvalue;
}
return c;
}
Cvar set(const char *cvarname, int cvarvalue, int cvarflags)
{
Cvar c = registry[std::string(cvarname)];
if (c) {
con_debug << "cvar::set " << cvarname << " already exist with value " << cvarvalue << std::endl;
} else {
con_debug << "cvar::set " << cvarname << " with value " << cvarvalue << std::endl;
c = new Cvar_t(cvarflags);
registry[std::string(cvarname)] = c;
(*c) = cvarvalue;
}
return c;
}
void unset(const char *cvarname)
{
Cvar c = registry[std::string(cvarname)];
if (c) {
con_debug << "cvar::unset " << cvarname << std::endl;
registry.erase(std::string(cvarname));
delete c;
}
}
void unset(const std::string &cvarname)
{
Cvar c = registry[cvarname];
if (c) {
con_debug << "cvar::unset " << cvarname << std::endl;
registry.erase(cvarname);
delete c;
}
}
Cvar find(const std::string &cvarname)
{
return registry[cvarname];
}
Cvar find(const char *cvarname)
{
return registry[std::string(cvarname)];
}
void list()
{
std::map<std::string, Cvar>::iterator registryiterator;
for (registryiterator = registry.begin(); registryiterator != registry.end(); registryiterator++) {
con_print << std::setw(4) << (*registryiterator).second->flags()
<< " " << (*registryiterator).first
<< " " << (*registryiterator).second->value() << std::endl;
}
}
} // namespace cvar
} // namespace core
|