Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126203
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/Config.cpp b/src/Config.cpp
index d818c87..8ba8f64 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -1,75 +1,91 @@
/** This file is part of Witch Blast.
*
* Witch Blast 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.
*
* Witch Blast 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 Witch Blast. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
+#include <ostream>
#include <fstream>
#include <string>
#include <iostream>
#include "Config.h"
Config::Config()
{
loadFromFile(CONFIG_FILE);
}
void Config::loadFromFile(string file)
{
ifstream f(file.c_str());
if (!f.is_open()) return;
string key;
while (f >> key)
{
string data;
if (f >> data)
{
configMap[key] = data;
}
}
f.close();
}
+void Config::saveToFile(std::string fileName, std::map<std::string, std::string> newMap)
+{
+ std::ofstream file(fileName.c_str(), ios::out | ios::trunc);
+ if (file)
+ {
+ map<std::string, std::string>::iterator it;
+
+ for(it = newMap.begin(); it != newMap.end(); it++)
+ {
+ file << it->first << " " << it->second << std::endl;
+ }
+ file.close();
+ }
+}
+
void Config::displayMap()
{
std::map<std::string, std::string>::const_iterator
mit (configMap.begin()),
mend(configMap.end());
for(;mit!=mend;++mit)
{
std::cout << "\"" << mit->first << "\"" << '\t' << mit->second << std::endl;
}
}
int Config::findInt(std::string key)
{
std::map<std::string, std::string>::const_iterator
mit(configMap.find(key)),
mend(configMap.end());
if(mit!=mend)
{
int value = atoi(mit->second.c_str());
return value;
}
else
{
return -99999;
}
return atoi(mit->second.c_str());
}
diff --git a/src/Config.h b/src/Config.h
index 34d4a51..fc92180 100644
--- a/src/Config.h
+++ b/src/Config.h
@@ -1,38 +1,39 @@
/** This file is part of Witch Blast.
*
* Witch Blast 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.
*
* Witch Blast 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 Witch Blast. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONFIG_H_INCLUDED
#define CONFIG_H_INCLUDED
#include <map>
#include "Constants.h"
using namespace std;
class Config
{
public:
Config();
void loadFromFile(string file);
+ void saveToFile(string file, std::map<std::string, std::string> newMap);
void displayMap();
int findInt(string key);
private:
std::map<std::string, std::string> configMap;
};
#endif // CONFIG_H_INCLUDED
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 10:55 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
68573
Default Alt Text
(3 KB)
Attached To
Mode
R78 witchblast
Attached
Detach File
Event Timeline