July 14, 2005

Using Flag based Enumerated Types


class EnumSample
{
#region ControlData

/// <summary>
/// Flag based enumerated type
/// </summary>
[Flags]
private enum ControlData
{
 /// <summary>
 /// No data of any kind available
 /// </summary>
 None = 0,
 /// <summary>
 /// Hist graph data is available
 /// </summary>
 Hist = 1,
 /// <summary>
 /// Curve graph data is available
 /// </summary>
 Curve = 2,
 /// <summary>
 /// XXX data is available
 /// </summary>
 XXX = 4
}


/// <summary>
/// Record what data is available for the viewer
/// </summary>
private ControlData m_ControlData = ControlData.None;

/// <summary>
/// Is the given Data Available
/// </summary>
/// <param name="datatype">Type of data required</param>
/// <returns></returns>
public bool IsDataAvailable(ControlData datatype)
{
  return ((m_ControlData & datatype) != ControlData.None);
}

/// <summary>
/// Add the given Data Available
/// </summary>
/// <param name="datatype">Type of data now available</param>
public void AddDataAvailable(ControlData value)
{
  m_ControlData |= value;
}

#endregion ControlData
}

No comments: