diff options
author | Neil <nyamatongwe@gmail.com> | 2019-04-07 12:20:58 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2019-04-07 12:20:58 +1000 |
commit | bdfbc5325157c037fdaa70d6c7fe757046f08906 (patch) | |
tree | b9d1155dc9e7b42b89ee978f6071ad526deea9a7 /src | |
parent | d126e56e2c800188a2546c241299453c2e4304a8 (diff) | |
download | scintilla-mirror-bdfbc5325157c037fdaa70d6c7fe757046f08906.tar.gz |
Backport: Make XPM, RGBAImage, and LineMarker copyable and noexcept moveable.
This simplifies and optimizes their use in other classes and containers.
Backport of changeset 7408:adc040eac41d.
Diffstat (limited to 'src')
-rw-r--r-- | src/LineMarker.cxx | 58 | ||||
-rw-r--r-- | src/LineMarker.h | 24 | ||||
-rw-r--r-- | src/XPM.h | 17 |
3 files changed, 51 insertions, 48 deletions
diff --git a/src/LineMarker.cxx b/src/LineMarker.cxx index ea5e5e780..d2c906d08 100644 --- a/src/LineMarker.cxx +++ b/src/LineMarker.cxx @@ -25,41 +25,41 @@ using namespace Scintilla; -LineMarker::~LineMarker() { -} - -LineMarker::LineMarker() { - markType = SC_MARK_CIRCLE; - fore = ColourDesired(0, 0, 0); - back = ColourDesired(0xff, 0xff, 0xff); - backSelected = ColourDesired(0xff, 0x00, 0x00); - alpha = SC_ALPHA_NOALPHA; - customDraw = nullptr; -} - -LineMarker::LineMarker(const LineMarker &) { +LineMarker::LineMarker(const LineMarker &other) { // 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.reset(); - image.reset(); - customDraw = nullptr; + markType = other.markType; + fore = other.fore; + back = other.back; + backSelected = other.backSelected; + alpha = other.alpha; + if (other.pxpm) + pxpm.reset(new XPM(*other.pxpm)); + else + pxpm = nullptr; + if (other.image) + image.reset(new RGBAImage(*other.image)); + else + image = nullptr; + customDraw = other.customDraw; } LineMarker &LineMarker::operator=(const LineMarker &other) { // 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; - pxpm.reset(); - image.reset(); - customDraw = nullptr; + markType = other.markType; + fore = other.fore; + back = other.back; + backSelected = other.backSelected; + alpha = other.alpha; + if (other.pxpm) + pxpm.reset(new XPM(*other.pxpm)); + else + pxpm = nullptr; + if (other.image) + image.reset(new RGBAImage(*other.image)); + else + image = nullptr; + customDraw = other.customDraw; } return *this; } diff --git a/src/LineMarker.h b/src/LineMarker.h index 28a63cd3b..8a15327d2 100644 --- a/src/LineMarker.h +++ b/src/LineMarker.h @@ -21,22 +21,26 @@ class LineMarker { public: enum typeOfFold { undefined, head, body, tail, headWithTail }; - int markType; - ColourDesired fore; - ColourDesired back; - ColourDesired backSelected; - int alpha; + int markType = SC_MARK_CIRCLE; + ColourDesired fore = ColourDesired(0, 0, 0); + ColourDesired back = ColourDesired(0xff, 0xff, 0xff); + ColourDesired backSelected = ColourDesired(0xff, 0x00, 0x00); + int alpha = SC_ALPHA_NOALPHA; 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 * platforms must implement as empty. */ - DrawLineMarkerFn customDraw; - LineMarker(); - LineMarker(const LineMarker &); - virtual ~LineMarker(); - LineMarker &operator=(const LineMarker &other); + DrawLineMarkerFn customDraw = nullptr; + + LineMarker() noexcept = default; + LineMarker(const LineMarker &other); + LineMarker(LineMarker &&) noexcept = default; + LineMarker &operator=(const LineMarker& other); + LineMarker &operator=(LineMarker&&) noexcept = default; + virtual ~LineMarker() = default; + void SetXPM(const char *textForm); void SetXPM(const char *const *linesForm); void SetRGBAImage(Point sizeRGBAImage, float scale, const unsigned char *pixelsRGBAImage); @@ -25,10 +25,10 @@ class XPM { public: explicit XPM(const char *textForm); explicit XPM(const char *const *linesForm); - XPM(const XPM &) = delete; - XPM(XPM &&) = delete; - XPM &operator=(const XPM &) = delete; - XPM &operator=(XPM &&) = delete; + XPM(const XPM &) = default; + XPM(XPM &&) noexcept = default; + XPM &operator=(const XPM &) = default; + XPM &operator=(XPM &&) noexcept = default; ~XPM(); void Init(const char *textForm); void Init(const char *const *linesForm); @@ -52,11 +52,10 @@ class RGBAImage { public: RGBAImage(int width_, int height_, float scale_, const unsigned char *pixels_); explicit RGBAImage(const XPM &xpm); - // Deleted so RGBAImage objects can not be copied. - RGBAImage(const RGBAImage &) = delete; - RGBAImage(RGBAImage &&) = delete; - RGBAImage &operator=(const RGBAImage &) = delete; - RGBAImage &operator=(RGBAImage &&) = delete; + RGBAImage(const RGBAImage &) = default; + RGBAImage(RGBAImage &&) noexcept = default; + RGBAImage &operator=(const RGBAImage &) = default; + RGBAImage &operator=(RGBAImage &&) noexcept = default; virtual ~RGBAImage(); int GetHeight() const { return height; } int GetWidth() const { return width; } |