#include "FWCore/Utilities/interface/Exception.h"
#include <Reflex/Reflex.h>
#include <string>
#include <sstream>
#include <vector>
Go to the source code of this file.
Functions | |
template<class MyType > | |
int | StringToEnumValue (const std::string &enumName) |
template<class MyType > | |
std::vector< int > | StringToEnumValue (const std::vector< std::string > &enumNames) |
int StringToEnumValue | ( | const std::string & | enumName | ) |
Convert a string into the enum value it corresponds to. Example: int value = StringToEnumValue<EcalRecHit::Flags>("kGood");
Definition at line 25 of file StringToEnumValue.h.
References Exception.
{ using namespace ROOT::Reflex; Reflex::Type rflxType = Reflex::Type::ByTypeInfo(typeid(MyType)); Reflex::Member member = rflxType.MemberByName(enumName); if (!member) { std::ostringstream err; err<<"StringToEnumValue Failure trying to convert " << enumName << " to int value"; throw cms::Exception("ConversionError",err.str()); } if (member.TypeOf().TypeInfo() != typeid(int)) { std::ostringstream err; err << "Type "<< member.TypeOf().Name() << " is not Enum"; throw cms::Exception("ConversionError",err.str()); } return Object_Cast<int>(member.Get()); } //
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 71 of file StringToEnumValue.h.
References runTheMatrix::ret.