![]() |
Disk ARchive
2.5.2
Full featured and portable backup and archiving tool
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 00025 00026 00027 #ifndef RANGE_HPP 00028 #define RANGE_HPP 00029 00030 #include <string> 00031 #include <set> 00032 #include <list> 00033 00034 #include "../my_config.h" 00035 #include "infinint.hpp" 00036 #include "deci.hpp" 00037 00038 namespace libdar 00039 { 00040 00041 class range 00042 { 00043 public: 00044 range() { parts.clear(); }; 00045 range(const infinint & low, const infinint & high) { parts.push_back(segment(low, high)); }; 00046 00047 void operator += (const range & ref); 00048 range operator + (const range & ref) const { range ret = *this; ret += ref; return ret; }; 00049 std::string display() const; 00050 00057 void reset_read() const; 00058 00065 bool read_next_segment(infinint & low, infinint & high) const; 00066 00067 private: 00068 class segment 00069 { 00070 public: 00071 segment(const infinint & x_low, const infinint & x_high) { low = x_low; high = x_high; }; 00072 00073 const infinint & get_low() const { return low; }; 00074 const infinint & get_high() const { return high; }; 00075 00076 bool overlaps_with(const segment & ref) const { return !(ref < *this) && !(ref > *this); }; 00077 void merge_with(const segment & ref); // only possible with a segment that overlaps with the current object 00078 00079 // if two segment make < or > true they cannot be replaced by a single segment 00080 bool operator < (const segment & ref) const { return high + 1 < ref.low; }; 00081 bool operator > (const segment & ref) const { return ref < *this; }; 00082 bool operator == (const segment & ref) const { return ref.high == high && ref.low == low; }; 00083 bool operator != (const segment & ref) const { return ! (*this == ref); }; 00084 00085 // if two segment make <= or >= true they can be replaced by a single (larger) segment 00086 bool operator <= (const segment & ref) const { return ref.low < low && low <= ref.high + 1 && ref.high < high; }; 00087 bool operator >= (const segment &ref) const { return ref <= *this; }; 00088 bool contains(const segment & ref) const { return low <= ref.low && ref.high <= high; }; 00089 00090 std::string display() const; 00091 00092 private: 00093 infinint low, high; 00094 }; 00095 00096 std::list<segment> parts; 00097 std::list<segment>::const_iterator read_cursor; 00098 00099 }; 00100 00101 00102 } // end of namespace 00103 00104 #endif