工具类库系列(三)-IniReader
来源:互联网 发布:学matlabgui编程的意义 编辑:程序博客网 时间:2024/05/29 18:35
第三个工具类:IniReader
就是读ini配置文件的一个工具类,很简单,就是封装了一下boost库的ptree
IniReader.h
#ifndef __IniReader_h__#define __IniReader_h__#include <string>#include <boost/property_tree/ptree.hpp>namespace common{namespace tool{class IniReader{public:IniReader();~IniReader();bool InitIni(const std::string& path);bool GetValue(const std::string& root, const std::string& key, std::string& value);bool GetValue(const std::string& root, const std::string& key, unsigned int& value);private:bool m_IsInit;boost::property_tree::ptree m_Pt;};}}#endif
IniReader.cpp
#include "IniReader.h"#include <boost/property_tree/ini_parser.hpp>namespace common{namespace tool{IniReader::IniReader(){m_IsInit = false;}IniReader::~IniReader(){}bool IniReader::InitIni(const std::string& path){try{boost::property_tree::ini_parser::read_ini(path, m_Pt);m_IsInit = true;}catch (...){m_IsInit = false;}return m_IsInit;}bool IniReader::GetValue(const std::string& root, const std::string& key, std::string& value){if (m_IsInit){try{std::string strTemp(root + "." + key);value = m_Pt.get<std::string>(strTemp);return true;}catch (...){return false;}}else{return false;}}bool IniReader::GetValue(const std::string& root, const std::string& key, unsigned int& value){if (m_IsInit){try{std::string strTemp(root + "." + key);value = m_Pt.get<unsigned int>(strTemp);return true;}catch (...){return false;}}else{return false;}}}}
0 0
- 工具类库系列(三)-IniReader
- java工具类系列 (三.ExceptionUtils)
- JavaWeb系列三-----通过工具类来产生验证码
- hibernate系列三:hibernate工具类及使用
- JVM系列:三、性能监控及工具
- FFmpeg命令行工具系列三---参数详解
- SDL系列讲解(三) 工具安装
- 工具类库系列(一)-StringTool
- 工具类库系列(二)-ExePath
- 工具类库系列(四)-CsvReader
- 工具类库系列(五)-Timer
- 工具类库系列(六)-TimeTool
- 工具类库系列(七)-Logger
- 工具类库系列(八)-WinService
- 工具类库系列(九)-ReflectEnum
- 工具类库系列(十)-Object
- 工具类库系列(十一)-ObjectMap
- 工具类库系列(十二)-ObjectSharedPtrMap
- 测试了一下php5.6的opcache的性能提升
- extjs中apply和applyIf的用法
- 进程与线程的区别
- 手把手教你高德基础地图+定位+设置Marker实现
- 显示传入第二个参数
- 工具类库系列(三)-IniReader
- 数据加载的妙招解析
- 内嵌汇编 jmp
- mysql常用命令
- 如何通过DICOM的tag来判断3D图像的方向
- 如何搭建局域网
- Caffe源码中添加新层 详细教程
- TCP/IP,HTTP,Socket的区别
- libhybris及EGL Platform-在Glibc生态中重用Android的驱动