From d44d0cbd7343e36ddd3657dd97cd5eb7018d2585 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sat, 26 Mar 2005 14:18:56 +0000 Subject: [PATCH] Added C/wxString array constructors to wxArrayString git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33074 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + docs/latex/wx/arrstrng.tex | 14 +++++++++++--- include/wx/arrstr.h | 6 ++++++ src/common/string.cpp | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 0f4e4b913c..54471363aa 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -14,6 +14,7 @@ All: - Fixed wxDateTime::SetToWeekDayInSameWeek(Sun, Monday_First). - Added WXK_SPECIAL keycodes for special hardware buttons. - Fixed bug with wxFile::Seek(-1, wxFromCurrent) +- Added wxString/C array constructors to wxArrayString All (GUI): diff --git a/docs/latex/wx/arrstrng.tex b/docs/latex/wx/arrstrng.tex index 6d53707dc5..68cc818143 100644 --- a/docs/latex/wx/arrstrng.tex +++ b/docs/latex/wx/arrstrng.tex @@ -60,13 +60,21 @@ functions. \func{}{wxArrayString}{\void} -\func{}{wxArrayString}{\param{const wxArrayString\&}{ array}} +Default constructor. -Default and copy constructors. +\func{}{wxArrayString}{\param{const wxArrayString\&}{ array}} -Note that when an array is assigned to a sorted array, its contents is +Copy constructor. Note that when an array is assigned to a sorted array, its contents is automatically sorted during construction. +\func{}{wxArrayString}{\param{size\_t}{ sz}, \param{const wxChar**}{ arr}} + +Constructor from a C string array. Pass a size {\it sz} and array {\it arr}. + +\func{}{wxArrayString}{\param{size\_t}{ sz}, \param{const wxString*}{ arr}} + +Constructor from a wxString array. Pass a size {\it sz} and array {\it arr}. + \membersection{wxArrayString::\destruct{wxArrayString}}\label{wxarraystringdtor} \func{}{\destruct{wxArrayString}}{} diff --git a/include/wx/arrstr.h b/include/wx/arrstr.h index 36091d589a..70bddf1737 100644 --- a/include/wx/arrstr.h +++ b/include/wx/arrstr.h @@ -42,6 +42,8 @@ public: wxArrayString() { } wxArrayString(const wxArrayString& a) : wxArrayStringBase(a) { } + wxArrayString(size_t sz, const wxChar** a); + wxArrayString(size_t sz, const wxString* a); int Index(const wxChar* sz, bool bCase = true, bool bFromEnd = false) const; @@ -110,6 +112,10 @@ public: // of course, using explicit would be even better - if all compilers // supported it... wxArrayString(int autoSort) { Init(autoSort != 0); } + // C string array ctor + wxArrayString(size_t sz, const wxChar** a); + // wxString string array ctor + wxArrayString(size_t sz, const wxString* a); // copy ctor wxArrayString(const wxArrayString& array); // assignment operator diff --git a/src/common/string.cpp b/src/common/string.cpp index d5c51592e0..211da2c5e3 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -2032,6 +2032,24 @@ int wxString::sprintf(const wxChar *pszFormat, ...) #include "wx/arrstr.h" +wxArrayString::wxArrayString(size_t sz, const wxChar** a) +{ +#if !wxUSE_STL + Init(false); +#endif + for (size_t i=0; i < sz; i++) + Add(a[i]); +} + +wxArrayString::wxArrayString(size_t sz, const wxString* a) +{ +#if !wxUSE_STL + Init(false); +#endif + for (size_t i=0; i < sz; i++) + Add(a[i]); +} + #if !wxUSE_STL // size increment = min(50% of current size, ARRAY_MAXSIZE_INCREMENT) -- 2.47.2