| 1 | /** @file RunStyles.h |
| 2 | ** Data structure used to store sparse styles. |
| 3 | **/ |
| 4 | // Copyright 1998-2007 by Neil Hodgson <neilh@scintilla.org> |
| 5 | // The License.txt file describes the conditions under which this software may be distributed. |
| 6 | |
| 7 | /// Styling buffer using one element for each run rather than using |
| 8 | /// a filled buffer. |
| 9 | |
| 10 | #ifndef RUNSTYLES_H |
| 11 | #define RUNSTYLES_H |
| 12 | |
| 13 | #include "SplitVector.h" |
| 14 | #include "Partitioning.h" |
| 15 | |
| 16 | #include <memory> |
| 17 | |
| 18 | namespace Scintilla::Internal { |
| 19 | |
| 20 | // Return for RunStyles::FillRange reports if anything was changed and the |
| 21 | // range that was changed. This may be trimmed from the requested range |
| 22 | // when some of the requested range already had the requested value. |
| 23 | template <typename DISTANCE> |
| 24 | struct FillResult { |
| 25 | bool changed; |
| 26 | DISTANCE position; |
| 27 | DISTANCE fillLength; |
| 28 | }; |
| 29 | |
| 30 | template <typename DISTANCE, typename STYLE> |
| 31 | class RunStyles { |
| 32 | private: |
| 33 | std::unique_ptr<Partitioning<DISTANCE>> starts; |
| 34 | std::unique_ptr<SplitVector<STYLE>> styles; |
| 35 | DISTANCE RunFromPosition(DISTANCE position) const noexcept; |
| 36 | DISTANCE SplitRun(DISTANCE position); |
| 37 | void RemoveRun(DISTANCE run); |
| 38 | void RemoveRunIfEmpty(DISTANCE run); |
| 39 | void RemoveRunIfSameAsPrevious(DISTANCE run); |
| 40 | public: |
| 41 | RunStyles(); |
| 42 | // Deleted so RunStyles objects can not be copied. |
| 43 | RunStyles(const RunStyles &) = delete; |
| 44 | RunStyles(RunStyles &&) = delete; |
| 45 | void operator=(const RunStyles &) = delete; |
| 46 | void operator=(RunStyles &&) = delete; |
| 47 | ~RunStyles(); |
| 48 | DISTANCE Length() const noexcept; |
| 49 | STYLE ValueAt(DISTANCE position) const noexcept; |
| 50 | DISTANCE FindNextChange(DISTANCE position, DISTANCE end) const noexcept; |
| 51 | DISTANCE StartRun(DISTANCE position) const noexcept; |
| 52 | DISTANCE EndRun(DISTANCE position) const noexcept; |
| 53 | // Returns changed=true if some values may have changed |
| 54 | FillResult<DISTANCE> FillRange(DISTANCE position, STYLE value, DISTANCE fillLength); |
| 55 | void SetValueAt(DISTANCE position, STYLE value); |
| 56 | void InsertSpace(DISTANCE position, DISTANCE insertLength); |
| 57 | void DeleteAll(); |
| 58 | void DeleteRange(DISTANCE position, DISTANCE deleteLength); |
| 59 | DISTANCE Runs() const noexcept; |
| 60 | bool AllSame() const noexcept; |
| 61 | bool AllSameAs(STYLE value) const noexcept; |
| 62 | DISTANCE Find(STYLE value, DISTANCE start) const noexcept; |
| 63 | |
| 64 | void Check() const; |
| 65 | }; |
| 66 | |
| 67 | } |
| 68 | |
| 69 | #endif |
| 70 | |