通用配置键值对容器
More...
#include <xmlinfo.h>
|
|
using | map_type = std::map<std::string, std::string, std::less<>> |
| | 配置映射类型
|
|
| map_type & | data () |
| | 获取配置数据映射
|
| const map_type & | data () const |
| | 获取配置数据映射(常量版本)
|
| std::size_t | size () const noexcept |
| | 获取配置项数量
|
| template<typename TVALUE> |
| bool | find (const char *akey, TVALUE &adata) const |
| | 查找并转换配置值
|
| bool | find (const char *akey, bool &adata) const |
| | 查找布尔配置值
|
| bool | find (const char *akey, std::string &adata) const |
| | 查找字符串配置值
|
| bool | find_view (const char *akey, std::string_view &adata) const |
| | 查找配置值(字符串视图版本)
|
| template<typename TFUN> |
| void | foreach (TFUN &&afun) const |
| | 遍历所有配置项
|
通用配置键值对容器
提供类型安全的配置值访问,支持:
- 按键名查询配置值
- 类型转换(通过tools::lexical_cast)
- 遍历所有配置项
config.xml_pop(xml_element);
int32_t value;
if (config.
find(
"key", value)) {
}
config.
foreach([](
const auto& pair) {
std::cout << pair.first << ": " << pair.second << std::endl;
});
◆ data() [1/2]
◆ data() [2/2]
| const map_type & ngl::xarg_info::data |
( |
| ) |
const |
|
inline |
获取配置数据映射(常量版本)
- Returns
- 配置映射常量引用
◆ find() [1/3]
| bool ngl::xarg_info::find |
( |
const char * | akey, |
|
|
bool & | adata ) const |
查找布尔配置值
查找布尔类型配置值
- Parameters
-
- Returns
- 查找成功返回true
先尝试文本布尔解析,失败后回退到lexical_cast。
- Parameters
-
- Return values
-
| true | 查找并解析成功 |
| false | 键不存在或解析失败 |
◆ find() [2/3]
| bool ngl::xarg_info::find |
( |
const char * | akey, |
|
|
std::string & | adata ) const |
查找字符串配置值
查找字符串类型配置值
- Parameters
-
- Returns
- 查找成功返回true
- Parameters
-
- Return values
-
◆ find() [3/3]
template<typename TVALUE>
| bool ngl::xarg_info::find |
( |
const char * | akey, |
|
|
TVALUE & | adata ) const |
|
inline |
查找并转换配置值
- Template Parameters
-
- Parameters
-
- Returns
- 查找成功返回true
保持与配置系统其余部分相同的转换策略, 所有转换都通过 tools::lexical_cast 进行。
◆ find_view()
| bool ngl::xarg_info::find_view |
( |
const char * | akey, |
|
|
std::string_view & | adata ) const |
查找配置值(字符串视图版本)
查找配置值并以string_view形式返回(零拷贝)
- Parameters
-
- Returns
- 查找成功返回true
- Parameters
-
- Return values
-
◆ foreach()
template<typename TFUN>
| void ngl::xarg_info::foreach |
( |
TFUN && | afun | ) |
const |
|
inline |
遍历所有配置项
- Template Parameters
-
- Parameters
-
◆ size()
| std::size_t ngl::xarg_info::size |
( |
| ) |
const |
|
inlinenoexcept |
The documentation for this class was generated from the following files:
- E:/GitHub/ngl_server/public/cpp/tools/tab/xml/xmlinfo.h
- E:/GitHub/ngl_server/public/cpp/tools/tab/xml/xmlinfo.cpp