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

📄 profile.hpp

📁 联通接收发送新程序
💻 HPP
字号:
/**************************************************************************/
/*	Copyright(C) 2001 by Nanjing XINWANG TEC CO.,LTD.					  */
/**************************************************************************/
/*	Name:		profile.hpp				Version: 1.0.0					  */
/*	Created by:	Zhangbo					Date: 2001-12-04				  */
/*	Content:	declare of class Profile								  */
/*	Comment:	read and write configuration							  */
/*	Modified:															  */
/**************************************************************************/

#ifndef	_PROFILE_HPP_
#define	_PROFILE_HPP_

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "log.hpp"

#include "mystring.hpp"

//default profile name
static const char	DEFAULT_FILE[]="..\\config\\cmicp.ini";
//length of one profile line
static const int	LINE_LEN = 1024;	

class Profile
{
public:
	Profile(const char* sProfile = DEFAULT_FILE)
	{
		assert((NULL != sProfile) && (0 != strlen(sProfile)));

		m_sFileName = new char[strlen(sProfile) + 1];
		if (NULL == m_sFileName)
		{
			g_clLog.Panic(0, "Memory exhausted !");
		}
		strcpy(m_sFileName, sProfile);

		m_pFile = fopen(m_sFileName, "r+");
		if (NULL == m_pFile)
		{
			g_clLog.Panic(errno, "Unable to open profile %s !", m_sFileName);
		}
	}

	~Profile()
	{
		if (NULL != m_sFileName)
		{
			delete []m_sFileName;
		}

		if (NULL != m_pFile) 
		{
			fclose(m_pFile);
			m_pFile = NULL;
		}
	}

	//COMMENT:	set profile name, and open it
	//INPUT:	sProfile -- name of profile
	//OUTPUT:	none
	//RETURN:	none
	void SetFileName(const char* sProfile);

	//COMMENT:	read profile
	//INPUT:	IsSection -- profile section name
	//			IsEntry -- profile entry name
	//OUTPUT:	sValue -- profile entry value
	//RETURN:	0 for OK, -1 for error
	int Read(const char* sSection, const char* sEntry, char* sValue);

	//COMMENT:	read the value with same section and entry of last reading
	//INPUT:	none
	//OUTPUT:	sValue -- profile entry value
	//RETURN:	0 for OK, -1 for error
	int ReadNext(char* sValue);

private:
	char*	m_sFileName;		//name of profile to be readed
	FILE*	m_pFile;			//file pointer of profile
	char	m_sSection[20 + 1];	//profile section name
	char	m_sEntry[LINE_LEN + 1];		//profile entry name

	//COMMENT:	search the section 
	//INPUT:	none
	//OUTPUT:	none
	//RETURN:	file get point after section.
	//			-1 for section is not in profile
	long SearchSection();

	//COMMENT:	search the entry
	//INPUT:	none
	//OUTPUT:	sValue -- the entry value user needed
	//RETURN:	file get point before section.
	//			-1 for section is not in profile
	long SearchEntry(char* sValue);
};

extern Profile g_clProfile; //global variable

#endif

⌨️ 快捷键说明

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