2
* This file is part of HexEditor plugin for Code::Blocks Studio
3
* Copyright (C) 2008-2009 Bartlomiej Swiecki
5
* HexEditor plugin 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 3 of the License, or
8
* (at your option) any later version.
10
* HexEditor pluging 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 HexEditor. If not, see <http://www.gnu.org/licenses/>.
19
* $Id: FileContentDisk.h 5456 2009-02-14 11:03:04Z byo $
20
* $HeadURL: svn+ssh://jenslody@svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/contrib/HexEditor/FileContentDisk.h $
23
#ifndef FILECONTENTDISK_H
24
#define FILECONTENTDISK_H
26
#include "FileContentBase.h"
27
#include "TestCasesBase.h"
32
/** \brief Class responsible for providing file content by reading from disk
33
* as much as possible.
35
* Parts of the file which has been modified are kept inside of the memory
37
class FileContentDisk: public FileContentBase
45
virtual ~FileContentDisk();
47
/** \brief Reading the data from the file */
48
virtual bool ReadFile( const wxString& fileName );
50
/** \brief Writing the data to the file */
51
virtual bool WriteFile( const wxString& fileName );
53
/** \brief Getting size of the content */
54
virtual OffsetT GetSize();
56
/** \brief Reading some part of data */
57
virtual OffsetT Read( void* buff, OffsetT position, OffsetT length );
59
/** \brief Return collection of tests for this class */
60
static TestCasesBase& GetTests();
67
/** \brief Create modification object for change operation */
68
virtual ModificationData* BuildChangeModification( OffsetT position, OffsetT length, const void* data = 0 );
70
/** \brief Create modification object for data add operation */
71
virtual ModificationData* BuildAddModification( OffsetT position, OffsetT length, const void* data = 0 );
73
/** \brief Create modification object for data remove operation */
74
virtual ModificationData* BuildRemoveModification( OffsetT position, OffsetT length );
76
/** \brief Set given block of data */
77
void SetBlock( const char* data, OffsetT pos, OffsetT lengthBefore, OffsetT lengthAfter );
80
/** \brief Class keeping informations about one data block */
83
OffsetT start; ///< \brief Block's start
84
OffsetT fileStart; ///< \brief Start position of this block in file
85
OffsetT size; ///< \brief Block's size
86
std::vector< char > data; ///< \brief Block's data, empty vector means that this block is from file
88
bool IsFromDisk() { return data.empty(); }
92
/** \brief Util routine used to add new data blocks */
93
DataBlock* InsertNewBlock( size_t blockIndex, OffsetT position );
95
class DiskModificationData;
97
wxString m_FileName; ///< \brief Name of opened file
98
wxFile m_File; ///< \brief File used as disk source
99
std::vector< DataBlock* > m_Contents; ///< \brief Contents of the data in form of blocks sorted by start offsets
100
bool m_TestMode; ///< \brief Flag indicating that we're running internal tests
102
/** \brief Delete all data blocks */
105
/** \brief Find index of block containing given data offset */
106
inline size_t FindBlock( OffsetT offset );
108
/** \brief Try to merge some blocks lying next to each other */
109
inline void MergeBlocks( size_t startPosition );
111
/** \brief Test buffers for damages made by bugs */
112
inline void ConsistencyCheck();
114
/** \brief Write contents to disk using the easiest method */
115
bool WriteFileEasiest( );
117
/** \brief Write contents to disk without using temporary files */
118
bool WriteFileOnDisk( );
120
/** \brief Write contents to disk using temporary file */
121
bool WriteFileTemporary( );
123
/** \brief Write to totally different file */
124
bool WriteToDifferentFile( const wxString& fileName );
126
/** \brief Dump the content to given wxFile file */
127
bool WriteToFile( wxFile& file );
129
/** \brief Reset m_Content blocks to contain data from file only */