annotate libgui/qterminal/libqterminal/unix/BlockArray.h @ 15862:98902367c781

gui: smaller minimal size of the command widget (bug #37038) * QUnixTerminalImpl.cpp(constructor): reduce minimal size of the terminal widget
author Torsten <ttl@justmail.de>
date Fri, 28 Dec 2012 21:08:26 +0100
parents 018c46ef8a0c
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15651
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
1 /*
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
2 This file is part of Konsole, an X terminal.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
3 Copyright (C) 2000 by Stephan Kulow <coolo@kde.org>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
4
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
5 Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
6
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
7 This program is free software; you can redistribute it and/or modify
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
9 the Free Software Foundation; either version 2 of the License, or
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
10 (at your option) any later version.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
11
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
12 This program is distributed in the hope that it will be useful,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
15 GNU General Public License for more details.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
16
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
18 along with this program; if not, write to the Free Software
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
20 02110-1301 USA.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
21 */
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
22
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
23 #ifndef BLOCKARRAY_H
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
24 #define BLOCKARRAY_H
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
25
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
26 #include <unistd.h>
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
27
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
28 #define BlockSize (1 << 12)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
29 #define ENTRIES ((BlockSize - sizeof(size_t) ) / sizeof(unsigned char))
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
30
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
31 struct Block {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
32 Block() { size = 0; }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
33 unsigned char data[ENTRIES];
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
34 size_t size;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
35 };
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
36
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
37 // ///////////////////////////////////////////////////////
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
38
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
39 class BlockArray {
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
40 public:
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
41 /**
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
42 * Creates a history file for holding
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
43 * maximal size blocks. If more blocks
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
44 * are requested, then it drops earlier
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
45 * added ones.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
46 */
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
47 BlockArray();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
48
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
49 /// destructor
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
50 ~BlockArray();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
51
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
52 /**
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
53 * adds the Block at the end of history.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
54 * This may drop other blocks.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
55 *
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
56 * The ownership on the block is transfered.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
57 * An unique index number is returned for accessing
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
58 * it later (if not yet dropped then)
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
59 *
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
60 * Note, that the block may be dropped completely
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
61 * if history is turned off.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
62 */
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
63 size_t append(Block *block);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
64
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
65 /**
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
66 * gets the block at the index. Function may return
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
67 * 0 if the block isn't available any more.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
68 *
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
69 * The returned block is strictly readonly as only
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
70 * maped in memory - and will be invalid on the next
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
71 * operation on this class.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
72 */
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
73 const Block *at(size_t index);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
74
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
75 /**
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
76 * reorders blocks as needed. If newsize is null,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
77 * the history is emptied completely. The indices
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
78 * returned on append won't change their semantic,
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
79 * but they may not be valid after this call.
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
80 */
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
81 bool setHistorySize(size_t newsize);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
82
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
83 size_t newBlock();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
84
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
85 Block *lastBlock() const;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
86
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
87 /**
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
88 * Convenient function to set the size in KBytes
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
89 * instead of blocks
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
90 */
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
91 bool setSize(size_t newsize);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
92
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
93 size_t len() const { return length; }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
94
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
95 bool has(size_t index) const;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
96
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
97 size_t getCurrent() const { return current; }
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
98
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
99 private:
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
100 void unmap();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
101 void increaseBuffer();
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
102 void decreaseBuffer(size_t newsize);
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
103
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
104 size_t size;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
105 // current always shows to the last inserted block
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
106 size_t current;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
107 size_t index;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
108
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
109 Block *lastmap;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
110 size_t lastmap_index;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
111 Block *lastblock;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
112
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
113 int ion;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
114 size_t length;
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
115
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
116 };
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
117
845cebf281aa Added files of QConsole.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff changeset
118 #endif