summaryrefslogtreecommitdiffstats
path: root/block.h
blob: d424d35c401fc09e0e0c219d8270c8e9ab12838a (plain)
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
/*  Lziprecover - Data recovery tool for the lzip format
    Copyright (C) 2009-2018 Antonio Diaz Diaz.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef INT64_MAX
#define INT64_MAX  0x7FFFFFFFFFFFFFFFLL
#endif


class Block
  {
  long long pos_, size_;		// pos + size <= INT64_MAX

public:
  Block( const long long p, const long long s ) : pos_( p ), size_( s ) {}

  long long pos() const { return pos_; }
  long long size() const { return size_; }
  long long end() const { return pos_ + size_; }

  void pos( const long long p ) { pos_ = p; }
  void size( const long long s ) { size_ = s; }

  bool operator==( const Block & b ) const
    { return pos_ == b.pos_ && size_ == b.size_; }
  bool operator!=( const Block & b ) const
    { return pos_ != b.pos_ || size_ != b.size_; }

  bool operator<( const Block & b ) const { return pos_ < b.pos_; }

  bool includes( const long long pos ) const
    { return ( pos_ <= pos && end() > pos ); }
  bool overlaps( const Block & b ) const
    { return ( pos_ < b.end() && b.pos_ < end() ); }

  void shift( Block & b ) { ++size_; ++b.pos_; --b.size_; }
  Block split( const long long pos );
  };


// defined in range_dec.cc
int range_decompress( const std::string & input_filename,
                      const std::string & default_output_filename,
                      Block range, const bool force, const bool ignore_errors,
                      const bool ignore_trailing, const bool loose_trailing,
                      const bool to_stdout );

// defined in repair.cc
int debug_delay( const std::string & input_filename, Block range );