13 #include "cetlib_except/exception.h" 26 std::vector<std::string> BuildPolicyNames() {
27 const char* cnames[] = {
28 #define NURANDOM_SEED_SERVICE_POLICY(x) #x, 30 #undef NURANDOM_SEED_SERVICE_POLICY 32 return std::vector<std::string>
33 { cnames, cnames +
sizeof(cnames)/
sizeof(cnames[0]) };
36 std::vector<std::string> PolicyNames { BuildPolicyNames() };
47 static_assert(static_cast<unsigned>(Policy::unDefined) == 0,
48 "\"unDefined\" policy needs to be the first one.");
52 std::vector<std::string>
const&
policyNames() { return ::PolicyNames; }
57 std::size_t
const index {
static_cast<unsigned>(policy) };
61 <<
"Invalid policy (index #" << index <<
")\n";
70 assert(!names.empty());
71 auto const nbegin {
begin(names) }, nend {
end(names) };
73 auto const iter = std::find(nbegin, nend, policyName);
75 Policy const policy = (iter == nend)
77 : static_cast<Policy>(std::distance(
begin(names), iter))
80 if (policy != Policy::unDefined)
return policy;
84 e <<
"rndm::details::policyFromName(\"" << policyName
85 <<
"\"): unrecognized policy.\nKnown policies are: ";
87 while (++iName != nend)
e <<
" '" << (*iName) <<
'\'';
std::vector< std::string > const & policyNames()
Returns a list of names of policies, in the same order as Policy enum.
Declaration of policy enumerator and names.
Policy
Enumeration of all supported random seed policies.
std::string const & policyName(Policy policy)
Returns the name of the specified policy.
#define NURANDOM_SEED_SERVICE_POLICIES
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Policy policyFromName(std::string const &policyName)
Returns the policy with the specified name.
cet::coded_exception< error, detail::translate > exception