线程安全的 INI 配置文件解析器(单例模式)
More...
#include <config.hpp>
|
| bool | load (const std::string &filename) |
| | 从文件加载配置
|
| |
| std::string | get (const std::string §ion, const std::string &key, const std::string &default_value="") |
| | 获取字符串类型的配置值
|
| |
| int | get_int (const std::string §ion, const std::string &key, int default_value=0) |
| | 获取整数类型的配置值
|
| |
| double | get_double (const std::string §ion, const std::string &key, double default_value=0.0) |
| | 获取浮点数类型的配置值
|
| |
线程安全的 INI 配置文件解析器(单例模式)
支持标准 INI 格式:
- [section] 定义配置节
- key = value 定义配置项
- ; 或 # 开头的行为注释
- Note
- 该类为单例模式,通过 instance() 获取唯一实例
- 使用示例
static Config & instance()
获取 Config 单例实例
Definition config.cpp:13
int get_int(const std::string §ion, const std::string &key, int default_value=0)
获取整数类型的配置值
Definition config.cpp:74
bool load(const std::string &filename)
从文件加载配置
Definition config.cpp:28
◆ get()
| std::string fix40::Config::get |
( |
const std::string & |
section, |
|
|
const std::string & |
key, |
|
|
const std::string & |
default_value = "" |
|
) |
| |
获取字符串类型的配置值
- Parameters
-
| section | 配置节名称 |
| key | 配置项名称 |
| default_value | 默认值,当配置项不存在时返回 |
- Returns
- std::string 配置值或默认值
◆ get_double()
| double fix40::Config::get_double |
( |
const std::string & |
section, |
|
|
const std::string & |
key, |
|
|
double |
default_value = 0.0 |
|
) |
| |
获取浮点数类型的配置值
- Parameters
-
| section | 配置节名称 |
| key | 配置项名称 |
| default_value | 默认值,当配置项不存在或转换失败时返回 |
- Returns
- double 配置值或默认值
◆ get_int()
| int fix40::Config::get_int |
( |
const std::string & |
section, |
|
|
const std::string & |
key, |
|
|
int |
default_value = 0 |
|
) |
| |
获取整数类型的配置值
- Parameters
-
| section | 配置节名称 |
| key | 配置项名称 |
| default_value | 默认值,当配置项不存在或转换失败时返回 |
- Returns
- int 配置值或默认值
◆ instance()
| Config & fix40::Config::instance |
( |
| ) |
|
|
static |
◆ load()
| bool fix40::Config::load |
( |
const std::string & |
filename | ) |
|
从文件加载配置
- Parameters
-
- Returns
- true 加载成功
-
false 加载失败(文件不存在或无法打开)
- Note
- 调用此方法会清空之前加载的所有配置
The documentation for this class was generated from the following files: