【发布时间】:2013-04-05 05:46:44
【问题描述】:
如标题所述:
struct AXmlConfigurator : private boost::noncopyable {
protected:
std::string configuration_file_;
std::map<std::string, std::string> parameters_;
ptree ptree_;
public:
AXmlConfigurator(const std::string &argConfigurationFile) :
configuration_file_(argConfigurationFile) {
read_xml(configuration_file_, ptree_);
}
~AXmlConfigurator() {}
template<typename Type> inline
Type get(const std::string & argPath, Type argDefault) const {
Type value = ptree_.get<Type>(argPath, argDefault);
parameters_.insert(std::pair<std::string,std::string>(argPath, value));
return value;
}
template<class Type , class Translator> inline
typename boost::enable_if<detail::is_translator<Translator>, Type>::type
get(const std::string &argPath, const Type &argDefault, Translator tr) const {
Type value = ptree_.get(argPath, argDefault);
parameters_.insert(std::pair<std::string,std::string>(argPath, value));
return value;
}
void logConfiguration() {
for(std::map<std::string, std::string>::const_iterator it = parameters_.begin() ; it != parameters_.end() ; ++it) {
std::cout << (*it).first << " => " << (*it).second << std::endl;
}
}
};
我想包装 boost::property_tree::ptree 以将参数/值作为字符串存储到映射中,然后通过 logConfiguration 显示它们。
问题在于 map 的插入不接受值作为字符串,因为值类型未指定...
我没有想法,因此感谢任何帮助!
【问题讨论】:
-
请显示您遇到的实际错误。如果我理解这个问题,那么您将无法理解错误告诉您的内容。 我们也是。 :)
-
您好,感谢您的帮助:),我在插入此 std::map 时尝试的所有内容都出现了各种错误,我可以理解它们与什么相关...地图等待 std ::pair<:string std::string> 虽然我提供了一个未指定的类型......所以我的问题更像是:你将如何实现这个目标?
-
不清楚为什么您希望
get处理未指定的类型而不是std::string。我们是否应该假设您要问如何将未指定的类型转换为std::string? -
正如你在这里看到的boost.org/doc/libs/1_53_0/doc/html/boost_propertytree/…,
get是模板化的,我想通过失去模板方面来包装它。所以是的,我或多或少需要一种方法来让我的地图接受未指定的value...