Click or drag to resize

EnumToName

Converts an enum value into a string representation..

template <typename T>
bool EnumToName(T enumVal, CString& strName) const;
Parameters
enumVal

[in] Enum value to be converted to a string.

strName

[out] String version of the specified enum value.

Return Value

Returns true if the conversion was successful, otherwise false.

Remarks

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.

Example

The following example demonstrates use of the EnumToName function.

C++
// 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;
}
See Also

Other Resources

Download a complete CHM version of this documentation here.