dolphin/Source/Plugins/InputPluginCommon/Src/IniFile.h
hrydgard a3c96ac42c Warp back to 5578. Sorry for the lost changes, please re-apply. Reason: 5579 is a complete disaster.
Not only does it change tons of files to switch to a new and non-working (it doesn't parse my ini files, at least) ini parser, it also reshuffles a lot of code and removes a plugin. The latter part is fine, but doing these two major switches in one revision, one of which is broken, is completely unacceptable. I said to merge tiny changes, not massive reworkings.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5589 8ced0084-cf51-0410-be5f-012b33b47a6e
2010-06-03 18:05:08 +00:00

61 lines
1.1 KiB
C++

#ifndef _INIFILE_H_
#define _INIFILE_H_
#include <fstream>
#include <map>
#include <string>
#include <sstream>
//
// IniFile
//
class IniSection : public std::map< std::string, std::string >
{
public:
void Set( const std::string& key, const std::string& val, const std::string& def = "" );
std::string Get( const std::string& key, const std::string& def = "" );
template <typename V, typename D>
void Set( const std::string& key, const V& val, const D& def = 0 )
{
if ( val != def )
{
std::ostringstream ss;
ss << long(val);
operator[](key) = ss.str();
}
else
{
iterator f = find(key);
if ( f != end() )
erase( f );
}
}
template <typename V>
V Get( const std::string& key, const V& def = 0 )
{
const const_iterator f = find(key);
if ( f != end() )
if ( false == f->second.empty() )
{
std::istringstream ss(f->second);
int val;
ss >> val;
return V(val);
}
return def;
}
};
class IniFile : public std::map< std::string, IniSection >
{
public:
typedef IniSection Section;
void Clean();
void Save( std::ostream& file );
void Load( std::istream& file );
};
#endif