Add a new wxUSE_STD_CONTAINERS_COMPATIBLY option.

This option, which is on by default unless the use of STL is disabled,
provides better interoperability with the standard library when it can be done
without breaking backwards compatibility.

The first example of its use is to allow passing std::vector<> of any string
compatible type to wxItemContainer::Append(), Insert() and Set(), allowing to
directly initialize various wxControls deriving from it such as wxChoice,
wxComboBox, wxListBox from a std::vector<> of strings.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78066 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-10-24 21:54:51 +00:00
parent 30c93fd705
commit 722057b3a0
16 changed files with 253 additions and 8 deletions

53
configure vendored
View File

@ -1125,6 +1125,7 @@ enable_mem_tracing
enable_shared
enable_stl
enable_std_containers
enable_std_containers_compat
enable_std_iostreams
enable_std_string
enable_std_string_conv_in_wxstring
@ -2055,6 +2056,7 @@ Optional Features:
--disable-shared create static library instead of shared
--enable-stl use standard C++ classes for everything
--enable-std_containers use standard C++ container classes
--enable-std_containers_compat use standard C++ container classes when it can be done compatible
--enable-std_iostreams use standard C++ stream classes
--enable-std_string use standard C++ string classes
--enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString
@ -4076,6 +4078,7 @@ esac
DEFAULT_wxUSE_ALL_FEATURES=yes
DEFAULT_wxUSE_STD_CONTAINERS=no
DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY=$DEFAULT_STD_FLAG
DEFAULT_wxUSE_STD_IOSTREAM=$DEFAULT_STD_FLAG
DEFAULT_wxUSE_STD_STRING=$DEFAULT_STD_FLAG
@ -6018,6 +6021,7 @@ $as_echo "$result" >&6; }
if test "$wxUSE_STL" = "yes"; then
DEFAULT_wxUSE_STD_CONTAINERS=yes
DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY=yes
DEFAULT_wxUSE_STD_IOSTREAM=yes
DEFAULT_wxUSE_STD_STRING=yes
fi
@ -6066,6 +6070,50 @@ fi
$as_echo "$result" >&6; }
enablestring=
defaultval=
if test -z "$defaultval"; then
if test x"$enablestring" = xdisable; then
defaultval=yes
else
defaultval=no
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for --${enablestring:-enable}-std_containers_compat" >&5
$as_echo_n "checking for --${enablestring:-enable}-std_containers_compat... " >&6; }
# Check whether --enable-std_containers_compat was given.
if test "${enable_std_containers_compat+set}" = set; then :
enableval=$enable_std_containers_compat;
if test "$enableval" = yes; then
wx_cv_use_std_containers_compat='wxUSE_STD_CONTAINERS_COMPATIBLY=yes'
else
wx_cv_use_std_containers_compat='wxUSE_STD_CONTAINERS_COMPATIBLY=no'
fi
else
wx_cv_use_std_containers_compat='wxUSE_STD_CONTAINERS_COMPATIBLY=${'DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY":-$defaultval}"
fi
eval "$wx_cv_use_std_containers_compat"
if test x"$enablestring" = xdisable; then
if test $wxUSE_STD_CONTAINERS_COMPATIBLY = no; then
result=yes
else
result=no
fi
else
result=$wxUSE_STD_CONTAINERS_COMPATIBLY
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $result" >&5
$as_echo "$result" >&6; }
enablestring=
defaultval=
if test -z "$defaultval"; then
@ -34499,6 +34547,11 @@ if test "$wxUSE_STD_CONTAINERS" = "yes"; then
fi
if test "$wxUSE_STD_CONTAINERS_COMPATIBLY" = "yes"; then
$as_echo "#define wxUSE_STD_CONTAINERS_COMPATIBLY 1" >>confdefs.h
fi
if test "$wxUSE_STD_IOSTREAM" = "yes"; then
$as_echo "#define wxUSE_STD_IOSTREAM 1" >>confdefs.h

View File

@ -331,6 +331,7 @@ dnl default)
DEFAULT_wxUSE_ALL_FEATURES=yes
DEFAULT_wxUSE_STD_CONTAINERS=no
DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY=$DEFAULT_STD_FLAG
DEFAULT_wxUSE_STD_IOSTREAM=$DEFAULT_STD_FLAG
DEFAULT_wxUSE_STD_STRING=$DEFAULT_STD_FLAG
@ -646,10 +647,12 @@ WX_ARG_DISABLE(shared, [ --disable-shared create static library inst
WX_ARG_ENABLE(stl, [ --enable-stl use standard C++ classes for everything], wxUSE_STL)
if test "$wxUSE_STL" = "yes"; then
DEFAULT_wxUSE_STD_CONTAINERS=yes
DEFAULT_wxUSE_STD_CONTAINERS_COMPATIBLY=yes
DEFAULT_wxUSE_STD_IOSTREAM=yes
DEFAULT_wxUSE_STD_STRING=yes
fi
WX_ARG_ENABLE(std_containers,[ --enable-std_containers use standard C++ container classes], wxUSE_STD_CONTAINERS)
WX_ARG_ENABLE(std_containers_compat, [ --enable-std_containers_compat use standard C++ container classes when it can be done compatible], wxUSE_STD_CONTAINERS_COMPATIBLY)
WX_ARG_ENABLE(std_iostreams, [ --enable-std_iostreams use standard C++ stream classes], wxUSE_STD_IOSTREAM)
WX_ARG_ENABLE(std_string, [ --enable-std_string use standard C++ string classes], wxUSE_STD_STRING)
WX_ARG_ENABLE(std_string_conv_in_wxstring, [ --enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString], wxUSE_STD_STRING_CONV_IN_WXSTRING)
@ -5654,6 +5657,10 @@ if test "$wxUSE_STD_CONTAINERS" = "yes"; then
AC_DEFINE(wxUSE_STD_CONTAINERS)
fi
if test "$wxUSE_STD_CONTAINERS_COMPATIBLY" = "yes"; then
AC_DEFINE(wxUSE_STD_CONTAINERS_COMPATIBLY)
fi
if test "$wxUSE_STD_IOSTREAM" = "yes"; then
AC_DEFINE(wxUSE_STD_IOSTREAM)
fi

View File

@ -32,6 +32,7 @@ Changes in behaviour which may result in build errors
All:
- Allow calling wxItemContainer::Add() and similar with std::vector<> argument.
- Add "%z" support to printf()-like functions like wxString::Format() (RIVDSL).
- Add wxPowerResourceBlocker (Tobias Taschner).
- Add wxApp::StoreCurrentException() and RethrowStoredException() and implement

View File

@ -299,12 +299,25 @@
#define wxUSE_STL 0
// This is not a real option but is used as the default value for
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS.
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY.
//
// Set it to 0 if you want to disable the use of all standard classes
// completely for some reason.
#define wxUSE_STD_DEFAULT 1
// Use standard C++ containers where it can be done without breaking backwards
// compatibility.
//
// This provides better interoperability with the standard library, e.g. with
// this option on it's possible to insert std::vector<> into many wxWidgets
// containers directly.
//
// Default is 1.
//
// Recommended setting is 1 unless you want to avoid all dependencies on the
// standard library.
#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT
// Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<>
// and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but
// usually more limited) implementations are used which allows to avoid the

View File

@ -14,6 +14,10 @@
#include "wx/defs.h"
#include "wx/string.h"
#if wxUSE_STD_CONTAINERS_COMPATIBLY
#include <vector>
#endif
// these functions are only used in STL build now but we define them in any
// case for compatibility with the existing code outside of the library which
// could be using them
@ -474,6 +478,16 @@ public:
m_data.ptr = strings;
}
#if wxUSE_STD_CONTAINERS_COMPATIBLY
// construct an adapter from a vector of strings (of any type)
template <class T>
wxArrayStringsAdapter(const std::vector<T>& strings)
: m_type(wxSTRING_POINTER), m_size(strings.size())
{
m_data.ptr = &strings[0];
}
#endif // wxUSE_STD_CONTAINERS_COMPATIBLY
// construct an adapter from a single wxString
wxArrayStringsAdapter(const wxString& s)
: m_type(wxSTRING_POINTER), m_size(1)

View File

@ -309,6 +309,14 @@
# endif
#endif /* !defined(wxUSE_STD_CONTAINERS) */
#ifndef wxUSE_STD_CONTAINERS_COMPATIBLY
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxUSE_STD_CONTAINERS_COMPATIBLY must be defined, please read comment near the top of this file."
# else
# define wxUSE_STD_CONTAINERS_COMPATIBLY 0
# endif
#endif /* !defined(wxUSE_STD_CONTAINERS_COMPATIBLY) */
#ifndef wxUSE_STD_STRING_CONV_IN_WXSTRING
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxUSE_STD_STRING_CONV_IN_WXSTRING must be defined, please read comment near the top of this file."

View File

@ -216,6 +216,10 @@ public:
wxClientData **clientData)
{ return AppendItems(wxArrayStringsAdapter(n, items), clientData); }
template <class T>
int Append(const std::vector<T>& items)
{ return AppendItems(items); }
// only for RTTI needs (separate name)
void AppendString(const wxString& item)
{ Append(item); }
@ -255,6 +259,9 @@ public:
wxClientData **clientData)
{ return InsertItems(wxArrayStringsAdapter(n, items), pos, clientData); }
template <class T>
int Insert(const std::vector<T>& items, unsigned int pos)
{ return InsertItems(items, pos); }
// replacing items
// ---------------
@ -272,6 +279,10 @@ public:
void Set(unsigned int n, const wxString *items, wxClientData **clientData)
{ Clear(); Append(n, items, clientData); }
template <class T>
void Set(const std::vector<T>& items)
{ Clear(); Append(items); }
// deleting items
// --------------

View File

@ -300,12 +300,25 @@
#define wxUSE_STL 0
// This is not a real option but is used as the default value for
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS.
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY.
//
// Set it to 0 if you want to disable the use of all standard classes
// completely for some reason.
#define wxUSE_STD_DEFAULT 1
// Use standard C++ containers where it can be done without breaking backwards
// compatibility.
//
// This provides better interoperability with the standard library, e.g. with
// this option on it's possible to insert std::vector<> into many wxWidgets
// containers directly.
//
// Default is 1.
//
// Recommended setting is 1 unless you want to avoid all dependencies on the
// standard library.
#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT
// Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<>
// and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but
// usually more limited) implementations are used which allows to avoid the

View File

@ -300,12 +300,25 @@
#define wxUSE_STL 0
// This is not a real option but is used as the default value for
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS.
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY.
//
// Set it to 0 if you want to disable the use of all standard classes
// completely for some reason.
#define wxUSE_STD_DEFAULT 1
// Use standard C++ containers where it can be done without breaking backwards
// compatibility.
//
// This provides better interoperability with the standard library, e.g. with
// this option on it's possible to insert std::vector<> into many wxWidgets
// containers directly.
//
// Default is 1.
//
// Recommended setting is 1 unless you want to avoid all dependencies on the
// standard library.
#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT
// Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<>
// and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but
// usually more limited) implementations are used which allows to avoid the

View File

@ -300,12 +300,25 @@
#define wxUSE_STL 0
// This is not a real option but is used as the default value for
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS.
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY.
//
// Set it to 0 if you want to disable the use of all standard classes
// completely for some reason.
#define wxUSE_STD_DEFAULT 1
// Use standard C++ containers where it can be done without breaking backwards
// compatibility.
//
// This provides better interoperability with the standard library, e.g. with
// this option on it's possible to insert std::vector<> into many wxWidgets
// containers directly.
//
// Default is 1.
//
// Recommended setting is 1 unless you want to avoid all dependencies on the
// standard library.
#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT
// Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<>
// and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but
// usually more limited) implementations are used which allows to avoid the

View File

@ -300,12 +300,25 @@
#define wxUSE_STL 0
// This is not a real option but is used as the default value for
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS.
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY.
//
// Set it to 0 if you want to disable the use of all standard classes
// completely for some reason.
#define wxUSE_STD_DEFAULT 1
// Use standard C++ containers where it can be done without breaking backwards
// compatibility.
//
// This provides better interoperability with the standard library, e.g. with
// this option on it's possible to insert std::vector<> into many wxWidgets
// containers directly.
//
// Default is 1.
//
// Recommended setting is 1 unless you want to avoid all dependencies on the
// standard library.
#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT
// Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<>
// and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but
// usually more limited) implementations are used which allows to avoid the

View File

@ -301,12 +301,25 @@
#define wxUSE_STL 0
// This is not a real option but is used as the default value for
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS.
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY.
//
// Set it to 0 if you want to disable the use of all standard classes
// completely for some reason.
#define wxUSE_STD_DEFAULT 1
// Use standard C++ containers where it can be done without breaking backwards
// compatibility.
//
// This provides better interoperability with the standard library, e.g. with
// this option on it's possible to insert std::vector<> into many wxWidgets
// containers directly.
//
// Default is 1.
//
// Recommended setting is 1 unless you want to avoid all dependencies on the
// standard library.
#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT
// Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<>
// and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but
// usually more limited) implementations are used which allows to avoid the

View File

@ -296,12 +296,25 @@
#define wxUSE_STL 0
// This is not a real option but is used as the default value for
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS.
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY.
//
// Set it to 0 if you want to disable the use of all standard classes
// completely for some reason.
#define wxUSE_STD_DEFAULT 1
// Use standard C++ containers where it can be done without breaking backwards
// compatibility.
//
// This provides better interoperability with the standard library, e.g. with
// this option on it's possible to insert std::vector<> into many wxWidgets
// containers directly.
//
// Default is 1.
//
// Recommended setting is 1 unless you want to avoid all dependencies on the
// standard library.
#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT
// Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<>
// and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but
// usually more limited) implementations are used which allows to avoid the

View File

@ -299,12 +299,25 @@
#define wxUSE_STL 0
// This is not a real option but is used as the default value for
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS.
// wxUSE_STD_IOSTREAM, wxUSE_STD_STRING and wxUSE_STD_CONTAINERS_COMPATIBLY.
//
// Set it to 0 if you want to disable the use of all standard classes
// completely for some reason.
#define wxUSE_STD_DEFAULT 1
// Use standard C++ containers where it can be done without breaking backwards
// compatibility.
//
// This provides better interoperability with the standard library, e.g. with
// this option on it's possible to insert std::vector<> into many wxWidgets
// containers directly.
//
// Default is 1.
//
// Recommended setting is 1 unless you want to avoid all dependencies on the
// standard library.
#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT
// Use standard C++ containers to implement wxVector<>, wxStack<>, wxDList<>
// and wxHashXXX<> classes. If disabled, wxWidgets own (mostly compatible but
// usually more limited) implementations are used which allows to avoid the

View File

@ -253,6 +253,21 @@ public:
*/
int Append(const wxArrayString& items);
/**
Appends several items at once into the control.
This is the same as the overload taking wxArrayString, except that it
works with the standard vector container.
The template argument @c T can be any type convertible to wxString,
including wxString itself but also @c std::string, @c char* or @c
wchar_t*.
@since 3.1.0
*/
template <typename T>
int Append(const std::vector<T>& items);
/**
Appends several items at once into the control.
@ -520,6 +535,21 @@ public:
*/
int Insert(const wxArrayString& items, unsigned int pos);
/**
Inserts several items at once into the control.
This is the same as the overload taking wxArrayString, except that it
works with the standard vector container.
The template argument @c T can be any type convertible to wxString,
including wxString itself but also @c std::string, @c char* or @c
wchar_t*.
@since 3.1.0
*/
template <typename T>
int Insert(const std::vector<T>& items);
/**
Inserts several items at once into the control.
@ -633,6 +663,21 @@ public:
*/
void Set(const wxArrayString& items);
/**
Replaces the current control contents with the given items.
This is the same as the overload taking wxArrayString, except that it
works with the standard vector container.
The template argument @c T can be any type convertible to wxString,
including wxString itself but also @c std::string, @c char* or @c
wchar_t*.
@since 3.1.0
*/
template <typename T>
void Set(const std::vector<T>& items);
/**
Replaces the current control contents with the given items.

View File

@ -209,6 +209,8 @@
#define wxUSE_STD_DEFAULT 0
#define wxUSE_STD_CONTAINERS_COMPATIBLY wxUSE_STD_DEFAULT
#define wxUSE_STD_CONTAINERS 0
#define wxUSE_STD_IOSTREAM wxUSE_STD_DEFAULT