mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 21:30:19 -06:00
Reformat all the things. Have fun with merge conflicts.
This commit is contained in:
@ -16,141 +16,135 @@
|
||||
|
||||
struct CaseInsensitiveStringCompare
|
||||
{
|
||||
bool operator() (const std::string& a, const std::string& b) const
|
||||
{
|
||||
return strcasecmp(a.c_str(), b.c_str()) < 0;
|
||||
}
|
||||
bool operator()(const std::string& a, const std::string& b) const
|
||||
{
|
||||
return strcasecmp(a.c_str(), b.c_str()) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
class IniFile
|
||||
{
|
||||
public:
|
||||
class Section
|
||||
{
|
||||
friend class IniFile;
|
||||
class Section
|
||||
{
|
||||
friend class IniFile;
|
||||
|
||||
public:
|
||||
Section() {}
|
||||
Section(const std::string& _name) : name(_name) {}
|
||||
public:
|
||||
Section() {}
|
||||
Section(const std::string& _name) : name(_name) {}
|
||||
bool Exists(const std::string& key) const;
|
||||
bool Delete(const std::string& key);
|
||||
|
||||
bool Exists(const std::string& key) const;
|
||||
bool Delete(const std::string& key);
|
||||
void Set(const std::string& key, const std::string& newValue);
|
||||
void Set(const std::string& key, const std::string& newValue, const std::string& defaultValue);
|
||||
|
||||
void Set(const std::string& key, const std::string& newValue);
|
||||
void Set(const std::string& key, const std::string& newValue, const std::string& defaultValue);
|
||||
void Set(const std::string& key, u32 newValue)
|
||||
{
|
||||
Set(key, StringFromFormat("0x%08x", newValue));
|
||||
}
|
||||
|
||||
void Set(const std::string& key, u32 newValue)
|
||||
{
|
||||
Set(key, StringFromFormat("0x%08x", newValue));
|
||||
}
|
||||
void Set(const std::string& key, float newValue)
|
||||
{
|
||||
Set(key, StringFromFormat("%#.9g", newValue));
|
||||
}
|
||||
|
||||
void Set(const std::string& key, float newValue)
|
||||
{
|
||||
Set(key, StringFromFormat("%#.9g", newValue));
|
||||
}
|
||||
void Set(const std::string& key, double newValue)
|
||||
{
|
||||
Set(key, StringFromFormat("%#.17g", newValue));
|
||||
}
|
||||
|
||||
void Set(const std::string& key, double newValue)
|
||||
{
|
||||
Set(key, StringFromFormat("%#.17g", newValue));
|
||||
}
|
||||
void Set(const std::string& key, int newValue) { Set(key, StringFromInt(newValue)); }
|
||||
void Set(const std::string& key, bool newValue) { Set(key, StringFromBool(newValue)); }
|
||||
template <typename T>
|
||||
void Set(const std::string& key, T newValue, const T defaultValue)
|
||||
{
|
||||
if (newValue != defaultValue)
|
||||
Set(key, newValue);
|
||||
else
|
||||
Delete(key);
|
||||
}
|
||||
|
||||
void Set(const std::string& key, int newValue)
|
||||
{
|
||||
Set(key, StringFromInt(newValue));
|
||||
}
|
||||
void Set(const std::string& key, const std::vector<std::string>& newValues);
|
||||
|
||||
void Set(const std::string& key, bool newValue)
|
||||
{
|
||||
Set(key, StringFromBool(newValue));
|
||||
}
|
||||
bool Get(const std::string& key, std::string* value,
|
||||
const std::string& defaultValue = NULL_STRING) const;
|
||||
bool Get(const std::string& key, int* value, int defaultValue = 0) const;
|
||||
bool Get(const std::string& key, u32* value, u32 defaultValue = 0) const;
|
||||
bool Get(const std::string& key, bool* value, bool defaultValue = false) const;
|
||||
bool Get(const std::string& key, float* value, float defaultValue = 0.0f) const;
|
||||
bool Get(const std::string& key, double* value, double defaultValue = 0.0) const;
|
||||
bool Get(const std::string& key, std::vector<std::string>* values) const;
|
||||
|
||||
template<typename T>
|
||||
void Set(const std::string& key, T newValue, const T defaultValue)
|
||||
{
|
||||
if (newValue != defaultValue)
|
||||
Set(key, newValue);
|
||||
else
|
||||
Delete(key);
|
||||
}
|
||||
bool operator<(const Section& other) const { return name < other.name; }
|
||||
protected:
|
||||
std::string name;
|
||||
|
||||
void Set(const std::string& key, const std::vector<std::string>& newValues);
|
||||
std::vector<std::string> keys_order;
|
||||
std::map<std::string, std::string, CaseInsensitiveStringCompare> values;
|
||||
|
||||
bool Get(const std::string& key, std::string* value, const std::string& defaultValue = NULL_STRING) const;
|
||||
bool Get(const std::string& key, int* value, int defaultValue = 0) const;
|
||||
bool Get(const std::string& key, u32* value, u32 defaultValue = 0) const;
|
||||
bool Get(const std::string& key, bool* value, bool defaultValue = false) const;
|
||||
bool Get(const std::string& key, float* value, float defaultValue = 0.0f) const;
|
||||
bool Get(const std::string& key, double* value, double defaultValue = 0.0) const;
|
||||
bool Get(const std::string& key, std::vector<std::string>* values) const;
|
||||
std::vector<std::string> lines;
|
||||
};
|
||||
|
||||
bool operator < (const Section& other) const
|
||||
{
|
||||
return name < other.name;
|
||||
}
|
||||
/**
|
||||
* Loads sections and keys.
|
||||
* @param filename filename of the ini file which should be loaded
|
||||
* @param keep_current_data If true, "extends" the currently loaded list of sections and keys with
|
||||
* the loaded data (and replaces existing entries). If false, existing data will be erased.
|
||||
* @warning Using any other operations than "Get*" and "Exists" is untested and will behave
|
||||
* unexpectedly
|
||||
* @todo This really is just a hack to support having two levels of gameinis (defaults and
|
||||
* user-specified) and should eventually be replaced with a less stupid system.
|
||||
*/
|
||||
bool Load(const std::string& filename, bool keep_current_data = false);
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
bool Save(const std::string& filename);
|
||||
|
||||
std::vector<std::string> keys_order;
|
||||
std::map<std::string, std::string, CaseInsensitiveStringCompare> values;
|
||||
// Returns true if key exists in section
|
||||
bool Exists(const std::string& sectionName, const std::string& key) const;
|
||||
|
||||
std::vector<std::string> lines;
|
||||
};
|
||||
template <typename T>
|
||||
bool GetIfExists(const std::string& sectionName, const std::string& key, T* value)
|
||||
{
|
||||
if (Exists(sectionName, key))
|
||||
return GetOrCreateSection(sectionName)->Get(key, value);
|
||||
|
||||
/**
|
||||
* Loads sections and keys.
|
||||
* @param filename filename of the ini file which should be loaded
|
||||
* @param keep_current_data If true, "extends" the currently loaded list of sections and keys with the loaded data (and replaces existing entries). If false, existing data will be erased.
|
||||
* @warning Using any other operations than "Get*" and "Exists" is untested and will behave unexpectedly
|
||||
* @todo This really is just a hack to support having two levels of gameinis (defaults and user-specified) and should eventually be replaced with a less stupid system.
|
||||
*/
|
||||
bool Load(const std::string& filename, bool keep_current_data = false);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Save(const std::string& filename);
|
||||
template <typename T>
|
||||
bool GetIfExists(const std::string& sectionName, const std::string& key, T* value, T defaultValue)
|
||||
{
|
||||
if (Exists(sectionName, key))
|
||||
return GetOrCreateSection(sectionName)->Get(key, value, defaultValue);
|
||||
else
|
||||
*value = defaultValue;
|
||||
|
||||
// Returns true if key exists in section
|
||||
bool Exists(const std::string& sectionName, const std::string& key) const;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T> bool GetIfExists(const std::string& sectionName, const std::string& key, T* value)
|
||||
{
|
||||
if (Exists(sectionName, key))
|
||||
return GetOrCreateSection(sectionName)->Get(key, value);
|
||||
bool GetKeys(const std::string& sectionName, std::vector<std::string>* keys) const;
|
||||
|
||||
return false;
|
||||
}
|
||||
void SetLines(const std::string& sectionName, const std::vector<std::string>& lines);
|
||||
bool GetLines(const std::string& sectionName, std::vector<std::string>* lines,
|
||||
const bool remove_comments = true) const;
|
||||
|
||||
template<typename T> bool GetIfExists(const std::string& sectionName, const std::string& key, T* value, T defaultValue)
|
||||
{
|
||||
if (Exists(sectionName, key))
|
||||
return GetOrCreateSection(sectionName)->Get(key, value, defaultValue);
|
||||
else
|
||||
*value = defaultValue;
|
||||
bool DeleteKey(const std::string& sectionName, const std::string& key);
|
||||
bool DeleteSection(const std::string& sectionName);
|
||||
|
||||
return false;
|
||||
}
|
||||
void SortSections();
|
||||
|
||||
bool GetKeys(const std::string& sectionName, std::vector<std::string>* keys) const;
|
||||
Section* GetOrCreateSection(const std::string& section);
|
||||
|
||||
void SetLines(const std::string& sectionName, const std::vector<std::string>& lines);
|
||||
bool GetLines(const std::string& sectionName, std::vector<std::string>* lines, const bool remove_comments = true) const;
|
||||
|
||||
bool DeleteKey(const std::string& sectionName, const std::string& key);
|
||||
bool DeleteSection(const std::string& sectionName);
|
||||
|
||||
void SortSections();
|
||||
|
||||
Section* GetOrCreateSection(const std::string& section);
|
||||
|
||||
// This function is related to parsing data from lines of INI files
|
||||
// It's used outside of IniFile, which is why it is exposed publicly
|
||||
// In particular it is used in PostProcessing for its configuration
|
||||
static void ParseLine(const std::string& line, std::string* keyOut, std::string* valueOut);
|
||||
// This function is related to parsing data from lines of INI files
|
||||
// It's used outside of IniFile, which is why it is exposed publicly
|
||||
// In particular it is used in PostProcessing for its configuration
|
||||
static void ParseLine(const std::string& line, std::string* keyOut, std::string* valueOut);
|
||||
|
||||
private:
|
||||
std::list<Section> sections;
|
||||
std::list<Section> sections;
|
||||
|
||||
const Section* GetSection(const std::string& section) const;
|
||||
Section* GetSection(const std::string& section);
|
||||
const Section* GetSection(const std::string& section) const;
|
||||
Section* GetSection(const std::string& section);
|
||||
|
||||
static const std::string& NULL_STRING;
|
||||
static const std::string& NULL_STRING;
|
||||
};
|
||||
|
Reference in New Issue
Block a user