[wpilib] Document simulation APIs (#3079)

- Remove sim checkstyle suppression
- Add [[nodiscard]] to C++ register callback functions
- Add a couple of missing sim functions

Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
Co-authored-by: Starlight220 <yotamshlomi@gmail.com>
This commit is contained in:
Peter Johnson
2021-01-11 21:55:45 -08:00
committed by GitHub
parent 26584ff145
commit 9c3b51ca0f
64 changed files with 4516 additions and 199 deletions

View File

@@ -25,26 +25,84 @@ class SimDeviceSim {
*/
explicit SimDeviceSim(const char* name);
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimValue GetValue(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimInt GetInt(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimLong GetLong(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimDouble GetDouble(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimEnum GetEnum(const char* name) const;
/**
* Get the property object with the given name.
*
* @param name the property name
* @return the property object
*/
hal::SimBoolean GetBoolean(const char* name) const;
/**
* Get all options for the given enum.
*
* @param val the enum
* @return names of the different values for that enum
*/
static std::vector<std::string> GetEnumOptions(hal::SimEnum val);
/**
* Get all properties.
*
* @param callback callback called for each property (SimValue). Signature
* of the callback must be const char*, HAL_SimValueHandle,
* int, const HAL_Value*
*/
template <typename F>
void EnumerateValues(F callback) const {
return HALSIM_EnumerateSimValues(
m_handle, &callback,
[](const char* name, void* param, HAL_SimValueHandle handle,
HAL_Bool readonly, const struct HAL_Value* value) {
std::invoke(*static_cast<F*>(param), name, handle, readonly, value);
int direction, const struct HAL_Value* value) {
std::invoke(*static_cast<F*>(param), name, handle, direction, value);
});
}
/**
* Get the raw handle of this object.
*
* @return the handle used to refer to this object
*/
operator HAL_SimDeviceHandle() const { return m_handle; } // NOLINT
template <typename F>
@@ -56,6 +114,9 @@ class SimDeviceSim {
});
}
/**
* Reset all SimDevice data.
*/
static void ResetData();
private: