summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/ConfigManager.cpp54
-rw-r--r--src/Common/ConfigManager.h45
-rw-r--r--src/Common/Makefile.am4
-rw-r--r--src/Common/Makefile.in7
-rw-r--r--src/Common/Util.h62
5 files changed, 167 insertions, 5 deletions
diff --git a/src/Common/ConfigManager.cpp b/src/Common/ConfigManager.cpp
new file mode 100644
index 0000000..2159c6e
--- /dev/null
+++ b/src/Common/ConfigManager.cpp
@@ -0,0 +1,54 @@
+/*
+ * ConfigManager.cpp
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * 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 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ConfigManager.h"
+#include "Util.h"
+#include <fstream>
+
+namespace Mad {
+namespace Common {
+
+bool ConfigManager::loadFile(const std::string &filename) {
+ std::ifstream file(filename.c_str());
+
+ if(!file.good())
+ return false;
+
+ while(!file.eof()) {
+ std::string line;
+
+ std::getline(file, line);
+ line = Util::trim(line);
+
+ if(line.empty() || line[0] == '#')
+ continue;
+
+ size_t pos = line.find_first_of(" \t");
+
+ if(pos == std::string::npos)
+ parseLine(line);
+ else
+ parseLine(line.substr(0, pos), Util::trim(line.substr(pos)));
+ }
+
+ return true;
+}
+
+}
+}
diff --git a/src/Common/ConfigManager.h b/src/Common/ConfigManager.h
new file mode 100644
index 0000000..ccbfbaa
--- /dev/null
+++ b/src/Common/ConfigManager.h
@@ -0,0 +1,45 @@
+/*
+ * ConfigManager.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * 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 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_COMMON_CONFIGMANAGER_H_
+#define MAD_COMMON_CONFIGMANAGER_H_
+
+#include <string>
+
+namespace Mad {
+namespace Common {
+
+class ConfigManager {
+ protected:
+ ConfigManager() {}
+
+ virtual bool parseLine(const std::string &key, const std::string &value = std::string()) = 0;
+
+ bool loadFile(const std::string &filename);
+
+ public:
+ virtual ~ConfigManager() {}
+
+ //virtual const std::string& getValue(const std::string &value) const = 0;
+};
+
+}
+}
+
+#endif /* MAD_COMMON_CONFIGMANAGER_H_ */
diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am
index aa2e45f..792aadc 100644
--- a/src/Common/Makefile.am
+++ b/src/Common/Makefile.am
@@ -1,5 +1,5 @@
noinst_LTLIBRARIES = libcommon.la
-libcommon_la_SOURCES = RequestManager.cpp
+libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp
-noinst_HEADERS = Request.h RequestManager.h
+noinst_HEADERS = ConfigManager.h Request.h RequestManager.h Util.h
diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in
index 55e52ce..48224e7 100644
--- a/src/Common/Makefile.in
+++ b/src/Common/Makefile.in
@@ -45,7 +45,7 @@ CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
libcommon_la_LIBADD =
-am_libcommon_la_OBJECTS = RequestManager.lo
+am_libcommon_la_OBJECTS = ConfigManager.lo RequestManager.lo
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/src
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -180,8 +180,8 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libcommon.la
-libcommon_la_SOURCES = RequestManager.cpp
-noinst_HEADERS = Request.h RequestManager.h
+libcommon_la_SOURCES = ConfigManager.cpp RequestManager.cpp
+noinst_HEADERS = ConfigManager.h Request.h RequestManager.h Util.h
all: all-am
.SUFFIXES:
@@ -233,6 +233,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConfigManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestManager.Plo@am__quote@
.cpp.o:
diff --git a/src/Common/Util.h b/src/Common/Util.h
new file mode 100644
index 0000000..19e1eeb
--- /dev/null
+++ b/src/Common/Util.h
@@ -0,0 +1,62 @@
+/*
+ * Util.h
+ *
+ * Copyright (C) 2008 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * 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 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTIL_H_
+#define UTIL_H_
+
+#include <string>
+#include <locale>
+
+namespace Mad {
+namespace Common {
+
+class Util {
+ private:
+ Util();
+
+ public:
+ static std::string tolower(const std::string &str) {
+ std::string ret;
+
+ for(std::string::const_iterator c = str.begin(); c != str.end(); ++c)
+ ret += std::tolower(*c);
+
+ return ret;
+ }
+
+ static std::string trim(const std::string &str) {
+ size_t beg, end;
+
+ beg = str.find_first_not_of(" \t");
+ end = str.find_last_not_of(" \t");
+
+ if(beg == std::string::npos)
+ beg = 0;
+
+ if(end != std::string::npos)
+ end = end-beg+1;
+
+ return str.substr(beg, end);
+ }
+};
+
+}
+}
+
+#endif /* UTIL_H_ */