依赖项:

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

ParseConfig.h

//Linux & C++11

#pragma once

//包含系统头文件
#include <string>
#include <exception>
#include <memory>
#include <map>

//宏定义:函数参数流向
#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<string, map<string, string>> initStaticMapConfs();

    //group 4:静态变量
    private:
        static string m_strConfFilePath;
        static map<string, map<string, string> > m_mConfs;

    };  //ParseConfig

}   //sinicheveen

ParseConfig.cpp


未完 ......

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

C++ 配置文件解析类 ParseConfig的更多相关文章

  1. ibatis源码学习2_初始化和配置文件解析

    问题在详细介绍ibatis初始化过程之前,让我们先来思考几个问题. 1. ibatis初始化的目标是什么?上文中提到过,ibatis初始化的核心目标是构造SqlMapClientImpl对象,主要是其 ...

  2. MyBatis配置文件解析

    MyBatis配置文件解析(概要) 1.configuration:根元素 1.1 properties:定义配置外在化 1.2 settings:一些全局性的配置 1.3 typeAliases:为 ...

  3. Hadoop配置文件解析

    Hadoop源码解析 2 --- Hadoop配置文件解析 1 Hadoop Configuration简介    Hadoop没有使用java.util.Properties管理配置文件, 也没有使 ...

  4. Hibernate的配置文件解析

    配置mybatis.xml或hibernate.cfg.xml报错: <property name="connection.url">jdbc:mysql://loca ...

  5. WCF中配置文件解析

    WCF中配置文件解析[1] 2014-06-14 WCF中配置文件解析 参考 WCF中配置文件解析 返回 在WCF Service Configuration Editor的使用中,我们通过配置工具自 ...

  6. 自己用的框架写了一个PHP模版解析类

    <?php if(!defined('IS_HEARTPHP')) exit('Access Denied'); /** * template.class.php 模板解析类 * * @copy ...

  7. nginx源代码分析--配置文件解析

    ngx-conf-parsing 对 Nginx 配置文件的一些认识: 配置指令具有作用域,分为全局作用域和使用 {} 创建其他作用域. 同一作用域的不同的配置指令没有先后顺序:同一作用域能否使用同样 ...

  8. PHP模板解析类实例

    作者:mckee 这篇文章主要介绍了PHP模板解析类,涉及php针对模板文件的解析与字符串处理的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下 <?php class template { ...

  9. Spring Security 入门(1-6-1)Spring Security - 配置文件解析和访问请求处理

    1.在pom.xml中添加maven坐标 <dependency> <groupId>org.springframework.security</groupId> ...

随机推荐

  1. python3.x中lambda表达式的处理与python2不一样

    lambda表达式,在python2中的表达式和python3不同,原来只要: >>> map(lambda x: x ** 2, [1, 2, 3, 4, 5])          ...

  2. 【洛谷】P3177 [HAOI2015]树上染色

    懒得复制题面了直接传送门吧 分析 直接求点与点之间的距离感觉不是很好求,所以我们考虑换一个求法. 瞄了一眼题解 距离跟路径上边的长度有关,所以我们直接来看每一条边的贡献吧(这谁想得到啊) 对于每一条边 ...

  3. 怎么判断是qq浏览器还是uc浏览器?

    这里我画红框的是不正确的,最好的办法就是打印出navigator.userAgent出来.uc浏览器检验是正确的.

  4. Lock接口的认识和使用

    保证线程安全演进: synchronized volatile AtomicInteger Lock接口提供的方法: void lock():加锁 void unlock():解锁 void lock ...

  5. nodejs express cheerio request爬虫

    const express = require('express') const cheerio = require('cheerio') const request = require(" ...

  6. 2019年领航杯 江苏省网络信息安全竞赛 初赛部分writeup

    赛题已上传,下载连接:https://github.com/raddyfiy/2019linghangcup 做出了全部的misc和前三道逆向题,排名第10,暂且贴一下writeup. 关卡一 编码解 ...

  7. 第07组 Alpha冲刺(1/6)

    队长:杨明哲 组长博客:求戳 作业博客:求再戳 队长:杨明哲 过去两天完成了哪些任务 文字/口头描述:完成了,网页后端的大部分工作.负责了很大一部分的后端工作. 展示GitHub当日代码/文档签入记录 ...

  8. Python有堆栈/堆,如何管理内存?

    Python有堆栈/堆,如何管理内存? - 代码日志 https://codeday.me/bug/20171016/86264.html

  9. Java8中的日期时间类

    测试类: import java.time.*; import java.time.format.DateTimeFormatter; public class App { public static ...

  10. Python之Pandas操作csv文件dataframe

    # -*- coding: utf-8 -*- # author:baoshan import pandas as pd def main(): aqi_data = pd.read_csv('chi ...