Use std::unique_ptr<> instead of wxDECLARE_SCOPED_PTR
Replace macro-based scoped pointers with the standard class. Also mention that using these macros and wxScopedPtr itself is deprecated (but there are too many occurrences of the latter in the code to change all of them now). Note that wxMsgCatalog ctor and dtor had to be moved out of line to allow using unique_ptr<> to an incomplete class as member. On the bright side, we can just use unique_ptr<> instead of wxPluralFormsNodePtr which was a local reimplementation of wxScopedPtr. No real changes.
This commit is contained in:
parent
26e99e9337
commit
347d7fcccb
11 changed files with 44 additions and 84 deletions
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@
|
|||
#include "wx/language.h"
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/strconv.h"
|
||||
#include "wx/scopedptr.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
// ============================================================================
|
||||
// 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<wxPluralFormsCalculator>;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// 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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 <memory>
|
||||
#endif // wxUSE_BASE
|
||||
|
||||
#if wxUSE_GUI
|
||||
|
|
@ -1341,7 +1338,7 @@ void wxEvtHandler::ProcessPendingEvents()
|
|||
}
|
||||
}
|
||||
|
||||
wxEventPtr event(pEvent);
|
||||
std::unique_ptr<wxEvent> 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
|
||||
|
|
|
|||
|
|
@ -16,10 +16,7 @@
|
|||
#ifndef WX_PRECOMP
|
||||
#endif
|
||||
|
||||
#include "wx/scopedptr.h"
|
||||
|
||||
wxDEFINE_SCOPED_PTR_TYPE(wxFSFile)
|
||||
wxDEFINE_SCOPED_PTR_TYPE(wxInputStream)
|
||||
#include <memory>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// wxFilterFSHandler
|
||||
|
|
@ -44,15 +41,15 @@ wxFSFile* wxFilterFSHandler::OpenFile(
|
|||
return nullptr;
|
||||
|
||||
wxString left = GetLeftLocation(location);
|
||||
wxFSFilePtr leftFile(fs.OpenFile(left));
|
||||
std::unique_ptr<wxFSFile> leftFile(fs.OpenFile(left));
|
||||
if (!leftFile.get())
|
||||
return nullptr;
|
||||
|
||||
wxInputStreamPtr leftStream(leftFile->DetachStream());
|
||||
std::unique_ptr<wxInputStream> leftStream(leftFile->DetachStream());
|
||||
if (!leftStream.get() || !leftStream->IsOk())
|
||||
return nullptr;
|
||||
|
||||
wxInputStreamPtr stream(factory->NewStream(leftStream.release()));
|
||||
std::unique_ptr<wxInputStream> stream(factory->NewStream(leftStream.release()));
|
||||
|
||||
// The way compressed streams are supposed to be served is e.g.:
|
||||
// Content-type: application/postscript
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@
|
|||
#include <string.h>
|
||||
#include "wx/gifdecod.h"
|
||||
#include "wx/scopedarray.h"
|
||||
#include "wx/scopedptr.h"
|
||||
#include "wx/scopeguard.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
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<GIFImage> pimg(new GIFImage());
|
||||
|
||||
wxScopeGuard guardDestroy = wxMakeObjGuard(*this, &wxGIFDecoder::Destroy);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <locale.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// 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<wxAppConsole>
|
||||
{
|
||||
public:
|
||||
explicit wxAppPtr(wxAppConsole *ptr = nullptr) : wxAppPtrBase(ptr) { }
|
||||
explicit wxAppPtr(wxAppConsole *ptr) : std::unique_ptr<wxAppConsole>(ptr) { }
|
||||
~wxAppPtr()
|
||||
{
|
||||
if ( get() )
|
||||
|
|
|
|||
|
|
@ -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 <grp.h>
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// 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<wxTarEntry> 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<wxTarEntry> e(entry);
|
||||
|
||||
if (!CloseEntry())
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -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<wxPluralFormsNode>;
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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 <memory>
|
||||
|
||||
// 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<wxZipEntry> 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<wxZipEntry> 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<wxZipEntry> 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<wxZipEntry> spPending(m_pending);
|
||||
m_pending = nullptr;
|
||||
m_lasterror = wxSTREAM_WRITE_ERROR;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue