WPILibC++ 2025.2.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
30
32 public:
33 virtual ~MathShared() = default;
34 virtual void ReportErrorV(fmt::string_view format, fmt::format_args args) = 0;
35 virtual void ReportWarningV(fmt::string_view format,
36 fmt::format_args args) = 0;
37 virtual void ReportUsage(MathUsageId id, int count) = 0;
38 virtual units::second_t GetTimestamp() = 0;
39
40 template <typename S, typename... Args>
41 inline void ReportError(const S& format, Args&&... args) {
42 ReportErrorV(format, fmt::make_format_args(args...));
43 }
44
45 template <typename S, typename... Args>
46 inline void ReportWarning(const S& format, Args&&... args) {
47 ReportWarningV(format, fmt::make_format_args(args...));
48 }
49};
50
52 public:
54
55 static void SetMathShared(std::unique_ptr<MathShared> shared);
56
57 static void ReportErrorV(fmt::string_view format, fmt::format_args args) {
58 GetMathShared().ReportErrorV(format, args);
59 }
60
61 template <typename S, typename... Args>
62 static inline void ReportError(const S& format, Args&&... args) {
63 ReportErrorV(format, fmt::make_format_args(args...));
64 }
65
66 static void ReportWarningV(fmt::string_view format, fmt::format_args args) {
67 GetMathShared().ReportWarningV(format, args);
68 }
69
70 template <typename S, typename... Args>
71 static inline void ReportWarning(const S& format, Args&&... args) {
72 ReportWarningV(format, fmt::make_format_args(args...));
73 }
74
75 static void ReportUsage(MathUsageId id, int count) {
76 GetMathShared().ReportUsage(id, count);
77 }
78
79 static units::second_t GetTimestamp() {
80 return GetMathShared().GetTimestamp();
81 }
82};
83
84} // namespace wpi::math
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Definition MathShared.h:31
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:41
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:46
virtual ~MathShared()=default
Definition MathShared.h:51
static void SetMathShared(std::unique_ptr< MathShared > shared)
static void ReportErrorV(fmt::string_view format, fmt::format_args args)
Definition MathShared.h:57
static MathShared & GetMathShared()
static void ReportError(const S &format, Args &&... args)
Definition MathShared.h:62
static units::second_t GetTimestamp()
Definition MathShared.h:79
static void ReportUsage(MathUsageId id, int count)
Definition MathShared.h:75
static void ReportWarning(const S &format, Args &&... args)
Definition MathShared.h:71
static void ReportWarningV(fmt::string_view format, fmt::format_args args)
Definition MathShared.h:66
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