From: Patrik Gornicz Date: Fri, 22 Aug 2008 17:40:38 +0000 (-0400) Subject: wip: config reader X-Git-Tag: v0.07~31 X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?p=physics.git;a=commitdiff_plain;h=87c9b12ffbcb8458c7e031045d34d2a1de5ea78a wip: config reader --- diff --git a/configs/test.cfg b/configs/test.cfg new file mode 100644 index 0000000..e965047 --- /dev/null +++ b/configs/test.cfg @@ -0,0 +1 @@ +Hello diff --git a/src/config/config.cpp b/src/config/config.cpp index 35efe4f..9aa6f86 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -16,6 +16,8 @@ */ #include "config.h" + +#include "reader.h" #include "../input/inputManager.h" /// ***** Private Method Headers ***** @@ -25,6 +27,7 @@ void cfg::init() { + readConfigs(NULL); // TODO read in config files } void cfg::clean() diff --git a/src/config/reader.cpp b/src/config/reader.cpp new file mode 100644 index 0000000..ce35ab8 --- /dev/null +++ b/src/config/reader.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. + * + * 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 . + */ + +#include "reader.h" +#include "../debug.h" + +#include +#include +#include + +using std::ifstream; +using std::string; + +char* configDir = "../configs/"; + +/// ***** Private Method Headers ***** + +void processLine(const string& str, keyMap* map); + +/// ***** Private Variables ***** + +/// ***** Public Methods ***** + +void readConfigs(keyMap* map) +{ + char fileName[64]; + + strcpy(fileName, configDir); + strcat(fileName, "test.cfg"); + + ifstream file(fileName); + + if( !file.is_open() ) + { + cerr << "Unable to open file " << fileName << "." << endl; + exit(1); + } + + while(true) + { + string line; + getline(file, line); + + if(file.eof()) + break; + + processLine(line, map); + } + + file.close(); +} + +/// ***** Private Methods ***** + +void processLine(const string& str, keyMap* map) +{ + cout << str << endl; +} diff --git a/src/config/reader.h b/src/config/reader.h new file mode 100644 index 0000000..672b6da --- /dev/null +++ b/src/config/reader.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com. + * + * 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 . + */ + + +#ifndef READER_H +#define READER_H + +#include +#include + +typedef std::map keyMap; + +/// ***** Header Methods ***** + +void readConfigs(keyMap*); + +#endif // READER_H