WPILibC++ 2027.0.0-alpha-2
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
17 public:
18 virtual ~MathShared() = default;
19 virtual void ReportErrorV(fmt::string_view format, fmt::format_args args) = 0;
20 virtual void ReportWarningV(fmt::string_view format,
21 fmt::format_args args) = 0;
22 virtual void ReportUsage(std::string_view resource,
23 std::string_view data) = 0;
24 virtual units::second_t GetTimestamp() = 0;
25
26 template <typename S, typename... Args>
27 inline void ReportError(const S& format, Args&&... args) {
28 ReportErrorV(format, fmt::make_format_args(args...));
29 }
30
31 template <typename S, typename... Args>
32 inline void ReportWarning(const S& format, Args&&... args) {
33 ReportWarningV(format, fmt::make_format_args(args...));
34 }
35};
36
38 public:
40
41 static void SetMathShared(std::unique_ptr<MathShared> shared);
42
43 static void ReportErrorV(fmt::string_view format, fmt::format_args args) {
44 GetMathShared().ReportErrorV(format, args);
45 }
46
47 template <typename S, typename... Args>
48 static inline void ReportError(const S& format, Args&&... args) {
49 ReportErrorV(format, fmt::make_format_args(args...));
50 }
51
52 static void ReportWarningV(fmt::string_view format, fmt::format_args args) {
53 GetMathShared().ReportWarningV(format, args);
54 }
55
56 template <typename S, typename... Args>
57 static inline void ReportWarning(const S& format, Args&&... args) {
58 ReportWarningV(format, fmt::make_format_args(args...));
59 }
60
61 static void ReportUsage(std::string_view resource, std::string_view data) {
62 GetMathShared().ReportUsage(resource, data);
63 }
64
65 static units::second_t GetTimestamp() {
66 return GetMathShared().GetTimestamp();
67 }
68};
69
70} // namespace wpi::math
#define WPILIB_DLLEXPORT
Definition SymbolExports.h:36
Definition MathShared.h:16
virtual void ReportUsage(std::string_view resource, std::string_view data)=0
virtual void ReportWarningV(fmt::string_view format, fmt::format_args args)=0
void ReportError(const S &format, Args &&... args)
Definition MathShared.h:27
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:32
virtual ~MathShared()=default
Definition MathShared.h:37
static void SetMathShared(std::unique_ptr< MathShared > shared)
static void ReportErrorV(fmt::string_view format, fmt::format_args args)
Definition MathShared.h:43
static void ReportUsage(std::string_view resource, std::string_view data)
Definition MathShared.h:61
static MathShared & GetMathShared()
static void ReportError(const S &format, Args &&... args)
Definition MathShared.h:48
static units::second_t GetTimestamp()
Definition MathShared.h:65
static void ReportWarning(const S &format, Args &&... args)
Definition MathShared.h:57
static void ReportWarningV(fmt::string_view format, fmt::format_args args)
Definition MathShared.h:52
FMT_INLINE auto format(const Locale &loc, format_string< T... > fmt, T &&... args) -> std::string
Definition format.h:4252
Definition MathShared.h:14
#define S(label, offset, message)
Definition Errors.h:113