Files
itgmania212121/stepmania/src/IniFile.h
T

135 lines
4.4 KiB
C++
Raw Normal View History

2004-05-23 02:27:51 +00:00
/* IniFile - Reading and writing .INI files. */
#ifndef INIFILE_H
#define INIFILE_H
2002-10-24 23:08:18 +00:00
#include <map>
using namespace std;
2002-10-24 23:08:18 +00:00
2004-12-10 09:46:09 +00:00
class RageBasicFile;
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
typedef keymap::iterator iterator;
iterator begin() { return keys.begin(); }
iterator end() { return keys.end(); }
2002-07-23 01:41:40 +00:00
private:
2004-05-23 02:27:51 +00:00
CString m_sPath;
2002-10-24 20:16:06 +00:00
2002-10-24 23:08:18 +00:00
keymap keys;
2001-11-03 10:52:42 +00:00
2004-05-23 02:27:51 +00:00
mutable CString m_sError;
2001-11-03 10:52:42 +00:00
public:
2004-05-23 02:27:51 +00:00
/* Retrieve the filename of the last file loaded. */
CString GetPath() const { return m_sPath; }
const CString &GetError() const { return m_sError; }
2001-11-03 10:52:42 +00:00
2004-05-23 02:27:51 +00:00
bool ReadFile( const CString &sPath );
2004-12-10 09:46:09 +00:00
bool ReadFile( RageBasicFile &sFile );
2004-05-23 02:27:51 +00:00
bool WriteFile( const CString &sPath );
2004-12-10 09:46:09 +00:00
bool WriteFile( RageBasicFile &sFile );
2001-11-03 10:52:42 +00:00
void Reset();
2002-10-24 23:08:18 +00:00
int GetNumKeys() const;
2004-05-23 02:27:51 +00:00
int GetNumValues( const CString &keyname ) const;
2001-11-03 10:52:42 +00:00
2004-05-23 02:27:51 +00:00
bool GetValue( const CString &key, const CString &valuename, CString& value ) const;
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
2004-05-23 02:27:51 +00:00
bool SetValue( const CString &key, const CString &valuename, const CString &value );
bool SetValue( const CString &key, const CString &valuename, int value );
bool SetValue( const CString &key, const CString &valuename, unsigned value );
bool SetValue( const CString &key, const CString &valuename, float value );
bool SetValue( const CString &key, const CString &valuename, bool value );
2001-11-03 10:52:42 +00:00
2004-05-23 02:27:51 +00:00
bool DeleteKey( const CString &keyname );
bool DeleteValue( const CString &keyname, const CString &valuename );
2001-11-03 10:52:42 +00:00
2004-05-23 02:27:51 +00:00
const key *GetKey( const CString &keyname ) const;
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. */
2004-05-23 02:27:51 +00:00
void RenameKey( const CString &from, const CString &to );
2001-11-03 10:52:42 +00:00
};
class IniFilePreserveOrder
{
public:
// all keys are of this type
typedef pair<CString, CString> key_value;
typedef vector<key_value> key;
typedef pair<CString, key> keymap_value;
typedef vector<keymap_value> keymap;
typedef keymap::const_iterator const_iterator;
const_iterator begin() const { return keys.begin(); }
const_iterator end() const { return keys.end(); }
typedef keymap::iterator iterator;
iterator begin() { return keys.begin(); }
iterator end() { return keys.end(); }
private:
CString m_sPath;
keymap keys;
mutable CString m_sError;
public:
/* Retrieve the filename of the last file loaded. */
CString GetPath() const { return m_sPath; }
const CString &GetError() const { return m_sError; }
bool ReadFile( const CString &sPath );
bool WriteFile( const CString &sPath );
bool SetValue( const CString &key, const CString &valuename, const CString &value );
};
#endif
2004-05-23 02:27:51 +00:00
/*
* (c) 2001-2004 Adam Clauss, Chris Danford
*
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/