Skip to content

Commit

Permalink
Specify all template parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Nov 29, 2023
1 parent 67e4d57 commit 5f71828
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
14 changes: 9 additions & 5 deletions wpimath/src/main/native/include/frc/proto/MatrixProto.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@

#include "frc/EigenCore.h"

template <int Rows, int Cols>
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Matrixd<Rows, Cols>> {
template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
requires(Cols != 1)
struct WPILIB_DLLEXPORT
wpi::Protobuf<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>> {
static google::protobuf::Message* New(google::protobuf::Arena* arena);
static frc::Matrixd<Rows, Cols> Unpack(const google::protobuf::Message& msg);
static void Pack(google::protobuf::Message* msg,
const frc::Matrixd<Rows, Cols>& value);
static frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols> Unpack(
const google::protobuf::Message& msg);
static void Pack(
google::protobuf::Message* msg,
const frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>& value);
};

#include "frc/proto/MatrixProto.inc"
22 changes: 14 additions & 8 deletions wpimath/src/main/native/include/frc/proto/MatrixProto.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
#include "frc/proto/MatrixProto.h"
#include "wpimath.pb.h"

template <int Rows, int Cols>
google::protobuf::Message* wpi::Protobuf<frc::Matrixd<Rows, Cols>>::New(
template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
requires(Cols != 1)
google::protobuf::Message*
wpi::Protobuf<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<wpi::proto::ProtobufMatrix>(
arena);
}

template <int Rows, int Cols>
frc::Matrixd<Rows, Cols> wpi::Protobuf<frc::Matrixd<Rows, Cols>>::Unpack(
template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
requires(Cols != 1)
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>
wpi::Protobuf<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufMatrix*>(&msg);
if (m->num_rows() != Rows || m->num_cols() != Cols) {
Expand All @@ -24,16 +28,18 @@ frc::Matrixd<Rows, Cols> wpi::Protobuf<frc::Matrixd<Rows, Cols>>::Unpack(
if (m->data_size() != Rows * Cols) {
// TODO Error
}
frc::Matrixd<Rows, Cols> mat;
frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols> mat;
for (int i = 0; i < Rows * Cols; i++) {
mat(i) = m->data(i);
}
return mat;
}

template <int Rows, int Cols>
void wpi::Protobuf<frc::Matrixd<Rows, Cols>>::Pack(
google::protobuf::Message* msg, const frc::Matrixd<Rows, Cols>& value) {
template <int Rows, int Cols, int Options, int MaxRows, int MaxCols>
requires(Cols != 1)
void wpi::Protobuf<frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>>::Pack(
google::protobuf::Message* msg,
const frc::Matrixd<Rows, Cols, Options, MaxRows, MaxCols>& value) {
auto m = static_cast<wpi::proto::ProtobufMatrix*>(msg);
m->set_num_rows(Rows);
m->set_num_cols(Cols);
Expand Down
13 changes: 8 additions & 5 deletions wpimath/src/main/native/include/frc/proto/VectorProto.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@

#include "frc/EigenCore.h"

template <int Size>
struct WPILIB_DLLEXPORT wpi::Protobuf<frc::Matrixd<Size, 1>> {
template <int Size, int Options, int MaxRows, int MaxCols>
struct WPILIB_DLLEXPORT
wpi::Protobuf<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>> {
static google::protobuf::Message* New(google::protobuf::Arena* arena);
static frc::Vectord<Size> Unpack(const google::protobuf::Message& msg);
static void Pack(google::protobuf::Message* msg,
const frc::Vectord<Size>& value);
static frc::Matrixd<Size, 1, Options, MaxRows, MaxCols> Unpack(
const google::protobuf::Message& msg);
static void Pack(
google::protobuf::Message* msg,
const frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>& value);
};

#include "frc/proto/VectorProto.inc"
19 changes: 11 additions & 8 deletions wpimath/src/main/native/include/frc/proto/VectorProto.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,33 @@
#include "frc/proto/VectorProto.h"
#include "wpimath.pb.h"

template <int Size>
google::protobuf::Message* wpi::Protobuf<frc::Vectord<Size>>::New(
template <int Size, int Options, int MaxRows, int MaxCols>
google::protobuf::Message*
wpi::Protobuf<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>>::New(
google::protobuf::Arena* arena) {
return google::protobuf::Arena::CreateMessage<wpi::proto::ProtobufVector>(
arena);
}

template <int Size>
frc::Vectord<Size> wpi::Protobuf<frc::Vectord<Size>>::Unpack(
template <int Size, int Options, int MaxRows, int MaxCols>
frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>
wpi::Protobuf<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>>::Unpack(
const google::protobuf::Message& msg) {
auto m = static_cast<const wpi::proto::ProtobufVector*>(&msg);
if (m->rows_size() != Size) {
// TODO Error
}
frc::Vectord<Size> vec;
frc::Matrixd<Size, 1, Options, MaxRows, MaxCols> vec;
for (int i = 0; i < Size; i++) {
vec(i) = m->rows(i);
}
return vec;
}

template <int Size>
void wpi::Protobuf<frc::Vectord<Size>>::Pack(google::protobuf::Message* msg,
const frc::Vectord<Size>& value) {
template <int Size, int Options, int MaxRows, int MaxCols>
void wpi::Protobuf<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>>::Pack(
google::protobuf::Message* msg,
const frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>& value) {
auto m = static_cast<wpi::proto::ProtobufVector*>(msg);
m->clear_rows();
for (int i = 0; i < Size; i++) {
Expand Down

0 comments on commit 5f71828

Please sign in to comment.