c++ parse html,C++ 配置文件解析类 ParseConfig

本文介绍了一个用C++实现的配置文件解析器类ParseConfig,包括解析配置文件、获取配置值及格式校验等功能。提供了从配置文件或内部映射中获取特定配置的方法。

依赖项:

依赖于 ProcessString 类,可从该篇博客获取「字符串处理类 ProcessString (包含常用字符串处理函数)」

ParseConfig.h

//Linux & C++11

#pragma once

//包含系统头文件

#include

#include

#include

#include

//宏定义:函数参数流向

#define IN

#define OUT

#define INOUT

//使用命名

using std::string;

using std::exception;

using std::shared_ptr;

using std::make_shared;

using std::map;

namespace sinicheveen

{

class ParseConfig

{

public:

//group 1:解析、获取配置

//解析配置文件到 map 中

static void parseConfFileIntoMap();

//输出 m_mConfs 中的配置项

static void printConfInMap();

//从 m_mConfs 中获取某个 section 下的某项配置

static string getSpecConfValFromMap(IN const string& strSectionName, IN const string& strConfName);

//从 m_mConfs 中获取某项配置,如果在多个 section 下有相同的配置名,则获取第一个 seciton 下的配置值

static string getSpecConfValFromMap(IN const string& strConfName);

//从配置文件中获取某个 section 下的某项配置

static string getSpecConfValFromFile(IN const string& strSectionName, IN const string& strConfName);

//从配置文件中获取某项配置,如果在多个 section 下有相同的配置名,则获取第一个 seciton 下的配置值

static string getSpecConfValFromFile(IN const string& strConfName);

//guoup 2:格式校验

//校验 section name 格式,格式必须是 [XXXX]

static void checkSectionNameFromat(INOUT const string& strConf, IN const uint32_t lineNum);

//校验配置项格式

static void checkConfItemFormat(INOUT const string& strConf, IN const uint32_t lineNum);

//group 3:静态成员初始化

//初始化静态成员 m_mConfs

static map> initStaticMapConfs();

//group 4:静态变量

private:

static string m_strConfFilePath;

static map > m_mConfs;

}; //ParseConfig

} //sinicheveen

ParseConfig.cpp

未完 ......

点击访问原文(进入后根据右侧标签,快速定位到本文)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值