Page MenuHomePhabricator (Chris)

Config.cpp
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

Config.cpp

/** 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);
}
bool Config::configFileExists()
{
return configFileExistsFlag;
}
void Config::loadFromFile(string file)
{
ifstream f(file.c_str());
if (!f.is_open())
{
configFileExistsFlag = false;
}
else
{
configFileExistsFlag = true;
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)
{
configFileExistsFlag = true;
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());
}

File Metadata

Mime Type
text/x-c
Expires
Sun, Nov 15, 3:08 PM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
121616
Default Alt Text
Config.cpp (2 KB)

Event Timeline