mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
artf4154: Get rid of raw pointers in C++.
This deals with the majority of the user-facing code in wpilibC++Devices and a substantial portion of it in wpilibC++. wpilibC++Sim and wpilibC++IntegrationTests are untouched except where it is necessary to make them work with the rest of the libraries. There is still a lot to do in the following areas: -The HAL (which we may not want to touch at all). -The I2C, Serial, and SPI interfaces in wpilibC++Devices, which I haven't gotten around to doing yet. -Most wpilibC++Devices classes have void* pointers for interacting with the HAL. -InterruptableSensorBase passes a void *params for the interrupt handler. -I haven't converted all the const char* to std::strings. -There are plenty of other cases of raw pointers still existing. -This doesn't fall directly under raw pointer stuff, but move syntax and rvalue references could be introduced in many places. -I haven't touched vision code. -The Resource classes conflict (one is in the hal, the other in wpilibC++). Someone should figure out a more permanent fix (eg, just renaming them), then doing what I did (making a new namespace for one of them, essentially the same as renaming it). A few other things: -I created a NullDeleter class which is marked as deprecated. What this does is it can be passed as the deleter to a std::shared_ptr so that when you are converting raw pointers to shared_ptrs the shared_ptr doesn't do any deletion if someone else owns the raw pointer. This should only be used in making old raw pointer UIs. -I had to alter the build.gradle so that it did not emit errors when deprecated functions called deprecated functions. Unfortunately, gradle doesn't appear to be actually printing out gcc warnigns for some reason. The best way I have found to fix this is to patch the toolchains (https://bitbucket.org/byteit101/toolchain-builder/pull-request/5/make-gcc-not-throw-warnings-for-nested/diff) so that a deprecated function calling a deprecated function is fine but a non-deprecated function calling a deprecated function will throw a warning (which we then elevate with -Werror). I believe that clang deals with this properly, although I have not tried it myself. Change-Id: Ib8090c66893576fe73654f4e9d268f9d37be06a2
This commit is contained in:
@@ -55,7 +55,10 @@ Joystick::Joystick(uint32_t port)
|
||||
*/
|
||||
Joystick::Joystick(uint32_t port, uint32_t numAxisTypes,
|
||||
uint32_t numButtonTypes)
|
||||
: m_port(port) {
|
||||
: m_ds(DriverStation::GetInstance()),
|
||||
m_port(port),
|
||||
m_axes(numAxisTypes),
|
||||
m_buttons(numButtonTypes) {
|
||||
if (!joySticksInitialized) {
|
||||
for (auto& joystick : joysticks) joystick = nullptr;
|
||||
joySticksInitialized = true;
|
||||
@@ -65,10 +68,6 @@ Joystick::Joystick(uint32_t port, uint32_t numAxisTypes,
|
||||
} else {
|
||||
joysticks[m_port] = this;
|
||||
}
|
||||
|
||||
m_ds = DriverStation::GetInstance();
|
||||
m_axes = new uint32_t[numAxisTypes];
|
||||
m_buttons = new uint32_t[numButtonTypes];
|
||||
}
|
||||
|
||||
Joystick *Joystick::GetStickForPort(uint32_t port) {
|
||||
@@ -80,11 +79,6 @@ Joystick *Joystick::GetStickForPort(uint32_t port) {
|
||||
return stick;
|
||||
}
|
||||
|
||||
Joystick::~Joystick() {
|
||||
delete[] m_buttons;
|
||||
delete[] m_axes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the X value of the joystick.
|
||||
* This depends on the mapping of the joystick connected to the current port.
|
||||
@@ -132,7 +126,7 @@ float Joystick::GetThrottle() const {
|
||||
* @return The value of the axis.
|
||||
*/
|
||||
float Joystick::GetRawAxis(uint32_t axis) const {
|
||||
return m_ds->GetStickAxis(m_port, axis);
|
||||
return m_ds.GetStickAxis(m_port, axis);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,7 +203,7 @@ bool Joystick::GetBumper(JoystickHand hand) const {
|
||||
* @return The state of the button.
|
||||
**/
|
||||
bool Joystick::GetRawButton(uint32_t button) const {
|
||||
return m_ds->GetStickButton(m_port, button);
|
||||
return m_ds.GetStickButton(m_port, button);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,7 +213,7 @@ bool Joystick::GetRawButton(uint32_t button) const {
|
||||
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
|
||||
*/
|
||||
int Joystick::GetPOV(uint32_t pov) const {
|
||||
return m_ds->GetStickPOV(m_port, pov);
|
||||
return m_ds.GetStickPOV(m_port, pov);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,14 +240,14 @@ bool Joystick::GetButton(ButtonType button) const {
|
||||
*
|
||||
* @return the number of axis for the current joystick
|
||||
*/
|
||||
int Joystick::GetAxisCount() const { return m_ds->GetStickAxisCount(m_port); }
|
||||
int Joystick::GetAxisCount() const { return m_ds.GetStickAxisCount(m_port); }
|
||||
|
||||
/**
|
||||
* Get the value of isXbox for the joystick.
|
||||
*
|
||||
* @return A boolean that is true if the joystick is an xbox controller.
|
||||
*/
|
||||
bool Joystick::GetIsXbox() const { return m_ds->GetJoystickIsXbox(m_port); }
|
||||
bool Joystick::GetIsXbox() const { return m_ds.GetJoystickIsXbox(m_port); }
|
||||
|
||||
/**
|
||||
* Get the HID type of the controller.
|
||||
@@ -261,7 +255,7 @@ bool Joystick::GetIsXbox() const { return m_ds->GetJoystickIsXbox(m_port); }
|
||||
* @return the HID type of the controller.
|
||||
*/
|
||||
Joystick::HIDType Joystick::GetType() const {
|
||||
return static_cast<HIDType>(m_ds->GetJoystickType(m_port));
|
||||
return static_cast<HIDType>(m_ds.GetJoystickType(m_port));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,11 +263,11 @@ Joystick::HIDType Joystick::GetType() const {
|
||||
*
|
||||
* @return the name of the controller.
|
||||
*/
|
||||
std::string Joystick::GetName() const { return m_ds->GetJoystickName(m_port); }
|
||||
std::string Joystick::GetName() const { return m_ds.GetJoystickName(m_port); }
|
||||
|
||||
// int Joystick::GetAxisType(uint8_t axis) const
|
||||
//{
|
||||
// return m_ds->GetJoystickAxisType(m_port, axis);
|
||||
// return m_ds.GetJoystickAxisType(m_port, axis);
|
||||
//}
|
||||
|
||||
/**
|
||||
@@ -282,7 +276,7 @@ std::string Joystick::GetName() const { return m_ds->GetJoystickName(m_port); }
|
||||
* @return the number of buttons on the current joystick
|
||||
*/
|
||||
int Joystick::GetButtonCount() const {
|
||||
return m_ds->GetStickButtonCount(m_port);
|
||||
return m_ds.GetStickButtonCount(m_port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -290,7 +284,7 @@ int Joystick::GetButtonCount() const {
|
||||
*
|
||||
* @return then umber of POVs for the current joystick
|
||||
*/
|
||||
int Joystick::GetPOVCount() const { return m_ds->GetStickPOVCount(m_port); }
|
||||
int Joystick::GetPOVCount() const { return m_ds.GetStickPOVCount(m_port); }
|
||||
|
||||
/**
|
||||
* Get the channel currently associated with the specified axis.
|
||||
|
||||
Reference in New Issue
Block a user