1 /** @file RunStyles.h 2 ** Data structure used to store sparse styles. 3 **/ 4 // Copyright 1998-2007 by Neil Hodgson <[email protected]> 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 namespace Scintilla { 14 15 // Return for RunStyles::FillRange reports if anything was changed and the 16 // range that was changed. This may be trimmed from the requested range 17 // when some of the requested range already had the requested value. 18 template <typename DISTANCE> 19 struct FillResult { 20 bool changed; 21 DISTANCE position; 22 DISTANCE fillLength; 23 }; 24 25 template <typename DISTANCE, typename STYLE> 26 class RunStyles { 27 private: 28 std::unique_ptr<Partitioning<DISTANCE>> starts; 29 std::unique_ptr<SplitVector<STYLE>> styles; 30 DISTANCE RunFromPosition(DISTANCE position) const noexcept; 31 DISTANCE SplitRun(DISTANCE position); 32 void RemoveRun(DISTANCE run); 33 void RemoveRunIfEmpty(DISTANCE run); 34 void RemoveRunIfSameAsPrevious(DISTANCE run); 35 public: 36 RunStyles(); 37 // Deleted so RunStyles objects can not be copied. 38 RunStyles(const RunStyles &) = delete; 39 RunStyles(RunStyles &&) = delete; 40 void operator=(const RunStyles &) = delete; 41 void operator=(RunStyles &&) = delete; 42 ~RunStyles(); 43 DISTANCE Length() const noexcept; 44 STYLE ValueAt(DISTANCE position) const noexcept; 45 DISTANCE FindNextChange(DISTANCE position, DISTANCE end) const noexcept; 46 DISTANCE StartRun(DISTANCE position) const noexcept; 47 DISTANCE EndRun(DISTANCE position) const noexcept; 48 // Returns changed=true if some values may have changed 49 FillResult<DISTANCE> FillRange(DISTANCE position, STYLE value, DISTANCE fillLength); 50 void SetValueAt(DISTANCE position, STYLE value); 51 void InsertSpace(DISTANCE position, DISTANCE insertLength); 52 void DeleteAll(); 53 void DeleteRange(DISTANCE position, DISTANCE deleteLength); 54 DISTANCE Runs() const noexcept; 55 bool AllSame() const noexcept; 56 bool AllSameAs(STYLE value) const noexcept; 57 DISTANCE Find(STYLE value, DISTANCE start) const noexcept; 58 59 void Check() const; 60 }; 61 62 } 63 64 #endif 65