From ce76f779c6cfd2155de825021cc645572fe43625 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 20 Mar 2005 15:42:41 +0000 Subject: [PATCH] added wxString ctor from std::string (inside #ifdef wxUSE_STD_STRING); removed pragma interface/implementation which force all inline functions to be defined in string.cpp git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32935 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/string.h | 45 +++++++++++++++++++++++++++++++------------ src/common/string.cpp | 4 ---- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/include/wx/string.h b/include/wx/string.h index 3b8db06455..fef44a0ca8 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -18,10 +18,6 @@ #ifndef _WX_WXSTRINGH__ #define _WX_WXSTRINGH__ -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma interface "string.h" -#endif - // ---------------------------------------------------------------------------- // headers // ---------------------------------------------------------------------------- @@ -163,7 +159,12 @@ inline int Stricmp(const char *psz1, const char *psz2) #endif // OS/compiler } -#if wxUSE_STL +// ---------------------------------------------------------------------------- +// deal with STL/non-STL/non-STL-but-wxUSE_STD_STRING +// ---------------------------------------------------------------------------- + +// in both cases we need to define wxStdString +#if wxUSE_STL || defined(wxUSE_STD_STRING) #include "wx/beforestd.h" #include @@ -171,19 +172,28 @@ inline int Stricmp(const char *psz1, const char *psz2) #if wxUSE_UNICODE #ifdef HAVE_STD_WSTRING - typedef std::wstring wxStringBase; + typedef std::wstring wxStdString; #else - typedef std::basic_string wxStringBase; + typedef std::basic_string wxStdString; #endif #else - typedef std::string wxStringBase; + typedef std::string wxStdString; #endif -#if (defined(__GNUG__) && (__GNUG__ < 3)) || \ - (defined(_MSC_VER) && (_MSC_VER <= 1200)) - #define wxSTRING_BASE_HASNT_CLEAR -#endif +#endif // need +#if wxUSE_STL + + // we don't need an extra ctor from std::string when copy ctor already does + // the work + #undef wxUSE_STD_STRING + + #if (defined(__GNUG__) && (__GNUG__ < 3)) || \ + (defined(_MSC_VER) && (_MSC_VER <= 1200)) + #define wxSTRING_BASE_HASNT_CLEAR + #endif + + typedef wxStdString wxStringBase; #else // if !wxUSE_STL #ifndef HAVE_STD_STRING_COMPARE @@ -645,6 +655,17 @@ public: wxString(const wxChar *psz, wxMBConv& WXUNUSED(conv), size_t nLength = npos) : wxStringBase(psz, nLength == npos ? wxStrlen(psz) : nLength) { } + // even we're not build with wxUSE_STL == 1 it is very convenient to allow + // implicit conversions from std::string to wxString as this allows to use + // the same strings in non-GUI and GUI code, however we don't want to + // unconditionally add this ctor as it would make wx lib dependent on + // libstdc++ on some Linux versions which is bad, so instead we ask the + // client code to define this wxUSE_STD_STRING symbol if they need it +#ifdef wxUSE_STD_STRING + wxString(const wxStdString& s) + : wxStringBase(s.c_str()) { } +#endif // wxUSE_STD_STRING + #if wxUSE_UNICODE // from multibyte string wxString(const char *psz, wxMBConv& conv, size_t nLength = npos); diff --git a/src/common/string.cpp b/src/common/string.cpp index 38351ff5f0..d5c51592e0 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -10,10 +10,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "string.h" -#endif - /* * About ref counting: * 1) all empty strings use g_strEmpty, nRefs = -1 (set in Init())