CMS 3D CMS Logo

Functions
StringToEnumValue.h File Reference
#include "FWCore/Utilities/interface/Exception.h"
#include "TEnum.h"
#include "TEnumConstant.h"
#include <cassert>
#include <string>
#include <sstream>
#include <vector>

Go to the source code of this file.

Functions

template<class MyType >
std::vector< int > StringToEnumValue (const std::vector< std::string > &enumNames)
 
template<typename MyEnum >
int StringToEnumValue (std::string const &enumConstName)
 

Function Documentation

◆ StringToEnumValue() [1/2]

template<class MyType >
std::vector<int> StringToEnumValue ( const std::vector< std::string > &  enumNames)

Convert a vector<string> into a vector<int> with the enum values it corresponds to. Example:

std::vector<std::string> names; names.push_back("kWeird"); names.push_back("kGood");

std::vector<int> ints = StringToEnumValue<EcalRecHit::Flags>(names);

std::copy(ints.begin(), ints.end(), std::ostream_iterator<int>(std::cout, "-"));

Definition at line 57 of file StringToEnumValue.h.

57  {
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 } //

References runTheMatrix::ret, str, AlCaHLTBitMon_QueryRunRegistry::string, and trackerHitRTTI::vector.

◆ StringToEnumValue() [2/2]

template<typename MyEnum >
int StringToEnumValue ( std::string const &  enumConstName)

Convert a string into the enum value it corresponds to. Example: int value = StringToEnumValue<EcalRecHit::Flags>("kGood");

Author
Stefano Argiro
Version
Id
StringToEnumValue.h,v 1.5 2012/08/28 22:28:38 wmtan Exp
Date
04 Mar 2011

Definition at line 25 of file StringToEnumValue.h.

25  {
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 }

References cms::cuda::assert().

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