#include "Config.h" #include CConfigurator::CConfigurator() { } CConfigurator::~CConfigurator() { } bool CConfigurator::Load(const char* szFileName) { FILE* lpFile = fopen(szFileName, "rt"); if(NULL != lpFile) { const int MAX_READ = 4096; char szRead[MAX_READ]; char* szDelimitChars = " =\t\n\r"; while(fgets(szRead, MAX_READ, lpFile)) { const char* szCommand = strtok(szRead, szDelimitChars); const char* szValue = strtok(NULL, szDelimitChars); if(0 != szCommand && 0 != szValue) { if(0 != strncmp(szCommand, TEXT("//"), strlen(TEXT("//")))) { m_ConfigMap.insert(std::make_pair(szCommand, szValue)); } } } fclose(lpFile); return true; } return false; } const char* CConfigurator::Get(const char* szKey) { ConfigMap::iterator end = m_ConfigMap.end(); ConfigMap::iterator find = m_ConfigMap.find(szKey); if(end != find) { return find->second.c_str(); } return 0; } void CConfigurator::Clear() { m_ConfigMap.clear(); }