summaryrefslogtreecommitdiff
path: root/src/miav_config.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/miav_config.cc')
-rw-r--r--src/miav_config.cc99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/miav_config.cc b/src/miav_config.cc
new file mode 100644
index 0000000..2af0ef1
--- /dev/null
+++ b/src/miav_config.cc
@@ -0,0 +1,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);
+}