diff options
author | Neil <nyamatongwe@gmail.com> | 2017-04-22 09:16:08 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2017-04-22 09:16:08 +1000 |
commit | b201e09daf251a0e3e5576b79643f6c4f841a4a9 (patch) | |
tree | bc7d0caf7e5a4d0635b7ee7ba593f4ee830a6072 | |
parent | 0801e0084a5cf87f424235d5947f5158474d5da4 (diff) | |
download | scintilla-mirror-b201e09daf251a0e3e5576b79643f6c4f841a4a9.tar.gz |
Using unique_ptr to simplify ownership of images, case folder, and list box.
-rw-r--r-- | src/AutoComplete.cxx | 5 | ||||
-rw-r--r-- | src/AutoComplete.h | 2 | ||||
-rw-r--r-- | src/Document.cxx | 12 | ||||
-rw-r--r-- | src/Document.h | 2 | ||||
-rw-r--r-- | src/Editor.cxx | 2 | ||||
-rw-r--r-- | src/LineMarker.cxx | 11 | ||||
-rw-r--r-- | src/LineMarker.h | 28 | ||||
-rw-r--r-- | src/XPM.cxx | 17 | ||||
-rw-r--r-- | src/XPM.h | 2 |
9 files changed, 29 insertions, 52 deletions
diff --git a/src/AutoComplete.cxx b/src/AutoComplete.cxx index cc4b46dfa..1c847ce0f 100644 --- a/src/AutoComplete.cxx +++ b/src/AutoComplete.cxx @@ -33,7 +33,6 @@ AutoComplete::AutoComplete() : typesep('?'), ignoreCase(false), chooseSingle(false), - lb(0), posStart(0), startLen(0), cancelAtStartPos(true), @@ -43,14 +42,12 @@ AutoComplete::AutoComplete() : widthLBDefault(100), heightLBDefault(100), autoSort(SC_ORDER_PRESORTED) { - lb = ListBox::Allocate(); + lb.reset(ListBox::Allocate()); } AutoComplete::~AutoComplete() { if (lb) { lb->Destroy(); - delete lb; - lb = 0; } } diff --git a/src/AutoComplete.h b/src/AutoComplete.h index 205d4e095..17998657b 100644 --- a/src/AutoComplete.h +++ b/src/AutoComplete.h @@ -27,7 +27,7 @@ public: bool ignoreCase; bool chooseSingle; - ListBox *lb; + std::unique_ptr<ListBox> lb; Sci::Position posStart; int startLen; /// Should autocompletion be canceled if editor's currentPos <= startPos? diff --git a/src/Document.cxx b/src/Document.cxx index b4ab37244..581358e52 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -95,7 +95,6 @@ int LexInterface::LineEndTypesSupported() { Document::Document() { refCount = 0; - pcf = NULL; #ifdef _WIN32 eolMode = SC_EOL_CRLF; #else @@ -118,7 +117,6 @@ Document::Document() { durationStyleOneLine = 0.00001; matchesValid = false; - regex = 0; UTF8BytesOfLeadInitialise(); @@ -139,9 +137,6 @@ Document::~Document() { delete pl; pl = nullptr; } - regex.release(); - delete pcf; - pcf = 0; } void Document::Init() { @@ -161,7 +156,7 @@ int Document::LineEndTypesSupported() const { bool Document::SetDBCSCodePage(int dbcsCodePage_) { if (dbcsCodePage != dbcsCodePage_) { dbcsCodePage = dbcsCodePage_; - SetCaseFolder(NULL); + SetCaseFolder(nullptr); cb.SetLineEndTypes(lineEndBitSet & LineEndTypesSupported()); return true; } else { @@ -1802,12 +1797,11 @@ bool Document::MatchesWordOptions(bool word, bool wordStart, Sci::Position pos, } bool Document::HasCaseFolder() const { - return pcf != 0; + return pcf != nullptr; } void Document::SetCaseFolder(CaseFolder *pcf_) { - delete pcf; - pcf = pcf_; + pcf.reset(pcf_); } Document::CharacterExtracted Document::ExtractCharacter(Sci::Position position) const { diff --git a/src/Document.h b/src/Document.h index 788f9bd33..62e26c6fc 100644 --- a/src/Document.h +++ b/src/Document.h @@ -210,7 +210,7 @@ private: int refCount; CellBuffer cb; CharClassify charClass; - CaseFolder *pcf; + std::unique_ptr<CaseFolder> pcf; Sci::Position endStyled; int styleClock; int enteredModification; diff --git a/src/Editor.cxx b/src/Editor.cxx index 81f3c1893..35c8a8d6b 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -5673,7 +5673,7 @@ void Editor::StyleSetMessage(unsigned int iMessage, uptr_t wParam, sptr_t lParam break; case SCI_STYLESETCHARACTERSET: vs.styles[wParam].characterSet = static_cast<int>(lParam); - pdoc->SetCaseFolder(NULL); + pdoc->SetCaseFolder(nullptr); break; case SCI_STYLESETVISIBLE: vs.styles[wParam].visible = lParam != 0; diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx index 6bb9f4e9a..d80a3c78c 100644 --- a/src/LineMarker.cxx +++ b/src/LineMarker.cxx @@ -26,20 +26,17 @@ using namespace Scintilla; #endif void LineMarker::SetXPM(const char *textForm) { - delete pxpm; - pxpm = new XPM(textForm); + pxpm.reset(new XPM(textForm)); markType = SC_MARK_PIXMAP; } void LineMarker::SetXPM(const char *const *linesForm) { - delete pxpm; - pxpm = new XPM(linesForm); + pxpm.reset(new XPM(linesForm)); markType = SC_MARK_PIXMAP; } void LineMarker::SetRGBAImage(Point sizeRGBAImage, float scale, const unsigned char *pixelsRGBAImage) { - delete image; - image = new RGBAImage(static_cast<int>(sizeRGBAImage.x), static_cast<int>(sizeRGBAImage.y), scale, pixelsRGBAImage); + image.reset(new RGBAImage(static_cast<int>(sizeRGBAImage.x), static_cast<int>(sizeRGBAImage.y), scale, pixelsRGBAImage)); markType = SC_MARK_RGBAIMAGE; } @@ -74,7 +71,7 @@ static void DrawMinus(Surface *surface, int centreX, int centreY, int armSize, C } void LineMarker::Draw(Surface *surface, PRectangle &rcWhole, Font &fontForCharacter, typeOfFold tFold, int marginStyle) const { - if (customDraw != NULL) { + if (customDraw) { customDraw(surface, rcWhole, fontForCharacter, tFold, marginStyle, this); return; } diff --git a/src/LineMarker.h b/src/LineMarker.h index fde11da0d..2006fe8fb 100644 --- a/src/LineMarker.h +++ b/src/LineMarker.h @@ -25,8 +25,8 @@ public: ColourDesired back; ColourDesired backSelected; int alpha; - XPM *pxpm; - RGBAImage *image; + std::unique_ptr<XPM> pxpm; + std::unique_ptr<RGBAImage> image; /** Some platforms, notably PLAT_CURSES, do not support Scintilla's native * Draw function for drawing line markers. Allow those platforms to override * it instead of creating a new method(s) in the Surface class that existing @@ -38,38 +38,32 @@ public: back = ColourDesired(0xff,0xff,0xff); backSelected = ColourDesired(0xff,0x00,0x00); alpha = SC_ALPHA_NOALPHA; - pxpm = NULL; - image = NULL; - customDraw = NULL; + customDraw = nullptr; } LineMarker(const LineMarker &) { - // Defined to avoid pxpm being blindly copied, not as a complete copy constructor + // Defined to avoid pxpm and image being blindly copied, not as a complete copy constructor. markType = SC_MARK_CIRCLE; fore = ColourDesired(0,0,0); back = ColourDesired(0xff,0xff,0xff); backSelected = ColourDesired(0xff,0x00,0x00); alpha = SC_ALPHA_NOALPHA; - pxpm = NULL; - image = NULL; - customDraw = NULL; + pxpm.reset(); + image.reset(); + customDraw = nullptr; } ~LineMarker() { - delete pxpm; - delete image; } LineMarker &operator=(const LineMarker &other) { - // Defined to avoid pxpm being blindly copied, not as a complete assignment operator + // Defined to avoid pxpm and image being blindly copied, not as a complete assignment operator. if (this != &other) { markType = SC_MARK_CIRCLE; fore = ColourDesired(0,0,0); back = ColourDesired(0xff,0xff,0xff); backSelected = ColourDesired(0xff,0x00,0x00); alpha = SC_ALPHA_NOALPHA; - delete pxpm; - pxpm = NULL; - delete image; - image = NULL; - customDraw = NULL; + pxpm.reset(); + image.reset(); + customDraw = nullptr; } return *this; } diff --git a/src/XPM.cxx b/src/XPM.cxx index 6e328ae97..818a1acdc 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -249,10 +249,6 @@ RGBAImageSet::~RGBAImageSet() { /// Remove all images. void RGBAImageSet::Clear() { - for (ImageMap::iterator it=images.begin(); it != images.end(); ++it) { - delete it->second; - it->second = 0; - } images.clear(); height = -1; width = -1; @@ -262,10 +258,9 @@ void RGBAImageSet::Clear() { void RGBAImageSet::Add(int ident, RGBAImage *image) { ImageMap::iterator it=images.find(ident); if (it == images.end()) { - images[ident] = image; + images[ident] = std::unique_ptr<RGBAImage>(image); } else { - delete it->second; - it->second = image; + it->second.reset(image); } height = -1; width = -1; @@ -275,15 +270,15 @@ void RGBAImageSet::Add(int ident, RGBAImage *image) { RGBAImage *RGBAImageSet::Get(int ident) { ImageMap::iterator it = images.find(ident); if (it != images.end()) { - return it->second; + return it->second.get(); } - return NULL; + return nullptr; } /// Give the largest height of the set. int RGBAImageSet::GetHeight() const { if (height < 0) { - for (const std::pair<int, RGBAImage*> &image : images) { + for (const std::pair<const int, std::unique_ptr<RGBAImage>> &image : images) { if (height < image.second->GetHeight()) { height = image.second->GetHeight(); } @@ -295,7 +290,7 @@ int RGBAImageSet::GetHeight() const { /// Give the largest width of the set. int RGBAImageSet::GetWidth() const { if (width < 0) { - for (const std::pair<int, RGBAImage*> &image : images) { + for (const std::pair<const int, std::unique_ptr<RGBAImage>> &image : images) { if (width < image.second->GetWidth()) { width = image.second->GetWidth(); } @@ -68,7 +68,7 @@ public: * A collection of RGBAImage pixmaps indexed by integer id. */ class RGBAImageSet { - typedef std::map<int, RGBAImage*> ImageMap; + typedef std::map<int, std::unique_ptr<RGBAImage>> ImageMap; ImageMap images; mutable int height; ///< Memorize largest height of the set. mutable int width; ///< Memorize largest width of the set. |