Add wxUniChar overload for nlohmann's internal char_traits

This commit is contained in:
Marek Roszko 2023-12-18 22:10:04 -05:00
parent a4b38fbb80
commit 5341af1a55
2 changed files with 21 additions and 14 deletions

View File

@ -21,23 +21,10 @@
#include <settings/grid_settings.h>
#include <nlohmann/json.hpp>
#include <wx/translation.h>
#include <core/json_serializers.h>
#include <units_provider.h>
namespace nlohmann
{
template <>
struct adl_serializer<wxString>
{
static void to_json( json& j, const wxString& s ) { j = s.ToUTF8(); }
static void from_json( const json& j, wxString& s )
{
s = wxString::FromUTF8( j.get<std::string>().c_str() );
}
};
} // namespace nlohmann
wxString GRID::MessageText( EDA_IU_SCALE aScale, EDA_UNITS aUnits, bool aDisplayUnits ) const
{
EDA_DATA_TYPE type = EDA_DATA_TYPE::DISTANCE;

View File

@ -28,6 +28,26 @@
#include <wx/string.h>
#include <optional>
NLOHMANN_JSON_NAMESPACE_BEGIN
namespace detail
{
// silly hack to silence warnings about std::char_traits<wxUniChar> not being supported by the standard
// nolhmann json internally has its own char_traits templated to support some exotic char traits
template <>
struct char_traits<wxUniChar> : std::char_traits<char>
{
using char_type = wxUniChar;
using int_type = uint32_t; // this is wxwidget's internal data type
// Redefine to_int_type function
static int_type to_int_type( char_type c ) noexcept { return static_cast<int_type>( c ); }
static char_type to_char_type( int_type i ) noexcept { return static_cast<char_type>( i ); }
static constexpr int_type eof() noexcept { return static_cast<int_type>( EOF ); }
};
} // namespace detail
NLOHMANN_JSON_NAMESPACE_END
namespace nlohmann
{