Skip to content

Commit

Permalink
Implement nested behavior for C++ structs
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Jul 21, 2024
1 parent a812c07 commit 557ebb1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ struct wpi::Struct<frc::SwerveDriveKinematics<NumModules>> {
std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const frc::SwerveDriveKinematics<NumModules>& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Translation2d>(fn);
}
};

static_assert(wpi::StructSerializable<frc::SwerveDriveKinematics<4>>);
static_assert(wpi::HasNestedStruct<frc::SwerveDriveKinematics<4>>);
static_assert(wpi::StructSerializable<frc::SwerveDriveKinematics<3>>);
static_assert(wpi::HasNestedStruct<frc::SwerveDriveKinematics<3>>);

#include "frc/kinematics/struct/SwerveDriveKinematicsStruct.inc"
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ struct wpi::Struct<frc::LinearSystem<States, Inputs, Outputs>> {
std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const frc::LinearSystem<States, Inputs, Outputs>& value);
static void ForEachNested(
std::invocable<std::string_view, std::string_view> auto fn) {
wpi::ForEachStructSchema<frc::Matrixd<States, States>>(fn);
wpi::ForEachStructSchema<frc::Matrixd<States, Inputs>>(fn);
wpi::ForEachStructSchema<frc::Matrixd<Outputs, States>>(fn);
wpi::ForEachStructSchema<frc::Matrixd<Outputs, Inputs>>(fn);
}
};

static_assert(wpi::StructSerializable<frc::LinearSystem<4, 3, 2>>);
static_assert(wpi::HasNestedStruct<frc::LinearSystem<4, 3, 2>>);
static_assert(wpi::StructSerializable<frc::LinearSystem<2, 3, 4>>);
static_assert(wpi::HasNestedStruct<frc::LinearSystem<2, 3, 4>>);

#include "frc/system/struct/LinearSystemStruct.inc"

0 comments on commit 557ebb1

Please sign in to comment.