[wpimath] Add macro for disabling units fmt support (#4609)

This commit is contained in:
Tyler Veness
2022-11-10 14:12:07 -08:00
committed by GitHub
parent 2b04159dec
commit 3d8d5936f9
2 changed files with 16 additions and 12 deletions

View File

@@ -75,7 +75,8 @@
#include <iostream>
#include <locale>
#include <string>
#else
#endif
#if !defined(UNIT_LIB_DISABLE_FMT)
#include <locale>
#include <string>
#include <fmt/format.h>
@@ -175,7 +176,7 @@ namespace units
* @param abbrev - abbreviated unit name, e.g. 'm'
* @note When UNIT_LIB_ENABLE_IOSTREAM isn't defined, the macro does not generate any code
*/
#if !defined(UNIT_LIB_ENABLE_IOSTREAM)
#if !defined(UNIT_LIB_DISABLE_FMT)
#define UNIT_ADD_IO(namespaceName, nameSingular, abbrev)\
}\
template <>\
@@ -200,7 +201,8 @@ namespace units
return units::detail::to_string(obj()) + std::string(" "#abbrev);\
}\
}
#else
#endif
#if defined(UNIT_LIB_ENABLE_IOSTREAM)
#define UNIT_ADD_IO(namespaceName, nameSingular, abbrev)\
namespace namespaceName\
{\
@@ -2864,13 +2866,15 @@ namespace units
namespace dimensionless
{
typedef unit_t<scalar, UNIT_LIB_DEFAULT_TYPE, decibel_scale> dB_t;
#if defined(UNIT_LIB_ENABLE_IOSTREAM)
inline std::ostream& operator<<(std::ostream& os, const dB_t& obj) { os << obj() << " dB"; return os; }
typedef dB_t dBi_t;
}
#else
}
#if defined(UNIT_LIB_ENABLE_IOSTREAM)
namespace dimensionless
inline std::ostream& operator<<(std::ostream& os, const dB_t& obj) { os << obj() << " dB"; return os; }
}
#endif
}
#if !defined(UNIT_LIB_DISABLE_FMT)
template <>
struct fmt::formatter<units::dimensionless::dB_t> : fmt::formatter<double>
{
@@ -2883,13 +2887,9 @@ struct fmt::formatter<units::dimensionless::dB_t> : fmt::formatter<double>
return fmt::format_to(out, " dB");
}
};
namespace units {
namespace dimensionless {
typedef dB_t dBi_t;
}
#endif
namespace units {
//------------------------------
// DECIBEL ARITHMETIC
//------------------------------
@@ -3439,4 +3439,6 @@ namespace units::literals {}
using namespace units::literals;
#endif // UNIT_HAS_LITERAL_SUPPORT
#if !defined(UNIT_LIB_DISABLE_FMT)
#include "frc/fmt/Units.h"
#endif