21#include <fmt/format.h>
31 wxXmlAttribute( aName, wxEmptyString ),
34 std::visit( [&]<
typename T0>( T0&& arg )
36 using T = std::decay_t<T0>;
38 if constexpr( std::is_same_v<T, int> )
40 wxXmlAttribute::SetValue( wxString::Format(
"%d", arg ) );
42 else if constexpr( std::is_same_v<T, double> )
46 if( arg != 0.0 && std::fabs( arg ) <= 0.0001 )
48 buf = fmt::format(
"{:.16f}", arg );
51 while( !buf.empty() && buf[buf.size() - 1] ==
'0' )
58 if( buf[buf.size() - 1] ==
'.' )
65 buf = fmt::format(
"{:.10g}", arg );
68 wxXmlAttribute::SetValue( buf );
70 else if constexpr( std::is_same_v<T, wxString> )
72 wxXmlAttribute::SetValue( arg );
76 static_assert(
sizeof(
T ) == 0,
"Missing type handling in XNODE::FormatContents" );
84 AddAttribute( aKey, aValue ? wxT(
"yes" ) : wxT(
"no" ) );
91 wxXmlNode::AddAttribute( attr );
98 wxXmlNode::AddAttribute( attr );
105 wxXmlNode::AddAttribute( attr );
113 case wxXML_ELEMENT_NODE:
118 out->
Print( 0,
")\n" );
120 out->
Print( 0,
")" );
133 for( wxXmlAttribute* attr = GetAttributes(); attr; attr = attr->GetNext() )
137 if(
auto xa =
dynamic_cast<XATTR*
>( attr ) )
141 std::visit( ["e]<
typename T0>( T0&& )
143 using T = std::decay_t<T0>;
145 if constexpr( std::is_same_v<T, int> || std::is_same_v<T, double> )
152 out->
Print( 0,
" (%s %s)",
154 quote ? out->
Quotew( attr->GetValue() ).c_str() :
TO_UTF8( attr->GetValue() ) );
160 case wxXML_ELEMENT_NODE:
163 if( child->GetType() != wxXML_TEXT_NODE )
166 out->
Print( 0,
"\n" );
168 child->Format( out );
172 child->Format( out );
178 case wxXML_TEXT_NODE:
179 out->
Print( 0,
" %s", out->
Quotew( GetContent() ).c_str() );
An extension of wxXmlAttribute that stores a variant type rather than just a string.
std::variant< wxString, int, double > VALUE_TYPE
VALUE_TYPE m_originalValue
XNODE * GetChildren() const
void FormatContents(OUTPUTFORMATTER *out) const
Write the contents of object as UTF8 out to an OUTPUTFORMATTER as an S-expression.
void AddAttribute(const wxString &aName, const wxString &aValue) override
void AddBool(const wxString &aKey, bool aValue)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.