⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inifile.h

📁 本人买的<<VC++项目开发实例>>源代码配套光盘.
💻 H
字号:
// IniFile.h: interface for the CIniFile class.
// Written by: Adam Clauss
// Email: pandcc3@comwerx.net
// You may use this class/code as you wish in your programs.  Feel free to distribute it, and
// email suggested changes to me.
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_INIFILE_H__D6BE0D97_13A8_11D4_A5D2_002078B03530__INCLUDED_)
#define AFX_INIFILE_H__D6BE0D97_13A8_11D4_A5D2_002078B03530__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afxtempl.h>
#include <iostream.h>
//##ModelId=3E18E0CF0000
class CIniFile  
{
	//all private variables
private:

	//stores pathname of ini file to read/write
	//##ModelId=3E18E0CF0001
	CString path;
	
	//all keys are of this time
	//##ModelId=3E18E0D00104
	struct key
	{
		//list of values in key
		//##ModelId=3E18E0D00106
		CArray<CString, CString> values; 

		//corresponding list of value names
		//##ModelId=3E18E0D00107
		CArray<CString, CString> names;
	};

	//list of keys in ini
	//##ModelId=3E18E0CF006F
	CArray<key, key> keys; 

	//corresponding list of keynames
	//##ModelId=3E18E0CF00A0
	CArray<CString, CString> names; 
	
	
	//all private functions
private:
	//overloaded to take CString
	//##ModelId=3E18E0CF00DC
	istream & getline( istream & is, CString & str );

	//returns index of specified value, in the specified key, or -1 if not found
	//##ModelId=3E18E0CF0110
	int FindValue(int keynum, CString valuename);

	//returns index of specified key, or -1 if not found
	//##ModelId=3E18E0CF014A
	int FindKey(CString keyname);


	//public variables
public:

	//will contain error info if one occurs
	//ended up not using much, just in ReadFile and GetValue
	//##ModelId=3E18E0CF014C
	CString error;


	//public functions
public:
	//##ModelId=3E18E0CF017C
	CString GetPath();
	//default constructor
	//##ModelId=3E18E0CF017D
	CIniFile();

	//constructor, can specify pathname here instead of using SetPath later
	//##ModelId=3E18E0CF01B8
	CIniFile(const CString& inipath);

	//default destructor
	//##ModelId=3E18E0CF01BA
	virtual ~CIniFile();

	//sets path of ini file to read and write from
	//##ModelId=3E18E0CF01EA
	void SetPath(CString newpath);

	//reads ini file specified using CIniFile::SetPath()
	//returns true if successful, false otherwise
	//##ModelId=3E18E0CF0226
	bool ReadFile();

	//writes data stored in class to ini file
	//##ModelId=3E18E0CF0227
	void WriteFile(); 

	//deletes all stored ini data
	//##ModelId=3E18E0CF0258
	void Reset();

	//returns number of keys currently in the ini
	//##ModelId=3E18E0CF0259
	int GetNumKeys();

	//returns number of values stored for specified key
	//##ModelId=3E18E0CF0294
	int GetNumValues(CString keyname);

	//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
	//##ModelId=3E18E0CF02C6
	CString GetValue(CString keyname, CString valuename); 
	//##ModelId=3E18E0CF02C9
	int GetValueI(CString keyname, CString valuename); 
	//##ModelId=3E18E0CF02CC
	double GetValueF(CString keyname, CString valuename);

	//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
	//##ModelId=3E18E0CF0304
	bool SetValue(CString keyname, CString valuename, CString value, bool create = 1);
	//##ModelId=3E18E0CF0335
	bool SetValueI(CString keyname, CString valuename, int value, bool create = 1);
	//##ModelId=3E18E0CF0370
	bool SetValueF(CString keyname, CString valuename, double value, bool create = 1);

	//deletes specified value
	//returns true if value existed and deleted, false otherwise
	//##ModelId=3E18E0CF0375
	bool DeleteValue(CString keyname, CString valuename);

	//deletes specified key and all values contained within
	//returns true if key existed and deleted, false otherwise
	//##ModelId=3E18E0CF03A4
	bool DeleteKey(CString keyname);
};

#endif // !defined(AFX_INIFILE_H__D6BE0D97_13A8_11D4_A5D2_002078B03530__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -