]> git.saurik.com Git - wxWidgets.git/commitdiff
Allow passing wxLongLong values directly to wx pseudo-vararg functions.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 17 May 2011 22:12:39 +0000 (22:12 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 17 May 2011 22:12:39 +0000 (22:12 +0000)
Allow passing wxLongLong objects when a "%lld" format specifier (or
equivalent) is used just as we already do for wxString objects when "%s" is
used. This is more convenient and makes wxLongLong closes to the native type.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/longlong.h
include/wx/strvararg.h
tests/strings/vararg.cpp

index f248bb6d21ac7721ccf00f18e03515052b87f172..7c76d5f6778ba3fe641e50c08c112c088fe25ac9 100644 (file)
@@ -1113,6 +1113,33 @@ template<> class numeric_limits<wxULongLong>
 
 #endif // wxUSE_LONGLONG_NATIVE
 
+// ----------------------------------------------------------------------------
+// Specialize wxArgNormalizer to allow using wxLongLong directly with wx pseudo
+// vararg functions.
+// ----------------------------------------------------------------------------
+
+// Notice that this must be done here and not in wx/strvararg.h itself because
+// we can't include wx/longlong.h from there as this header itself includes
+// wx/string.h which includes wx/strvararg.h too, so to avoid the circular
+// dependencies we can only do it here (or add another header just for this but
+// it doesn't seem necessary).
+#include "wx/strvararg.h"
+
+template<>
+struct WXDLLIMPEXP_BASE wxArgNormalizer<wxLongLong>
+{
+     wxArgNormalizer(wxLongLong value,
+                     const wxFormatString *fmt, unsigned index)
+         : m_value(value)
+     {
+         wxASSERT_ARG_TYPE( fmt, index, wxFormatString::Arg_LongLongInt );
+     }
+
+     wxLongLong_t get() const { return m_value.GetValue(); }
+
+     wxLongLong m_value;
+};
+
 #endif // wxUSE_LONGLONG
 
 #endif // _WX_LONGLONG_H
index eff6e627cb7962c989840e2027403521a2588d4a..0bde80b3a675504d8e853e489ae0725d148a4dff 100644 (file)
@@ -825,7 +825,7 @@ WX_ARG_NORMALIZER_FORWARD(const signed char&, signed char);
 #undef WX_ARG_NORMALIZER_FORWARD
 #undef _WX_ARG_NORMALIZER_FORWARD_IMPL
 
-#undef wxASSERT_ARG_TYPE
+// NB: Don't #undef wxASSERT_ARG_TYPE here as it's also used in wx/longlong.h.
 
 // ----------------------------------------------------------------------------
 // WX_VA_ARG_STRING
index 56582e9a67a775f99dacf2e911e4a5f81939de81..14fb85ff9483994036231c877283ccec06053e33 100644 (file)
@@ -39,6 +39,9 @@ private:
         CPPUNIT_TEST( CharPrintf );
 #if wxUSE_STD_STRING
         CPPUNIT_TEST( StdString );
+#endif
+#if wxUSE_LONGLONG
+        CPPUNIT_TEST( LongLongPrintf );
 #endif
         CPPUNIT_TEST( Sscanf );
         CPPUNIT_TEST( RepeatedPrintf );
@@ -49,6 +52,9 @@ private:
     void CharPrintf();
 #if wxUSE_STD_STRING
     void StdString();
+#endif
+#if wxUSE_LONGLONG
+    void LongLongPrintf();
 #endif
     void Sscanf();
     void RepeatedPrintf();
@@ -152,6 +158,18 @@ void VarArgTestCase::StdString()
 }
 #endif // wxUSE_STD_STRING
 
+#if wxUSE_LONGLONG
+void VarArgTestCase::LongLongPrintf()
+{
+    const char * const llfmt = "%" wxLongLongFmtSpec "d";
+
+    CPPUNIT_ASSERT_EQUAL( "17", wxString::Format(llfmt, wxLL(17)) );
+
+    wxLongLong ll = 1234567890;
+    CPPUNIT_ASSERT_EQUAL( "1234567890", wxString::Format(llfmt, ll) );
+}
+#endif // wxUSE_LONGLONG
+
 void VarArgTestCase::Sscanf()
 {
     int i = 0;