我在管理器类中工作,它包含表示路径的字符串。从这个字符串中,我想使用如下代码获得一个 boost.uuid:
m_log->addMessage("Generating UUID from path",ZEL_APPENDER,LOGLEVEL_DEBUG);
boost::uuids::string_generator str_gen;
boost::uuids::uuid generatedUUID = str_gen(full_path);
assert(generatedUUID.is_nil() == false);
char msg[500];
snprintf(msg,500,"Successfully generated UUID %s from path",boost::uuids::to_string(generatedUUID).c_str());
m_log->addMessage(msg,ZEL_APPENDER,LOGLEVEL_DEBUG);
但不幸的是,我发现生成的字符串总是相同的,即使 full_path 不同。
此外,当我尝试使用像这样的超简单示例时:
string s1("helloworld");
boost::uuids::string_generator str_gen;
boost::uuids::uuid generatedUUID = str_gen(s1);
cout << "s1: " << boost::uuids::to_string(generatedUUID) << endl;
Boost 抛出一个运行时异常,指出该字符串无效。你可以帮帮我吗?我找到的唯一文档来源是 here
提前致谢。
最佳答案
基于code in the header该代码不会生成哈希,而是解析UUID-as-string并将其转换为uuid。
听起来您正在寻找基于路径的哈希,这与 UUID 不同。 UUID 旨在是唯一的,这意味着例如可以将具有相同值的路径存储在不同 UUID 下的关联容器中。
你最好还是看看 Boost.Hash .
关于c++ - 从 boost.path 字符串生成 boost.uuid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4475338/