Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 9b235638c87a9ce7e11d58791194fc578c08af7b (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
/*
   core/cvar.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_CORE_CVAR_H__
#define __INCLUDED_CORE_CVAR_H__

#include <string>
#include <map>

namespace core
{

/// the cvar container class
class Cvar_t
{
public:

	Cvar_t(unsigned int cvflags = 0);
	
	Cvar_t &operator=(const char *other);
	Cvar_t &operator=(const std::string &other);
	Cvar_t &operator=(int other);
	Cvar_t &operator=(float other);
	
	unsigned int flags() const;
	float value() const;
	const std::string &text() const;
	
private:
	std::string 	cvar_text;
	float 		cvar_value;
	unsigned int 	cvar_flags;
};

/// general cvar type
typedef Cvar_t *Cvar;

/// the cvar registry
namespace cvar
{

/// cvar flags
enum Flags {Archive=2, ReadOnly=4};

/// get a cvar value from the registry
/** If the a cvar with the given name already exists in the registry,
 *  its value will not be changed. If the cvar does not exist,
 *  it will be created
 */
Cvar get(const char *name, const char *value, int flags=0);
/// get a cvar value from the registry
/** If the a cvar with the given name already exists in the registry,
 *  its value will not be changed. If the cvar does not exist,
 *  it will be created
 */
Cvar get(const char *name, float value, int flags=0);

/// set a cvar value
/** If the a cvar with the given name already exists in the registry,
 * its value will be replaced
 */
Cvar set(const char *name, const char *value, int flags=0);
/// set a cvar value
/** If the a cvar with the given name already exists in the registry,
 * its value will be replaced
 */
Cvar set(const char *name, float value, int flags=0);

/// delete a cvar from the registry
void unset(const char *name);

/// delete a cvar from the registry
void unset(const std::string &name);

/// search for a named cvar, returns 0 if not found
Cvar find(const std::string &name);

/// search for a named cvar, returns 0 if not found
Cvar find(const char *name);

/// list the cvar registry
void list();

/// the Cvar registry
extern std::map<std::string, Cvar> registry;

} // namespace cvar

} // namespace core

#endif // __INCLUDED_CORE_CVAR_H__