// accounts for string changes done by wxArgNormalizer<>
//
// Note that this class can _only_ be used for function arguments!
-#ifdef __VISUALC__
- // "struct 'wx[W]CharBuffer<T>' 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) {}
// 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<wxFormatString*>(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<wxFormatString*>(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
const wxString * const m_str;
const wxCStrData * const m_cstr;
- DECLARE_NO_ASSIGN_CLASS(wxFormatString)
+ wxDECLARE_NO_ASSIGN_CLASS(wxFormatString);
};
// these two helper classes are used to find wxFormatString argument among fixed
template<>
struct wxFormatStringArgumentFinder<wxFormatString>
-{
- static wxFormatStringArgument find(const wxFormatString& arg)
- { return wxFormatStringArgument(&arg); }
-};
+ : public wxFormatStringArgumentFinder<const wxFormatString&> {};
+
+// avoid passing big objects by value to wxFormatStringArgumentFinder::find()
+// (and especially wx[W]CharBuffer with its auto_ptr<> style semantics!):
+template<>
+struct wxFormatStringArgumentFinder<wxString>
+ : public wxFormatStringArgumentFinder<const wxString&> {};
+
+template<>
+struct wxFormatStringArgumentFinder<wxScopedCharBuffer>
+ : public wxFormatStringArgumentFinder<const wxScopedCharBuffer&> {};
+
+template<>
+struct wxFormatStringArgumentFinder<wxScopedWCharBuffer>
+ : public wxFormatStringArgumentFinder<const wxScopedWCharBuffer&> {};
+
+template<>
+struct wxFormatStringArgumentFinder<wxCharBuffer>
+ : public wxFormatStringArgumentFinder<const wxCharBuffer&> {};
+
+template<>
+struct wxFormatStringArgumentFinder<wxWCharBuffer>
+ : public wxFormatStringArgumentFinder<const wxWCharBuffer&> {};
// ----------------------------------------------------------------------------
template<typename CharType>
struct wxArgNormalizerWithBuffer
{
- typedef wxCharTypeBuffer<CharType> CharBuffer;
+ typedef wxScopedCharTypeBuffer<CharType> CharBuffer;
wxArgNormalizerWithBuffer() {}
wxArgNormalizerWithBuffer(const CharBuffer& buf,
{
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 )
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*);
// 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;
}