Skip to content

Commit

Permalink
Fix usage of namespace {} in .inc files
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Jul 16, 2024
1 parent c8dfb43 commit c9c1126
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@

#include "frc/controller/struct/SimpleMotorFeedforwardStruct.h"

namespace {
constexpr size_t kKsOff = 0;
constexpr size_t kKvOff = kKsOff + 8;
constexpr size_t kKaOff = kKvOff + 8;
} // namespace

template <class Distance>
frc::SimpleMotorFeedforward<Distance>
wpi::Struct<frc::SimpleMotorFeedforward<Distance>>::Unpack(
std::span<const uint8_t> data) {
constexpr size_t kKsOff = 0;
constexpr size_t kKvOff = kKsOff + 8;
constexpr size_t kKaOff = kKvOff + 8;
return {units::volt_t{wpi::UnpackStruct<double, kKsOff>(data)},
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::kv_unit>{
wpi::UnpackStruct<double, kKvOff>(data)},
Expand All @@ -27,6 +24,9 @@ template <class Distance>
void wpi::Struct<frc::SimpleMotorFeedforward<Distance>>::Pack(
std::span<uint8_t> data,
const frc::SimpleMotorFeedforward<Distance>& value) {
constexpr size_t kKsOff = 0;
constexpr size_t kKvOff = kKsOff + 8;
constexpr size_t kKaOff = kKvOff + 8;
wpi::PackStruct<kKsOff>(data, value.kS.value());
wpi::PackStruct<kKvOff>(
data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@

#include "frc/kinematics/struct/SwerveDriveKinematicsStruct.h"

namespace {
constexpr size_t kModulesOff = 0;
} // namespace

template <size_t NumModules>
frc::SwerveDriveKinematics<NumModules>
wpi::Struct<frc::SwerveDriveKinematics<NumModules>>::Unpack(
std::span<const uint8_t> data) {
constexpr size_t kModulesOff = 0;
return frc::SwerveDriveKinematics<NumModules>{
wpi::UnpackStructArray<frc::Translation2d, kModulesOff, NumModules>(
data)};
Expand All @@ -23,5 +20,6 @@ template <size_t NumModules>
void wpi::Struct<frc::SwerveDriveKinematics<NumModules>>::Pack(
std::span<uint8_t> data,
const frc::SwerveDriveKinematics<NumModules>& value) {
constexpr size_t kModulesOff = 0;
wpi::PackStructArray<kModulesOff, NumModules>(data, value.GetModules());
}
6 changes: 2 additions & 4 deletions wpimath/src/main/native/include/frc/struct/MatrixStruct.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

#include "frc/struct/MatrixStruct.h"

namespace {
constexpr size_t kDataOff = 0;
} // namespace

template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
requires(Cols != 1)
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>
wpi::Struct<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>::Unpack(
std::span<const uint8_t> data) {
constexpr size_t kDataOff = 0;
wpi::array<double, Rows * Cols> mat_data =
wpi::UnpackStructArray<double, kDataOff, Rows * Cols>(data);
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols> mat;
Expand All @@ -29,6 +26,7 @@ template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
void wpi::Struct<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>::Pack(
std::span<uint8_t> data,
const frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>& value) {
constexpr size_t kDataOff = 0;
wpi::array<double, Rows * Cols> mat_data(wpi::empty_array);
for (int i = 0; i < Rows * Cols; i++) {
mat_data[i] = value(i);
Expand Down
6 changes: 2 additions & 4 deletions wpimath/src/main/native/include/frc/struct/VectorStruct.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@

#include "frc/struct/VectorStruct.h"

namespace {
constexpr size_t kDataOff = 0;
} // namespace

template <int Size, int Options, int MaxRows, int MaxCols>
frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>
wpi::Struct<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>>::Unpack(
std::span<const uint8_t> data) {
constexpr size_t kDataOff = 0;
wpi::array<double, Size> vec_data =
wpi::UnpackStructArray<double, kDataOff, Size>(data);
frc::Matrixd<Size, 1, Options, MaxRows, MaxCols> vec;
Expand All @@ -27,6 +24,7 @@ template <int Size, int Options, int MaxRows, int MaxCols>
void wpi::Struct<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>>::Pack(
std::span<uint8_t> data,
const frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>& value) {
constexpr size_t kDataOff = 0;
wpi::array<double, Size> vec_data(wpi::empty_array);
for (int i = 0; i < Size; i++) {
vec_data[i] = value(i);
Expand Down

0 comments on commit c9c1126

Please sign in to comment.