1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/***************************************************************************
kbigbuffer.h - description
-------------------
begin : Mit Jun 02 2003
copyright : (C) 2003 by Friedrich W. H. Kossebau
email : Friedrich.W.H@Kossebau.de
***************************************************************************/
/***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License version 2 as published by the Free Software Foundation. *
* *
***************************************************************************/
#ifndef KHE_KBIGBUFFER_H
#define KHE_KBIGBUFFER_H
// qt specific
#include <qvaluevector.h>
#include <qfile.h>
// lib specific
#include "kdatabuffer.h"
#include "khexedit_export.h"
namespace KHE {
/** base class for all Data buffers that are used to display
* TODO: think about a way to inform KHexEdit that there has been
* a change in the buffer outside. what kind of changes are possible?
*@author Friedrich W. H. Kossebau
*/
class KHEXEDIT_EXPORT KBigBuffer : public KDataBuffer
{
typedef QValueVector<char *> KPageOfChar;
public:
/** default is only 50*4k = 200k memory image */
KBigBuffer( int NP = 50, int PS = 4096 );
virtual ~KBigBuffer();
public: // KDataBuffer API
virtual bool prepareRange( KSection Range ) const;
virtual const char *dataSet( KSection S ) const;
virtual char datum( unsigned int Offset ) const;
virtual int size() const;
virtual bool isReadOnly() const;
virtual bool isModified() const;
virtual int insert( int Pos, const char*, int Length );
virtual int remove( KSection S );
virtual unsigned int replace( KSection S, const char*, unsigned int InputLength );
virtual int move( int DestPos, KSection SourceSection );
virtual int fill( char FillChar, int Length = -1, unsigned int Pos = 0 );
virtual void setDatum( unsigned int Offset, const char Char );
virtual void setModified( bool M = true );
//virtual int find( const char*, int Length, int Pos = 0 ) const;
virtual int find( const char*KeyData, int Length, KSection Section ) const;
virtual int rfind( const char*, int Length, int Pos = -1 ) const;
/* virtual int find( const QString &expr, bool cs, bool wo, bool forward = true, int *index = 0 ); */
public:
void setReadOnly( bool RO = true );
bool isOpen() const;
bool open (const QString& filename );
bool close();
protected:
bool ensurePageLoaded( unsigned int PageIndex ) const;
bool freePage( unsigned int PageIndex ) const;
protected:
/** */
mutable QFile File;
/** */
bool ReadOnly:1;
bool IsOpen:1;
bool AtEOF:1;
/** maximum number of pages which could be currently loaded */
unsigned int NoOfUsedPages;
/** number of actually not used pages (in terms of NoOfUsedPages) */
mutable int NoOfFreePages;
/** number of bytes in a page */
unsigned int PageSize;
/** first currently loaded page */
mutable int FirstPage;
/** last currently loaded page */
mutable int LastPage;
/** */
mutable KPageOfChar Data;
/** */
unsigned int Size;
/** current offset */
mutable unsigned int OffsetOfActualPage;
/** points to the actual page */
mutable char* ActualPage;
};
inline int KBigBuffer::size() const { return Size; }
inline bool KBigBuffer::isReadOnly() const { return ReadOnly; }
inline bool KBigBuffer::isModified() const { return false; }
inline void KBigBuffer::setReadOnly( bool RO ) { ReadOnly = RO; }
inline void KBigBuffer::setModified( bool ) {}
inline void KBigBuffer::setDatum( unsigned int, const char ) {}
inline bool KBigBuffer::isOpen() const { return File.isOpen(); }
}
#endif
|