2002-07-23 01:41:40 +00:00
|
|
|
#pragma once
|
2001-11-04 19:34:28 +00:00
|
|
|
/*
|
|
|
|
|
-----------------------------------------------------------------------------
|
2002-07-23 01:41:40 +00:00
|
|
|
Class: IniFile
|
2001-11-04 19:34:28 +00:00
|
|
|
|
|
|
|
|
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
|
2001-11-04 19:34:28 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
class IniFile
|
|
|
|
|
{
|
|
|
|
|
//all private variables
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
//stores pathname of ini file to read/write
|
|
|
|
|
CString path;
|
|
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
public:
|
2001-11-03 10:52:42 +00:00
|
|
|
//all keys are of this time
|
2002-07-23 01:41:40 +00:00
|
|
|
struct key
|
|
|
|
|
{
|
|
|
|
|
//list of values in key
|
|
|
|
|
CArray<CString, CString> values;
|
2001-11-03 10:52:42 +00:00
|
|
|
|
2002-07-23 01:41:40 +00:00
|
|
|
//corresponding list of value names
|
|
|
|
|
CArray<CString, CString> names;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
2001-11-03 10:52:42 +00:00
|
|
|
//list of keys in ini
|
|
|
|
|
CArray<key, key> keys;
|
|
|
|
|
|
|
|
|
|
//corresponding list of keynames
|
|
|
|
|
CArray<CString, CString> names;
|
2002-07-23 01:41:40 +00:00
|
|
|
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
//all private functions
|
|
|
|
|
private:
|
2002-07-23 01:41:40 +00:00
|
|
|
//returns index of specified value, in the specified key, or -1 if not found
|
|
|
|
|
int FindValue(int keynum, CString valuename);
|
2001-11-03 10:52:42 +00:00
|
|
|
|
|
|
|
|
//returns index of specified key, or -1 if not found
|
|
|
|
|
int FindKey(CString keyname);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//public variables
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
//will contain error info if one occurs
|
|
|
|
|
//ended up not using much, just in ReadFile and GetValue
|
|
|
|
|
CString error;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//public functions
|
|
|
|
|
public:
|
|
|
|
|
//default constructor
|
|
|
|
|
IniFile();
|
|
|
|
|
|
|
|
|
|
//constructor, can specify pathname here instead of using SetPath later
|
|
|
|
|
IniFile(CString inipath);
|
|
|
|
|
|
|
|
|
|
//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
|
|
|
|
|
int GetNumKeys();
|
|
|
|
|
|
|
|
|
|
//returns number of values stored for specified key
|
2002-07-23 01:41:40 +00:00
|
|
|
int GetNumValues(CString keyname);
|
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-07-23 01:41:40 +00:00
|
|
|
bool GetValue(CString key, CString valuename, CString& value);
|
|
|
|
|
bool GetValueI(CString key, CString valuename, int& value);
|
|
|
|
|
bool GetValueF(CString key, CString valuename, float& value);
|
|
|
|
|
bool GetValueB(CString key, 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-07-23 01:41:40 +00:00
|
|
|
bool SetValue(CString key, CString valuename, CString value, bool create = 1);
|
|
|
|
|
bool SetValueI(CString key, CString valuename, int value, bool create = 1);
|
|
|
|
|
bool SetValueF(CString key, CString valuename, float value, bool create = 1);
|
|
|
|
|
bool SetValueB(CString key, 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-07-23 01:41:40 +00:00
|
|
|
bool DeleteValue(CString keyname, 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-07-23 01:41:40 +00:00
|
|
|
bool DeleteKey(CString keyname);
|
|
|
|
|
|
|
|
|
|
key* GetKey(CString keyname);
|
2001-11-03 10:52:42 +00:00
|
|
|
};
|