24#include <QTemporaryFile> 
   31#include "BlockArray.h" 
   50    virtual ~HistoryFile();
 
   52    virtual void add(
const unsigned char *bytes, 
int len);
 
   53    virtual void get(
unsigned char *bytes, 
int len, 
int loc);
 
   61    bool isMapped() 
const;
 
   66    QTemporaryFile tmpFile;
 
   78    static const int MAP_THRESHOLD = -1000;
 
   92    HistoryScroll(HistoryType *);
 
   93    virtual ~HistoryScroll();
 
   95    virtual bool hasScroll();
 
   98    virtual int getLines() = 0;
 
   99    virtual int getLineLen(
int lineno) = 0;
 
  100    virtual void getCells(
int lineno, 
int colno, 
int count, std::span<Character> res) = 0;
 
  101    virtual bool isWrappedLine(
int lineno) = 0;
 
  104    Character getCell(
int lineno, 
int colno)
 
  107        getCells(lineno, colno, 1, std::span(&res, 1));
 
  112    virtual void addCells(std::span<const Character> a, 
int count) = 0;
 
  115    virtual void addCellsVector(
const QVector<Character> &cells)
 
  117        auto span = std::span<const Character>{cells.
data(), size_t(cells.
size())};
 
  118        addCells(span, cells.
size());
 
  121    virtual void addLine(
bool previousWrapped = 
false) = 0;
 
  128    const HistoryType &getType()
 
  134    HistoryType *m_histType;
 
  143class HistoryScrollFile : 
public HistoryScroll
 
  146    HistoryScrollFile(
const QString &logFileName);
 
  147    ~HistoryScrollFile() 
override;
 
  149    int getLines() 
override;
 
  150    int getLineLen(
int lineno) 
override;
 
  151    void getCells(
int lineno, 
int colno, 
int count, std::span<Character> res) 
override;
 
  152    bool isWrappedLine(
int lineno) 
override;
 
  154    void addCells(std::span<const Character> a, 
int count) 
override;
 
  155    void addLine(
bool previousWrapped = 
false) 
override;
 
  158    int startOfLine(
int lineno);
 
  160    QString m_logFileName;
 
  163    HistoryFile lineflags; 
 
  169class HistoryScrollBuffer : 
public HistoryScroll
 
  172    typedef QVector<Character> HistoryLine;
 
  174    HistoryScrollBuffer(
unsigned int maxNbLines = 1000);
 
  175    ~HistoryScrollBuffer() 
override;
 
  177    int getLines() 
override;
 
  178    int getLineLen(
int lineno) 
override;
 
  179    void getCells(
int lineno, 
int colno, 
int count, std::span<Character> res) 
override;
 
  180    bool isWrappedLine(
int lineno) 
override;
 
  182    void addCells(std::span<const Character> a, 
int count) 
override;
 
  183    void addCellsVector(
const QVector<Character> &cells) 
override;
 
  184    void addLine(
bool previousWrapped = 
false) 
override;
 
  186    void setMaxNbLines(
unsigned int nbLines);
 
  187    unsigned int maxNbLines()
 const 
  189        return _maxLineCount;
 
  193    int bufferIndex(
int lineNumber) 
const;
 
  195    HistoryLine *_historyBuffer;
 
  196    QBitArray _wrappedLine;
 
  228class HistoryScrollNone : 
public HistoryScroll
 
  232    ~HistoryScrollNone() 
override;
 
  234    bool hasScroll() 
override;
 
  236    int getLines() 
override;
 
  237    int getLineLen(
int lineno) 
override;
 
  238    void getCells(
int lineno, 
int colno, 
int count, std::span<Character> res) 
override;
 
  239    bool isWrappedLine(
int lineno) 
override;
 
  241    void addCells(std::span<const Character> a, 
int count) 
override;
 
  242    void addLine(
bool previousWrapped = 
false) 
override;
 
  248class HistoryScrollBlockArray : 
public HistoryScroll
 
  251    HistoryScrollBlockArray(
size_t size);
 
  252    ~HistoryScrollBlockArray() 
override;
 
  254    int getLines() 
override;
 
  255    int getLineLen(
int lineno) 
override;
 
  256    void getCells(
int lineno, 
int colno, 
int count, std::span<Character> res) 
override;
 
  257    bool isWrappedLine(
int lineno) 
override;
 
  259    void addCells(std::span<const Character> a, 
int count) 
override;
 
  260    void addLine(
bool previousWrapped = 
false) 
override;
 
  263    BlockArray m_blockArray;
 
  264    QHash<int, size_t> m_lineLengths;
 
  272typedef QVector<Character> TextLine;
 
  277    bool equalsFormat(
const CharacterFormat &other)
 const 
  279        return other.rendition == rendition && other.fgColor == fgColor && other.bgColor == bgColor;
 
  282    bool equalsFormat(
const Character &c)
 const 
  284        return c.rendition == rendition && c.foregroundColor == fgColor && c.backgroundColor == bgColor;
 
  287    void setFormat(
const Character &c)
 
  289        rendition = c.rendition;
 
  290        fgColor = c.foregroundColor;
 
  291        bgColor = c.backgroundColor;
 
  294    CharacterColor fgColor, bgColor;
 
  299class CompactHistoryBlock
 
  302    CompactHistoryBlock()
 
  304        blockLength = 4096 * 64; 
 
  305        head = (quint8 *)mmap(
nullptr, blockLength, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
 
  307        Q_ASSERT(head != MAP_FAILED);
 
  308        tail = blockStart = head;
 
  312    virtual ~CompactHistoryBlock()
 
  315        munmap(blockStart, blockLength);
 
  318    virtual unsigned int remaining()
 
  320        return blockStart + blockLength - tail;
 
  322    virtual unsigned length()
 
  326    virtual void *allocate(
size_t length);
 
  327    virtual bool contains(
void *addr)
 
  329        return addr >= blockStart && addr < (blockStart + blockLength);
 
  331    virtual void deallocate();
 
  332    virtual bool isInUse()
 
  334        return allocCount != 0;
 
  345class CompactHistoryBlockList
 
  348    CompactHistoryBlockList(){};
 
  349    ~CompactHistoryBlockList();
 
  351    void *allocate(
size_t size);
 
  352    void deallocate(
void *);
 
  359    QList<CompactHistoryBlock *> list;
 
  362class CompactHistoryLine
 
  365    CompactHistoryLine(
const TextLine &, CompactHistoryBlockList &blockList);
 
  366    virtual ~CompactHistoryLine();
 
  369    static void *
operator new(
size_t size, CompactHistoryBlockList &blockList);
 
  370    static void operator delete(
void *){};
 
  372    virtual void getCharacters(Character *array, 
int length, 
int startColumn);
 
  373    virtual void getCharacter(
int index, Character &r);
 
  374    virtual bool isWrapped()
 const 
  378    virtual void setWrapped(
bool isWrapped)
 
  382    virtual unsigned int getLength()
 const 
  388    CompactHistoryBlockList &blockList;
 
  389    CharacterFormat *formatArray;
 
  392    quint16 formatLength;
 
  396class CompactHistoryScroll : 
public HistoryScroll
 
  398    typedef QList<CompactHistoryLine *> HistoryArray;
 
  401    CompactHistoryScroll(
unsigned int maxNbLines = 1000);
 
  402    ~CompactHistoryScroll() 
override;
 
  404    int getLines() 
override;
 
  405    int getLineLen(
int lineno) 
override;
 
  406    void getCells(
int lineno, 
int colno, 
int count, std::span<Character> res) 
override;
 
  407    bool isWrappedLine(
int lineno) 
override;
 
  409    void addCells(std::span<const Character> a, 
int count) 
override;
 
  410    void addCellsVector(
const TextLine &cells) 
override;
 
  411    void addLine(
bool previousWrapped = 
false) 
override;
 
  413    void setMaxNbLines(
unsigned int nbLines);
 
  414    unsigned int maxNbLines()
 const 
  416        return _maxLineCount;
 
  420    bool hasDifferentColors(
const TextLine &line) 
const;
 
  422    CompactHistoryBlockList blockList;
 
  424    unsigned int _maxLineCount;
 
  435    virtual ~HistoryType();
 
  441    virtual bool isEnabled() 
const = 0;
 
  445    bool isUnlimited()
 const 
  447        return maximumLineCount() == 0;
 
  453    virtual int maximumLineCount() 
const = 0;
 
  455    virtual std::unique_ptr<HistoryScroll> scroll(std::unique_ptr<HistoryScroll> &&) 
const = 0;
 
  458class HistoryTypeNone : 
public HistoryType
 
  463    bool isEnabled() 
const override;
 
  464    int maximumLineCount() 
const override;
 
  466    std::unique_ptr<HistoryScroll> scroll(std::unique_ptr<HistoryScroll> &&) 
const override;
 
  469class HistoryTypeBlockArray : 
public HistoryType
 
  472    HistoryTypeBlockArray(
size_t size);
 
  474    bool isEnabled() 
const override;
 
  475    int maximumLineCount() 
const override;
 
  477    std::unique_ptr<HistoryScroll> scroll(std::unique_ptr<HistoryScroll> &&) 
const override;
 
  484class HistoryTypeFile : 
public HistoryType
 
  487    HistoryTypeFile(
const QString &fileName = QString());
 
  489    bool isEnabled() 
const override;
 
  490    virtual const QString &getFileName() 
const;
 
  491    int maximumLineCount() 
const override;
 
  493    std::unique_ptr<HistoryScroll> scroll(std::unique_ptr<HistoryScroll> &&) 
const override;
 
  499class HistoryTypeBuffer : 
public HistoryType
 
  501    friend class HistoryScrollBuffer;
 
  504    HistoryTypeBuffer(
unsigned int nbLines);
 
  506    bool isEnabled() 
const override;
 
  507    int maximumLineCount() 
const override;
 
  509    std::unique_ptr<HistoryScroll> scroll(std::unique_ptr<HistoryScroll> &&) 
const override;
 
  512    unsigned int m_nbLines;
 
  515class CompactHistoryType : 
public HistoryType
 
  518    CompactHistoryType(
unsigned int size);
 
  520    bool isEnabled() 
const override;
 
  521    int maximumLineCount() 
const override;
 
  523    std::unique_ptr<HistoryScroll> scroll(std::unique_ptr<HistoryScroll> &&) 
const override;
 
  526    unsigned int m_nbLines;
 
qsizetype size() const const