CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
StringToEnumValue.h File Reference
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/TypeWithDict.h"
#include <string>
#include <sstream>
#include <vector>

Go to the source code of this file.

Functions

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

Function Documentation

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

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.6 2013/01/25 23:27:41 wmtan Exp
Date
04 Mar 2011

Definition at line 25 of file StringToEnumValue.h.

References dtTPAnalyzer_cfg::dataType, and edm::TypeWithDict::stringToEnumValue().

25  {
26  edm::TypeWithDict dataType(typeid(MyType), kIsEnum);
27  return dataType.stringToEnumValue(enumMemberName);
28 }
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 53 of file StringToEnumValue.h.

References run_regression::ret, and AlCaHLTBitMon_QueryRunRegistry::string.

53  {
54 
55  using std::vector;
56  using std::string;
57 
58  vector<int> ret;
59  vector<string>::const_iterator str=enumNames.begin();
60  for (;str!=enumNames.end();++str){
61  ret.push_back( StringToEnumValue<MyType>(*str));
62  }
63  return ret;
64 
65 } //