![]() | EnumToName |
Converts an enum value into a string representation..
template <typename T> bool EnumToName(T enumVal, CString& strName) const;
[in] Enum value to be converted to a string.
[out] String version of the specified enum value.
Returns true if the conversion was successful, otherwise false.
This function is typically used to report errors when enum values are not supported. For instance, it is much more helpful to the user if an error is reported as "Trigger source cannot be set to Acme4321TriggerSourceExternal" as opposed to "Trigger source cannot be set to 3".
Note that this function is used for a completely different purpose than the EnumToCommand function, which is used to map between enum values and their associated instrument commands.
The following example demonstrates use of the EnumToName function.
// CoAcme4321.cpp HRESULT Acme4321::ConfigureTrigger(IviFgenTriggerSource eSource) { HRESULT hr = S_OK; // Only internal and external triggering are supported switch (eSource) { case IviFgenTriggerSourceInternal: hr = io.WriteString(_T("TRIG:SOUR INT")); break; case IviFgenTriggerSourceExternal: hr = io.WriteString(_T("TRIG:SOUR EXT")); break; default: CString strEnum; EnumToName<IviFgenTriggerSource>(eSource, strEnum); hr = err.InvalidValue(_T("eSource"), strEnum); break; } return hr; }