sSkillMapTable[skillTemp.GetID()] = skillTemp;
}
}
#include "CppCSV.h"
#include
//#include "stringparser.h"
bool CppCSV::LoadCSV(const char *path)
{
FILE *pFile = fopen(path, "r");
if (pFile)
{
fseek(pFile, 0, SEEK_END);
u32 uSize = ftell(pFile);
rewind(pFile);
char *fileBuffer = new char[uSize];
fread(fileBuffer, 1, uSize, pFile);
map
u32 uiIndex = 1;
char *pBegin = fileBuffer;
char *pEnd = strchr(pBegin, '\n');
pBegin = pEnd + 1;
pEnd = strchr(pBegin, '\n');
while (pEnd)
{
string strTemp;
strTemp.insert(0, pBegin, pEnd-pBegin);
assert(!strTemp.empty());
stringMap[uiIndex++] = strTemp;
pBegin = pEnd + 1;
pEnd = strchr(pBegin, '\n');
}
delete []fileBuffer;
fileBuffer = NULL;
pBegin = NULL;
pEnd = NULL;
map
for (; iter != stringMap.end(); ++iter)
{
vector
map
assert(GetParamFromString(iter->second, stringVec) > 0);
vector
for (; idx != stringVec.size(); ++idx)
{
stringMapTemp[idx + 1] = stringVec[idx];
}
m_stringMap[iter->first] = stringMapTemp;
}
fclose(pFile);
m_CSVName = path;
return true;
}
else
{
return false;
}
}
bool CppCSV::SaveCSV(const char *path /* = NULL */)
{
if (path != NULL)
{
m_CSVName = path;
}
FILE *pFile = fopen(m_CSVName.c_str(), "w");
if (pFile)
{
map
for (; iter != m_stringMap.end(); ++iter)
{
map
map
for (; it != rStringMap.end(); ++it)
{
string strTemp = it->second;
strTemp += ',';
fwrite(strTemp.c_str(), 1, 1, pFile);
}
char delim = '\n';
fwrite(&delim, 1, 1, pFile);
}
fclose(pFile);
return true;
}
else
{
return false;
}
}
bool CppCSV::GetIntValue(u32 uiRow, u32 uiCol, int &riValue)
{
string *pStr = GetStringValue(uiRow, uiCol);
if (pStr)
{
riValue = atoi(pStr->c_str());
return true;
}
else
{
return false;
}
}
bool CppCSV::GetFloatValue(u32 uiRow, u32 uiCol, float &rfValue)
{
string *pStr = GetStringValue(uiRow, uiCol);
if (pStr)
{
rfValue = atof(pStr->c_str());
return true;
}
else
{
return false;
}
}
string* CppCSV::GetStringValue(u32 uiRow, u32 uiCol)
{
map
if (iter != m_stringMap.end())
{
map
map
if (it != rStrMap.end())
{
return &(it->second);
}
else
{
return NULL;
}
}
else
{
return NULL;
}
}
//用于分割字符串,将CSV表格中的一行按照规则解析成一组字符串,存储在一个vector中
//根据CSV表格中所存储的数据的不同,重载各函数
int CppCSV::GetParamFromString(string str, vector
{
char *token = strtok(const_cast
while (token)
{
string strTemp = token;
stringVec.push_back(strTemp);
token = strtok(NULL, &delim);
}
return stringVec.size();
}
void CppCSV::GetSkillRecordMapTable(map
{
map
for (; iter != m_stringMap.end(); ++iter)
{
map
SkillRecord skillTemp;
skillTemp.SetID(atoi(strmap[1].c_str()));
skillTemp.SetPath(strmap[2]);
skillTemp.SetName(strmap[3]);
skillTemp.SetHurt(atoi(strmap[4].c_str()));
skillTemp.SetPlayTime(atoi(strmap[5].c_str()));
sSkillMa