Files
itgmania212121/stepmania/src/IniFile.h
T

94 lines
2.9 KiB
C++
Raw Normal View History

2002-07-23 01:41:40 +00:00
#pragma once
/*
-----------------------------------------------------------------------------
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>
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
CString error;
//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);
//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 =
//overloaded to return CString, int, and double,
//returns "", or 0 if key/value not found. Sets error member to show problem
2002-08-22 22:12:29 +00:00
bool GetValue(const CString &key, const CString &valuename, CString& value);
bool GetValueI(const CString &key, const CString &valuename, int& value);
bool GetValueF(const CString &key, const CString &valuename, float& value);
bool GetValueB(const CString &key, const CString &valuename, bool& value);
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
//overloaded to accept CString, int, and double
2002-08-22 22:12:29 +00:00
bool SetValue(const CString &key, const CString &valuename, const CString &value, bool create = 1);
bool SetValueI(const CString &key, const CString &valuename, int value, bool create = 1);
bool SetValueF(const CString &key, const CString &valuename, float value, bool create = 1);
bool SetValueB(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
2002-10-24 23:08:18 +00:00
const_iterator GetKey(const CString &keyname) const;
2001-11-03 10:52:42 +00:00
};