blob: 2af0ef1aaff44f362b078fc00c21942ebe2a5987 (
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
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/***************************************************************************
* miav_config.cc
*
* Sat Feb 19 14:13:19 CET 2005
* Copyright 2005 Bent Bisballe
* deva@aasimon.org
****************************************************************************/
/*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include "miav_config.h"
MiavConfig::MiavConfig(char *file)
{
configs = NULL;
_cfg *cfg;
// TODO: Read config from file.
// Add a config
configs = cfg = (_cfg*) malloc(sizeof(_cfg));
cfg->name = new string("cpr_host");
cfg->stringval = new string("cpr.j.auh.dk");
cfg->next = (_cfg*) malloc(sizeof(_cfg));
// Add another config
cfg = cfg->next;
cfg->name = new string("cpr_port");
cfg->intval = 10301;
cfg->next = (_cfg*) malloc(sizeof(_cfg));
// Add another config
cfg = cfg->next;
cfg->name = new string("screensize");
cfg->floatval = 19.0f;
cfg->next = NULL;
}
MiavConfig::~MiavConfig()
{
_cfg *die = NULL;
_cfg *cfg = configs;
while(cfg) {
if(die) free(die);
die = cfg;
cfg = cfg->next;
}
if(die) free(die);
}
int MiavConfig::readInt(char *node)
{
return findNode(node)->intval;
}
bool MiavConfig::readBool(char *node)
{
return findNode(node)->boolval;
}
string *MiavConfig::readString(char *node)
{
return findNode(node)->stringval;
}
float MiavConfig::readFloat(char *node)
{
return findNode(node)->floatval;
}
_cfg *MiavConfig::findNode(char* node)
{
_cfg *cfg = configs;
while(cfg) {
if(!strcmp(node, cfg->name->c_str())) return cfg;
cfg = cfg->next;
}
fprintf(stderr, "ERROR: Request for nonexisting node \"%s\"!\n", node);
exit(1);
}
|