2008-07-12 17:40:22 +00:00
|
|
|
// Copyright (C) 2003-2008 Dolphin Project.
|
|
|
|
|
|
|
|
// 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, version 2.0.
|
|
|
|
|
|
|
|
// 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
|
|
|
#ifndef _INIFILE_H
|
|
|
|
#define _INIFILE_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "StringUtil.h"
|
|
|
|
|
|
|
|
class Section
|
|
|
|
{
|
2008-10-13 19:21:25 +00:00
|
|
|
public:
|
|
|
|
Section();
|
|
|
|
Section(const std::string& _name);
|
|
|
|
Section(const Section& other);
|
|
|
|
std::vector<std::string>lines;
|
|
|
|
std::string name;
|
|
|
|
std::string comment;
|
|
|
|
|
|
|
|
bool operator<(const Section& other) const
|
|
|
|
{
|
|
|
|
return(name < other.name);
|
|
|
|
}
|
2008-07-12 17:40:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IniFile
|
|
|
|
{
|
2008-10-13 19:21:25 +00:00
|
|
|
public:
|
|
|
|
IniFile();
|
|
|
|
~IniFile();
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-13 19:21:25 +00:00
|
|
|
bool Load(const char* filename);
|
|
|
|
bool Save(const char* filename);
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-13 19:21:25 +00:00
|
|
|
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);
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-13 19:21:25 +00:00
|
|
|
// 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);
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-13 19:21:25 +00:00
|
|
|
bool GetKeys(const char* sectionName, std::vector<std::string>& keys);
|
|
|
|
bool GetLines(const char* sectionName, std::vector<std::string>& lines);
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-13 19:21:25 +00:00
|
|
|
bool DeleteKey(const char* sectionName, const char* key);
|
|
|
|
bool DeleteSection(const char* sectionName);
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-13 19:21:25 +00:00
|
|
|
void SortSections();
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-13 19:21:25 +00:00
|
|
|
void ParseLine(const std::string& line, std::string* keyOut, std::string* valueOut, std::string* commentOut);
|
|
|
|
std::string* GetLine(Section* section, const char* key, std::string* valueOut, std::string* commentOut);
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-13 19:21:25 +00:00
|
|
|
private:
|
|
|
|
std::vector<Section>sections;
|
2008-07-12 17:40:22 +00:00
|
|
|
|
2008-10-13 19:21:25 +00:00
|
|
|
Section* GetSection(const char* section);
|
|
|
|
Section* GetOrCreateSection(const char* section);
|
|
|
|
std::string* GetLine(const char* section, const char* key);
|
|
|
|
void CreateSection(const char* section);
|
2008-07-12 17:40:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|