سؤال

I'm working in a manager class, that holds string representing paths. From this strings, I'd like to have a boost.uuid using a code like this:

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);

But unfortunatelly, I found that generated string is always the same, even if full_path is diferent.

Also, when I try with an ultra simple example like this:

 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 throws a runtime exception saying that string is invalid. Could you help me? The only source of documentation I've found is here

Thanks in advance.

هل كانت مفيدة؟

المحلول

Based on the code in the header the code does not generate hashes but instead parses a UUID-as-string and converts it to a uuid.

It sounds like you are looking for a hash based on the path, which is not the same as a UUID. UUIDs are intended to be unique, implying that e.g. one could have paths of the same value stored in an associative container under different UUIDs.

You might be better off looking at Boost.Hash.

نصائح أخرى

I think you should read http://www.boost.org/doc/libs/1_59_0/libs/uuid/uuid.html#boost/uuid/string_generator.hpp carefully. You use String Generator,but in article The boost::uuids::string_generator class generates a uuid from a string. if you want use boost::uuids::string_generator,you must use correct format string in your gen().

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top