cbinconfig.cpp

来自「液晶电视完整代码可实现人机界面」· C++ 代码 · 共 88 行

CPP
88
字号
#include "CBinConfig.h"///////////////////////////////////////////////////////////////////////////////CBinConfig::CBinConfig(char* confilename){	m_IsReady = true;	m_config = new tagBinConfig;	LoadInfoFromXml(confilename);	printf("从XML中载入参数完成\n\n");}///////////////////////////////////////////////////////////////////////////////int CBinConfig::LoadInfoFromXml(char *xmlfilename){	int iRetval = 0, counter;	printf("配置文件 = [%s]\n", xmlfilename);	CBaseNode baseNode(xmlfilename);	bool bRetval = baseNode.IsReady();	if(bRetval) //如果对XML初始化成功 那么开始读入XML中内容	{		baseNode.GetAttributeValue(baseNode.GetRootNode(), 																"madefor", 																m_config->madefor, "0");		printf("madefor = [%s]  ", m_config->madefor);		baseNode.GetAttributeValue(baseNode.GetRootNode(), 																"desc", 																m_config->desc, "0");		printf("desc = [%s]  ", m_config->desc);		baseNode.GetAttributeValue(baseNode.GetRootNode(), 																"parametercount", 																m_config->parametercount, "0");		printf("parametercount = [%s]\n", m_config->parametercount);				m_config->pameters = (tagBinParameter *)malloc(sizeof(tagBinParameter) * atoi(m_config->parametercount));		NODELIST tagList = baseNode.GetRootNode()->children;		counter = 0;		while(tagList != NULL)		{			if(counter <= (atoi(m_config->parametercount) -1))			{				if(baseNode.IsRightNode(tagList, "parameter"))				{					baseNode.GetAttributeValue(tagList, "name", m_config->pameters[counter].name, "0");					printf("name    = [%-15s]   ", m_config->pameters[counter].name);					baseNode.GetAttributeValue(tagList, "value", m_config->pameters[counter].value, "");					printf("value = [%-8s]   ", m_config->pameters[counter].value);					baseNode.GetAttributeValue(tagList, "desc", m_config->pameters[counter].desc, "");					printf("desc = [%-20s]\n", m_config->pameters[counter].desc);										counter++;				}			}			else			{				printf("\n配置文件中参数个数与实际内容不符! 配置文件配置有错误!\n");				m_IsReady = false;				break;			}			tagList = tagList->next;		}	}	return iRetval;}///////////////////////////////////////////////////////////////////////////////bool CBinConfig::GetParameterValueByName(const char* name, char* value){	bool result = false;	if(!m_IsReady)	{		return result;	}	int I;	for(I = 0; I < atoi(m_config->parametercount); I++)	{		if(strcmp(name, m_config->pameters[I].name) == 0)		{			memcpy(value, m_config->pameters[I].value, strlen(m_config->pameters[I].value));			result = true;			break;		}	}	return result;}

⌨️ 快捷键说明

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