WPILibC++ 2024.3.2
MathShared.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 <memory>
8
9#include <fmt/format.h>
10#include <wpi/SymbolExports.h>
11
12#include "units/time.h"
13
14namespace wpi::math {
15
16enum class MathUsageId {
17 kKinematics_DifferentialDrive,
18 kKinematics_MecanumDrive,
19 kKinematics_SwerveDrive,
22 kOdometry_DifferentialDrive,
23 kOdometry_SwerveDrive,
24 kOdometry_MecanumDrive,
27};
28
30 public:
31 virtual ~MathShared() = default;
34 fmt::format_args args) = 0;
35 virtual void ReportUsage(MathUsageId id, int count) = 0;
36 virtual units::second_t GetTimestamp() = 0;
37
38 template <typename S, typename... Args>
39 inline void ReportError(const S& format, Args&&... args) {
41 }
42
43 template <typename S, typename... Args>
44 inline void ReportWarning(const S& format, Args&&... args) {
45 ReportWarningV(format, fmt::make_format_args(args...));
46 }
47};
48
50 public:
52
53 static void SetMathShared(std::unique_ptr<MathShared> shared);
54
56 GetMathShared().ReportErrorV(format, args);
57 }
58
59 template <typename S, typename... Args>
60 static inline void ReportError(const S& format, Args&&... args) {
62 }
63
65 GetMathShared().ReportWarningV(format, args);
66 }
67
68 template <typename S, typename... Args>
69 static inline void ReportWarning(const S& format, Args&&... args) {
70 ReportWarningV(format, fmt::make_format_args(args...));
71 }
72
73 static void ReportUsage(MathUsageId id, int count) {
74 GetMathShared().ReportUsage(id, count);
75 }
76
77 static units::second_t GetTimestamp() {
78 return GetMathShared().GetTimestamp();
79 }
80};
81
82} // namespace wpi::math
#define WPILIB_DLLEXPORT
Definition: SymbolExports.h:36
Definition: MathShared.h:29
virtual void ReportWarningV(fmt::string_view format, fmt::format_args args)=0
virtual void ReportUsage(MathUsageId id, int count)=0
void ReportError(const S &format, Args &&... args)
Definition: MathShared.h:39
virtual void ReportErrorV(fmt::string_view format, fmt::format_args args)=0
virtual units::second_t GetTimestamp()=0
void ReportWarning(const S &format, Args &&... args)
Definition: MathShared.h:44
virtual ~MathShared()=default
Definition: MathShared.h:49
static void SetMathShared(std::unique_ptr< MathShared > shared)
static void ReportErrorV(fmt::string_view format, fmt::format_args args)
Definition: MathShared.h:55
static MathShared & GetMathShared()
static void ReportError(const S &format, Args &&... args)
Definition: MathShared.h:60
static units::second_t GetTimestamp()
Definition: MathShared.h:77
static void ReportUsage(MathUsageId id, int count)
Definition: MathShared.h:73
static void ReportWarning(const S &format, Args &&... args)
Definition: MathShared.h:69
static void ReportWarningV(fmt::string_view format, fmt::format_args args)
Definition: MathShared.h:64
basic_string_view< char > string_view
Definition: core.h:501
constexpr auto make_format_args(T &... args) -> format_arg_store< Context, remove_cvref_t< T >... >
\rst Constructs a ~fmtformat_arg_store object that contains references to arguments and can be implic...
Definition: core.h:1824
basic_format_args< format_context > format_args
An alias to basic_format_args<format_context>.
Definition: core.h:1971
constexpr auto count() -> size_t
Definition: core.h:1203
void ReportErrorV(int32_t status, const char *fileName, int lineNumber, const char *funcName, fmt::string_view format, fmt::format_args args)
Reports an error to the driver station (using HAL_SendError).
Definition: MathShared.h:14
MathUsageId
Definition: MathShared.h:16
#define S(label, offset, message)
Definition: Errors.h:119
auto format(wformat_string< T... > fmt, T &&... args) -> std::wstring
Definition: xchar.h:108