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