[wpiutil] Struct: Change from GetTypeString() to GetTypeName() (#6872)

This makes it easier to define schemas when the type name is non-trivial (e.g., templated structs).

This is breaking for a) custom struct implementations and b) anything calling `wpi::Struct<T>::GetTypeString(info...)` in C++ directly. In both cases, it's a simple translation: For A, rename `GetTypeString()` to `GetTypeName()` and remove the struct: at the beginning, and for B, use `wpi::GetStructTypeString<T>(info...)` instead.
This commit is contained in:
Joseph Eng
2024-07-27 20:23:45 -07:00
committed by GitHub
parent 5dcaa6d671
commit 158fb23072
58 changed files with 185 additions and 162 deletions

View File

@@ -15,8 +15,8 @@ public class ArmFeedforwardStruct implements Struct<ArmFeedforward> {
}
@Override
public String getTypeString() {
return "struct:ArmFeedforward";
public String getTypeName() {
return "ArmFeedforward";
}
@Override

View File

@@ -16,8 +16,8 @@ public class DifferentialDriveWheelVoltagesStruct
}
@Override
public String getTypeString() {
return "struct:DifferentialDriveWheelVoltages";
public String getTypeName() {
return "DifferentialDriveWheelVoltages";
}
@Override

View File

@@ -15,8 +15,8 @@ public class ElevatorFeedforwardStruct implements Struct<ElevatorFeedforward> {
}
@Override
public String getTypeString() {
return "struct:ElevatorFeedforward";
public String getTypeName() {
return "ElevatorFeedforward";
}
@Override

View File

@@ -16,8 +16,8 @@ public class Ellipse2dStruct implements Struct<Ellipse2d> {
}
@Override
public String getTypeString() {
return "struct:Ellipse2d";
public String getTypeName() {
return "Ellipse2d";
}
@Override

View File

@@ -17,8 +17,8 @@ public class Pose2dStruct implements Struct<Pose2d> {
}
@Override
public String getTypeString() {
return "struct:Pose2d";
public String getTypeName() {
return "Pose2d";
}
@Override

View File

@@ -17,8 +17,8 @@ public class Pose3dStruct implements Struct<Pose3d> {
}
@Override
public String getTypeString() {
return "struct:Pose3d";
public String getTypeName() {
return "Pose3d";
}
@Override

View File

@@ -15,8 +15,8 @@ public class QuaternionStruct implements Struct<Quaternion> {
}
@Override
public String getTypeString() {
return "struct:Quaternion";
public String getTypeName() {
return "Quaternion";
}
@Override

View File

@@ -16,8 +16,8 @@ public class Rectangle2dStruct implements Struct<Rectangle2d> {
}
@Override
public String getTypeString() {
return "struct:Rectangle2d";
public String getTypeName() {
return "Rectangle2d";
}
@Override

View File

@@ -15,8 +15,8 @@ public class Rotation2dStruct implements Struct<Rotation2d> {
}
@Override
public String getTypeString() {
return "struct:Rotation2d";
public String getTypeName() {
return "Rotation2d";
}
@Override

View File

@@ -16,8 +16,8 @@ public class Rotation3dStruct implements Struct<Rotation3d> {
}
@Override
public String getTypeString() {
return "struct:Rotation3d";
public String getTypeName() {
return "Rotation3d";
}
@Override

View File

@@ -17,8 +17,8 @@ public class Transform2dStruct implements Struct<Transform2d> {
}
@Override
public String getTypeString() {
return "struct:Transform2d";
public String getTypeName() {
return "Transform2d";
}
@Override

View File

@@ -17,8 +17,8 @@ public class Transform3dStruct implements Struct<Transform3d> {
}
@Override
public String getTypeString() {
return "struct:Transform3d";
public String getTypeName() {
return "Transform3d";
}
@Override

View File

@@ -15,8 +15,8 @@ public class Translation2dStruct implements Struct<Translation2d> {
}
@Override
public String getTypeString() {
return "struct:Translation2d";
public String getTypeName() {
return "Translation2d";
}
@Override

View File

@@ -15,8 +15,8 @@ public class Translation3dStruct implements Struct<Translation3d> {
}
@Override
public String getTypeString() {
return "struct:Translation3d";
public String getTypeName() {
return "Translation3d";
}
@Override

View File

@@ -15,8 +15,8 @@ public class Twist2dStruct implements Struct<Twist2d> {
}
@Override
public String getTypeString() {
return "struct:Twist2d";
public String getTypeName() {
return "Twist2d";
}
@Override

View File

@@ -15,8 +15,8 @@ public class Twist3dStruct implements Struct<Twist3d> {
}
@Override
public String getTypeString() {
return "struct:Twist3d";
public String getTypeName() {
return "Twist3d";
}
@Override

View File

@@ -15,8 +15,8 @@ public class ChassisSpeedsStruct implements Struct<ChassisSpeeds> {
}
@Override
public String getTypeString() {
return "struct:ChassisSpeeds";
public String getTypeName() {
return "ChassisSpeeds";
}
@Override

View File

@@ -15,8 +15,8 @@ public class DifferentialDriveKinematicsStruct implements Struct<DifferentialDri
}
@Override
public String getTypeString() {
return "struct:DifferentialDriveKinematics";
public String getTypeName() {
return "DifferentialDriveKinematics";
}
@Override

View File

@@ -16,8 +16,8 @@ public class DifferentialDriveWheelPositionsStruct
}
@Override
public String getTypeString() {
return "struct:DifferentialDriveWheelPositions";
public String getTypeName() {
return "DifferentialDriveWheelPositions";
}
@Override

View File

@@ -15,8 +15,8 @@ public class DifferentialDriveWheelSpeedsStruct implements Struct<DifferentialDr
}
@Override
public String getTypeString() {
return "struct:DifferentialDriveWheelSpeeds";
public String getTypeName() {
return "DifferentialDriveWheelSpeeds";
}
@Override

View File

@@ -16,8 +16,8 @@ public class MecanumDriveKinematicsStruct implements Struct<MecanumDriveKinemati
}
@Override
public String getTypeString() {
return "struct:MecanumDriveKinematics";
public String getTypeName() {
return "MecanumDriveKinematics";
}
@Override

View File

@@ -15,8 +15,8 @@ public class MecanumDriveWheelPositionsStruct implements Struct<MecanumDriveWhee
}
@Override
public String getTypeString() {
return "struct:MecanumDriveWheelPositions";
public String getTypeName() {
return "MecanumDriveWheelPositions";
}
@Override

View File

@@ -15,8 +15,8 @@ public class MecanumDriveWheelSpeedsStruct implements Struct<MecanumDriveWheelSp
}
@Override
public String getTypeString() {
return "struct:MecanumDriveWheelSpeeds";
public String getTypeName() {
return "MecanumDriveWheelSpeeds";
}
@Override

View File

@@ -16,8 +16,8 @@ public class SwerveModulePositionStruct implements Struct<SwerveModulePosition>
}
@Override
public String getTypeString() {
return "struct:SwerveModulePosition";
public String getTypeName() {
return "SwerveModulePosition";
}
@Override

View File

@@ -16,8 +16,8 @@ public class SwerveModuleStateStruct implements Struct<SwerveModuleState> {
}
@Override
public String getTypeString() {
return "struct:SwerveModuleState";
public String getTypeName() {
return "SwerveModuleState";
}
@Override

View File

@@ -15,8 +15,8 @@ public class DCMotorStruct implements Struct<DCMotor> {
}
@Override
public String getTypeString() {
return "struct:DCMotor";
public String getTypeName() {
return "DCMotor";
}
@Override

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::ArmFeedforward> {
static constexpr std::string_view GetTypeString() {
return "struct:ArmFeedforward";
}
static constexpr std::string_view GetTypeName() { return "ArmFeedforward"; }
static constexpr size_t GetSize() { return 32; }
static constexpr std::string_view GetSchema() {
return "double ks;double kg;double kv;double ka";

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::DifferentialDriveWheelVoltages> {
static constexpr std::string_view GetTypeString() {
return "struct:DifferentialDriveWheelVoltages";
static constexpr std::string_view GetTypeName() {
return "DifferentialDriveWheelVoltages";
}
static constexpr size_t GetSize() { return 16; }
static constexpr std::string_view GetSchema() {

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::ElevatorFeedforward> {
static constexpr std::string_view GetTypeString() {
return "struct:ElevatorFeedforward";
static constexpr std::string_view GetTypeName() {
return "ElevatorFeedforward";
}
static constexpr size_t GetSize() { return 32; }
static constexpr std::string_view GetSchema() {

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Ellipse2d> {
static constexpr std::string_view GetTypeString() {
return "struct:Ellipse2d";
}
static constexpr std::string_view GetTypeName() { return "Ellipse2d"; }
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Pose2d>() + 16;
}

View File

@@ -11,7 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Pose2d> {
static constexpr std::string_view GetTypeString() { return "struct:Pose2d"; }
static constexpr std::string_view GetTypeName() { return "Pose2d"; }
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Translation2d>() +
wpi::GetStructSize<frc::Rotation2d>();

View File

@@ -11,7 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Pose3d> {
static constexpr std::string_view GetTypeString() { return "struct:Pose3d"; }
static constexpr std::string_view GetTypeName() { return "Pose3d"; }
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Translation3d>() +
wpi::GetStructSize<frc::Rotation3d>();

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Quaternion> {
static constexpr std::string_view GetTypeString() {
return "struct:Quaternion";
}
static constexpr std::string_view GetTypeName() { return "Quaternion"; }
static constexpr size_t GetSize() { return 32; }
static constexpr std::string_view GetSchema() {
return "double w;double x;double y;double z";

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Rectangle2d> {
static constexpr std::string_view GetTypeString() {
return "struct:Rectangle2d";
}
static constexpr std::string_view GetTypeName() { return "Rectangle2d"; }
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Pose2d>() + 16;
}

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Rotation2d> {
static constexpr std::string_view GetTypeString() {
return "struct:Rotation2d";
}
static constexpr std::string_view GetTypeName() { return "Rotation2d"; }
static constexpr size_t GetSize() { return 8; }
static constexpr std::string_view GetSchema() { return "double value"; }

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Rotation3d> {
static constexpr std::string_view GetTypeString() {
return "struct:Rotation3d";
}
static constexpr std::string_view GetTypeName() { return "Rotation3d"; }
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Quaternion>();
}

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Transform2d> {
static constexpr std::string_view GetTypeString() {
return "struct:Transform2d";
}
static constexpr std::string_view GetTypeName() { return "Transform2d"; }
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Translation2d>() +
wpi::GetStructSize<frc::Rotation2d>();

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Transform3d> {
static constexpr std::string_view GetTypeString() {
return "struct:Transform3d";
}
static constexpr std::string_view GetTypeName() { return "Transform3d"; }
static constexpr size_t GetSize() {
return wpi::GetStructSize<frc::Translation3d>() +
wpi::GetStructSize<frc::Rotation3d>();

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Translation2d> {
static constexpr std::string_view GetTypeString() {
return "struct:Translation2d";
}
static constexpr std::string_view GetTypeName() { return "Translation2d"; }
static constexpr size_t GetSize() { return 16; }
static constexpr std::string_view GetSchema() { return "double x;double y"; }

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Translation3d> {
static constexpr std::string_view GetTypeString() {
return "struct:Translation3d";
}
static constexpr std::string_view GetTypeName() { return "Translation3d"; }
static constexpr size_t GetSize() { return 24; }
static constexpr std::string_view GetSchema() {
return "double x;double y;double z";

View File

@@ -11,7 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Twist2d> {
static constexpr std::string_view GetTypeString() { return "struct:Twist2d"; }
static constexpr std::string_view GetTypeName() { return "Twist2d"; }
static constexpr size_t GetSize() { return 24; }
static constexpr std::string_view GetSchema() {
return "double dx;double dy;double dtheta";

View File

@@ -11,7 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::Twist3d> {
static constexpr std::string_view GetTypeString() { return "struct:Twist3d"; }
static constexpr std::string_view GetTypeName() { return "Twist3d"; }
static constexpr size_t GetSize() { return 48; }
static constexpr std::string_view GetSchema() {
return "double dx;double dy;double dz;double rx;double ry;double rz";

View File

@@ -11,9 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::ChassisSpeeds> {
static constexpr std::string_view GetTypeString() {
return "struct:ChassisSpeeds";
}
static constexpr std::string_view GetTypeName() { return "ChassisSpeeds"; }
static constexpr size_t GetSize() { return 24; }
static constexpr std::string_view GetSchema() {
return "double vx;double vy;double omega";

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::DifferentialDriveKinematics> {
static constexpr std::string_view GetTypeString() {
return "struct:DifferentialDriveKinematics";
static constexpr std::string_view GetTypeName() {
return "DifferentialDriveKinematics";
}
static constexpr size_t GetSize() { return 8; }
static constexpr std::string_view GetSchema() { return "double track_width"; }

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::DifferentialDriveWheelPositions> {
static constexpr std::string_view GetTypeString() {
return "struct:DifferentialDriveWheelPositions";
static constexpr std::string_view GetTypeName() {
return "DifferentialDriveWheelPositions";
}
static constexpr size_t GetSize() { return 16; }
static constexpr std::string_view GetSchema() {

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::DifferentialDriveWheelSpeeds> {
static constexpr std::string_view GetTypeString() {
return "struct:DifferentialDriveWheelSpeeds";
static constexpr std::string_view GetTypeName() {
return "DifferentialDriveWheelSpeeds";
}
static constexpr size_t GetSize() { return 16; }
static constexpr std::string_view GetSchema() {

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::MecanumDriveKinematics> {
static constexpr std::string_view GetTypeString() {
return "struct:MecanumDriveKinematics";
static constexpr std::string_view GetTypeName() {
return "MecanumDriveKinematics";
}
static constexpr size_t GetSize() {
return 4 * wpi::GetStructSize<frc::Translation2d>();

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::MecanumDriveWheelPositions> {
static constexpr std::string_view GetTypeString() {
return "struct:MecanumDriveWheelPositions";
static constexpr std::string_view GetTypeName() {
return "MecanumDriveWheelPositions";
}
static constexpr size_t GetSize() { return 32; }
static constexpr std::string_view GetSchema() {

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::MecanumDriveWheelSpeeds> {
static constexpr std::string_view GetTypeString() {
return "struct:MecanumDriveWheelSpeeds";
static constexpr std::string_view GetTypeName() {
return "MecanumDriveWheelSpeeds";
}
static constexpr size_t GetSize() { return 32; }
static constexpr std::string_view GetSchema() {

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::SwerveModulePosition> {
static constexpr std::string_view GetTypeString() {
return "struct:SwerveModulePosition";
static constexpr std::string_view GetTypeName() {
return "SwerveModulePosition";
}
static constexpr size_t GetSize() {
return 8 + wpi::GetStructSize<frc::Rotation2d>();

View File

@@ -11,8 +11,8 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::SwerveModuleState> {
static constexpr std::string_view GetTypeString() {
return "struct:SwerveModuleState";
static constexpr std::string_view GetTypeName() {
return "SwerveModuleState";
}
static constexpr size_t GetSize() {
return 8 + wpi::GetStructSize<frc::Rotation2d>();

View File

@@ -11,7 +11,7 @@
template <>
struct WPILIB_DLLEXPORT wpi::Struct<frc::DCMotor> {
static constexpr std::string_view GetTypeString() { return "struct:DCMotor"; }
static constexpr std::string_view GetTypeName() { return "DCMotor"; }
static constexpr size_t GetSize() { return 40; }
static constexpr std::string_view GetSchema() {
return "double nominal_voltage;double stall_torque;double "