datablock.h

Go to the documentation of this file.
00001 // This file is part of par2cmdline (a PAR 2.0 compatible file verification and
00002 // repair tool). See https://parchive.sourceforge.net for details of PAR 2.0.
00003 //
00004 // Copyright (c) 2003 Peter Brian Clements
00005 //
00006 // par2cmdline is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // par2cmdline is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00019 
00020 #ifndef __DATABLOCK_H__
00021 #define __DATABLOCK_H__
00022 
00023 class DiskFile;
00024 
00025 // A Data Block is a block of data of a specific length at a specific
00026 // offset in a specific file.
00027 
00028 // It may be either a block of data in a source file from which recovery
00029 // data is being computed, a block of recovery data in a recovery file, or
00030 // a block in a target file that is being reconstructed.
00031 
00032 class DataBlock
00033 {
00034 public:
00035   DataBlock(void);
00036   ~DataBlock(void);
00037 
00038 public:
00039   // Set the length of the block
00040   void SetLength(u64 length);
00041 
00042   // Set the location of the block
00043   void SetLocation(DiskFile *diskfile, u64 offset);
00044   void ClearLocation(void);
00045 
00046 public:
00047   // Check to see if the location of the block has been set
00048   bool IsSet(void) const;
00049 
00050   // Which disk file is this data block in
00051   DiskFile* GetDiskFile(void) const;
00052 
00053   // What offset is the block located at
00054   u64 GetOffset(void) const;
00055 
00056   // What is the length of this block
00057   u64 GetLength(void) const;
00058 
00059 public:
00060   // Open the disk file if it is not already open (so that it can be read)
00061   bool Open(void);
00062 
00063   // Read some of the data from disk into memory.
00064   bool ReadData(u64 position, size_t size, void *buffer);
00065 
00066   // Write some of the data from memory to disk
00067   bool WriteData(u64 position, size_t size, const void *buffer, size_t &wrote);
00068 
00069 protected:
00070   DiskFile *diskfile;  // Which disk file is the block associated with
00071   u64       offset;    // What is the file offset
00072   u64       length;    // How large is the block
00073 };
00074 
00075 
00076 // Construct the data block
00077 inline DataBlock::DataBlock(void)
00078 {
00079   diskfile = 0;
00080   offset = 0;
00081   length = 0;
00082 }
00083 
00084 // Destroy the data block
00085 inline DataBlock::~DataBlock(void)
00086 {
00087 }
00088 
00089 // Set the length of the block
00090 inline void DataBlock::SetLength(u64 _length)
00091 {
00092   length = _length;
00093 }
00094 
00095 // Set the location of the block
00096 inline void DataBlock::SetLocation(DiskFile *_diskfile, u64 _offset)
00097 {
00098   diskfile = _diskfile;
00099   offset = _offset;
00100 }
00101 
00102 // Clear the location of the block
00103 inline void DataBlock::ClearLocation(void)
00104 {
00105   diskfile = 0;
00106   offset = 0;
00107 }
00108 
00109 // Check to see of the location is known
00110 inline bool DataBlock::IsSet(void) const
00111 {
00112   return (diskfile != 0);
00113 }
00114 
00115 // Which disk file is this data block in
00116 inline DiskFile* DataBlock::GetDiskFile(void) const
00117 {
00118   return diskfile;
00119 }
00120 
00121 // What offset is the block located at
00122 inline u64 DataBlock::GetOffset(void) const
00123 {
00124   return offset;
00125 }
00126 
00127 // What is the length of this block
00128 inline u64 DataBlock::GetLength(void) const
00129 {
00130   return length;
00131 }
00132 
00133 #endif // __DATABLOCK_H__

Generated on Sun Oct 12 01:45:29 2008 for NNTPGrab by  1.5.4