MauiKit Terminal

BlockArray.h
1/*
2 This file is part of Konsole, an X terminal.
3 SPDX-FileCopyrightText: 2000 Stephan Kulow <coolo@kde.org>
4
5 Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA.
18*/
19
20#ifndef BLOCKARRAY_H
21#define BLOCKARRAY_H
22
23#include <cstdio>
24#include <unistd.h>
25
26constexpr auto QTERMWIDGET_BLOCKSIZE = 1 << 12;
27constexpr auto ENTRIES = ((QTERMWIDGET_BLOCKSIZE - sizeof(size_t)) / sizeof(unsigned char));
28
29namespace Konsole
30{
31
32struct Block {
33 constexpr Block()
34 {
35 size = 0;
36 }
37 unsigned char data[ENTRIES];
38 size_t size;
39};
40
41// ///////////////////////////////////////////////////////
42
43class BlockArray
44{
45public:
46 /**
47 * Creates a history file for holding
48 * maximal size blocks. If more blocks
49 * are requested, then it drops earlier
50 * added ones.
51 */
52 BlockArray();
53
54 /// destructor
55 ~BlockArray();
56
57 /**
58 * adds the Block at the end of history.
59 * This may drop other blocks.
60 *
61 * The ownership on the block is transfered.
62 * An unique index number is returned for accessing
63 * it later (if not yet dropped then)
64 *
65 * Note, that the block may be dropped completely
66 * if history is turned off.
67 */
68 size_t append(Block *block);
69
70 /**
71 * gets the block at the index. Function may return
72 * 0 if the block isn't available any more.
73 *
74 * The returned block is strictly readonly as only
75 * maped in memory - and will be invalid on the next
76 * operation on this class.
77 */
78 const Block *at(size_t index);
79
80 /**
81 * reorders blocks as needed. If newsize is null,
82 * the history is emptied completely. The indices
83 * returned on append won't change their semantic,
84 * but they may not be valid after this call.
85 */
86 bool setHistorySize(size_t newsize);
87
88 size_t newBlock();
89
90 Block *lastBlock() const;
91
92 /**
93 * Convenient function to set the size in KBytes
94 * instead of blocks
95 */
96 bool setSize(size_t newsize);
97
98 size_t len() const
99 {
100 return length;
101 }
102
103 bool has(size_t index) const;
104
105 size_t getCurrent() const
106 {
107 return current;
108 }
109
110private:
111 void unmap();
112 void increaseBuffer();
113 void decreaseBuffer(size_t newsize);
114 void moveBlock(FILE *fion, int cursor, int newpos, char *buffer2);
115
116 size_t size;
117 // current always shows to the last inserted block
118 size_t current;
119 size_t index;
120
121 Block *lastmap;
122 size_t lastmap_index;
123 Block *lastblock;
124
125 int ion;
126 size_t length;
127
128 int blocksize = 0;
129};
130
131}
132
133#endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:57:30 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.