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
This commit is contained in:
hrydgard
2010-06-03 18:05:08 +00:00
parent 3236aa9e73
commit a3c96ac42c
118 changed files with 8868 additions and 2530 deletions

View File

@ -18,105 +18,74 @@
#ifndef _INIFILE_H_
#define _INIFILE_H_
#include "CommonTypes.h"
#include <fstream>
#include <map>
#include <string>
#include <sstream>
#include <vector>
// some things that include IniFile.h rely on this being here
#include "StringUtil.h"
class IniFile;
class Section : public std::map<std::string, std::string>
class Section
{
friend class IniFile;
public:
Section() : m_use_lines(false) {}
Section();
Section(const std::string& _name);
Section(const Section& other);
std::vector<std::string>lines;
std::string name;
std::string comment;
bool Exists(const std::string& key) const;
void Delete(const std::string& key);
void SetLines(const std::vector<std::string>& lines);
void GetLines(std::vector<std::string>& lines);
bool Get(const std::string& key, std::string* const val, const std::string& def = "") const;
void Set(const std::string& key, const std::string& val, const std::string& def = "");
template <typename V>
void Set(const std::string& key, const V val)
bool operator<(const Section& other) const
{
std::ostringstream ss;
ss << val;
operator[](key) = ss.str();
return(name < other.name);
}
// if val doesn't match def, set the key's value to val
// otherwise delete that key
//
// this removed a lot of redundant code in the game-properties stuff
template <typename V, typename D>
void Set(const std::string& key, const V val, const D def)
{
if (val != def)
Set(key, val);
else
{
iterator f = find(key);
if (f != end())
erase(f);
}
}
template <typename V>
bool Get(const std::string& key, V* const val) const
{
const const_iterator f = find(key);
if (f != end())
{
std::istringstream ss(f->second);
ss >> *val;
return true;
}
return false;
}
template <typename V, typename D>
bool Get(const std::string& key, V* const val, const D def) const
{
if (Get(key, val))
return true;
*val = def;
return false;
}
protected:
void Save(std::ostream& file) const;
std::vector<std::string> m_lines;
private:
bool m_use_lines;
};
class IniFile : public std::map<std::string, Section>
class IniFile
{
public:
void Clean();
bool Exists(const std::string& section) const;
void Delete(const std::string& section);
IniFile();
~IniFile();
bool Save(const char filename[]) const;
bool Load(const char filename[]);
bool Load(const char* filename);
bool Save(const char* filename);
bool Save(const std::string& filename) const;
bool Load(const std::string& filename);
void Set(const char* sectionName, const char* key, const char* newValue);
void Set(const char* sectionName, const char* key, int newValue);
void Set(const char* sectionName, const char* key, u32 newValue);
void Set(const char* sectionName, const char* key, bool newValue);
void Set(const char* sectionName, const char* key, const std::string& newValue) {Set(sectionName, key, newValue.c_str());}
void Set(const char* sectionName, const char* key, const std::vector<std::string>& newValues);
void Save(std::ostream& file) const;
void Load(std::istream& file);
void SetLines(const char* sectionName, const std::vector<std::string> &lines);
// Returns true if exists key in section
bool Exists(const char* sectionName, const char* key) const;
// getter should be const
bool Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue = "");
bool Get(const char* sectionName, const char* key, int* value, int defaultValue = 0);
bool Get(const char* sectionName, const char* key, u32* value, u32 defaultValue = 0);
bool Get(const char* sectionName, const char* key, bool* value, bool defaultValue = false);
bool Get(const char* sectionName, const char* key, std::vector<std::string>& values);
bool GetKeys(const char* sectionName, std::vector<std::string>& keys) const;
bool GetLines(const char* sectionName, std::vector<std::string>& lines) const;
bool DeleteKey(const char* sectionName, const char* key);
bool DeleteSection(const char* sectionName);
void SortSections();
void ParseLine(const std::string& line, std::string* keyOut, std::string* valueOut, std::string* commentOut) const;
std::string* GetLine(Section* section, const char* key, std::string* valueOut, std::string* commentOut);
private:
std::vector<Section>sections;
const Section* GetSection(const char* section) const;
Section* GetSection(const char* section);
Section* GetOrCreateSection(const char* section);
std::string* GetLine(const char* section, const char* key);
void CreateSection(const char* section);
};
#endif // _INIFILE_H_