【发布时间】:2019-07-03 11:51:45
【问题描述】:
我正在尝试使用唯一的数字 id 索引从 boost::multi_index_container 中检索一个值。我以前从未使用过boost::multi_index_container,所以我很难理解它们是如何工作的。它们看起来有点像数据库,我想做的就是通过指定 id 来检索项目。任何帮助将不胜感激。
这是数据类型:
typedef boost::multi_index_container<
// Multi index container holds pointers to the subnets.
Subnet6Ptr,
// The following holds all indexes.
boost::multi_index::indexed_by<
// First is the random access index allowing for accessing
// objects just like we'd do with a vector.
boost::multi_index::random_access<
boost::multi_index::tag<SubnetRandomAccessIndexTag>
>,
// Second index allows for searching using subnet identifier.
boost::multi_index::ordered_unique<
boost::multi_index::tag<SubnetSubnetIdIndexTag>,
boost::multi_index::const_mem_fun<Subnet, SubnetID, &Subnet::getID>
>,
// Third index allows for searching using an output from toText function.
boost::multi_index::ordered_unique<
boost::multi_index::tag<SubnetPrefixIndexTag>,
boost::multi_index::const_mem_fun<Subnet, std::string, &Subnet::toText>
>
>
> Subnet6Collection;
Subnet6Collection 对象是在 dhcpv6-server (KEA) 加载其配置文件时创建的。此文件包含每个子网的可选数字 id 值,数据类型中为 SubnetID。
我想通过指定SubnetID 来检索Subnet6Ptr。
【问题讨论】:
-
这是一个数据库成语。为什么不直接使用(许多非常好的)c++ API 到 SQLite?或者至少将解决方案描述为基于关系数据库。假设键值存储由于某种原因是不够的......而且最低限度是你“允许”使用哪个 C++。
-
@ChefGladiator 他们正在尝试使用某些库提供的
Subnet6Collection类型的对象,而不是重写库以使用SQL