From fc87d8cd1d80b0e1d43be5839eb7a3a0efde8777 Mon Sep 17 00:00:00 2001 From: Tom Poole Date: Wed, 11 Jul 2018 15:07:00 +0100 Subject: [PATCH] Made some more JUCE classes trivially copyable --- .../maths/juce_StatisticsAccumulator.h | 15 +++++------- .../effects/juce_DropShadowEffect.cpp | 5 ---- .../effects/juce_DropShadowEffect.h | 6 ++--- .../geometry/juce_AffineTransform.cpp | 24 ------------------- .../geometry/juce_AffineTransform.h | 10 ++++---- .../juce_graphics/geometry/juce_BorderSize.h | 12 +++------- modules/juce_graphics/geometry/juce_Line.h | 16 ++++--------- .../geometry/juce_Parallelogram.h | 19 ++++----------- .../placement/juce_Justification.h | 8 ++----- .../placement/juce_RectanglePlacement.cpp | 11 --------- .../placement/juce_RectanglePlacement.h | 8 +++---- 11 files changed, 31 insertions(+), 103 deletions(-) diff --git a/modules/juce_core/maths/juce_StatisticsAccumulator.h b/modules/juce_core/maths/juce_StatisticsAccumulator.h index 3e00bce4fa..4c62b13899 100644 --- a/modules/juce_core/maths/juce_StatisticsAccumulator.h +++ b/modules/juce_core/maths/juce_StatisticsAccumulator.h @@ -36,11 +36,7 @@ class StatisticsAccumulator public: //============================================================================== /** Constructs a new StatisticsAccumulator. */ - StatisticsAccumulator() noexcept - : count (0), - minimum ( std::numeric_limits::infinity()), - maximum (-std::numeric_limits::infinity()) - {} + StatisticsAccumulator() = default; //============================================================================== /** Add a new value to the accumulator. @@ -116,7 +112,7 @@ private: //============================================================================== struct KahanSum { - KahanSum() noexcept : sum(), error() {} + KahanSum() = default; operator FloatType() const noexcept { return sum; } void JUCE_NO_ASSOCIATIVE_MATH_OPTIMISATIONS operator+= (FloatType value) noexcept @@ -127,13 +123,14 @@ private: sum = newSum; } - FloatType sum, error; + FloatType sum{}, error{}; }; //============================================================================== - size_t count; + size_t count { 0 }; KahanSum sum, sumSquares; - FloatType minimum, maximum; + FloatType minimum { std::numeric_limits::infinity() }, + maximum { -std::numeric_limits::infinity() }; }; } // namespace juce diff --git a/modules/juce_graphics/effects/juce_DropShadowEffect.cpp b/modules/juce_graphics/effects/juce_DropShadowEffect.cpp index 8e2bf23060..6ea68dd38f 100644 --- a/modules/juce_graphics/effects/juce_DropShadowEffect.cpp +++ b/modules/juce_graphics/effects/juce_DropShadowEffect.cpp @@ -68,11 +68,6 @@ static void blurSingleChannelImage (Image& image, int radius) } //============================================================================== -DropShadow::DropShadow() noexcept - : colour (0x90000000), radius (4) -{ -} - DropShadow::DropShadow (Colour shadowColour, const int r, Point o) noexcept : colour (shadowColour), radius (r), offset (o) { diff --git a/modules/juce_graphics/effects/juce_DropShadowEffect.h b/modules/juce_graphics/effects/juce_DropShadowEffect.h index 99a73e1d88..ee5d38f56c 100644 --- a/modules/juce_graphics/effects/juce_DropShadowEffect.h +++ b/modules/juce_graphics/effects/juce_DropShadowEffect.h @@ -36,7 +36,7 @@ namespace juce struct JUCE_API DropShadow { /** Creates a default drop-shadow effect. */ - DropShadow() noexcept; + DropShadow() = default; /** Creates a drop-shadow object with the given parameters. */ DropShadow (Colour shadowColour, int radius, Point offset) noexcept; @@ -56,10 +56,10 @@ struct JUCE_API DropShadow In most cases you'll probably want to leave this as black with an alpha value of around 0.5 */ - Colour colour; + Colour colour { 0x90000000 }; /** The approximate spread of the shadow. */ - int radius; + int radius { 4 }; /** The offset of the shadow. */ Point offset; diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.cpp b/modules/juce_graphics/geometry/juce_AffineTransform.cpp index 1b508dad99..d10f4c0625 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.cpp +++ b/modules/juce_graphics/geometry/juce_AffineTransform.cpp @@ -27,18 +27,6 @@ namespace juce { -AffineTransform::AffineTransform() noexcept - : mat00 (1.0f), mat01 (0), mat02 (0), - mat10 (0), mat11 (1.0f), mat12 (0) -{ -} - -AffineTransform::AffineTransform (const AffineTransform& other) noexcept - : mat00 (other.mat00), mat01 (other.mat01), mat02 (other.mat02), - mat10 (other.mat10), mat11 (other.mat11), mat12 (other.mat12) -{ -} - AffineTransform::AffineTransform (float m00, float m01, float m02, float m10, float m11, float m12) noexcept : mat00 (m00), mat01 (m01), mat02 (m02), @@ -46,18 +34,6 @@ AffineTransform::AffineTransform (float m00, float m01, float m02, { } -AffineTransform& AffineTransform::operator= (const AffineTransform& other) noexcept -{ - mat00 = other.mat00; - mat01 = other.mat01; - mat02 = other.mat02; - mat10 = other.mat10; - mat11 = other.mat11; - mat12 = other.mat12; - - return *this; -} - bool AffineTransform::operator== (const AffineTransform& other) const noexcept { return mat00 == other.mat00 diff --git a/modules/juce_graphics/geometry/juce_AffineTransform.h b/modules/juce_graphics/geometry/juce_AffineTransform.h index 77d747c6a5..85427116f8 100644 --- a/modules/juce_graphics/geometry/juce_AffineTransform.h +++ b/modules/juce_graphics/geometry/juce_AffineTransform.h @@ -45,10 +45,10 @@ class JUCE_API AffineTransform final public: //============================================================================== /** Creates an identity transform. */ - AffineTransform() noexcept; + AffineTransform() = default; /** Creates a copy of another transform. */ - AffineTransform (const AffineTransform& other) noexcept; + AffineTransform (const AffineTransform&) = default; /** Creates a transform from a set of raw matrix values. @@ -62,7 +62,7 @@ public: float mat10, float mat11, float mat12) noexcept; /** Copies from another AffineTransform object */ - AffineTransform& operator= (const AffineTransform& other) noexcept; + AffineTransform& operator= (const AffineTransform&) = default; /** Compares two transforms. */ bool operator== (const AffineTransform& other) const noexcept; @@ -282,8 +282,8 @@ public: (mat10 mat11 mat12) ( 0 0 1 ) */ - float mat00, mat01, mat02; - float mat10, mat11, mat12; + float mat00 { 1.0f }, mat01 { 0.0f }, mat02 { 0.0f }; + float mat10 { 0.0f }, mat11 { 1.0f }, mat12 { 0.0f }; }; } // namespace juce diff --git a/modules/juce_graphics/geometry/juce_BorderSize.h b/modules/juce_graphics/geometry/juce_BorderSize.h index 92a69cd926..fdbb4480d5 100644 --- a/modules/juce_graphics/geometry/juce_BorderSize.h +++ b/modules/juce_graphics/geometry/juce_BorderSize.h @@ -46,16 +46,10 @@ public: /** Creates a null border. All sizes are left as 0. */ - BorderSize() noexcept - : top(), left(), bottom(), right() - { - } + BorderSize() = default; /** Creates a copy of another border. */ - BorderSize (const BorderSize& other) noexcept - : top (other.top), left (other.left), bottom (other.bottom), right (other.right) - { - } + BorderSize (const BorderSize&) = default; /** Creates a border with the given gaps. */ BorderSize (ValueType topGap, ValueType leftGap, ValueType bottomGap, ValueType rightGap) noexcept @@ -149,7 +143,7 @@ public: private: //============================================================================== - ValueType top, left, bottom, right; + ValueType top{}, left{}, bottom{}, right{}; }; } // namespace juce diff --git a/modules/juce_graphics/geometry/juce_Line.h b/modules/juce_graphics/geometry/juce_Line.h index fbe666ea0a..e6876fbe84 100644 --- a/modules/juce_graphics/geometry/juce_Line.h +++ b/modules/juce_graphics/geometry/juce_Line.h @@ -49,13 +49,10 @@ class Line public: //============================================================================== /** Creates a line, using (0, 0) as its start and end points. */ - Line() noexcept {} + Line() = default; /** Creates a copy of another line. */ - Line (const Line& other) noexcept - : start (other.start), end (other.end) - { - } + Line (const Line&) = default; /** Creates a line based on the coordinates of its start and end points. */ Line (ValueType startX, ValueType startY, ValueType endX, ValueType endY) noexcept @@ -70,15 +67,10 @@ public: } /** Copies a line from another one. */ - Line& operator= (const Line& other) noexcept - { - start = other.start; - end = other.end; - return *this; - } + Line& operator= (const Line&) = default; /** Destructor. */ - ~Line() noexcept {} + ~Line() = default; //============================================================================== /** Returns the x coordinate of the line's start point. */ diff --git a/modules/juce_graphics/geometry/juce_Parallelogram.h b/modules/juce_graphics/geometry/juce_Parallelogram.h index 11541c3eef..e418dcf6ba 100644 --- a/modules/juce_graphics/geometry/juce_Parallelogram.h +++ b/modules/juce_graphics/geometry/juce_Parallelogram.h @@ -41,15 +41,10 @@ public: //============================================================================== /** Creates a parallelogram with zero size at the origin. */ - Parallelogram() noexcept - { - } + Parallelogram() = default; /** Creates a copy of another parallelogram. */ - Parallelogram (const Parallelogram& other) noexcept - : topLeft (other.topLeft), topRight (other.topRight), bottomLeft (other.bottomLeft) - { - } + Parallelogram (const Parallelogram&) = default; /** Creates a parallelogram based on 3 points. */ Parallelogram (Point topLeftPosition, @@ -67,16 +62,10 @@ public: { } - Parallelogram& operator= (const Parallelogram& other) noexcept - { - topLeft = other.topLeft; - topRight = other.topRight; - bottomLeft = other.bottomLeft; - return *this; - } + Parallelogram& operator= (const Parallelogram&) = default; /** Destructor. */ - ~Parallelogram() noexcept {} + ~Parallelogram() = default; //============================================================================== /** Returns true if the parallelogram has a width or height of more than zero. */ diff --git a/modules/juce_graphics/placement/juce_Justification.h b/modules/juce_graphics/placement/juce_Justification.h index 2da66ea492..cd4a143d6c 100644 --- a/modules/juce_graphics/placement/juce_Justification.h +++ b/modules/juce_graphics/placement/juce_Justification.h @@ -46,14 +46,10 @@ public: Justification (int justificationFlags) noexcept : flags (justificationFlags) {} /** Creates a copy of another Justification object. */ - Justification (const Justification& other) noexcept : flags (other.flags) {} + Justification (const Justification&) = default; /** Copies another Justification object. */ - Justification& operator= (const Justification& other) noexcept - { - flags = other.flags; - return *this; - } + Justification& operator= (const Justification&) = default; bool operator== (const Justification& other) const noexcept { return flags == other.flags; } bool operator!= (const Justification& other) const noexcept { return flags != other.flags; } diff --git a/modules/juce_graphics/placement/juce_RectanglePlacement.cpp b/modules/juce_graphics/placement/juce_RectanglePlacement.cpp index 6f718c0948..05bcc8066a 100644 --- a/modules/juce_graphics/placement/juce_RectanglePlacement.cpp +++ b/modules/juce_graphics/placement/juce_RectanglePlacement.cpp @@ -27,17 +27,6 @@ namespace juce { -RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) noexcept - : flags (other.flags) -{ -} - -RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) noexcept -{ - flags = other.flags; - return *this; -} - bool RectanglePlacement::operator== (const RectanglePlacement& other) const noexcept { return flags == other.flags; diff --git a/modules/juce_graphics/placement/juce_RectanglePlacement.h b/modules/juce_graphics/placement/juce_RectanglePlacement.h index b6803d20d8..16ab8f303f 100644 --- a/modules/juce_graphics/placement/juce_RectanglePlacement.h +++ b/modules/juce_graphics/placement/juce_RectanglePlacement.h @@ -45,13 +45,13 @@ public: inline RectanglePlacement (int placementFlags) noexcept : flags (placementFlags) {} /** Creates a default RectanglePlacement object, which is equivalent to using the 'centred' flag. */ - inline RectanglePlacement() noexcept : flags (centred) {} + inline RectanglePlacement() = default; /** Creates a copy of another RectanglePlacement object. */ - RectanglePlacement (const RectanglePlacement&) noexcept; + RectanglePlacement (const RectanglePlacement&) = default; /** Copies another RectanglePlacement object. */ - RectanglePlacement& operator= (const RectanglePlacement&) noexcept; + RectanglePlacement& operator= (const RectanglePlacement&) = default; bool operator== (const RectanglePlacement&) const noexcept; bool operator!= (const RectanglePlacement&) const noexcept; @@ -169,7 +169,7 @@ public: private: //============================================================================== - int flags; + int flags { centred }; }; } // namespace juce