WPILibC++ 2026.1.1
Loading...
Searching...
No Matches
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
35
37 public:
38 virtual ~MathShared() = default;
39 virtual void ReportErrorV(fmt::string_view format, fmt::format_args args) = 0;
40 virtual void ReportWarningV(fmt::string_view format,
41 fmt::format_args args) = 0;
42 virtual void ReportUsage(MathUsageId id, int count) = 0;
43 virtual units::second_t GetTimestamp() = 0;
44
45 template <typename S, typename... Args>
46 inline void ReportError(const S& format, Args&&... args) {
47 ReportErrorV(format, fmt::make_format_args(args...));
48 }
49
50 template <typename S, typename... Args>
51 inline void ReportWarning(const S& format, Args&&... args) {
52 ReportWarningV(format, fmt::make_format_args(args...));
53 }
54};
55
57 public:
59
60 static void SetMathShared(std::unique_ptr<MathShared> shared);
61
62 static void ReportErrorV(fmt::string_view format, fmt::format_args args) {
63 GetMathShared().ReportErrorV(format, args);
64 }
65
66 template <typename S, typename... Args>
67 static inline void ReportError(const S& format, Args&&... args) {
68 ReportErrorV(format, fmt::make_format_args(args...));
69 }
70
71 static void ReportWarningV(fmt::string_view format, fmt::format_args args) {
72 GetMathShared().ReportWarningV(format, args);
73 }
74
75 template <typename S, typename... Args>
76 static inline void ReportWarning(const S& format, Args&&... args) {
77 ReportWarningV(format, fmt::make_format_args(args...));
78 }
79
80 static void ReportUsage(MathUsageId id, int count) {
81 GetMathShared().ReportUsage(id, count);
82 }
83
84 static units::second_t GetTimestamp() {
85 return GetMathShared().GetTimestamp();
86 }
87};
88
89} // namespace wpi::math
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Definition MathShared.h:36
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:46
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:51
virtual ~MathShared()=default
Definition MathShared.h:56
static void SetMathShared(std::unique_ptr< MathShared > shared)
static void ReportErrorV(fmt::string_view format, fmt::format_args args)
Definition MathShared.h:62
static MathShared & GetMathShared()
static void ReportError(const S &format, Args &&... args)
Definition MathShared.h:67
static units::second_t GetTimestamp()
Definition MathShared.h:84
static void ReportUsage(MathUsageId id, int count)
Definition MathShared.h:80
static void ReportWarning(const S &format, Args &&... args)
Definition MathShared.h:76
static void ReportWarningV(fmt::string_view format, fmt::format_args args)
Definition MathShared.h:71
FMT_INLINE auto format(detail::locale_ref loc, format_string< T... > fmt, T &&... args) -> std::string
Definition format.h:4146
Definition MathShared.h:14
MathUsageId
Definition MathShared.h:16
#define S(label, offset, message)
Definition Errors.h:113