/usr/include/dar/range.hpp is in libdar-dev 2.5.14+bis-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | /*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2052 Denis Corbin
//
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// to contact the author : http://dar.linux.free.fr/email.html
/*********************************************************************/
/// \file range.hpp
/// \brief class than provide a way to manipulate and represent range of integer numbers (infinint)
/// \ingroup Private
#ifndef RANGE_HPP
#define RANGE_HPP
#include <string>
#include <set>
#include <list>
#include "/usr/include/dar/libdar_my_config.h"
#include "/usr/include/dar/infinint.hpp"
#include "/usr/include/dar/deci.hpp"
namespace libdar
{
class range
{
public:
range() { parts.clear(); };
range(const infinint & low, const infinint & high) { parts.push_back(segment(low, high)); };
void operator += (const range & ref);
range operator + (const range & ref) const { range ret = *this; ret += ref; return ret; };
std::string display() const;
/// provides a way to read range contents segment by segment
///
/// \note reset_read() is to be called once then read_next_segment()
/// will return true for each new segment giving in argument its low and high value
/// when no more segment are available it returns false, reset_read() can be call at
/// any time to reset the reading operation
void reset_read() const;
/// read the next available segment
///
/// \param[out] low when read_next_segment() returns true, contains the low value of the next segment
/// \param[out] high when read_next_segment() returns true, contains the high value of the next segment
/// \return true and set the low and high value when a next segment is available in the range, returns
/// false if all segment have been read low and high are not modified in that case.
bool read_next_segment(infinint & low, infinint & high) const;
private:
class segment
{
public:
segment(const infinint & x_low, const infinint & x_high) { low = x_low; high = x_high; };
const infinint & get_low() const { return low; };
const infinint & get_high() const { return high; };
bool overlaps_with(const segment & ref) const { return !(ref < *this) && !(ref > *this); };
void merge_with(const segment & ref); // only possible with a segment that overlaps with the current object
// if two segment make < or > true they cannot be replaced by a single segment
bool operator < (const segment & ref) const { return high + 1 < ref.low; };
bool operator > (const segment & ref) const { return ref < *this; };
bool operator == (const segment & ref) const { return ref.high == high && ref.low == low; };
bool operator != (const segment & ref) const { return ! (*this == ref); };
// if two segment make <= or >= true they can be replaced by a single (larger) segment
bool operator <= (const segment & ref) const { return ref.low < low && low <= ref.high + 1 && ref.high < high; };
bool operator >= (const segment &ref) const { return ref <= *this; };
bool contains(const segment & ref) const { return low <= ref.low && ref.high <= high; };
std::string display() const;
private:
infinint low, high;
};
std::list<segment> parts;
std::list<segment>::const_iterator read_cursor;
};
} // end of namespace
#endif
|