WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
VectorStruct.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <fmt/format.h>
8#include <wpi/ct_string.h>
9#include <wpi/struct/Struct.h>
10
11#include "frc/EigenCore.h"
12
13template <int Size, int Options, int MaxRows, int MaxCols>
14struct wpi::Struct<frc::Matrixd<Size, 1, Options, MaxRows, MaxCols>> {
15 static constexpr ct_string kTypeName =
16 wpi::Concat("Vector__"_ct_string, wpi::NumToCtString<Size>());
17 static constexpr std::string_view GetTypeName() { return kTypeName; }
18 static constexpr size_t GetSize() { return Size * 8; }
19 static constexpr ct_string kSchema = wpi::Concat(
20 "double data["_ct_string, wpi::NumToCtString<Size>(), "]"_ct_string);
21 static constexpr std::string_view GetSchema() { return kSchema; }
22
24 std::span<const uint8_t> data) {
25 constexpr size_t kDataOff = 0;
29 for (int i = 0; i < Size; i++) {
30 vec(i) = vec_data[i];
31 }
32 return vec;
33 }
34
35 static void Pack(
36 std::span<uint8_t> data,
38 constexpr size_t kDataOff = 0;
40 for (int i = 0; i < Size; i++) {
41 vec_data[i] = value(i);
42 }
44 }
45};
46
This class is a wrapper around std::array that does compile time size checking.
Definition array.h:26
Specifies that a type is capable of raw struct serialization and deserialization.
Definition Struct.h:69
Definition CAN.h:11
Eigen::Matrix< double, Rows, Cols, Options, MaxRows, MaxCols > Matrixd
Definition EigenCore.h:21
constexpr auto NumToCtString()
Converts any integral to a ct_string at compile-time.
Definition ct_string.h:202
constexpr auto Concat(ct_string< Char, Traits, N1 > const &s1, ct_string< Char, Traits, N > const &... s)
Concatenates multiple fixed_strings into a larger fixed_string at compile time.
Definition ct_string.h:168
void PackStructArray(std::span< uint8_t > data, const wpi::array< T, N > &arr)
Pack a serialized struct array starting at a given offset within the data.
Definition Struct.h:234
constexpr empty_array_t empty_array
Definition array.h:16
wpi::array< T, N > UnpackStructArray(std::span< const uint8_t > data)
Unpack a serialized struct array starting at a given offset within the data.
Definition Struct.h:172
static frc::Matrixd< Size, 1, Options, MaxRows, MaxCols > Unpack(std::span< const uint8_t > data)
Definition VectorStruct.h:23
static constexpr std::string_view GetSchema()
Definition VectorStruct.h:21
static void Pack(std::span< uint8_t > data, const frc::Matrixd< Size, 1, Options, MaxRows, MaxCols > &value)
Definition VectorStruct.h:35
static constexpr size_t GetSize()
Definition VectorStruct.h:18
static constexpr std::string_view GetTypeName()
Definition VectorStruct.h:17
Struct serialization template.
Definition Struct.h:39
Fixed length string (array of character) for compile time use.
Definition ct_string.h:29