CMS 3D CMS Logo

StringToEnumValue.h
Go to the documentation of this file.
1 #ifndef _CommonTools_Utils_StringToEnumValue_h_
2 #define _CommonTools_Utils_StringToEnumValue_h_
3 
5 #include "TEnum.h"
6 #include "TEnumConstant.h"
7 #include <cassert>
8 #include <string>
9 #include <sstream>
10 #include <vector>
11 
24 template <typename MyEnum>
25 int StringToEnumValue(std::string const& enumConstName) {
26  TEnum* en = TEnum::GetEnum(typeid(MyEnum));
27  if (en != nullptr) {
28  if (TEnumConstant const* enc = en->GetConstant(enumConstName.c_str())) {
29  return enc->GetValue();
30  }
31  }
32  assert(0);
33  return -1;
34 }
35 
56 template <class MyType>
57 std::vector<int> StringToEnumValue(const std::vector<std::string>& enumNames) {
58  using std::string;
59  using std::vector;
60 
61  vector<int> ret;
62  vector<string>::const_iterator str = enumNames.begin();
63  for (; str != enumNames.end(); ++str) {
64  ret.push_back(StringToEnumValue<MyType>(*str));
65  }
66  return ret;
67 
68 } //
69 
70 #endif
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:373
cms::cuda::assert
assert(be >=bs)
str
#define str(s)
Definition: TestProcessor.cc:51
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
Exception.h
StringToEnumValue
int StringToEnumValue(std::string const &enumConstName)
Definition: StringToEnumValue.h:25