CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StringToEnumValue.h
Go to the documentation of this file.
1 #ifndef _CommonTools_Utils_StringToEnumValue_h_
2 #define _CommonTools_Utils_StringToEnumValue_h_
3 
4 
6 #include "TEnum.h"
7 #include "TEnumConstant.h"
8 #include <cassert>
9 #include <string>
10 #include <sstream>
11 #include <vector>
12 
13 
26 template <typename MyEnum>
27 int StringToEnumValue(std::string const& enumConstName){
28  TEnum* en = TEnum::GetEnum(typeid(MyEnum));
29  if (en != nullptr){
30  if (TEnumConstant const* enc = en->GetConstant(enumConstName.c_str())){
31  return enc->GetValue();
32  }
33  }
34  assert(0);
35  return -1;
36 }
37 
38 
60 template <class MyType>
61 std::vector<int> StringToEnumValue(const std::vector<std::string> & enumNames){
62 
63  using std::vector;
64  using std::string;
65 
66  vector<int> ret;
67  vector<string>::const_iterator str=enumNames.begin();
68  for (;str!=enumNames.end();++str){
69  ret.push_back( StringToEnumValue<MyType>(*str));
70  }
71  return ret;
72 
73 } //
74 
75 #endif
assert(m_qm.get())
int StringToEnumValue(std::string const &enumConstName)