| Disk ARchive 2.5.10 Full featured and portable backup and archiving tool

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

range.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program 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 this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21
25
26
27 #ifndef RANGE_HPP
28 #define RANGE_HPP
29
30 #include <string>
31 #include <set>
32 #include <list>
33
34 #include "../my_config.h"
35 #include "infinint.hpp"
36 #include "deci.hpp"
37
38 namespace libdar
39 {
40
41 class range
42 {
43 public:
44 range() { parts.clear(); };
45 range(const infinint & low, const infinint & high) { parts.push_back(segment(low, high)); };
46
47 void operator += (const range & ref);
48 range operator + (const range & ref) const { range ret = *this; ret += ref; return ret; };
49 std::string display() const;
50
57 void reset_read() const;
58
65 bool read_next_segment(infinint & low, infinint & high) const;
66
67 private:
68 class segment
69 {
70 public:
71 segment(const infinint & x_low, const infinint & x_high) { low = x_low; high = x_high; };
72
73 const infinint & get_low() const { return low; };
74 const infinint & get_high() const { return high; };
75
76 bool overlaps_with(const segment & ref) const { return !(ref < *this) && !(ref > *this); };
77 void merge_with(const segment & ref); // only possible with a segment that overlaps with the current object
78
79 // if two segment make < or > true they cannot be replaced by a single segment
80 bool operator < (const segment & ref) const { return high + 1 < ref.low; };
81 bool operator > (const segment & ref) const { return ref < *this; };
82 bool operator == (const segment & ref) const { return ref.high == high && ref.low == low; };
83 bool operator != (const segment & ref) const { return ! (*this == ref); };
84
85 // if two segment make <= or >= true they can be replaced by a single (larger) segment
86 bool operator <= (const segment & ref) const { return ref.low < low && low <= ref.high + 1 && ref.high < high; };
87 bool operator >= (const segment &ref) const { return ref <= *this; };
88 bool contains(const segment & ref) const { return low <= ref.low && ref.high <= high; };
89
90 std::string display() const;
91
92 private:
93 infinint low, high;
94 };
95
96 std::list<segment> parts;
97 std::list<segment>::const_iterator read_cursor;
98
99 };
100
101
102 } // end of namespace
103
104 #endif
libdar::operator+=
std::vector< T > operator+=(std::vector< T > &a, const std::vector< T > &b)
template function to add two vectors
Definition: tools.hpp:332
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
deci.hpp
manages the decimal representation of infinint
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47