Simple factory to create an enumerator for a given enumeration. More...
#include "utl/ConsecutiveEnumFactory.h"
Static Public Member Functions | |
static EnumType | Create (const int k) |
int version of the overloaded creation method. More... | |
static EnumType | Create (const std::string &tag) |
std::string version of the overloaded creation method. More... | |
Static Public Attributes | |
static const unsigned int | kNumEnum = last - first + 1 |
Static Private Member Functions | |
template<typename T > | |
static EnumType | Handle (const T &t) |
Error handling. More... | |
Simple factory to create an enumerator for a given enumeration.
Provides two alternatives for creation, via an int or via an std::string, both under the form of an overloaded method called Create.
As implied by the name, it is required (but not actually checked by some language construct) that the enumeration is defined with consecutive values. Also, the fact that EnumType
is actually an enum is not checked. The behavior under error (i.e. no enumerator with the given value) is defined by NoConversionPolicy
. The implied condition First <= Last is not checked either. This method is mainly useful in terms of I/O of enumerators.
The Tags
is expected to have a length equal to the number of enumerators (as implied by First
and Last
) and to be in correspondence with the order defined in the enumertion. That is Tags
[i] contains the label for the enumerator with First + i integral value.
It may be convinent for clients to define a typedef as an alias for the particular needed instantiation of this class.
For a given enumerator type there should be a single instantiation of the template class.
EnumType | The actual enumeration type. |
Last | The greatest enumerator. |
Tags | Labels for each of the enumerators. |
NoConversionPolicy | Policy type for no conversion. It is supposed to define a method compatible with the following signature EnumType Handle(const std::string&). This argument defaults to an exception throwing policy (utl::ThrowPolicy) , with exception type utl::IOFailureException. Via the allowed return value of Handle the user can provide an error-condition value. |
First | The smallest enumerator. Defaults to zero (expicitly converted to the EnumType ). |
This class is related, is some way, to utl::ObjectFactory but this last class is much more complex (and useful) than the one here defined.
Definition at line 118 of file ConsecutiveEnumFactory.h.
|
inlinestatic |
int version of the overloaded creation method.
Definition at line 139 of file ConsecutiveEnumFactory.h.
Referenced by utl::ConfigParameter::ConfigParameter(), mdet::Module::GetAreaKind(), mdet::Fiber::GetAttenuationReference(), mdet::Module::GetPhotoDetector(), mdet::Pixel::GetPulseParametrization(), MdPileUpCorrecterAG::MdPileUpCorrecter::Init(), MdPatternFinderAG::MdPatternFinder::Init(), MdMuonEstimatorAG::MdMuonEstimator::Init(), MdMuonCounterAG::MdMuonCounter::Init(), MdLDFFinderAG::MdLDFFinder::Init(), MdOptoElectronicSimulatorAG::MdOptoElectronicSimulator::Init(), and MdCounterSimulatorAG::MdCounterSimulator::Init().
|
inlinestatic |
std::string version of the overloaded creation method.
Definition at line 148 of file ConsecutiveEnumFactory.h.
|
inlinestaticprivate |
Error handling.
Definition at line 123 of file ConsecutiveEnumFactory.h.
|
static |
Number of enumerators. Calculated based on the fact that are consecutive.
Definition at line 135 of file ConsecutiveEnumFactory.h.