preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Hash.cpp
Go to the documentation of this file.
1#include <boost/uuid/name_generator.hpp>
2#include <boost/uuid/string_generator.hpp>
3#include <boost/uuid/uuid_io.hpp>
4
5#include "utils/Hash.hpp"
6#include "utils/assertion.hpp"
7
8namespace precice::utils {
9
11try {
12 boost::uuids::string_generator ns_gen;
13 auto ns = ns_gen("af7ce8f2-a9ee-46cb-38ee-71c318aa3580"); // md5 hash of precice.org as namespace
14
15 boost::uuids::name_generator gen{ns};
16 std::string hash = boost::uuids::to_string(gen(s.data(), s.size()));
17 hash.erase(std::remove(hash.begin(), hash.end(), '-'), hash.end());
18 return hash;
19
20} catch (const std::runtime_error &e) {
21 PRECICE_UNREACHABLE("preCICE hashing failed", e.what());
22 return "";
23}
24
25} // namespace precice::utils
#define PRECICE_UNREACHABLE(...)
Definition assertion.hpp:93
T begin(T... args)
T data(T... args)
T end(T... args)
T erase(T... args)
contains precice-related utilities.
std::string preciceHash(std::string_view s)
creates a portable hash of the given input
Definition Hash.cpp:10
T size(T... args)
T what(T... args)