Source · fairmq/tools/
Unique.cxxsource
1/********************************************************************************2 * Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *3 * *4 * This software is distributed under the terms of the *5 * GNU Lesser General Public Licence (LGPL) version 3, *6 * copied verbatim in the file "LICENSE" *7 ********************************************************************************/8 9#include <fairmq/tools/Unique.h>10 11// We have to force boost::uuids to rely on /dev/*random instead of getrandom(2) or getentropy(3)12// otherwise on some systems we'd get boost::uuids::entropy_error13#define BOOST_UUID_RANDOM_PROVIDER_FORCE_POSIX14 15#include <boost/functional/hash.hpp>16#include <boost/uuid/uuid.hpp>17#include <boost/uuid/uuid_generators.hpp>18#include <boost/uuid/uuid_io.hpp>19 20using namespace std;21 22namespace fair::mq::tools23{24 25// generates UUID string26string Uuid()27{28 boost::uuids::random_generator gen;29 boost::uuids::uuid u = gen();30 return boost::uuids::to_string(u);31}32 33// generates UUID and returns its hash34size_t UuidHash()35{36 boost::uuids::random_generator gen;37 boost::hash<boost::uuids::uuid> uuid_hasher;38 boost::uuids::uuid u = gen();39 return uuid_hasher(u);40}41 42} // namespace fair::mq::tools