~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/plugins/contrib/HexEditor/FileContentDisk.h

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* This file is part of HexEditor plugin for Code::Blocks Studio
 
3
* Copyright (C) 2008-2009 Bartlomiej Swiecki
 
4
*
 
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.
 
9
*
 
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.
 
14
*
 
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/>.
 
17
*
 
18
* $Revision: 5456 $
 
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 $
 
21
*/
 
22
 
 
23
#ifndef FILECONTENTDISK_H
 
24
#define FILECONTENTDISK_H
 
25
 
 
26
#include "FileContentBase.h"
 
27
#include "TestCasesBase.h"
 
28
 
 
29
#include <vector>
 
30
#include <wx/file.h>
 
31
 
 
32
/** \brief Class responsible for providing file content by reading from disk
 
33
 *         as much as possible.
 
34
 *
 
35
 * Parts of the file which has been modified are kept inside of the memory
 
36
 */
 
37
class FileContentDisk: public FileContentBase
 
38
{
 
39
    public:
 
40
 
 
41
        /** \brief Ctor */
 
42
        FileContentDisk();
 
43
 
 
44
        /** \brief Dctor */
 
45
        virtual ~FileContentDisk();
 
46
 
 
47
        /** \brief Reading the data from the file */
 
48
        virtual bool ReadFile( const wxString& fileName );
 
49
 
 
50
        /** \brief Writing the data to the file */
 
51
        virtual bool WriteFile( const wxString& fileName );
 
52
 
 
53
        /** \brief Getting size of the content */
 
54
        virtual OffsetT GetSize();
 
55
 
 
56
        /** \brief Reading some part of data */
 
57
        virtual OffsetT Read( void* buff, OffsetT position, OffsetT length );
 
58
 
 
59
        /** \brief Return collection of tests for this class */
 
60
        static TestCasesBase& GetTests();
 
61
 
 
62
        class TestData;
 
63
 
 
64
 
 
65
    protected:
 
66
 
 
67
        /** \brief Create modification object for change operation */
 
68
        virtual ModificationData* BuildChangeModification( OffsetT position, OffsetT length, const void* data = 0 );
 
69
 
 
70
        /** \brief Create modification object for data add operation */
 
71
        virtual ModificationData* BuildAddModification( OffsetT position, OffsetT length, const void* data = 0 );
 
72
 
 
73
        /** \brief Create modification object for data remove operation */
 
74
        virtual ModificationData* BuildRemoveModification( OffsetT position, OffsetT length );
 
75
 
 
76
        /** \brief Set given block of data */
 
77
        void SetBlock( const char* data, OffsetT pos, OffsetT lengthBefore, OffsetT lengthAfter );
 
78
 
 
79
 
 
80
        /** \brief Class keeping informations about one data block */
 
81
        struct DataBlock
 
82
        {
 
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
 
87
 
 
88
            bool IsFromDisk() { return data.empty(); }
 
89
        };
 
90
 
 
91
 
 
92
        /** \brief Util routine used to add new data blocks */
 
93
        DataBlock* InsertNewBlock( size_t blockIndex, OffsetT position );
 
94
 
 
95
        class DiskModificationData;
 
96
 
 
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
 
101
 
 
102
        /** \brief Delete all data blocks */
 
103
        void ClearBlocks();
 
104
 
 
105
        /** \brief Find index of block containing given data offset */
 
106
        inline size_t FindBlock( OffsetT offset );
 
107
 
 
108
        /** \brief Try to merge some blocks lying next to each other */
 
109
        inline void MergeBlocks( size_t startPosition );
 
110
 
 
111
        /** \brief Test buffers for damages made by bugs */
 
112
        inline void ConsistencyCheck();
 
113
 
 
114
        /** \brief Write contents to disk using the easiest method */
 
115
        bool WriteFileEasiest( );
 
116
 
 
117
        /** \brief Write contents to disk without using temporary files */
 
118
        bool WriteFileOnDisk( );
 
119
 
 
120
        /** \brief Write contents to disk using temporary file */
 
121
        bool WriteFileTemporary( );
 
122
 
 
123
        /** \brief Write to totally different file */
 
124
        bool WriteToDifferentFile( const wxString& fileName );
 
125
 
 
126
        /** \brief Dump the content to given wxFile file */
 
127
        bool WriteToFile( wxFile& file );
 
128
 
 
129
        /** \brief Reset m_Content blocks to contain data from file only */
 
130
        void ResetBlocks();
 
131
 
 
132
};
 
133
 
 
134
#endif