diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Decoration.cxx | 46 | ||||
-rw-r--r-- | src/Decoration.h | 2 |
2 files changed, 31 insertions, 17 deletions
diff --git a/src/Decoration.cxx b/src/Decoration.cxx index f2e564254..8d901b9ec 100644 --- a/src/Decoration.cxx +++ b/src/Decoration.cxx @@ -34,6 +34,13 @@ namespace { template <typename POS> class Decoration : public IDecoration { int indicator; + + // pos_cast(): cast Sci::Position to either 32-bit or 64-bit value + // This avoids warnings from Visual C++ Code Analysis and shortens code + static constexpr POS pos_cast(Sci::Position pos) noexcept { + return static_cast<POS>(pos); + } + public: RunStyles<POS, int> rs; @@ -50,19 +57,19 @@ public: return rs.Length(); } int ValueAt(Sci::Position position) const noexcept override { - return rs.ValueAt(static_cast<POS>(position)); + return rs.ValueAt(pos_cast(position)); } Sci::Position StartRun(Sci::Position position) const noexcept override { - return rs.StartRun(static_cast<POS>(position)); + return rs.StartRun(pos_cast(position)); } Sci::Position EndRun(Sci::Position position) const noexcept override { - return rs.EndRun(static_cast<POS>(position)); + return rs.EndRun(pos_cast(position)); } void SetValueAt(Sci::Position position, int value) override { - rs.SetValueAt(static_cast<POS>(position), value); + rs.SetValueAt(pos_cast(position), value); } void InsertSpace(Sci::Position position, Sci::Position insertLength) override { - rs.InsertSpace(static_cast<POS>(position), static_cast<POS>(insertLength)); + rs.InsertSpace(pos_cast(position), pos_cast(insertLength)); } Sci::Position Runs() const noexcept override { return rs.Runs(); @@ -85,6 +92,13 @@ class DecorationList : public IDecorationList { void Delete(int indicator); void DeleteAnyEmpty(); void SetView(); + + // pos_cast(): cast Sci::Position to either 32-bit or 64-bit value + // This avoids warnings from Visual C++ Code Analysis and shortens code + static constexpr POS pos_cast(Sci::Position pos) noexcept { + return static_cast<POS>(pos); + } + public: DecorationList(); @@ -96,7 +110,7 @@ public: void SetCurrentIndicator(int indicator) override; int GetCurrentIndicator() const noexcept override { return currentIndicator; } - void SetCurrentValue(int value) override; + void SetCurrentValue(int value) noexcept override; int GetCurrentValue() const noexcept override { return currentValue; } // Returns changed=true if some values may have changed @@ -139,7 +153,7 @@ template <typename POS> Decoration<POS> *DecorationList<POS>::Create(int indicator, Sci::Position length) { currentIndicator = indicator; std::unique_ptr<Decoration<POS>> decoNew = std::make_unique<Decoration<POS>>(indicator); - decoNew->rs.InsertSpace(0, static_cast<POS>(length)); + decoNew->rs.InsertSpace(0, pos_cast(length)); typename std::vector<std::unique_ptr<Decoration<POS>>>::iterator it = std::lower_bound( decorationList.begin(), decorationList.end(), decoNew, @@ -172,7 +186,7 @@ void DecorationList<POS>::SetCurrentIndicator(int indicator) { } template <typename POS> -void DecorationList<POS>::SetCurrentValue(int value) { +void DecorationList<POS>::SetCurrentValue(int value) noexcept { currentValue = value ? value : 1; } @@ -185,7 +199,7 @@ FillResult<Sci::Position> DecorationList<POS>::FillRange(Sci::Position position, } } // Converting result from POS to Sci::Position as callers not polymorphic. - const FillResult<POS> frInPOS = current->rs.FillRange(static_cast<POS>(position), value, static_cast<POS>(fillLength)); + const FillResult<POS> frInPOS = current->rs.FillRange(pos_cast(position), value, pos_cast(fillLength)); const FillResult<Sci::Position> fr { frInPOS.changed, frInPOS.position, frInPOS.fillLength }; if (current->Empty()) { Delete(currentIndicator); @@ -198,9 +212,9 @@ void DecorationList<POS>::InsertSpace(Sci::Position position, Sci::Position inse const bool atEnd = position == lengthDocument; lengthDocument += insertLength; for (const std::unique_ptr<Decoration<POS>> &deco : decorationList) { - deco->rs.InsertSpace(static_cast<POS>(position), static_cast<POS>(insertLength)); + deco->rs.InsertSpace(pos_cast(position), pos_cast(insertLength)); if (atEnd) { - deco->rs.FillRange(static_cast<POS>(position), 0, static_cast<POS>(insertLength)); + deco->rs.FillRange(pos_cast(position), 0, pos_cast(insertLength)); } } } @@ -209,7 +223,7 @@ template <typename POS> void DecorationList<POS>::DeleteRange(Sci::Position position, Sci::Position deleteLength) { lengthDocument -= deleteLength; for (const std::unique_ptr<Decoration<POS>> &deco : decorationList) { - deco->rs.DeleteRange(static_cast<POS>(position), static_cast<POS>(deleteLength)); + deco->rs.DeleteRange(pos_cast(position), pos_cast(deleteLength)); } DeleteAnyEmpty(); if (decorationList.size() != decorationView.size()) { @@ -253,7 +267,7 @@ template <typename POS> int DecorationList<POS>::AllOnFor(Sci::Position position) const noexcept { int mask = 0; for (const std::unique_ptr<Decoration<POS>> &deco : decorationList) { - if (deco->rs.ValueAt(static_cast<POS>(position))) { + if (deco->rs.ValueAt(pos_cast(position))) { if (deco->Indicator() < static_cast<int>(Scintilla::IndicatorNumbers::Ime)) { mask |= 1u << deco->Indicator(); } @@ -266,7 +280,7 @@ template <typename POS> int DecorationList<POS>::ValueAt(int indicator, Sci::Position position) noexcept { const Decoration<POS> *deco = DecorationFromIndicator(indicator); if (deco) { - return deco->rs.ValueAt(static_cast<POS>(position)); + return deco->rs.ValueAt(pos_cast(position)); } return 0; } @@ -275,7 +289,7 @@ template <typename POS> Sci::Position DecorationList<POS>::Start(int indicator, Sci::Position position) noexcept { const Decoration<POS> *deco = DecorationFromIndicator(indicator); if (deco) { - return deco->rs.StartRun(static_cast<POS>(position)); + return deco->rs.StartRun(pos_cast(position)); } return 0; } @@ -284,7 +298,7 @@ template <typename POS> Sci::Position DecorationList<POS>::End(int indicator, Sci::Position position) noexcept { const Decoration<POS> *deco = DecorationFromIndicator(indicator); if (deco) { - return deco->rs.EndRun(static_cast<POS>(position)); + return deco->rs.EndRun(pos_cast(position)); } return 0; } diff --git a/src/Decoration.h b/src/Decoration.h index c8faafec9..9c47d6c08 100644 --- a/src/Decoration.h +++ b/src/Decoration.h @@ -32,7 +32,7 @@ public: virtual void SetCurrentIndicator(int indicator) = 0; virtual int GetCurrentIndicator() const noexcept = 0; - virtual void SetCurrentValue(int value) = 0; + virtual void SetCurrentValue(int value) noexcept = 0; virtual int GetCurrentValue() const noexcept = 0; // Returns with changed=true if some values may have changed |