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:
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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."
|
||||
|
@@ -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
|
||||
// --------------
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user