diff options
author | Neil <nyamatongwe@gmail.com> | 2017-05-02 10:06:46 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2017-05-02 10:06:46 +1000 |
commit | ffeb34c29ffd27e1a1a67cb26ceec8fc1253a410 (patch) | |
tree | 59d17870a0bea7b8a058100fdd98666227e7684e /src/Editor.h | |
parent | 782ada0bab34bb56c4023c070e6eb355ca32cdf2 (diff) | |
download | scintilla-mirror-ffeb34c29ffd27e1a1a67cb26ceec8fc1253a410.tar.gz |
Use unique_ptr for drawing surfaces and don't check for allocation failure
as that throws an exception.
Also use unique_ptr for tab stop positions.
Diffstat (limited to 'src/Editor.h')
-rw-r--r-- | src/Editor.h | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/src/Editor.h b/src/Editor.h index 9ddb753e6..69c816270 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -602,39 +602,34 @@ public: */ class AutoSurface { private: - Surface *surf; + std::unique_ptr<Surface> surf; public: - AutoSurface(Editor *ed, int technology = -1) : surf(0) { + AutoSurface(Editor *ed, int technology = -1) { if (ed->wMain.GetID()) { - surf = Surface::Allocate(technology != -1 ? technology : ed->technology); - if (surf) { - surf->Init(ed->wMain.GetID()); - surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); - surf->SetDBCSMode(ed->CodePage()); - } + surf.reset(Surface::Allocate(technology != -1 ? technology : ed->technology)); + surf->Init(ed->wMain.GetID()); + surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); + surf->SetDBCSMode(ed->CodePage()); } } - AutoSurface(SurfaceID sid, Editor *ed, int technology = -1) : surf(0) { + AutoSurface(SurfaceID sid, Editor *ed, int technology = -1) { if (ed->wMain.GetID()) { - surf = Surface::Allocate(technology != -1 ? technology : ed->technology); - if (surf) { - surf->Init(sid, ed->wMain.GetID()); - surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); - surf->SetDBCSMode(ed->CodePage()); - } + surf.reset(Surface::Allocate(technology != -1 ? technology : ed->technology)); + surf->Init(sid, ed->wMain.GetID()); + surf->SetUnicodeMode(SC_CP_UTF8 == ed->CodePage()); + surf->SetDBCSMode(ed->CodePage()); } } // Deleted so AutoSurface objects can not be copied. AutoSurface(const AutoSurface &) = delete; void operator=(const AutoSurface &) = delete; ~AutoSurface() { - delete surf; } Surface *operator->() const { - return surf; + return surf.get(); } operator Surface *() const { - return surf; + return surf.get(); } }; |