boost::program_options - 如何处理 INI 文件中具有相同名称的多个部分

发布于 2024-10-08 18:48:58 字数 305 浏览 0 评论 0原文

在如下配置中;有没有办法处理各个部分。

我正在寻找一种以可靠的方式验证下面各个“服务器”部分的方法。

[basic]
number_of_servers=3

[server]
ip=10.20.30.40
password=sdfslkhf    

[server]
ip=10.20.30.41
password=sdfslkhf

[server]
ip=10.20.30.42
password=sdfslkhf

[server]
password=sdfslkhf

[server]
ip=10.20.30.42

In a config like below; is there a way to handle individual sections.

I am looking for a way to validate individual "server" sections below, in a reliable manner.

[basic]
number_of_servers=3

[server]
ip=10.20.30.40
password=sdfslkhf    

[server]
ip=10.20.30.41
password=sdfslkhf

[server]
ip=10.20.30.42
password=sdfslkhf

[server]
password=sdfslkhf

[server]
ip=10.20.30.42

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

轻拂→两袖风尘 2024-10-15 18:48:58

使用 boost::program_options 解析 INI 文件时,选项名称​​必须以其包含的节名称作为前缀。

换句话说,部分是选项“标识符”的一部分,但我认为您没有办法识别给定的server.ip变量属于哪个部分(因此,这是关联的server.password)。

我认为你应该考虑 Boost.PropertyTree (这也支持 INI 文件解析)来完成此任务。

When using boost::program_options to parse a INI file, the option names must be prefixed by their enclosing section names.

In other words, sections are part of the option 'identifier', but I don't think you have a way to identify to which section a given server.ip variable belongs (and thus, which is the associated server.password).

I think you should consider Boost.PropertyTree (which also supports INI file parsing) for this task.

回心转意 2024-10-15 18:48:58

来自这里

选项名称是相对于节名,所以下面的配置文件part:

  [gui.accessibility]
  visual_bell=yes

相当于

  gui.accessibility.visual_bell=yes

但是目前还没有办法区分同名的节。

更新:

Qt 的 QSettings 通常通过使用“/n”后缀数组中的值(部分?)来解决此问题。所以你可以使用:

[server/0]
...
[server/1]
...
[server/2]
...

From here:

The option names are relative to the section names, so the following configuration file part:

  [gui.accessibility]
  visual_bell=yes

is equivalent to

  gui.accessibility.visual_bell=yes

But there is currently no way to distinguish sections with the same name.

UPDATE:

Qt's QSettings usually solves this by postfixing values (sections?) from an array with "/n". So you could use:

[server/0]
...
[server/1]
...
[server/2]
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文