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

📄 titlefile.cpp

📁 基于SAA7113的MPEG-4程序
💻 CPP
字号:
// TitleFile.cpp: implementation of the CTitleFile class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TitleFile.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTitleFile* CTitleFile::m_pInstance = NULL;

CTitleFile* CTitleFile::getInstance()
{
	if(m_pInstance==NULL)
		m_pInstance = new CTitleFile();

	return m_pInstance;

}

void CTitleFile::releaseInstance()
{
	if(m_pInstance)
		delete m_pInstance;

	m_pInstance = NULL;
}

CTitleFile::CTitleFile()
{
	m_strFileName = "";
}

CTitleFile::~CTitleFile()
{

}

void CTitleFile::InitFile(CString strFile)
{
	m_strFileName = strFile;
}

//设置某一个KEY下的ValueName和Value
void CTitleFile::SetValue(CString strKey,CString strName,CString strValue)
{
	if(m_strFileName.IsEmpty())
		return;

	CIniFile tf;
	string path(m_strFileName.GetBuffer(0));
	tf.SetPath(path);
	m_strFileName.ReleaseBuffer();

	tf.ReadFile();

	string strkey(strKey.GetBuffer(0));
	string strvaluename(strName.GetBuffer(0));
	string strvalue(strValue.GetBuffer(0));
	
	tf.SetValue(strkey,strvaluename,strvalue);

	strKey.ReleaseBuffer();
	strName.ReleaseBuffer();
	strValue.ReleaseBuffer();

	tf.WriteFile();
}

//获得某KEY下的某ValueName的Value
void CTitleFile::GetValue(CString strKey,CString strName,CString& strValue)
{
	if(m_strFileName.IsEmpty())
		return;

	CIniFile tf;
	string path(m_strFileName.GetBuffer(0));
	tf.SetPath(path);
	m_strFileName.ReleaseBuffer();

	tf.ReadFile();

	string strkey(strKey.GetBuffer(0));
	string strvaluename(strName.GetBuffer(0));
	string strvalue;
	
	strvalue = tf.GetValue(strkey,strvaluename);

	strValue.Format("%s",strvalue.c_str());

	strKey.ReleaseBuffer();
	strName.ReleaseBuffer();

}

//删除某一个KEY下的ValueName
void CTitleFile::DelValue(CString strKey,CString strName)
{
	if(m_strFileName.IsEmpty())
		return;

	CIniFile tf;
	string path(m_strFileName.GetBuffer(0));
	tf.SetPath(path);
	m_strFileName.ReleaseBuffer();

	tf.ReadFile();
		
	string strkey(strKey.GetBuffer(0));
	string strvalue(strName.GetBuffer(0));

	int inum = tf.GetNumValues(strkey);
	
	tf.DeleteValue(strkey,strvalue);

	if(inum<=1)
		tf.DeleteKey(strkey);
	
	strKey.ReleaseBuffer();
	strName.ReleaseBuffer();

	tf.WriteFile();
}

//删除所有的KEY及其ValueName
void CTitleFile::DelAllKeys()
{
	if(m_strFileName.IsEmpty())
		return;

	CIniFile tf;
	string path(m_strFileName.GetBuffer(0));
	tf.SetPath(path);
	m_strFileName.ReleaseBuffer();

	tf.Reset();

	tf.WriteFile();
}

//获得所有KEY
void CTitleFile::GetAllKeys(CStringList& strKeyList)
{
	if(m_strFileName.IsEmpty())
		return;

	strKeyList.RemoveAll();

	CIniFile tf;
	string path(m_strFileName.GetBuffer(0));
	tf.SetPath(path);
	m_strFileName.ReleaseBuffer();
	
	tf.ReadFile();

	for(int i=0;i<tf.GetNumKeys();i++)
	{
		string strtemp;
		strtemp = tf.GetKeyName(i);
		
		CString strr ;
		strr.Format("%s",strtemp.c_str());
		strKeyList.AddTail(strr);
	}	
}

//获得某KEY下的所有ValueName
void CTitleFile::GetAllNamesInKey(CString strKey,CStringList& strNameList)
{
	if(m_strFileName.IsEmpty())
		return;

	CIniFile tf;
	string path(m_strFileName.GetBuffer(0));
	tf.SetPath(path);
	m_strFileName.ReleaseBuffer();	

	tf.ReadFile();
	
	
	strNameList.RemoveAll();

	string strkey(strKey.GetBuffer(0));
	int indexKey = tf.FindKey(strkey);	
	for(int i=0;i<tf.NumValues(indexKey);i++)
	{
		string strtemp;
		strtemp = tf.GetValueName(strkey,i);
		
		CString strr ;
		strr.Format("%s",strtemp.c_str());
		strNameList.AddTail(strr);
	}
}

⌨️ 快捷键说明

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