Files
itgmania212121/stepmania/src/IniFile.h
T

105 lines
3.4 KiB
C++
Raw Normal View History

#ifndef INIFILE_H
#define INIFILE_H
/*
-----------------------------------------------------------------------------
2002-07-23 01:41:40 +00:00
Class: IniFile
Desc: Wrapper for reading and writing an .ini file.
2002-05-19 01:59:48 +00:00
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
2002-07-23 01:41:40 +00:00
Adam Clauss
Chris Danford
-----------------------------------------------------------------------------
*/
2002-10-24 23:08:18 +00:00
#include <map>
using namespace std;
2002-10-24 23:08:18 +00:00
2001-11-03 10:52:42 +00:00
class IniFile
{
2002-07-23 01:41:40 +00:00
public:
2002-10-24 20:16:06 +00:00
// all keys are of this type
2001-11-03 10:52:42 +00:00
2002-10-24 23:08:18 +00:00
typedef map<CString, CString> key;
typedef map<CString, key> keymap;
typedef keymap::const_iterator const_iterator;
const_iterator begin() const { return keys.begin(); }
const_iterator end() const { return keys.end(); }
2002-07-23 01:41:40 +00:00
private:
2002-10-24 20:16:06 +00:00
//stores pathname of ini file to read/write
CString path;
2002-10-24 23:08:18 +00:00
// keys in ini
keymap keys;
2001-11-03 10:52:42 +00:00
public:
//will contain error info if one occurs
//ended up not using much, just in ReadFile and GetValue
2003-05-22 19:35:57 +00:00
mutable CString error;
2001-11-03 10:52:42 +00:00
//constructor, can specify pathname here instead of using SetPath later
2002-08-20 02:12:19 +00:00
IniFile(CString inipath = "");
2001-11-03 10:52:42 +00:00
//default destructor
virtual ~IniFile();
//sets path of ini file to read and write from
void SetPath(CString newpath);
2003-01-05 02:54:44 +00:00
CString GetPath() const { return path; }
2001-11-03 10:52:42 +00:00
//reads ini file specified using IniFile::SetPath()
//returns true if successful, false otherwise
2002-07-23 01:41:40 +00:00
bool ReadFile();
2001-11-03 10:52:42 +00:00
//writes data stored in class to ini file
void WriteFile();
//deletes all stored ini data
void Reset();
//returns number of keys currently in the ini
2002-10-24 23:08:18 +00:00
int GetNumKeys() const;
2001-11-03 10:52:42 +00:00
//returns number of values stored for specified key
2002-10-24 23:08:18 +00:00
int GetNumValues(const CString &keyname) const;
2001-11-03 10:52:42 +00:00
//gets value of [keyname] valuename =
//returns "", or 0 if key/value not found. Sets error member to show problem
2003-05-22 19:35:57 +00:00
bool GetValue(const CString &key, const CString &valuename, CString& value) const;
2003-10-02 02:03:29 +00:00
bool GetValue(const CString &key, const CString &valuename, int& value) const;
bool GetValue(const CString &key, const CString &valuename, unsigned& value) const;
bool GetValue(const CString &key, const CString &valuename, float& value) const;
bool GetValue(const CString &key, const CString &valuename, bool& value) const;
2001-11-03 10:52:42 +00:00
//sets value of [keyname] valuename =.
//specify the optional paramter as false (0) if you do not want it to create
//the key if it doesn't exist. Returns true if data entered, false otherwise
2002-08-22 22:12:29 +00:00
bool SetValue(const CString &key, const CString &valuename, const CString &value, bool create = 1);
2003-10-02 02:11:47 +00:00
bool SetValue(const CString &key, const CString &valuename, int value, bool create = 1);
bool SetValue(const CString &key, const CString &valuename, unsigned value, bool create = 1);
bool SetValue(const CString &key, const CString &valuename, float value, bool create = 1);
bool SetValue(const CString &key, const CString &valuename, bool value, bool create = 1);
2001-11-03 10:52:42 +00:00
//deletes specified value
//returns true if value existed and deleted, false otherwise
2002-08-22 22:12:29 +00:00
bool DeleteValue(const CString &keyname, const CString &valuename);
2001-11-03 10:52:42 +00:00
//deletes specified key and all values contained within
//returns true if key existed and deleted, false otherwise
2002-08-22 22:12:29 +00:00
bool DeleteKey(const CString &keyname);
2002-07-23 01:41:40 +00:00
2003-01-03 22:37:44 +00:00
const key *GetKey(const CString &keyname) const;
2003-02-09 00:46:35 +00:00
void SetValue(const CString &keyname, const key &key);
2003-01-03 22:37:44 +00:00
/* Rename a key. For example, call RenameKey("foo", "main") after
* reading an INI where [foo] is an alias to [main]. If to already
* exists, nothing happens. */
void RenameKey(const CString &from, const CString &to);
2001-11-03 10:52:42 +00:00
};
#endif