diff --git a/include/wx/scopedptr.h b/include/wx/scopedptr.h index d316f3f47f..3e99905d3a 100644 --- a/include/wx/scopedptr.h +++ b/include/wx/scopedptr.h @@ -27,6 +27,9 @@ #ifndef _WX_SCOPED_PTR_H_ #define _WX_SCOPED_PTR_H_ +// Everything in this file is deprecated and must not be used any longer, +// simply use std::unique_ptr<> instead. + #include "wx/defs.h" #include "wx/checkeddelete.h" diff --git a/include/wx/translation.h b/include/wx/translation.h index ed3027c8dd..2dbe851702 100644 --- a/include/wx/translation.h +++ b/include/wx/translation.h @@ -21,7 +21,8 @@ #include "wx/language.h" #include "wx/hashmap.h" #include "wx/strconv.h" -#include "wx/scopedptr.h" + +#include // ============================================================================ // global decls @@ -75,7 +76,7 @@ class WXDLLIMPEXP_FWD_BASE wxTranslationsLoader; class WXDLLIMPEXP_FWD_BASE wxLocale; class wxPluralFormsCalculator; -wxDECLARE_SCOPED_PTR(wxPluralFormsCalculator, wxPluralFormsCalculatorPtr) +using wxPluralFormsCalculatorPtr = std::unique_ptr; // ---------------------------------------------------------------------------- // wxMsgCatalog corresponds to one loaded message catalog. @@ -86,7 +87,7 @@ class WXDLLIMPEXP_BASE wxMsgCatalog public: // Ctor is protected, because CreateFromXXX functions must be used, // but destruction should be unrestricted - ~wxMsgCatalog() = default; + ~wxMsgCatalog(); // load the catalog from disk or from data; caller is responsible for // deleting them if not null @@ -103,9 +104,7 @@ public: const wxString *GetString(const wxString& sz, unsigned n = UINT_MAX, const wxString& ct = wxEmptyString) const; protected: - wxMsgCatalog(const wxString& domain) - : m_pNext(nullptr), m_domain(domain) - {} + wxMsgCatalog(const wxString& domain); private: // variable pointing to the next element in a linked list (or nullptr) diff --git a/interface/wx/scopedptr.h b/interface/wx/scopedptr.h index fd7e8e87f0..9d353ce48b 100644 --- a/interface/wx/scopedptr.h +++ b/interface/wx/scopedptr.h @@ -8,6 +8,11 @@ /** @class wxScopedPtr + Deprecated equivalent of standard @c unique_ptr template class. + + Please don't use this class, and especially its macro-based versions, in + the new code. + This is a simple scoped smart pointer implementation that is similar to the Boost smart pointers (see http://www.boost.org) but rewritten to use macros instead. diff --git a/samples/ownerdrw/ownerdrw.cpp b/samples/ownerdrw/ownerdrw.cpp index 00ca423ed3..6ac0b1dd13 100644 --- a/samples/ownerdrw/ownerdrw.cpp +++ b/samples/ownerdrw/ownerdrw.cpp @@ -159,8 +159,7 @@ void OwnerDrawnFrame::InitMenu() pItem->SetBitmaps(bmpBell); file_menu->Append(pItem); - pItem = new wxMenuItem(file_menu, Menu_Bitmap2, "So&und", - "icon changes!", wxITEM_CHECK); + pItem = new wxMenuItem(file_menu, Menu_Bitmap2, "So&und with a very very very very very very long label", "", wxITEM_CHECK); pItem->SetFont(fontBmp); pItem->SetBitmaps(bmpSound, bmpNoSound); file_menu->Append(pItem); diff --git a/src/common/event.cpp b/src/common/event.cpp index e17b8553cf..02b1b50385 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -45,10 +45,7 @@ #include "wx/thread.h" #if wxUSE_BASE - #include "wx/scopedptr.h" - - wxDECLARE_SCOPED_PTR(wxEvent, wxEventPtr) - wxDEFINE_SCOPED_PTR(wxEvent, wxEventPtr) + #include #endif // wxUSE_BASE #if wxUSE_GUI @@ -1341,7 +1338,7 @@ void wxEvtHandler::ProcessPendingEvents() } } - wxEventPtr event(pEvent); + std::unique_ptr event(pEvent); // it's important we remove event from list before processing it, else a // nested event loop, for example from a modal dialog, might process the diff --git a/src/common/fs_filter.cpp b/src/common/fs_filter.cpp index bc4c717c91..abf92e3e7c 100644 --- a/src/common/fs_filter.cpp +++ b/src/common/fs_filter.cpp @@ -16,10 +16,7 @@ #ifndef WX_PRECOMP #endif -#include "wx/scopedptr.h" - -wxDEFINE_SCOPED_PTR_TYPE(wxFSFile) -wxDEFINE_SCOPED_PTR_TYPE(wxInputStream) +#include //---------------------------------------------------------------------------- // wxFilterFSHandler @@ -44,15 +41,15 @@ wxFSFile* wxFilterFSHandler::OpenFile( return nullptr; wxString left = GetLeftLocation(location); - wxFSFilePtr leftFile(fs.OpenFile(left)); + std::unique_ptr leftFile(fs.OpenFile(left)); if (!leftFile.get()) return nullptr; - wxInputStreamPtr leftStream(leftFile->DetachStream()); + std::unique_ptr leftStream(leftFile->DetachStream()); if (!leftStream.get() || !leftStream->IsOk()) return nullptr; - wxInputStreamPtr stream(factory->NewStream(leftStream.release())); + std::unique_ptr stream(factory->NewStream(leftStream.release())); // The way compressed streams are supposed to be served is e.g.: // Content-type: application/postscript diff --git a/src/common/gifdecod.cpp b/src/common/gifdecod.cpp index c716c55f7b..74d9adfbec 100644 --- a/src/common/gifdecod.cpp +++ b/src/common/gifdecod.cpp @@ -23,9 +23,10 @@ #include #include "wx/gifdecod.h" #include "wx/scopedarray.h" -#include "wx/scopedptr.h" #include "wx/scopeguard.h" +#include + enum { GIF_MARKER_EXT = '!', // 0x21 @@ -65,10 +66,6 @@ public: wxDECLARE_NO_COPY_CLASS(GIFImage); }; -wxDECLARE_SCOPED_PTR(GIFImage, GIFImagePtr) -wxDEFINE_SCOPED_PTR(GIFImage, GIFImagePtr) - - //--------------------------------------------------------------------------- // GIFImage constructor //--------------------------------------------------------------------------- @@ -782,7 +779,7 @@ wxGIFErrorCode wxGIFDecoder::LoadGIF(wxInputStream& stream) case GIF_MARKER_SEP: { // allocate memory for IMAGEN struct - GIFImagePtr pimg(new GIFImage()); + std::unique_ptr pimg(new GIFImage()); wxScopeGuard guardDestroy = wxMakeObjGuard(*this, &wxGIFDecoder::Destroy); diff --git a/src/common/init.cpp b/src/common/init.cpp index effd602fdc..f7d5682f83 100644 --- a/src/common/init.cpp +++ b/src/common/init.cpp @@ -30,7 +30,6 @@ #include "wx/init.h" #include "wx/atomic.h" -#include "wx/scopedptr.h" #include "wx/except.h" #if defined(__WINDOWS__) @@ -55,6 +54,8 @@ #include #endif +#include + // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -72,13 +73,10 @@ public: // we need a special kind of auto pointer to wxApp which not only deletes the // pointer it holds in its dtor but also resets the global application pointer -wxDECLARE_SCOPED_PTR(wxAppConsole, wxAppPtrBase) -wxDEFINE_SCOPED_PTR(wxAppConsole, wxAppPtrBase) - -class wxAppPtr : public wxAppPtrBase +class wxAppPtr : public std::unique_ptr { public: - explicit wxAppPtr(wxAppConsole *ptr = nullptr) : wxAppPtrBase(ptr) { } + explicit wxAppPtr(wxAppConsole *ptr) : std::unique_ptr(ptr) { } ~wxAppPtr() { if ( get() ) diff --git a/src/common/tarstrm.cpp b/src/common/tarstrm.cpp index 57e8e9a938..07762b6618 100644 --- a/src/common/tarstrm.cpp +++ b/src/common/tarstrm.cpp @@ -22,7 +22,6 @@ #include "wx/buffer.h" #include "wx/datetime.h" -#include "wx/scopedptr.h" #include "wx/filename.h" #include "wx/thread.h" @@ -33,6 +32,7 @@ #include #endif +#include ///////////////////////////////////////////////////////////////////////////// // constants @@ -629,8 +629,6 @@ void wxTarEntry::SetMode(int mode) ///////////////////////////////////////////////////////////////////////////// // Input stream -wxDEFINE_SCOPED_PTR_TYPE(wxTarEntry) - wxTarInputStream::wxTarInputStream(wxInputStream& stream, wxMBConv& conv /*=wxConvLocal*/) : wxArchiveInputStream(stream, conv) @@ -672,7 +670,7 @@ wxTarEntry *wxTarInputStream::GetNextEntry() if (!IsOk()) return nullptr; - wxTarEntryPtr entry(new wxTarEntry); + std::unique_ptr entry(new wxTarEntry); entry->SetMode(GetHeaderNumber(TAR_MODE)); entry->SetUserId(GetHeaderNumber(TAR_UID)); @@ -1088,7 +1086,7 @@ wxTarOutputStream::~wxTarOutputStream() bool wxTarOutputStream::PutNextEntry(wxTarEntry *entry) { - wxTarEntryPtr e(entry); + std::unique_ptr e(entry); if (!CloseEntry()) return false; diff --git a/src/common/translation.cpp b/src/common/translation.cpp index ce4dbd869c..c00969e94e 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -383,22 +383,7 @@ bool wxPluralFormsScanner::nextToken() class wxPluralFormsNode; -// NB: Can't use wxDEFINE_SCOPED_PTR_TYPE because wxPluralFormsNode is not -// fully defined yet: -class wxPluralFormsNodePtr -{ -public: - wxPluralFormsNodePtr(wxPluralFormsNode *p = nullptr) : m_p(p) {} - ~wxPluralFormsNodePtr(); - wxPluralFormsNode& operator*() const { return *m_p; } - wxPluralFormsNode* operator->() const { return m_p; } - wxPluralFormsNode* get() const { return m_p; } - wxPluralFormsNode* release(); - void reset(wxPluralFormsNode *p); - -private: - wxPluralFormsNode *m_p; -}; +using wxPluralFormsNodePtr = std::unique_ptr; class wxPluralFormsNode { @@ -416,26 +401,6 @@ private: wxPluralFormsNodePtr m_nodes[3]; }; -wxPluralFormsNodePtr::~wxPluralFormsNodePtr() -{ - delete m_p; -} -wxPluralFormsNode* wxPluralFormsNodePtr::release() -{ - wxPluralFormsNode *p = m_p; - m_p = nullptr; - return p; -} -void wxPluralFormsNodePtr::reset(wxPluralFormsNode *p) -{ - if (p != m_p) - { - delete m_p; - m_p = p; - } -} - - void wxPluralFormsNode::setNode(unsigned i, wxPluralFormsNode* n) { m_nodes[i].reset(n); @@ -518,8 +483,6 @@ private: wxPluralFormsNodePtr m_plural; }; -wxDEFINE_SCOPED_PTR(wxPluralFormsCalculator, wxPluralFormsCalculatorPtr) - void wxPluralFormsCalculator::init(wxPluralFormsToken::Number nplurals, wxPluralFormsNode* plural) { @@ -1183,6 +1146,13 @@ bool wxMsgCatalogFile::FillHash(wxStringToStringHashMap& hash, // wxMsgCatalog class // ---------------------------------------------------------------------------- +wxMsgCatalog::wxMsgCatalog(const wxString& domain) + : m_pNext(nullptr), m_domain(domain) +{ +} + +wxMsgCatalog::~wxMsgCatalog() = default; + /* static */ wxMsgCatalog *wxMsgCatalog::CreateFromFile(const wxString& filename, const wxString& domain) diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index 28c708576c..3da939dba4 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -24,10 +24,11 @@ #include "wx/datstrm.h" #include "wx/zstream.h" #include "wx/mstream.h" -#include "wx/scopedptr.h" #include "wx/wfstream.h" #include "zlib.h" +#include + // value for the 'version needed to extract' field (20 means 2.0) enum { VERSION_NEEDED_TO_EXTRACT = 20, @@ -1571,10 +1572,6 @@ private: ///////////////////////////////////////////////////////////////////////////// // Input stream -// leave the default wxZipEntryPtr free for users -wxDECLARE_SCOPED_PTR(wxZipEntry, wxZipEntryPtr_) -wxDEFINE_SCOPED_PTR (wxZipEntry, wxZipEntryPtr_) - // constructor // wxZipInputStream::wxZipInputStream(wxInputStream& stream, @@ -1805,7 +1802,7 @@ wxZipEntry *wxZipInputStream::GetNextEntry() if (!IsOk()) return nullptr; - wxZipEntryPtr_ entry(new wxZipEntry(m_entry)); + std::unique_ptr entry(new wxZipEntry(m_entry)); entry->m_backlink = m_weaklinks->AddEntry(entry.get(), entry->GetKey()); return entry.release(); } @@ -2224,7 +2221,7 @@ bool wxZipOutputStream::PutNextDirEntry( bool wxZipOutputStream::CopyEntry(wxZipEntry *entry, wxZipInputStream& inputStream) { - wxZipEntryPtr_ e(entry); + std::unique_ptr e(entry); return inputStream.DoOpen(e.get(), true) && @@ -2394,7 +2391,7 @@ bool wxZipOutputStream::CloseCompressor(wxOutputStream *comp) void wxZipOutputStream::CreatePendingEntry(const void *buffer, size_t size) { wxASSERT(IsOk() && m_pending && !m_comp); - wxZipEntryPtr_ spPending(m_pending); + std::unique_ptr spPending(m_pending); m_pending = nullptr; Buffer bufs[] = { @@ -2435,7 +2432,7 @@ void wxZipOutputStream::CreatePendingEntry(const void *buffer, size_t size) void wxZipOutputStream::CreatePendingEntry() { wxASSERT(IsOk() && m_pending && !m_comp); - wxZipEntryPtr_ spPending(m_pending); + std::unique_ptr spPending(m_pending); m_pending = nullptr; m_lasterror = wxSTREAM_WRITE_ERROR;