Konsole
BlockArray.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef BLOCKARRAY_H
00022 #define BLOCKARRAY_H
00023
00024 #include <unistd.h>
00025
00026
00027
00028 #define BlockSize (1 << 12)
00029 #define ENTRIES ((BlockSize - sizeof(size_t) ) / sizeof(unsigned char))
00030
00031 namespace Konsole
00032 {
00033
00034 struct Block {
00035 Block() { size = 0; }
00036 unsigned char data[ENTRIES];
00037 size_t size;
00038 };
00039
00040
00041
00042 class BlockArray {
00043 public:
00050 BlockArray();
00051
00053 ~BlockArray();
00054
00066 size_t append(Block *block);
00067
00076 const Block *at(size_t index);
00077
00084 bool setHistorySize(size_t newsize);
00085
00086 size_t newBlock();
00087
00088 Block *lastBlock() const;
00089
00094 bool setSize(size_t newsize);
00095
00096 size_t len() const { return length; }
00097
00098 bool has(size_t index) const;
00099
00100 size_t getCurrent() const { return current; }
00101
00102 private:
00103 void unmap();
00104 void increaseBuffer();
00105 void decreaseBuffer(size_t newsize);
00106
00107 size_t size;
00108
00109 size_t current;
00110 size_t index;
00111
00112 Block *lastmap;
00113 size_t lastmap_index;
00114 Block *lastblock;
00115
00116 int ion;
00117 size_t length;
00118
00119 };
00120
00121 }
00122
00123 #endif