#ifndef _READCONFIG_H_
#define _READCONFIG_H_
#include <string>
#include <map>
#include <vector>
#include <iostram>
#include <fstream>
#define MAX_BUFFLEN 1024
typedef map< string, string, less<string> > strMap;
typedef strMap::iterator strmapIt;
const char * const MIDDLESTRING = "__**__";
using namespace std;
// 此类用于格式化string字符串
class SString : public string
{
public:
SString &Format(const char *_format, ...)
{
char szBuffer[MAX_BUFFLEN];
memset(szBuffer, 0x00, sizeof(szBuffer));
va_list ap;
va_start(ap, _format);
try
{
vsnprintf(szBuffer, MAX_BUFFLEN, _format, ap);
}
catch(...)
{
cout<<"ERROR: format the string failed..."<<endl;
return *this;
}
va_end(ap);
this->append(szBuffer);
return *this;
}
};
// 该类用于根据传入的数据,将数据存入map中
class CAnalyzeValue
{
private:
string m_strSect;
strMap *m_pMap;
public:
CAnalyzeValue(strMap &strmap):m_pMap(&strmap)
{
m_strSect = "";
}
~CAnalyzeValue()
{
}
void operator () (const string &strInput) const
{
int iFirst = strInput.find('[');
int iLast = strInput.find(']');
if (iFirst != string::npos && iLast != string::npos && iFirst != iLast + 1)
{
m_strSect = strInput.substr(iFirst + 1, iLast - iFirst - 1);
return;
}
if (m_strSect.empty())
{
return;
}
iFirst = strInput.find('=');
if (iFirst == string::npos)
{
return;
}
string strTemp1 = strInput.substr(0, iFirst);
string strTemp2 = strInput.substr(iFirst + 1, string::npos);
iFirst = strTemp1.find_first_not_of(" /t");
iLast = strTemp1.find_last_not_of(" /t");
if (iFirst == string::npos || iLast == string::npos)
{
return;
}
string strKey = strTemp1.substr(iFirst + 1, iLast - iFirst + 1);
iFirst = strTemp2.find_first_not_of(" /t");
if (((iLast = strTemp2.find("/t#", iFirst)) != string::npos) ||
((iLast = strTemp2.find(" #", iFirst)) != string::npos) ||
((iLast = strTemp2.find("/t//", iFirst)) != string::npos) ||
((iLast = strTemp2.find(" //", iFirst)) != string::npos))
{
strTemp2 = strTemp2.substr(0, iLast - iFirst);
}
iLast = strTemp2.find_last_not_of(" /t");
if (iFirst == string::npos || iLast == string::npos)
{
return;
}
string strValue = strTemp2.substr(iFirst, iLast - iFirst + 1);
string strMapkey = m_strSect + MIDDLESTRING;
strMapkey += strKey;
(*m_pMap)[strMapkey] = strValue;
return;
}
};
// 此类用于读取配置文件
class CReadConfig
{
public:
CReadConfig()
{
}
~CReadConfig()
{
}
bool OpenFile(const char *FileName)
{
return
}
string ReadCfg(const char * pSect, const char * pKey)
{
string strMapKey = pSect;
strMapKey += MIDDLESTRING;
strMapKey += pKey;
strmapIt iter;
iter = mapcfg.find(strMapKey);
if (iter == mapcfg.end())
{
return "";
}
else
{
return iter->second;
}
}
protected:
bool Do_OpenFile(const char *FileName)
{
ifstream fin(FileName);
if (!fin.is_open())
{
return false;
}
vector<string> strVect;
while (!fin.eof())
{
string strInput = "";
getline(fin, strInput, '/n');
strVect.push_back(strInput);
}
if (strVect.empty())
{
return false;
}
for_each(strVect.begin(), strVect.end(), CAnalyzeValue(mapcfg));
}
private:
strMap mapcfg;
};
#endif
分享到:
相关推荐
用于STL文件读取与显示的C语言程序,简单方便实用。
C++读取STL文件,输出所有三角形的顶点坐标
本程序提供了std::string 类型的Format格式化函数,以及两种格式化string字符串的方法,主方法在str.hpp文件中,测试文件在string_format.cpp中,已测试可用
这个小程序可以读取简易的配置文件; 完全由c++标准库写成,可以帮助还在学习C++的同学练练手;
c++ STL string学习资料 包括string 的所有用法,以及注意点 以及国际标准等
本资源包含基于C++的VTK对不同格式的文件进行读取与另存源码和用到的素材文件。 实例1:读取STL文件并渲染显示 实例2:读取VTI文件并渲染显示 实例3:读取VTK文件并渲染显示 实例4:读取MHA文件并渲染显示 实例5:...
STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL格式模型文件STL...
用于三维光学形貌扫描完成后,生成的stl文件的读取,并形成俯视投影云图
介绍 string类的常用函数,讲解细致,透彻,非常实用
很全的STL string类的函数方法,便于查询
python可视化界面基于vtk模块实现stl文件的读取并可视化.zip
C++ STL--数据结构与算法实现(余文溪)示例程序代码.rar
在matlab中读取点云数据stl文件并在界面显示
C++ 对模板(Template)支持得很好,STL 就是借助模板把常用的数据结构及其算法都实现了一遍,并且做到了数据结构和算法的分离。例如,vector 的底层为顺序表(数组),list 的底层为双向链表,deque 的底层为循环...
C++ STL中文版 C++ STL中文版 C++ STL中文版 C++ STL中文版 C++ STL中文版
c++ STL, stl,stl的学习c++ STL, stl,stl的学习c++ STL, stl,stl的学习c++ STL, stl,stl的学习
C++ STL 教程 涉及泛型编程思想 标准模板 迭代器 泛型算法 容器 等
扫描完整版 C++ STL标准程序库开发指南 C++ STL标准程序库开发指南
微软c++ STL源代码微软c++ STL源代码微软c++ STL源代码微软c++ STL源代码微软c++ STL源代码微软c++ STL源代码微软c++ STL源代码微软c++ STL源代码微软c++ STL源代码微软c++ STL源代码微软c++ STL源代码微软c++ STL源...
C++ stl中重要容器string类的构造方法与基本概念和一些有用的字符串操作