~ubuntu-branches/debian/experimental/nzbget/experimental

« back to all changes in this revision

Viewing changes to lib/par2/datablock.h

  • Committer: Package Import Robot
  • Author(s): Andreas Moog
  • Date: 2014-12-25 12:58:06 UTC
  • mfrom: (1.2.1) (3.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20141225125806-vnzgajhm7mju9933
Tags: 14.1+dfsg-1
* New Upstream release (Closes: #768863)
* debian/patches:
  - Remove 0010_unnecessary_gcryptdep.patch, included upstream
  - Refresh remaining patches
* debian/control:
  - Remove no longer needed build-depends on libpar2-dev and libsigc++-dev
* debian/nzbget.conf
  - Update sample configuration file to include new options introduced by
    new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  This file is part of par2cmdline (a PAR 2.0 compatible file verification and
 
2
//  repair tool). See http://parchive.sourceforge.net for details of PAR 2.0.
 
3
//
 
4
//  Copyright (c) 2003 Peter Brian Clements
 
5
//
 
6
//  par2cmdline is free software; you can redistribute it and/or modify
 
7
//  it under the terms of the GNU General Public License as published by
 
8
//  the Free Software Foundation; either version 2 of the License, or
 
9
//  (at your option) any later version.
 
10
//
 
11
//  par2cmdline is distributed in the hope that it will be useful,
 
12
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
//  GNU General Public License for more details.
 
15
//
 
16
//  You should have received a copy of the GNU General Public License
 
17
//  along with this program; if not, write to the Free Software
 
18
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
19
 
 
20
#ifndef __DATABLOCK_H__
 
21
#define __DATABLOCK_H__
 
22
 
 
23
class DiskFile;
 
24
 
 
25
// A Data Block is a block of data of a specific length at a specific
 
26
// offset in a specific file.
 
27
 
 
28
// It may be either a block of data in a source file from which recovery
 
29
// data is being computed, a block of recovery data in a recovery file, or
 
30
// a block in a target file that is being reconstructed.
 
31
 
 
32
class DataBlock
 
33
{
 
34
public:
 
35
  DataBlock(void);
 
36
  ~DataBlock(void);
 
37
 
 
38
public:
 
39
  // Set the length of the block
 
40
  void SetLength(u64 length);
 
41
 
 
42
  // Set the location of the block
 
43
  void SetLocation(DiskFile *diskfile, u64 offset);
 
44
  void ClearLocation(void);
 
45
 
 
46
public:
 
47
  // Check to see if the location of the block has been set
 
48
  bool IsSet(void) const;
 
49
 
 
50
  // Which disk file is this data block in
 
51
  DiskFile* GetDiskFile(void) const;
 
52
 
 
53
  // What offset is the block located at
 
54
  u64 GetOffset(void) const;
 
55
 
 
56
  // What is the length of this block
 
57
  u64 GetLength(void) const;
 
58
 
 
59
public:
 
60
  // Open the disk file if it is not already open (so that it can be read)
 
61
  bool Open(void);
 
62
 
 
63
  // Read some of the data from disk into memory.
 
64
  bool ReadData(u64 position, size_t size, void *buffer);
 
65
 
 
66
  // Write some of the data from memory to disk
 
67
  bool WriteData(u64 position, size_t size, const void *buffer, size_t &wrote);
 
68
 
 
69
protected:
 
70
  DiskFile *diskfile;  // Which disk file is the block associated with
 
71
  u64       offset;    // What is the file offset
 
72
  u64       length;    // How large is the block
 
73
};
 
74
 
 
75
 
 
76
// Construct the data block
 
77
inline DataBlock::DataBlock(void)
 
78
{
 
79
  diskfile = 0;
 
80
  offset = 0;
 
81
  length = 0;
 
82
}
 
83
 
 
84
// Destroy the data block
 
85
inline DataBlock::~DataBlock(void)
 
86
{
 
87
}
 
88
 
 
89
// Set the length of the block
 
90
inline void DataBlock::SetLength(u64 _length)
 
91
{
 
92
  length = _length;
 
93
}
 
94
 
 
95
// Set the location of the block
 
96
inline void DataBlock::SetLocation(DiskFile *_diskfile, u64 _offset)
 
97
{
 
98
  diskfile = _diskfile;
 
99
  offset = _offset;
 
100
}
 
101
 
 
102
// Clear the location of the block
 
103
inline void DataBlock::ClearLocation(void)
 
104
{
 
105
  diskfile = 0;
 
106
  offset = 0;
 
107
}
 
108
 
 
109
// Check to see of the location is known
 
110
inline bool DataBlock::IsSet(void) const
 
111
{
 
112
  return (diskfile != 0);
 
113
}
 
114
 
 
115
// Which disk file is this data block in
 
116
inline DiskFile* DataBlock::GetDiskFile(void) const
 
117
{
 
118
  return diskfile;
 
119
}
 
120
 
 
121
// What offset is the block located at
 
122
inline u64 DataBlock::GetOffset(void) const
 
123
{
 
124
  return offset;
 
125
}
 
126
 
 
127
// What is the length of this block
 
128
inline u64 DataBlock::GetLength(void) const
 
129
{
 
130
  return length;
 
131
}
 
132
 
 
133
#endif // __DATABLOCK_H__