Fix crash if key bindings specified in profile cannot be found. Improve
[personal-kdebase.git] / apps / konsole / src / BlockArray.h
blobc529cbb8f1ef3a43dc411bf05ec1979982f036d6
1 /*
2 This file is part of Konsole, an X terminal.
3 Copyright 2000 by Stephan Kulow <coolo@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301 USA.
21 #ifndef BLOCKARRAY_H
22 #define BLOCKARRAY_H
24 #include <unistd.h>
26 //#error Do not use in KDE 2.1
28 #define BlockSize (1 << 12)
29 #define ENTRIES ((BlockSize - sizeof(size_t) ) / sizeof(unsigned char))
31 namespace Konsole
34 struct Block {
35 Block() { size = 0; }
36 unsigned char data[ENTRIES];
37 size_t size;
40 // ///////////////////////////////////////////////////////
42 class BlockArray {
43 public:
44 /**
45 * Creates a history file for holding
46 * maximal size blocks. If more blocks
47 * are requested, then it drops earlier
48 * added ones.
50 BlockArray();
52 /// destructor
53 ~BlockArray();
55 /**
56 * adds the Block at the end of history.
57 * This may drop other blocks.
59 * The ownership on the block is transfered.
60 * An unique index number is returned for accessing
61 * it later (if not yet dropped then)
63 * Note, that the block may be dropped completely
64 * if history is turned off.
66 size_t append(Block *block);
68 /**
69 * gets the block at the index. Function may return
70 * 0 if the block isn't available any more.
72 * The returned block is strictly readonly as only
73 * maped in memory - and will be invalid on the next
74 * operation on this class.
76 const Block *at(size_t index);
78 /**
79 * reorders blocks as needed. If newsize is null,
80 * the history is emptied completely. The indices
81 * returned on append won't change their semantic,
82 * but they may not be valid after this call.
84 bool setHistorySize(size_t newsize);
86 size_t newBlock();
88 Block *lastBlock() const;
90 /**
91 * Convenient function to set the size in KBytes
92 * instead of blocks
94 bool setSize(size_t newsize);
96 size_t len() const { return length; }
98 bool has(size_t index) const;
100 size_t getCurrent() const { return current; }
102 private:
103 void unmap();
104 void increaseBuffer();
105 void decreaseBuffer(size_t newsize);
107 size_t size;
108 // current always shows to the last inserted block
109 size_t current;
110 size_t index;
112 Block *lastmap;
113 size_t lastmap_index;
114 Block *lastblock;
116 int ion;
117 size_t length;
123 #endif