Allow initializing wxScopedArray more conveniently.

Typical wxScopedArray initialization uses "new T[n]" expression, allow to omit
most of it and specify just n, the number of elements to allocate.

Use the new shorter form in the places where wxScopedArray(new ...) was used
(which is in almost all of them)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75504 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2013-12-31 14:03:34 +00:00
parent dd4291f962
commit 5cd81ca598
10 changed files with 26 additions and 11 deletions

View File

@ -9,6 +9,10 @@ Note: This file contains the list of changes since wxWidgets 3.x, please see
3.1.0: (released 2014-xx-xx) 3.1.0: (released 2014-xx-xx)
---------------------------- ----------------------------
All:
- Add wxScopedArray ctor taking the number of elements to allocate.
All (GUI): All (GUI):
- XRC handler for wxAuiToolBar added (Kinaou Hervé). - XRC handler for wxAuiToolBar added (Kinaou Hervé).

View File

@ -25,6 +25,7 @@ public:
typedef T element_type; typedef T element_type;
wxEXPLICIT wxScopedArray(T * array = NULL) : m_array(array) { } wxEXPLICIT wxScopedArray(T * array = NULL) : m_array(array) { }
wxEXPLICIT wxScopedArray(size_t count) : m_array(new T[count]) { }
~wxScopedArray() { delete [] m_array; } ~wxScopedArray() { delete [] m_array; }

View File

@ -129,6 +129,16 @@ public:
*/ */
explicit wxScopedArray(T * array = NULL); explicit wxScopedArray(T * array = NULL);
/**
Constructor allocating a new array of the specified size.
@param count
The number of elements to allocate.
@since 3.1.0
*/
explicit wxScopedArray(size_t count);
/// Destructor destroy the array. /// Destructor destroy the array.
~wxScopedArray(); ~wxScopedArray();

View File

@ -1810,7 +1810,7 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates,
int noTemplates, bool sort) int noTemplates, bool sort)
{ {
wxArrayString strings; wxArrayString strings;
wxScopedArray<wxDocTemplate *> data(new wxDocTemplate *[noTemplates]); wxScopedArray<wxDocTemplate *> data(noTemplates);
int i; int i;
int n = 0; int n = 0;
@ -1888,7 +1888,7 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates,
int noTemplates, bool sort) int noTemplates, bool sort)
{ {
wxArrayString strings; wxArrayString strings;
wxScopedArray<wxDocTemplate *> data(new wxDocTemplate *[noTemplates]); wxScopedArray<wxDocTemplate *> data(noTemplates);
int i; int i;
int n = 0; int n = 0;

View File

@ -138,7 +138,7 @@ wxString GetPreferredUILanguage(const wxArrayString& available)
NULL, NULL,
&bufferSize) ) &bufferSize) )
{ {
wxScopedArray<WCHAR> langs(new WCHAR[bufferSize]); wxScopedArray<WCHAR> langs(bufferSize);
if ( (*s_pfnGetUserPreferredUILanguages)(MUI_LANGUAGE_NAME, if ( (*s_pfnGetUserPreferredUILanguages)(MUI_LANGUAGE_NAME,
&numLangs, &numLangs,
langs.get(), langs.get(),

View File

@ -626,7 +626,7 @@ bool wxClipboard::AddData( wxDataObject *data )
// get formats from wxDataObjects // get formats from wxDataObjects
const size_t count = data->GetFormatCount(); const size_t count = data->GetFormatCount();
wxDataFormatArray formats(new wxDataFormat[count]); wxDataFormatArray formats(count);
data->GetAllFormats(formats.get()); data->GetAllFormats(formats.get());
// always provide TIMESTAMP as a target, see comments in selection_handler // always provide TIMESTAMP as a target, see comments in selection_handler
@ -690,7 +690,7 @@ bool wxClipboard::GetData( wxDataObject& data )
// get all supported formats from wxDataObjects: notice that we are setting // get all supported formats from wxDataObjects: notice that we are setting
// the object data, so we need them in "Set" direction // the object data, so we need them in "Set" direction
const size_t count = data.GetFormatCount(wxDataObject::Set); const size_t count = data.GetFormatCount(wxDataObject::Set);
wxDataFormatArray formats(new wxDataFormat[count]); wxDataFormatArray formats(count);
data.GetAllFormats(formats.get(), wxDataObject::Set); data.GetAllFormats(formats.get(), wxDataObject::Set);
for ( size_t i = 0; i < count; i++ ) for ( size_t i = 0; i < count; i++ )

View File

@ -264,7 +264,7 @@ void wxClipboardCallback( Widget xwidget, long* data_id,
wxCharBuffer buffer(size); wxCharBuffer buffer(size);
size_t count = dobj->GetFormatCount( wxDataObject::Get ); size_t count = dobj->GetFormatCount( wxDataObject::Get );
wxDataFormatScopedArray dfarr( new wxDataFormat[count] ); wxDataFormatScopedArray dfarr(count);
dobj->GetAllFormats( dfarr.get(), wxDataObject::Get ); dobj->GetAllFormats( dfarr.get(), wxDataObject::Get );
if( !dobj->GetDataHere( dfarr[*priv], buffer.data() ) ) if( !dobj->GetDataHere( dfarr[*priv], buffer.data() ) )
@ -300,7 +300,7 @@ bool wxClipboard::AddData( wxDataObject *data )
return false; return false;
size_t count = data->GetFormatCount( wxDataObject::Get ); size_t count = data->GetFormatCount( wxDataObject::Get );
wxDataFormatScopedArray dfarr( new wxDataFormat[count] ); wxDataFormatScopedArray dfarr(count);
data->GetAllFormats( dfarr.get(), wxDataObject::Get ); data->GetAllFormats( dfarr.get(), wxDataObject::Get );
for( size_t i = 0; i < count; ++i ) for( size_t i = 0; i < count; ++i )
@ -413,7 +413,7 @@ bool wxClipboard::GetData( wxDataObject& data )
int count; int count;
unsigned long max_name_length; unsigned long max_name_length;
size_t dfcount = data.GetFormatCount( wxDataObject::Set ); size_t dfcount = data.GetFormatCount( wxDataObject::Set );
wxDataFormatScopedArray dfarr( new wxDataFormat[dfcount] ); wxDataFormatScopedArray dfarr(dfcount);
data.GetAllFormats( dfarr.get(), wxDataObject::Set ); data.GetAllFormats( dfarr.get(), wxDataObject::Set );
if( XmClipboardInquireCount( xdisplay, xwindow, &count, &max_name_length ) if( XmClipboardInquireCount( xdisplay, xwindow, &count, &max_name_length )

View File

@ -860,7 +860,7 @@ size_t wxMenu::CopyAccels(wxAcceleratorEntry *accels) const
wxAcceleratorTable *wxMenu::CreateAccelTable() const wxAcceleratorTable *wxMenu::CreateAccelTable() const
{ {
const size_t count = m_accels.size(); const size_t count = m_accels.size();
wxScopedArray<wxAcceleratorEntry> accels(new wxAcceleratorEntry[count]); wxScopedArray<wxAcceleratorEntry> accels(count);
CopyAccels(accels.get()); CopyAccels(accels.get());
return new wxAcceleratorTable(count, accels.get()); return new wxAcceleratorTable(count, accels.get());

View File

@ -894,7 +894,7 @@ STDMETHODIMP wxIDataObject::EnumFormatEtc(DWORD dwDir,
nFormatCount = wx_truncate_cast(ULONG, ourFormatCount + sysFormatCount); nFormatCount = wx_truncate_cast(ULONG, ourFormatCount + sysFormatCount);
// fill format array with formats ... // fill format array with formats ...
wxScopedArray<wxDataFormat> formats(new wxDataFormat[nFormatCount]); wxScopedArray<wxDataFormat> formats(nFormatCount);
// ... from content data (supported formats) // ... from content data (supported formats)
m_pDataObject->GetAllFormats(formats.get(), dir); m_pDataObject->GetAllFormats(formats.get(), dir);

View File

@ -931,7 +931,7 @@ bool wxToolBar::Realize()
// Next add the buttons and separators // Next add the buttons and separators
// ----------------------------------- // -----------------------------------
wxScopedArray<TBBUTTON> buttons(new TBBUTTON[nTools]); wxScopedArray<TBBUTTON> buttons(nTools);
// this array will hold the indices of all controls in the toolbar // this array will hold the indices of all controls in the toolbar
wxArrayInt controlIds; wxArrayInt controlIds;