WPILibC++ 2024.1.1-beta-4
hal::SimDevice Class Reference

A move-only C++ wrapper around a HAL simulator device handle. More...

#include <hal/SimDevice.h>

Public Types

enum  Direction { kInput = HAL_SimValueInput , kOutput = HAL_SimValueOutput , kBidir = HAL_SimValueBidir }
 Direction of a simulated value (from the perspective of user code). More...
 

Public Member Functions

 SimDevice ()=default
 Default constructor that results in an "empty" object that is false in a boolean context. More...
 
 SimDevice (const char *name)
 Creates a simulated device. More...
 
 SimDevice (const char *name, int index)
 Creates a simulated device. More...
 
 SimDevice (const char *name, int index, int channel)
 Creates a simulated device. More...
 
 ~SimDevice ()
 
 SimDevice (const SimDevice &)=delete
 
SimDeviceoperator= (const SimDevice &)=delete
 
 SimDevice (SimDevice &&rhs)
 
SimDeviceoperator= (SimDevice &&rhs)
 
 operator bool () const
 Determine if handle is empty. More...
 
 operator HAL_SimDeviceHandle () const
 Get the internal device handle. More...
 
std::string GetName () const
 Get the name of the simulated device. More...
 
SimValue CreateValue (const char *name, int32_t direction, const HAL_Value &initialValue)
 Creates a value on the simulated device. More...
 
SimInt CreateInt (const char *name, int32_t direction, int32_t initialValue)
 Creates an int value on the simulated device. More...
 
SimLong CreateLong (const char *name, int32_t direction, int64_t initialValue)
 Creates a long value on the simulated device. More...
 
SimDouble CreateDouble (const char *name, int32_t direction, double initialValue)
 Creates a double value on the simulated device. More...
 
SimEnum CreateEnum (const char *name, int32_t direction, std::initializer_list< const char * > options, int32_t initialValue)
 Creates an enumerated value on the simulated device. More...
 
SimEnum CreateEnum (const char *name, int32_t direction, std::span< const char *const > options, int32_t initialValue)
 Creates an enumerated value on the simulated device. More...
 
SimEnum CreateEnumDouble (const char *name, int32_t direction, std::initializer_list< const char * > options, std::initializer_list< double > optionValues, int32_t initialValue)
 Creates an enumerated value on the simulated device with double values. More...
 
SimEnum CreateEnumDouble (const char *name, int32_t direction, std::span< const char *const > options, std::span< const double > optionValues, int32_t initialValue)
 Creates an enumerated value on the simulated device with double values. More...
 
SimBoolean CreateBoolean (const char *name, int32_t direction, bool initialValue)
 Creates a boolean value on the simulated device. More...
 

Protected Attributes

HAL_SimDeviceHandle m_handle = HAL_kInvalidHandle
 

Detailed Description

A move-only C++ wrapper around a HAL simulator device handle.

Member Enumeration Documentation

◆ Direction

Direction of a simulated value (from the perspective of user code).

Enumerator
kInput 
kOutput 
kBidir 

Constructor & Destructor Documentation

◆ SimDevice() [1/6]

hal::SimDevice::SimDevice ( )
default

Default constructor that results in an "empty" object that is false in a boolean context.

◆ SimDevice() [2/6]

hal::SimDevice::SimDevice ( const char *  name)
inlineexplicit

Creates a simulated device.

The device name must be unique. Returns null if the device name already exists. If multiple instances of the same device are desired, recommend appending the instance/unique identifier in brackets to the base name, e.g. "device[1]".

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namedevice name

◆ SimDevice() [3/6]

hal::SimDevice::SimDevice ( const char *  name,
int  index 
)

Creates a simulated device.

The device name must be unique. Returns null if the device name already exists. This is a convenience method that appends index in brackets to the device name, e.g. passing index=1 results in "device[1]" for the device name.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namedevice name
indexdevice index number to append to name

◆ SimDevice() [4/6]

hal::SimDevice::SimDevice ( const char *  name,
int  index,
int  channel 
)

Creates a simulated device.

The device name must be unique. Returns null if the device name already exists. This is a convenience method that appends index and channel in brackets to the device name, e.g. passing index=1 and channel=2 results in "device[1,2]" for the device name.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namedevice name
indexdevice index number to append to name
channeldevice channel number to append to name

◆ ~SimDevice()

hal::SimDevice::~SimDevice ( )
inline

◆ SimDevice() [5/6]

hal::SimDevice::SimDevice ( const SimDevice )
delete

◆ SimDevice() [6/6]

hal::SimDevice::SimDevice ( SimDevice &&  rhs)
inline

Member Function Documentation

◆ CreateBoolean()

SimBoolean hal::SimDevice::CreateBoolean ( const char *  name,
int32_t  direction,
bool  initialValue 
)
inline

Creates a boolean value on the simulated device.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated boolean value object

◆ CreateDouble()

SimDouble hal::SimDevice::CreateDouble ( const char *  name,
int32_t  direction,
double  initialValue 
)
inline

Creates a double value on the simulated device.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated double value object

◆ CreateEnum() [1/2]

SimEnum hal::SimDevice::CreateEnum ( const char *  name,
int32_t  direction,
std::initializer_list< const char * >  options,
int32_t  initialValue 
)
inline

Creates an enumerated value on the simulated device.

Enumerated values are always in the range 0 to numOptions-1.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namevalue name
directioninput/output/bidir (from perspective of user code)
optionsarray of option descriptions
initialValueinitial value (selection)
Returns
simulated enum value object

◆ CreateEnum() [2/2]

SimEnum hal::SimDevice::CreateEnum ( const char *  name,
int32_t  direction,
std::span< const char *const >  options,
int32_t  initialValue 
)
inline

Creates an enumerated value on the simulated device.

Enumerated values are always in the range 0 to numOptions-1.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namevalue name
directioninput/output/bidir (from perspective of user code)
optionsarray of option descriptions
initialValueinitial value (selection)
Returns
simulated enum value object

◆ CreateEnumDouble() [1/2]

SimEnum hal::SimDevice::CreateEnumDouble ( const char *  name,
int32_t  direction,
std::initializer_list< const char * >  options,
std::initializer_list< double >  optionValues,
int32_t  initialValue 
)
inline

Creates an enumerated value on the simulated device with double values.

Enumerated values are always in the range 0 to numOptions-1.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namevalue name
directioninput/output/bidir (from perspective of user code)
optionsarray of option descriptions
optionValuesarray of option values (must be the same size as options)
initialValueinitial value (selection)
Returns
simulated enum value object

◆ CreateEnumDouble() [2/2]

SimEnum hal::SimDevice::CreateEnumDouble ( const char *  name,
int32_t  direction,
std::span< const char *const >  options,
std::span< const double >  optionValues,
int32_t  initialValue 
)
inline

Creates an enumerated value on the simulated device with double values.

Enumerated values are always in the range 0 to numOptions-1.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namevalue name
directioninput/output/bidir (from perspective of user code)
optionsarray of option descriptions
optionValuesarray of option values (must be the same size as options)
initialValueinitial value (selection)
Returns
simulated enum value object

◆ CreateInt()

SimInt hal::SimDevice::CreateInt ( const char *  name,
int32_t  direction,
int32_t  initialValue 
)
inline

Creates an int value on the simulated device.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated double value object

◆ CreateLong()

SimLong hal::SimDevice::CreateLong ( const char *  name,
int32_t  direction,
int64_t  initialValue 
)
inline

Creates a long value on the simulated device.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated double value object

◆ CreateValue()

SimValue hal::SimDevice::CreateValue ( const char *  name,
int32_t  direction,
const HAL_Value initialValue 
)
inline

Creates a value on the simulated device.

If not in simulation, results in an "empty" object that evaluates to false in a boolean context.

Parameters
namevalue name
directioninput/output/bidir (from perspective of user code)
initialValueinitial value
Returns
simulated value object

◆ GetName()

std::string hal::SimDevice::GetName ( ) const
inline

Get the name of the simulated device.

Returns
name

◆ operator bool()

hal::SimDevice::operator bool ( ) const
inlineexplicit

Determine if handle is empty.

Should be used to optimize out code paths that are taken/not taken in simulation.

Returns
False if handle is empty, true if handle is valid.

◆ operator HAL_SimDeviceHandle()

hal::SimDevice::operator HAL_SimDeviceHandle ( ) const
inline

Get the internal device handle.

Returns
internal handle

◆ operator=() [1/2]

SimDevice & hal::SimDevice::operator= ( const SimDevice )
delete

◆ operator=() [2/2]

SimDevice & hal::SimDevice::operator= ( SimDevice &&  rhs)
inline

Member Data Documentation

◆ m_handle

HAL_SimDeviceHandle hal::SimDevice::m_handle = HAL_kInvalidHandle
protected

The documentation for this class was generated from the following file: