From 9ce9188ff696d50d97e115378c3d860fcf3dab1e Mon Sep 17 00:00:00 2001 From: Noam Zaks Date: Wed, 16 Jun 2021 10:52:24 +0300 Subject: [PATCH] [wpimath] Add ReportWarning to MathShared (#3441) --- wpilibc/src/main/native/cppcs/RobotBase.cpp | 5 +++++ wpimath/src/main/native/cpp/MathShared.cpp | 2 ++ .../src/main/native/include/wpimath/MathShared.h | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index dc2b3f1918..4710670338 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -77,6 +77,11 @@ class WPILibMathShared : public wpi::math::MathShared { args); } + void ReportWarningV(fmt::string_view format, fmt::format_args args) override { + frc::ReportErrorV(warn::Warning, __FILE__, __LINE__, __FUNCTION__, format, + args); + } + void ReportUsage(wpi::math::MathUsageId id, int count) override { switch (id) { case wpi::math::MathUsageId::kKinematics_DifferentialDrive: diff --git a/wpimath/src/main/native/cpp/MathShared.cpp b/wpimath/src/main/native/cpp/MathShared.cpp index 500f821512..5252e876fc 100644 --- a/wpimath/src/main/native/cpp/MathShared.cpp +++ b/wpimath/src/main/native/cpp/MathShared.cpp @@ -12,6 +12,8 @@ namespace { class DefaultMathShared : public MathShared { public: void ReportErrorV(fmt::string_view format, fmt::format_args args) override {} + void ReportWarningV(fmt::string_view format, fmt::format_args args) override { + } void ReportUsage(MathUsageId id, int count) override {} }; } // namespace diff --git a/wpimath/src/main/native/include/wpimath/MathShared.h b/wpimath/src/main/native/include/wpimath/MathShared.h index e161d1a69f..53ef770b7d 100644 --- a/wpimath/src/main/native/include/wpimath/MathShared.h +++ b/wpimath/src/main/native/include/wpimath/MathShared.h @@ -25,12 +25,19 @@ class MathShared { public: virtual ~MathShared() = default; virtual void ReportErrorV(fmt::string_view format, fmt::format_args args) = 0; + virtual void ReportWarningV(fmt::string_view format, + fmt::format_args args) = 0; virtual void ReportUsage(MathUsageId id, int count) = 0; template inline void ReportError(const S& format, Args&&... args) { ReportErrorV(format, fmt::make_args_checked(format, args...)); } + + template + inline void ReportWarning(const S& format, Args&&... args) { + ReportWarningV(format, fmt::make_args_checked(format, args...)); + } }; class MathSharedStore { @@ -48,6 +55,15 @@ class MathSharedStore { ReportErrorV(format, fmt::make_args_checked(format, args...)); } + static void ReportWarningV(fmt::string_view format, fmt::format_args args) { + GetMathShared().ReportWarningV(format, args); + } + + template + static inline void ReportWarning(const S& format, Args&&... args) { + ReportWarningV(format, fmt::make_args_checked(format, args...)); + } + static void ReportUsage(MathUsageId id, int count) { GetMathShared().ReportUsage(id, count); }