~ubuntu-branches/ubuntu/utopic/qgis/utopic

« back to all changes in this revision

Viewing changes to src/plugins/grass/qtermwidget/BlockArray.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of Konsole, an X terminal.
 
3
    Copyright (C) 2000 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
//#error Do not use in KDE 2.1
 
29
 
 
30
#define BlockSize (1 << 12)
 
31
#define ENTRIES   ((BlockSize - sizeof(size_t) ) / sizeof(unsigned char))
 
32
 
 
33
namespace Konsole
 
34
{
 
35
 
 
36
  struct Block
 
37
  {
 
38
    Block() { size = 0; }
 
39
    unsigned char data[ENTRIES];
 
40
    size_t size;
 
41
  };
 
42
 
 
43
// ///////////////////////////////////////////////////////
 
44
 
 
45
  class BlockArray
 
46
  {
 
47
    public:
 
48
      /**
 
49
      * Creates a history file for holding
 
50
      * maximal size blocks. If more blocks
 
51
      * are requested, then it drops earlier
 
52
      * added ones.
 
53
      */
 
54
      BlockArray();
 
55
 
 
56
      /// destructor
 
57
      ~BlockArray();
 
58
 
 
59
      /**
 
60
      * adds the Block at the end of history.
 
61
      * This may drop other blocks.
 
62
      *
 
63
      * The ownership on the block is transfered.
 
64
      * An unique index number is returned for accessing
 
65
      * it later (if not yet dropped then)
 
66
      *
 
67
      * Note, that the block may be dropped completely
 
68
      * if history is turned off.
 
69
      */
 
70
      size_t append( Block *block );
 
71
 
 
72
      /**
 
73
      * gets the block at the index. Function may return
 
74
      * 0 if the block isn't available any more.
 
75
      *
 
76
      * The returned block is strictly readonly as only
 
77
      * maped in memory - and will be invalid on the next
 
78
      * operation on this class.
 
79
      */
 
80
      const Block *at( size_t index );
 
81
 
 
82
      /**
 
83
      * reorders blocks as needed. If newsize is null,
 
84
      * the history is emptied completely. The indices
 
85
      * returned on append won't change their semantic,
 
86
      * but they may not be valid after this call.
 
87
      */
 
88
      bool setHistorySize( size_t newsize );
 
89
 
 
90
      size_t newBlock();
 
91
 
 
92
      Block *lastBlock() const;
 
93
 
 
94
      /**
 
95
      * Convenient function to set the size in KBytes
 
96
      * instead of blocks
 
97
      */
 
98
      bool setSize( size_t newsize );
 
99
 
 
100
      size_t len() const { return length; }
 
101
 
 
102
      bool has( size_t index ) const;
 
103
 
 
104
      size_t getCurrent() const { return current; }
 
105
 
 
106
    private:
 
107
      void unmap();
 
108
      void increaseBuffer();
 
109
      void decreaseBuffer( size_t newsize );
 
110
 
 
111
      size_t size;
 
112
      // current always shows to the last inserted block
 
113
      size_t current;
 
114
      size_t index;
 
115
 
 
116
      Block *lastmap;
 
117
      size_t lastmap_index;
 
118
      Block *lastblock;
 
119
 
 
120
      int ion;
 
121
      size_t length;
 
122
 
 
123
  };
 
124
 
 
125
}
 
126
 
 
127
#endif