X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/04e7692af163f3c6f1e58f01e7be665882d65ce9..f66ecdc4fbfa14f18f95331ba859a85baee36ae6:/include/wx/strvararg.h diff --git a/include/wx/strvararg.h b/include/wx/strvararg.h index bd7d867b3c..29b4ae041b 100644 --- a/include/wx/strvararg.h +++ b/include/wx/strvararg.h @@ -124,25 +124,20 @@ class WXDLLIMPEXP_FWD_BASE wxString; // accounts for string changes done by wxArgNormalizer<> // // Note that this class can _only_ be used for function arguments! -#ifdef __VISUALC__ - // "struct 'wx[W]CharBuffer' needs to have dll-interface to be used by - // clients of class 'wxString'" - this is private, we don't care - #pragma warning (disable:4251) -#endif class WXDLLIMPEXP_BASE wxFormatString { public: wxFormatString(const char *str) - : m_char(wxCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {} + : m_char(wxScopedCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {} wxFormatString(const wchar_t *str) - : m_wchar(wxWCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {} + : m_wchar(wxScopedWCharBuffer::CreateNonOwned(str)), m_str(NULL), m_cstr(NULL) {} wxFormatString(const wxString& str) : m_str(&str), m_cstr(NULL) {} wxFormatString(const wxCStrData& str) : m_str(NULL), m_cstr(&str) {} - wxFormatString(const wxCharBuffer& str) + wxFormatString(const wxScopedCharBuffer& str) : m_char(str), m_str(NULL), m_cstr(NULL) {} - wxFormatString(const wxWCharBuffer& str) + wxFormatString(const wxScopedWCharBuffer& str) : m_wchar(str), m_str(NULL), m_cstr(NULL) {} @@ -159,35 +154,36 @@ public: // n-th variadic argument desired representation ArgumentType GetArgumentType(unsigned n) const; + // returns the value passed to ctor, only converted to wxString, similarly + // to other InputAsXXX() methods + wxString InputAsString() const; + #if !wxUSE_UNICODE_WCHAR operator const char*() const - { return wx_const_cast(wxFormatString*, this)->AsChar(); } + { return const_cast(this)->AsChar(); } private: - // InputAsChar() returns the value converted passed to ctor, only converted + // InputAsChar() returns the value passed to ctor, only converted // to char, while AsChar() takes the the string returned by InputAsChar() // and does format string conversion on it as well (and similarly for // ..AsWChar() below) const char* InputAsChar(); const char* AsChar(); - wxCharBuffer m_convertedChar; + wxScopedCharBuffer m_convertedChar; #endif // !wxUSE_UNICODE_WCHAR #if wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY public: operator const wchar_t*() const - { return wx_const_cast(wxFormatString*, this)->AsWChar(); } + { return const_cast(this)->AsWChar(); } private: const wchar_t* InputAsWChar(); const wchar_t* AsWChar(); - wxWCharBuffer m_convertedWChar; + wxScopedWCharBuffer m_convertedWChar; #endif // wxUSE_UNICODE && !wxUSE_UTF8_LOCALE_ONLY private: - wxCharBuffer m_char; - wxWCharBuffer m_wchar; -#ifdef __VISUALC__ - #pragma warning (default:4251) -#endif + wxScopedCharBuffer m_char; + wxScopedWCharBuffer m_wchar; // NB: we can use a pointer here, because wxFormatString is only used // as function argument, so it has shorter life than the string @@ -195,7 +191,7 @@ private: const wxString * const m_str; const wxCStrData * const m_cstr; - DECLARE_NO_COPY_CLASS(wxFormatString) + wxDECLARE_NO_ASSIGN_CLASS(wxFormatString); }; // these two helper classes are used to find wxFormatString argument among fixed @@ -235,10 +231,29 @@ struct wxFormatStringArgumentFinder template<> struct wxFormatStringArgumentFinder -{ - static wxFormatStringArgument find(const wxFormatString& arg) - { return wxFormatStringArgument(&arg); } -}; + : public wxFormatStringArgumentFinder {}; + +// avoid passing big objects by value to wxFormatStringArgumentFinder::find() +// (and especially wx[W]CharBuffer with its auto_ptr<> style semantics!): +template<> +struct wxFormatStringArgumentFinder + : public wxFormatStringArgumentFinder {}; + +template<> +struct wxFormatStringArgumentFinder + : public wxFormatStringArgumentFinder {}; + +template<> +struct wxFormatStringArgumentFinder + : public wxFormatStringArgumentFinder {}; + +template<> +struct wxFormatStringArgumentFinder + : public wxFormatStringArgumentFinder {}; + +template<> +struct wxFormatStringArgumentFinder + : public wxFormatStringArgumentFinder {}; // ---------------------------------------------------------------------------- @@ -307,7 +322,7 @@ struct wxArgNormalizerWchar : public wxArgNormalizer template struct wxArgNormalizerWithBuffer { - typedef wxCharTypeBuffer CharBuffer; + typedef wxScopedCharTypeBuffer CharBuffer; wxArgNormalizerWithBuffer() {} wxArgNormalizerWithBuffer(const CharBuffer& buf, @@ -402,12 +417,12 @@ struct wxArgNormalizerUtf8 { if ( wxLocaleIsUtf8 ) { - m_value = wxCharBuffer::CreateNonOwned(s); + m_value = wxScopedCharBuffer::CreateNonOwned(s); } else { // convert to widechar string first: - wxWCharBuffer buf(wxConvLibc.cMB2WC(s)); + wxScopedWCharBuffer buf(wxConvLibc.cMB2WC(s)); // then to UTF-8: if ( buf ) @@ -478,6 +493,10 @@ WX_ARG_NORMALIZER_FORWARD(char*, const char*); WX_ARG_NORMALIZER_FORWARD(wchar_t*, const wchar_t*); // versions for passing wx[W]CharBuffer: +WX_ARG_NORMALIZER_FORWARD(wxScopedCharBuffer, const char*); +WX_ARG_NORMALIZER_FORWARD(const wxScopedCharBuffer&, const char*); +WX_ARG_NORMALIZER_FORWARD(wxScopedWCharBuffer, const wchar_t*); +WX_ARG_NORMALIZER_FORWARD(const wxScopedWCharBuffer&, const wchar_t*); WX_ARG_NORMALIZER_FORWARD(wxCharBuffer, const char*); WX_ARG_NORMALIZER_FORWARD(const wxCharBuffer&, const char*); WX_ARG_NORMALIZER_FORWARD(wxWCharBuffer, const wchar_t*); @@ -561,7 +580,7 @@ struct wxArgNormalizerNarrowChar // FIXME-UTF8: which one is better default in absence of fmt string // (i.e. when used like e.g. Foo("foo", "bar", 'c', NULL)? if ( !fmt || fmt->GetArgumentType(index) == wxFormatString::Arg_Char ) - m_value = wxUniChar(value).GetValue(); + m_value = wx_truncate_cast(T, wxUniChar(value).GetValue()); else m_value = value; }